From 10bdc704556158e0bf5539e41600c2d18d7841b5 Mon Sep 17 00:00:00 2001 From: gggeek Date: Tue, 11 Mar 2014 12:04:37 +0000 Subject: [PATCH] Do not use autoloadhelper as we need inis anyway; Fix integer and float datatype checkers; Tag release 0.2 --- bin/php/checkattributes.php | 23 ++++--- bin/php/checkschema.php | 23 ++++--- .../datatypecheckers/ezdbiezfloatchecker.php | 19 +++-- .../ezdbiezintegerchecker.php | 19 +++-- classes/ezdbiautoloadhelper.php | 69 +++++++++++++++++++ classes/ezdbischemachecker.php | 1 + classes/schemafileformat/ezdbiiniformat.php | 1 + interfaces/ezdbischemafileformatinterface.php | 4 ++ 8 files changed, 133 insertions(+), 26 deletions(-) create mode 100644 classes/ezdbiautoloadhelper.php diff --git a/bin/php/checkattributes.php b/bin/php/checkattributes.php index 0f7aaf5..321798b 100644 --- a/bin/php/checkattributes.php +++ b/bin/php/checkattributes.php @@ -11,8 +11,8 @@ // Inject our own autoloader after the std one, as this script is supposed to be // executable even when extension has not been activated -require_once ( dirname( __FILE__ ) . '/../../classes/ezdbiautoloadhelper.php' ); -spl_autoload_register( array( 'ezdbiAutoloadHelper', 'autoload' ) ); +//require_once ( dirname( __FILE__ ) . '/../../classes/ezdbiautoloadhelper.php' ); +//spl_autoload_register( array( 'ezdbiAutoloadHelper', 'autoload' ) ); // Inject our own autoloader after the std one, as this script is supposed to be // executable even when extension has not been activated @@ -20,7 +20,8 @@ $cli = eZCLI::instance(); -$script = eZScript::instance( array( 'description' => ( "Generate Datatype Integrity Report" ), +$script = eZScript::instance( array( + 'description' => "Generate Datatype Integrity Report", 'use-session' => false, 'use-modules' => true, 'use-extensions' => true ) ); @@ -34,7 +35,6 @@ 'displaychecks' => 'Display the list of checks instead of executing them' ) ); - $script->initialize(); if ( count( $options['arguments'] ) < 1 && ! $options['displaychecks'] ) @@ -52,7 +52,10 @@ $argType = 'datatype'; } -$cli->output( "Checking $argType '$type'..." ); +if ( !$options['displaychecks'] ) +{ + $cli->output( "Checking $argType '$type'..." ); +} try { @@ -62,7 +65,7 @@ if ( $options['displaychecks'] ) { $checker->loadDatatypeChecks(); - $violations = null; + $violations = array(); } else { @@ -99,9 +102,11 @@ $script->shutdown( -1 ); } -$cli->output( 'Done!' ); -$cli->output(); - +if ( !$options['displaychecks'] ) +{ + $cli->output( 'Done!' ); + $cli->output(); +} $cli->output( ezdbiReportGenerator::getText( $violations, $checker->getChecks(), $options['displaychecks'] ) ); $script->shutdown(); diff --git a/bin/php/checkschema.php b/bin/php/checkschema.php index 51109e1..b16ffb9 100644 --- a/bin/php/checkschema.php +++ b/bin/php/checkschema.php @@ -11,12 +11,13 @@ // Inject our own autoloader after the std one, as this script is supposed to be // executable even when extension has not been activated -require_once ( dirname( __FILE__ ) . '/../../classes/ezdbiautoloadhelper.php' ); -spl_autoload_register( array( 'ezdbiAutoloadHelper', 'autoload' ) ); +//require_once ( dirname( __FILE__ ) . '/../../classes/ezdbiautoloadhelper.php' ); +//spl_autoload_register( array( 'ezdbiAutoloadHelper', 'autoload' ) ); $cli = eZCLI::instance(); -$script = eZScript::instance( array( 'description' => ( "Generate DB Integrity Report" ), +$script = eZScript::instance( array( + 'description' => "Generate DB Integrity Report", 'use-session' => false, 'use-modules' => true, 'use-extensions' => true ) ); @@ -32,10 +33,12 @@ 'displaychecks' => 'Display the list of checks instead of executing them' ) ); - $script->initialize(); -$cli->output( 'Checking schema...' ); +if ( !$options['displaychecks'] ) +{ + $cli->output( 'Checking schema...' ); +} if ( $options['schemafile'] == '' ) { @@ -51,7 +54,7 @@ $checker->loadChecksFile( $options['schemafile'], $options['schemaformat'] ); if ( $options['displaychecks'] ) { - $violations = null; + $violations = array(); } else { @@ -59,9 +62,11 @@ } -$cli->output( 'Done!' ); -$cli->output(); - +if ( !$options['displaychecks'] ) +{ + $cli->output( 'Done!' ); + $cli->output(); +} $cli->output( ezdbiReportGenerator::getText( $violations, $checker->getChecks(), $options['displaychecks'] ) ); $script->shutdown(); diff --git a/classes/datatypecheckers/ezdbiezfloatchecker.php b/classes/datatypecheckers/ezdbiezfloatchecker.php index 3c4d773..f09e707 100644 --- a/classes/datatypecheckers/ezdbiezfloatchecker.php +++ b/classes/datatypecheckers/ezdbiezfloatchecker.php @@ -16,8 +16,19 @@ public function __construct( eZContentClassAttribute $contentClassAttribute ) { parent::__construct( $contentClassAttribute ); - $this->min = $contentClassAttribute->attribute( eZFloatType::MIN_FIELD ); - $this->max = $contentClassAttribute->attribute( eZFloatType::MAX_FIELD ); + // talk about a braindead datatype... + switch( $contentClassAttribute->attribute( eZFloatType::INPUT_STATE_FIELD ) ) + { + case eZFloatType::HAS_MIN_VALUE: + $this->min = $contentClassAttribute->attribute( eZFloatType::MAX_FIELD ); + break; + case eZFloatType::HAS_MAX_VALUE: + $this->max = $contentClassAttribute->attribute( eZFloatType::MAX_FIELD ); + break; + case eZFloatType::HAS_MIN_MAX_VALUE: + $this->min = $contentClassAttribute->attribute( eZFloatType::MIN_FIELD ); + $this->max = $contentClassAttribute->attribute( eZFloatType::MAX_FIELD ); + } } /** @@ -32,11 +43,11 @@ public function checkObjectAttribute( array $contentObjectAttribute ) // do not check attributes which do not even contain images if ( $contentObjectAttribute->attribute( 'has_content' ) ) { - if ( (string)$this->min !== '' && $value < $this->min ) + if ( $this->min !== null && $value < $this->min ) { return array( "Float smaller than {$this->min}: $value" . $this->postfixErrorMsg( $contentObjectAttribute ) ); } - if ( (string)$this->max !== '' && $value > $this->max ) + if ( $this->max !== null && $value > $this->max ) { return array( "Float bigger than {$this->max}: $value" . $this->postfixErrorMsg( $contentObjectAttribute ) ); } diff --git a/classes/datatypecheckers/ezdbiezintegerchecker.php b/classes/datatypecheckers/ezdbiezintegerchecker.php index f37cbea..bf31aa2 100644 --- a/classes/datatypecheckers/ezdbiezintegerchecker.php +++ b/classes/datatypecheckers/ezdbiezintegerchecker.php @@ -16,8 +16,19 @@ public function __construct( eZContentClassAttribute $contentClassAttribute ) { parent::__construct( $contentClassAttribute ); - $this->min = $contentClassAttribute->attribute( eZIntegerType::MIN_VALUE_FIELD ); - $this->max = $contentClassAttribute->attribute( eZIntegerType::MAX_VALUE_FIELD ); + // talk about a braindead datatype... + switch( $contentClassAttribute->attribute( eZIntegerType::INPUT_STATE_FIELD ) ) + { + case eZIntegerType::HAS_MIN_VALUE: + $this->min = $contentClassAttribute->attribute( eZIntegerType::MAX_VALUE_FIELD ); + break; + case eZIntegerType::HAS_MAX_VALUE: + $this->max = $contentClassAttribute->attribute( eZIntegerType::MAX_VALUE_FIELD ); + break; + case eZIntegerType::HAS_MIN_MAX_VALUE: + $this->min = $contentClassAttribute->attribute( eZIntegerType::MIN_VALUE_FIELD ); + $this->max = $contentClassAttribute->attribute( eZIntegerType::MAX_VALUE_FIELD ); + } } /** @@ -32,11 +43,11 @@ public function checkObjectAttribute( array $contentObjectAttribute ) // do not check attributes which do not even contain images if ( $contentObjectAttribute->attribute( 'has_content' ) ) { - if ( (string)$this->min !== '' && $value < $this->min ) + if ( $this->min !== null && $value < $this->min ) { return array( "Integer smaller than {$this->min}: $value" . $this->postfixErrorMsg( $contentObjectAttribute ) ); } - if ( (string)$this->max !== '' && $value > $this->max ) + if ( $this->max !== null && $value > $this->max ) { return array( "Integer bigger than {$this->max}: $value" . $this->postfixErrorMsg( $contentObjectAttribute ) ); } diff --git a/classes/ezdbiautoloadhelper.php b/classes/ezdbiautoloadhelper.php new file mode 100644 index 0000000..9c08a17 --- /dev/null +++ b/classes/ezdbiautoloadhelper.php @@ -0,0 +1,69 @@ +basePath = 'extension/ezdbintegrity'; + + $autoloadOptions->searchKernelFiles = false; + $autoloadOptions->searchKernelOverride = false; + $autoloadOptions->searchExtensionFiles = true; + $autoloadOptions->searchTestFiles = false; + $autoloadOptions->writeFiles = false; + $autoloadOptions->displayProgress = false; + + $autoloadGenerator = new eZAutoloadGenerator( $autoloadOptions ); + // We have to jump through hoops to get eZAutoloadGenerator give us back an array + $autoloadGenerator->setOutputCallback( array( 'ezdbiAutoloadHelper', 'autoloadCallback' ) ); + + try + { + $autoloadGenerator->buildAutoloadArrays(); + $autoloadGenerator->printAutoloadArray(); + } + catch ( Exception $e ) + { + echo $e->getMessage() . "\n"; + } + } + + /** + * Used as callback for eZAutoloadGenerator + */ + public static function autoloadCallback( $php, $label ) + { + // callback is called many times with info messages, only use the good one + if ( strpos( $php, '', ), '', $php ); + self::$ezpClasses = eval( $php ); + // fix path to be proper relative to eZ root + foreach ( self::$ezpClasses as $key => $val ) + { + self::$ezpClasses[$key] = 'extension/ezdbintegrity/' . $val; + } + } + +} \ No newline at end of file diff --git a/classes/ezdbischemachecker.php b/classes/ezdbischemachecker.php index ede3acb..e354257 100644 --- a/classes/ezdbischemachecker.php +++ b/classes/ezdbischemachecker.php @@ -11,6 +11,7 @@ class ezdbiSchemaChecker extends ezdbiBaseChecker protected $db; /// @var eZDBSchemaInterface $schema protected $schema; + protected $checks; public function __construct( $dsn='' ) diff --git a/classes/schemafileformat/ezdbiiniformat.php b/classes/schemafileformat/ezdbiiniformat.php index 10432d3..333ff6f 100644 --- a/classes/schemafileformat/ezdbiiniformat.php +++ b/classes/schemafileformat/ezdbiiniformat.php @@ -16,6 +16,7 @@ class ezdbiIniFormat implements ezdbiSchemaFileFormatInterface public function parseFile( $filename ) { $ini = eZINI::instance( $filename ); + $checks = new ezdbiSchemaChecks(); foreach( $ini->group( 'ForeignKeys' ) as $table => $value ) { diff --git a/interfaces/ezdbischemafileformatinterface.php b/interfaces/ezdbischemafileformatinterface.php index a5cba8c..876d801 100644 --- a/interfaces/ezdbischemafileformatinterface.php +++ b/interfaces/ezdbischemafileformatinterface.php @@ -7,6 +7,10 @@ interface ezdbiSchemaFileFormatInterface { + /** + * @param string $filename + * @return ezdbiSchemaChecks + */ public function parseFile( $filename ); public function writeFile( $filename, ezdbiSchemaChecks $schemaChecks );