From 1d25be875d3fb7fbf24fdd755a9b0f068692e42d Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Thu, 3 Apr 2008 20:52:08 +0000 Subject: [PATCH] [3.1.0] Maintenance scripts emit and honor proper exit codes git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1640 48356398-32a2-884e-a903-53898d9a118a --- extras/FSTools.php | 2 +- library/HTMLPurifier/ConfigSchema/Interchange/Directive.php | 3 ++- maintenance/common.php | 4 ++-- maintenance/flush-definition-cache.php | 3 +-- maintenance/flush.php | 3 ++- maintenance/generate-includes.php | 1 + maintenance/generate-schema-cache.php | 1 + 7 files changed, 10 insertions(+), 7 deletions(-) diff --git a/extras/FSTools.php b/extras/FSTools.php index 7b5e7619..a37273a5 100644 --- a/extras/FSTools.php +++ b/extras/FSTools.php @@ -68,7 +68,7 @@ class FSTools } // Loop through the folder $dir = $this->dir($source); - while (false !== $entry = $dir->read()) { + while ( false !== ($entry = $dir->read()) ) { // Skip pointers if ($entry == '.' || $entry == '..') { continue; diff --git a/library/HTMLPurifier/ConfigSchema/Interchange/Directive.php b/library/HTMLPurifier/ConfigSchema/Interchange/Directive.php index 688939a0..302d7921 100644 --- a/library/HTMLPurifier/ConfigSchema/Interchange/Directive.php +++ b/library/HTMLPurifier/ConfigSchema/Interchange/Directive.php @@ -38,7 +38,8 @@ class HTMLPurifier_ConfigSchema_Interchange_Directive public $allowed; /** - * List of aliases for the directive, e.g. array('Alt.Directive'). + * List of aliases for the directive, + * e.g. array(new HTMLPurifier_ConfigSchema_Interchange_Id('Ns', 'Dir'))). */ public $aliases = array(); diff --git a/maintenance/common.php b/maintenance/common.php index 52e00453..eb57300e 100644 --- a/maintenance/common.php +++ b/maintenance/common.php @@ -2,9 +2,9 @@ function assertCli() { if (php_sapi_name() != 'cli' && !getenv('PHP_IS_CLI')) { - echo 'Script cannot be called from web-browser (if you are calling via cli, + echo 'Script cannot be called from web-browser (if you are indeed calling via cli, set environment variable PHP_IS_CLI to work around this).'; - exit; + exit(1); } } diff --git a/maintenance/flush-definition-cache.php b/maintenance/flush-definition-cache.php index 22037620..d0ebaba5 100755 --- a/maintenance/flush-definition-cache.php +++ b/maintenance/flush-definition-cache.php @@ -22,8 +22,7 @@ if (isset($argv[1])) { if (in_array($argv[1], $names)) { $names = array($argv[1]); } else { - echo "Did not recognized cache parameter {$argv[1]} as valid cache, aborting.\n"; - exit; + throw new Exception("Cache parameter {$argv[1]} is not a valid cache"); } } diff --git a/maintenance/flush.php b/maintenance/flush.php index 0d92f13f..325edf45 100644 --- a/maintenance/flush.php +++ b/maintenance/flush.php @@ -13,8 +13,9 @@ assertCli(); function e($cmd) { echo "\$ $cmd\n"; - passthru($cmd); + passthru($cmd, $status); echo "\n"; + if ($status) exit($status); } e('php generate-includes.php'); diff --git a/maintenance/generate-includes.php b/maintenance/generate-includes.php index 129fb5e4..d8295bd0 100644 --- a/maintenance/generate-includes.php +++ b/maintenance/generate-includes.php @@ -27,6 +27,7 @@ $exclude_files = array( // Determine what files need to be included: echo 'Scanning for files... '; $raw_files = $FS->globr('.', '*.php'); +if (!$raw_files) throw new Exception('Did not find any PHP source files'); $files = array(); foreach ($raw_files as $file) { $file = substr($file, 2); // rm leading './' diff --git a/maintenance/generate-schema-cache.php b/maintenance/generate-schema-cache.php index a61615c9..04c5f2bf 100644 --- a/maintenance/generate-schema-cache.php +++ b/maintenance/generate-schema-cache.php @@ -16,6 +16,7 @@ $target = '../library/HTMLPurifier/ConfigSchema/schema.ser'; $FS = new FSTools(); $files = $FS->globr('../library/HTMLPurifier/ConfigSchema/schema', '*.txt'); +if (!$files) throw new Exception('Did not find any schema files'); $parser = new HTMLPurifier_StringHashParser(); $builder = new HTMLPurifier_ConfigSchema_InterchangeBuilder();