Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/BaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion src/Command/UpgradeModxCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class UpgradeModxCommand extends BaseCommand

public $loadConfig = false;
public $loadModx = true;
public $isUpgrade = true;

protected function configure()
{
Expand Down Expand Up @@ -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>Warning:: could not clean up the setup config file, please remove this manually.</warning>");
}

// 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;
Expand Down
43 changes: 40 additions & 3 deletions src/Mixins/DownloadModx.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ protected function download($version)
* Unzips the package zip to the current directory
*
* @param $package
* @throws \Exception
*/
protected function unzip($package)
{
Expand Down Expand Up @@ -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);
Expand All @@ -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/* ./");
}
}

/**
Expand Down