Skip to content

Commit

Permalink
Do not use autoloadhelper as we need inis anyway; Fix integer and flo…
Browse files Browse the repository at this point in the history
…at datatype checkers; Tag release 0.2
  • Loading branch information
gggeek committed Mar 11, 2014
1 parent 065177e commit 10bdc70
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 26 deletions.
23 changes: 14 additions & 9 deletions bin/php/checkattributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@

// 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
////spl_autoload_register( array( 'autoloadHelper', 'autoload' ) );

$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 ) );
Expand All @@ -34,7 +35,6 @@
'displaychecks' => 'Display the list of checks instead of executing them'
)
);

$script->initialize();

if ( count( $options['arguments'] ) < 1 && ! $options['displaychecks'] )
Expand All @@ -52,7 +52,10 @@
$argType = 'datatype';
}

$cli->output( "Checking $argType '$type'..." );
if ( !$options['displaychecks'] )
{
$cli->output( "Checking $argType '$type'..." );
}

try
{
Expand All @@ -62,7 +65,7 @@
if ( $options['displaychecks'] )
{
$checker->loadDatatypeChecks();
$violations = null;
$violations = array();
}
else
{
Expand Down Expand Up @@ -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();
23 changes: 14 additions & 9 deletions bin/php/checkschema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
Expand All @@ -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'] == '' )
{
Expand All @@ -51,17 +54,19 @@
$checker->loadChecksFile( $options['schemafile'], $options['schemaformat'] );
if ( $options['displaychecks'] )
{
$violations = null;
$violations = array();
}
else
{
$violations = $checker->checkSchema( $options['displayrows'] );
}


$cli->output( 'Done!' );
$cli->output();

if ( !$options['displaychecks'] )
{
$cli->output( 'Done!' );
$cli->output();
}
$cli->output( ezdbiReportGenerator::getText( $violations, $checker->getChecks(), $options['displaychecks'] ) );

$script->shutdown();
19 changes: 15 additions & 4 deletions classes/datatypecheckers/ezdbiezfloatchecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}

/**
Expand All @@ -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 ) );
}
Expand Down
19 changes: 15 additions & 4 deletions classes/datatypecheckers/ezdbiezintegerchecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}

/**
Expand All @@ -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 ) );
}
Expand Down
69 changes: 69 additions & 0 deletions classes/ezdbiautoloadhelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

/**
* A custom autoloader, provided in case this extension is not properly activated in eZ4
*/
class ezdbiAutoloadHelper
{
protected static $ezpClasses = null;

public static function autoload( $className )
{
if ( !is_array( self::$ezpClasses ) )
{
self::initializeAutoload();
}
if ( isset( self::$ezpClasses[$className] ) )
{
require( self::$ezpClasses[$className] );
}
}

protected static function initializeAutoload()
{
$autoloadOptions = new ezpAutoloadGeneratorOptions();

$autoloadOptions->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' ) !== 0 )
{
return;
}
$php = str_replace( array( '<?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;
}
}

}
1 change: 1 addition & 0 deletions classes/ezdbischemachecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ezdbiSchemaChecker extends ezdbiBaseChecker
protected $db;
/// @var eZDBSchemaInterface $schema
protected $schema;

protected $checks;

public function __construct( $dsn='' )
Expand Down
1 change: 1 addition & 0 deletions classes/schemafileformat/ezdbiiniformat.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
4 changes: 4 additions & 0 deletions interfaces/ezdbischemafileformatinterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

interface ezdbiSchemaFileFormatInterface
{
/**
* @param string $filename
* @return ezdbiSchemaChecks
*/
public function parseFile( $filename );

public function writeFile( $filename, ezdbiSchemaChecks $schemaChecks );
Expand Down

0 comments on commit 10bdc70

Please sign in to comment.