Skip to content

Commit 4648e5b

Browse files
authored
Merge pull request #379 from modmore/advanced-upgrade
Upgrade advanced installation
2 parents 087659a + 07e7fd0 commit 4648e5b

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

src/BaseCommand.php

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ abstract class BaseCommand extends Command
2626

2727
public $loadConfig = true;
2828
public $loadMODX = true;
29+
public $isUpgrade = false;
2930

3031
/**
3132
* Initializes the command just after the input has been validated.

src/Command/UpgradeModxCommand.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class UpgradeModxCommand extends BaseCommand
1919

2020
public $loadConfig = false;
2121
public $loadModx = true;
22+
public $isUpgrade = true;
2223

2324
protected function configure()
2425
{
@@ -58,13 +59,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
5859

5960
// Actually run the CLI setup
6061
exec("php -d date.timezone={$tz} {$wd}setup/index.php --installmode=upgrade --config={$config}", $setupOutput);
61-
$output->writeln($setupOutput[0]);
6262

6363
// Try to clean up the config file
6464
if (!unlink($config)) {
6565
$output->writeln("<warning>Warning:: could not clean up the setup config file, please remove this manually.</warning>");
6666
}
6767

68+
// Remove setup directory if upgrade process left it there.
69+
if (is_dir("{$wd}setup/")) {
70+
exec("rm -rf {$wd}setup/");
71+
}
72+
6873
$output->writeln('Done! ' . $this->getRunStats());
6974

7075
return 0;

src/Mixins/DownloadModx.php

+39-2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ protected function download($version)
7373
* Unzips the package zip to the current directory
7474
*
7575
* @param $package
76+
* @throws \Exception
7677
*/
7778
protected function unzip($package)
7879
{
@@ -131,14 +132,50 @@ protected function retrieveFromCache($version)
131132
{
132133
$version = 'modx-' . str_replace('modx-', '', $version);
133134

134-
135135
$path = GITIFY_CACHE_DIR . $version;
136136

137137
if (!file_exists($path) || !is_dir($path)) {
138138
$this->download($version);
139139
}
140140

141-
exec("cp -r $path/* ./");
141+
// Handle potential custom paths on upgrade
142+
if ($this->isUpgrade) {
143+
require_once './config.core.php';
144+
if (MODX_CORE_PATH) {
145+
require_once MODX_CORE_PATH . 'config/config.inc.php';
146+
// Need to avoid the easier route with rsync as it may not be installed
147+
$paths = [
148+
'core' => MODX_CORE_PATH,
149+
'connectors' => MODX_CONNECTORS_PATH,
150+
'manager' => MODX_MANAGER_PATH
151+
];
152+
foreach ($paths as $k => $customPath) {
153+
// Throw out default config files
154+
if (file_exists("$path/$k/config.core.php")) {
155+
unlink("$path/$k/config.core.php");
156+
}
157+
// Copy each dir to path specified in config file then remove that dir from source
158+
exec("cp -r $path/$k/* $customPath");
159+
exec("rm -rf $path/$k");
160+
}
161+
162+
unlink("$path/config.core.php");
163+
164+
// Now copy remaining contents
165+
exec("cp -r $path/* ./");
166+
167+
// Hard wipe cache
168+
if (is_dir(MODX_CORE_PATH . 'cache/')) {
169+
exec('rm -rf ' . MODX_CORE_PATH . 'cache/*');
170+
}
171+
172+
// Re-extract package to source dir, so it's ready for another run.
173+
$this->unzip($path . '.zip');
174+
}
175+
}
176+
else {
177+
exec("cp -r $path/* ./");
178+
}
142179
}
143180

144181
/**

0 commit comments

Comments
 (0)