diff --git a/src/BaseCommand.php b/src/BaseCommand.php index d2312d0..74631c3 100644 --- a/src/BaseCommand.php +++ b/src/BaseCommand.php @@ -26,6 +26,7 @@ abstract class BaseCommand extends Command public $loadConfig = true; public $loadMODX = true; + public $isUpgrade = false; /** * Initializes the command just after the input has been validated. diff --git a/src/Command/UpgradeModxCommand.php b/src/Command/UpgradeModxCommand.php index 69c7eae..186ac33 100644 --- a/src/Command/UpgradeModxCommand.php +++ b/src/Command/UpgradeModxCommand.php @@ -19,6 +19,7 @@ class UpgradeModxCommand extends BaseCommand public $loadConfig = false; public $loadModx = true; + public $isUpgrade = true; protected function configure() { @@ -58,13 +59,17 @@ protected function execute(InputInterface $input, OutputInterface $output) // Actually run the CLI setup exec("php -d date.timezone={$tz} {$wd}setup/index.php --installmode=upgrade --config={$config}", $setupOutput); - $output->writeln($setupOutput[0]); // Try to clean up the config file if (!unlink($config)) { $output->writeln("Warning:: could not clean up the setup config file, please remove this manually."); } + // Remove setup directory if upgrade process left it there. + if (is_dir("{$wd}setup/")) { + exec("rm -rf {$wd}setup/"); + } + $output->writeln('Done! ' . $this->getRunStats()); return 0; diff --git a/src/Mixins/DownloadModx.php b/src/Mixins/DownloadModx.php index 05df46a..fce4c19 100644 --- a/src/Mixins/DownloadModx.php +++ b/src/Mixins/DownloadModx.php @@ -73,6 +73,7 @@ protected function download($version) * Unzips the package zip to the current directory * * @param $package + * @throws \Exception */ protected function unzip($package) { @@ -108,7 +109,7 @@ protected function fetchUrl($version) $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); - curl_setopt($ch, CURLOPT_TIMEOUT, 10); + curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_NOBODY, 1); curl_exec($ch); @@ -131,14 +132,50 @@ protected function retrieveFromCache($version) { $version = 'modx-' . str_replace('modx-', '', $version); - $path = GITIFY_CACHE_DIR . $version; if (!file_exists($path) || !is_dir($path)) { $this->download($version); } - exec("cp -r $path/* ./"); + // Handle potential custom paths on upgrade + if ($this->isUpgrade) { + require_once './config.core.php'; + if (MODX_CORE_PATH) { + require_once MODX_CORE_PATH . 'config/config.inc.php'; + // Need to avoid the easier route with rsync as it may not be installed + $paths = [ + 'core' => MODX_CORE_PATH, + 'connectors' => MODX_CONNECTORS_PATH, + 'manager' => MODX_MANAGER_PATH + ]; + foreach ($paths as $k => $customPath) { + // Throw out default config files + if (file_exists("$path/$k/config.core.php")) { + unlink("$path/$k/config.core.php"); + } + // Copy each dir to path specified in config file then remove that dir from source + exec("cp -r $path/$k/* $customPath"); + exec("rm -rf $path/$k"); + } + + unlink("$path/config.core.php"); + + // Now copy remaining contents + exec("cp -r $path/* ./"); + + // Hard wipe cache + if (is_dir(MODX_CORE_PATH . 'cache/')) { + exec('rm -rf ' . MODX_CORE_PATH . 'cache/*'); + } + + // Re-extract package to source dir, so it's ready for another run. + $this->unzip($path . '.zip'); + } + } + else { + exec("cp -r $path/* ./"); + } } /**