diff --git a/setup/cli/modules/deploy.php b/setup/cli/modules/deploy.php index 9ddde333f885193258f5d1b4eba1175d8ee1f0e8..3d959b393815fce5e95305b7d16c82c41f65c91c 100644 --- a/setup/cli/modules/deploy.php +++ b/setup/cli/modules/deploy.php @@ -87,6 +87,46 @@ class Deployment extends Unpacker { } } + function copyFile($src, $dest) { + static $short = false; + static $version = false; + + if (substr($src, -4) != '.php') + return parent::copyFile($src, $dest); + + if (!$short) { + $hash = exec('git rev-parse HEAD'); + $short = substr($hash, 0, 7); + } + + if (!$version) + $version = exec('git describe'); + + if (!$short || !$version) + return parent::copyFile($src, $dest); + + $source = file_get_contents($src); + $source = preg_replace(':<script(.*) src="(.*).js"></script>:', + '<script$1 src="$2.js?'.$short.'"></script>', + $source); + $source = preg_replace(':<link(.*) href="(.*).css"([^/>]*)/?>:', # <?php + '<link$1 href="$2.css?'.$short.'"$3/>', + $source); + // Set THIS_VERSION + $source = preg_replace("/^(\s*)define\s*\(\s*'THIS_VERSION'.*$/m", + "\1define('THIS_VERSION', '".$version."'); // Set by installer", + $source); + // Disable error display + $source = preg_replace("/^(\s*)ini_set\s*\(\s*'(display_errors|display_startup_errors)'.*$/m", + "$1ini_set('$2', '0'); // Set by installer", + $source); + + if (!file_put_contents($dest, $source)) + die("Unable to apply rewrite rules to ".$dest); + + return true; + } + function run($args, $options) { $this->destination = $args['install-path']; if (!is_dir($this->destination)) @@ -122,7 +162,6 @@ class Deployment extends Unpacker { if (!$options['dry-run']) { if ($include != "{$this->destination}/include/") $this->change_include_dir($include); - $this->touch_version(); } if ($options['clean']) { @@ -134,30 +173,6 @@ class Deployment extends Unpacker { "*/.htaccess")); } } - - function touch_version($version=false) { - if (!$version) - $version = exec('git describe'); - if (!$version) - return false; - - $bootstrap_php = $this->destination . '/bootstrap.php'; - $lines = explode("\n", file_get_contents($bootstrap_php)); - # Find the line that defines INCLUDE_DIR - $match = array(); - foreach ($lines as &$line) { - // TODO: Change THIS_VERSION inline to be current `git describe` - if (preg_match("/(\s*)define\s*\(\s*'THIS_VERSION'/", $line, $match)) { - # Replace the definition with the new locatin - $line = $match[1] . "define('THIS_VERSION', '" - . $version - . "'); // Set by installer"; - break; - } - } - if (!file_put_contents($bootstrap_php, implode("\n", $lines))) - die("Unable to write version information to bootstrap.php\n"); - } } Module::register('deploy', 'Deployment'); diff --git a/setup/cli/modules/unpack.php b/setup/cli/modules/unpack.php index f200538ff5dcc5c911f8410e769b5aecfd6d01ef..ecc6823d85bcd00b9314d477c61d1b434795617f 100644 --- a/setup/cli/modules/unpack.php +++ b/setup/cli/modules/unpack.php @@ -88,6 +88,10 @@ class Unpacker extends Module { return false; } + function copyFile($src, $dest) { + return copy($src, $dest); + } + /** * Copy from source to desination, perhaps recursing up to n folders. * Exclusions are also permitted. If any files match an MD5 sum, they @@ -120,7 +124,7 @@ class Unpacker extends Module { if ($verbose) $this->stdout->write($target."\n"); if (!$dryrun) - copy($file, $target); + $this->copyFile($file, $target); } } if ($recurse) { diff --git a/setup/cli/package.php b/setup/cli/package.php index 10fa537644dde35388e29a488aa19961dbdcf68e..6a1c68e6afd72508111ecff90ec410a0e62ff3a4 100755 --- a/setup/cli/package.php +++ b/setup/cli/package.php @@ -134,6 +134,8 @@ if(($mds = glob("$stage_path/*.md"))) { # Make an archive of the stage folder $version = exec('git describe'); +$hash = exec('git rev-parse HEAD'); +$short = substr($hash, 0, 7); $pwd = getcwd(); chdir($stage_path); @@ -143,6 +145,10 @@ chdir($stage_path); shell_exec("sed -ri -e \" s/( *)define\('THIS_VERSION'.*/\\1define('THIS_VERSION', '$version');/ \" upload/bootstrap.php"); +shell_exec("find upload -name '*.php' -print0 | xargs -0 sed -i -e ' + s:<script\(.*\) src=\"\(.*\).js\"></script>:<script\\1 src=\"\\2.js?$short\"></script>: + s:<link\(.*\) href=\"\(.*\).css\"\(.*\)*/*>:<link\\1 href=\"\\2.css?$short\"\\3>: + '"); shell_exec("find upload -name '*.php' -print0 | xargs -0 sed -i -e \" s/\( *\)ini_set( *'display_errors'[^])]*);/\\1ini_set('display_errors', 0);/ s/\( *\)ini_set( *'display_startup_errors'[^])]*);/\\1ini_set('display_startup_errors', 0);/