Skip to content

Commit

Permalink
Allow command lien scripts ro be interrupted and still output the rep…
Browse files Browse the repository at this point in the history
…ort; tag for 0.7.0 release
  • Loading branch information
gggeek committed Jul 26, 2016
1 parent dfa5494 commit a5e4e14
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 5 deletions.
42 changes: 42 additions & 0 deletions bin/php/checkattributes.php
Expand Up @@ -87,6 +87,19 @@
}
}

if ( function_exists( 'pcntl_signal' ) )
{
pcntl_signal(SIGTERM, 'onStopSignal');
pcntl_signal(SIGINT, 'onStopSignal');
saveState( array(
'cli' => $cli,
'script' => $script,
'checks' => $checks,
'violations' => &$violations,
'options' => $options
) );
}

foreach( array_keys( $types ) as $type )
{
$cli->output( "\nNow checking $type ..." );
Expand All @@ -95,6 +108,11 @@
{
$violations[$type] = $typeViolations;
}

if ( function_exists( 'pcntl_signal' ) )
{
pcntl_signal_dispatch();
}
}

$cli->output( 'Done!' );
Expand All @@ -110,3 +128,27 @@
$cli->error( $e->getMessage() );
$script->shutdown( -1 );
}

function onStopSignal( $sigNo )
{
global $scriptState;

$violations = $scriptState['violations'];
$cli = $scriptState['cli'];
$checks = $scriptState['checks'];
$options = $scriptState['options'];
$script = $scriptState['script'];

$cli->output( ezdbiReportGenerator::getText( $violations, $checks, $options['displaychecks'] ) );

$script->shutdown();
die();
}

// We can not just use $GLOBALS as sometimes the script is run within a class (in eZ5), sometimes not...
function saveState($stateArray)
{
global $scriptState;

$scriptState = $stateArray;
}
44 changes: 44 additions & 0 deletions bin/php/checkschema.php
Expand Up @@ -53,16 +53,31 @@

try
{

$violations = array();
$checker = new ezdbiSchemaChecker( $options['database'] );
$checker->loadChecksFile( $options['schemafile'], $options['schemaformat'] );
$checks = $checker->getChecks();

if ( function_exists( 'pcntl_signal' ) )
{
pcntl_signal(SIGTERM, 'onStopSignal');
pcntl_signal(SIGINT, 'onStopSignal');
saveState( array(
'cli' => $cli,
'script' => $script,
'checks' => $checks,
'violations' => &$violations,
'options' => $options
) );
}

if ( $options['displaychecks'] )
{
}
else
{
$i = 0;
foreach ( array_keys( $checks ) as $check )
{
$cli->output( "\nNow checking $check ..." );
Expand All @@ -71,6 +86,11 @@
{
$violations[$check] = $violation;
}

if ( function_exists( 'pcntl_signal' ) )
{
pcntl_signal_dispatch();
}
}

$cli->output( 'Done!' );
Expand All @@ -86,3 +106,27 @@
$cli->error( $e->getMessage() );
$script->shutdown( -1 );
}

function onStopSignal( $sigNo )
{
global $scriptState;

$violations = $scriptState['violations'];
$cli = $scriptState['cli'];
$checks = $scriptState['checks'];
$options = $scriptState['options'];
$script = $scriptState['script'];

$cli->output( ezdbiReportGenerator::getText( $violations, $checks, $options['displaychecks'] ) );

$script->shutdown();
die();
}

// We can not just use $GLOBALS as sometimes the script is run within a class (in eZ5), sometimes not...
function saveState($stateArray)
{
global $scriptState;

$scriptState = $stateArray;
}
42 changes: 42 additions & 0 deletions bin/php/checkstorage.php
Expand Up @@ -45,6 +45,19 @@
}
else
{
if ( function_exists( 'pcntl_signal' ) )
{
pcntl_signal(SIGTERM, 'onStopSignal');
pcntl_signal(SIGINT, 'onStopSignal');
saveState( array(
'cli' => $cli,
'script' => $script,
'checks' => $checks,
'violations' => &$violations,
'options' => $options
) );
}

foreach ( array_keys( $checks ) as $check )
{
$cli->output( "\nNow checking $check ..." );
Expand All @@ -53,6 +66,11 @@
{
$violations[$check] = $violation;
}

if ( function_exists( 'pcntl_signal' ) )
{
pcntl_signal_dispatch();
}
}
}

Expand All @@ -65,3 +83,27 @@
$cli->error( $e->getMessage() );
$script->shutdown( -1 );
}

function onStopSignal( $sigNo )
{
global $scriptState;

$violations = $scriptState['violations'];
$cli = $scriptState['cli'];
$checks = $scriptState['checks'];
$options = $scriptState['options'];
$script = $scriptState['script'];

$cli->output( ezdbiReportGenerator::getText( $violations, $checks, $options['displaychecks'] ) );

$script->shutdown();
die();
}

// We can not just use $GLOBALS as sometimes the script is run within a class (in eZ5), sometimes not...
function saveState($stateArray)
{
global $scriptState;

$scriptState = $stateArray;
}
2 changes: 1 addition & 1 deletion doc/changelogs/changelog-0.5.1-to-0.6
Expand Up @@ -4,5 +4,5 @@ changelog from version 0.5.1 to 0.6.0 - released 2016.7.4

. output of commands on the cli has changed

. checkstorage command has gained an option not only validate offending rows for foreign keys, not mismatched column definitions
. checkstorage command has gained an option to only validate offending rows for foreign keys, not mismatched column definitions
(useful because in the default eZPublish database schema there are still some violations)
5 changes: 5 additions & 0 deletions doc/changelogs/changelog-0.6.1-to-0.7.0
@@ -0,0 +1,5 @@
changelog from version 0.6.1 to 0.7.0 - released 2016.7.26

. allow cli scripts to be interrupted with ctrl-c and still display their output

. fix 2 queries for checking schema validity (would not run on all mysql versions)
2 changes: 0 additions & 2 deletions doc/todo
@@ -1,7 +1,5 @@
# general

. allow cli scripts to be interrupted with ctrl-c and still display their output

. allow cli scripts to connect to a different database

. start planning for the "bundle" version: load all field defs from services, use built-in validations etc...
Expand Down
2 changes: 1 addition & 1 deletion extension.xml
Expand Up @@ -2,7 +2,7 @@
<software>
<metadata>
<name>eZ DB Integrity extension</name>
<version>0.6.1</version>
<version>0.7.0</version>
<copyright>Copyright (C) 2014-216 Gaetano Giunta</copyright>
<license>GNU General Public License v2.0</license>
</metadata>
Expand Down
2 changes: 1 addition & 1 deletion ezinfo.php
Expand Up @@ -6,7 +6,7 @@ static function info()
{
return array(
'Name' => "<a href=\"http://projects.ez.no/ezdbintegrity\">eZ DB Integrity extension</a>",
'Version' => "0.6.1",
'Version' => "0.7.0",
'Copyright' => "Copyright (C) 2014-2016 Gaetano Giunta",
'License' => "GNU General Public License v2.0"
);
Expand Down

0 comments on commit a5e4e14

Please sign in to comment.