Created
August 8, 2017 11:07
-
-
Save albe/1e3313c1f3006c6d34d1c51083f8fd2b to your computer and use it in GitHub Desktop.
pimcore update cli
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
chdir(__DIR__); | |
include_once("startup.php"); | |
echo "\n"; | |
try { | |
$opts = new \Zend_Console_Getopt(array( | |
'to=s' => 'the revision to update to', | |
'skipdl|sd' => 'skip the download of files', | |
'verbose|v' => 'show detailed information during the update', | |
'list|l' => 'show a list of all available releases', | |
'help|h' => 'display this help' | |
)); | |
} catch (Exception $e) { | |
echo "There's a problem with your commandline interface."; | |
echo "\n"; | |
echo "For details, see the error below:"; | |
echo "\n"; | |
echo $e->getMessage(); | |
exit; | |
} | |
try { | |
$opts->parse(); | |
} catch (\Zend_Console_Getopt_Exception $e) { | |
echo "There's a problem with your configuration."; | |
echo "\n"; | |
echo "For details, see the error below:"; | |
echo "\n"; | |
echo $e->getMessage(); | |
exit; | |
} | |
if ($opts->getOption("list")) { | |
$available = \Pimcore\Update::getAvailableUpdates(); | |
echo "VERSION - REVISION - DATE\n"; | |
foreach ($available["releases"] as $release) { | |
echo $release["version"] . " - " . $release["text"] . "\n"; | |
} | |
exit; | |
} | |
// display help message | |
if ($opts->getOption("help") || !$opts->getOption("to")) { | |
echo $opts->getUsageMessage(); | |
exit; | |
} | |
// defaults | |
$config = array( | |
"verbose" => false | |
); | |
$tmpConfig = $config; | |
foreach ($config as $key => $value) { | |
if ($opts->getOption($key)) { | |
$tmpConfig[$key] = $opts->getOption($key); | |
} | |
} | |
$config = $tmpConfig; | |
\Zend_Registry::set("config", $config); | |
$toRevision = $opts->getOption("to"); | |
$jobs = \Pimcore\Update::getJobs($toRevision); | |
$downloadVersionFile = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/update/downloaded"; | |
if (!$opts->getOption("skipdl")) { | |
$lastAttemptedDownload = @file_get_contents($downloadVersionFile); | |
foreach ($jobs["parallel"] as $job) { | |
if ($job["type"] === 'download' && (!$lastAttemptedDownload || $job["revision"] >= $lastAttemptedDownload)) { | |
verboseMessage("download " . $job["revision"] . "..."); | |
@file_put_contents($downloadVersionFile, $job["revision"], LOCK_EX); | |
\Pimcore\Update::downloadData($job["revision"], $job["url"]); | |
} | |
} | |
} | |
foreach ($jobs["procedural"] as $job) { | |
switch ($job["type"]) { | |
case "preupdate": | |
case "postupdate": | |
verboseMessage($job["type"] . " script " . $job["revision"]); | |
\Pimcore\Update::executeScript($job["revision"], $job["type"]); | |
break; | |
case "files": | |
verboseMessage("files " . $job["revision"]); | |
\Pimcore\Update::installData($job["revision"]); | |
break; | |
case "languages": | |
verboseMessage("languages"); | |
\Pimcore\Update::downloadLanguages(); | |
break; | |
case "cleanup": | |
verboseMessage("cleanup"); | |
\Pimcore\Update::cleanup(); | |
break; | |
} | |
} | |
verboseMessage("------------------------------------------------"); | |
verboseMessage("update finished"); | |
@unlink($downloadVersionFile); | |
function verboseMessage($m) { | |
$config = \Zend_Registry::get("config"); | |
if ($config["verbose"]) { | |
echo $m . "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An CLI update script for old pimcore versions that did not yet have the console tool with update feature.
Usage:
copy to your
[pimcore folder]/pimcore/cli
To show a list of available release updates:
php pimcore/cli/update.php --list
To update to a specific revision:
php pimcore/cli/update.php --to [revision] [--v] [--skipdl]
The script itself tries to avoid redownloading all the stuff if it fails in between. I noticed that the "jobs" list sometimes contains an unsorted list of revisions, e.g. 3690 following the dl script for 3700. In that case (or anything other that is suitable), just use the --skipdl flag to fully skip the download process and just do the actual update.