/** * Constructor. * * @param string $name The name of the application * @param string $version The version of the application * * @api */ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN') { parent::__construct('Pimcore CLI', Version::getVersion()); // init default autoload namespaces $this->initDefaultAutoloadNamespaces(); // allow to register commands here (e.g. through plugins) \Pimcore::getEventManager()->trigger('system.console.init', $this); $dispatcher = new EventDispatcher(); $this->setDispatcher($dispatcher); $dispatcher->addListener(ConsoleEvents::COMMAND, function (ConsoleCommandEvent $event) { if ($event->getInput()->getOption("maintenance-mode")) { // enable maintenance mode if requested $maintenanceModeId = 'cache-warming-dummy-session-id'; $event->getOutput()->writeln('Activating maintenance mode with ID <comment>' . $maintenanceModeId . '</comment> ...'); Admin::activateMaintenanceMode($maintenanceModeId); } }); $dispatcher->addListener(ConsoleEvents::TERMINATE, function (ConsoleTerminateEvent $event) { if ($event->getInput()->getOption("maintenance-mode")) { $event->getOutput()->writeln('Deactivating maintenance mode...'); Admin::deactivateMaintenanceMode(); } }); }
protected function disableMaintenanceMode() { if ($this->input->getOption('maintenanceMode')) { $this->output->writeln('Deactivating maintenance mode...'); Admin::deactivateMaintenanceMode(); } }
public function maintenanceAction() { $this->checkPermission("maintenance_mode"); if ($this->getParam("activate")) { Tool\Admin::activateMaintenanceMode(); } if ($this->getParam("deactivate")) { Tool\Admin::deactivateMaintenanceMode(); } $this->_helper->json(["success" => true]); }
$types = explode(",", $opts->getOption("types")); } if (in_array("document", $types)) { $docTypes = null; if ($opts->getOption("documentTypes")) { $docTypes = explode(",", $opts->getOption("documentTypes")); } Warmer::documents($docTypes); } if (in_array("asset", $types)) { $assetTypes = null; if ($opts->getOption("assetTypes")) { $assetTypes = explode(",", $opts->getOption("assetTypes")); } Warmer::assets($assetTypes); } if (in_array("object", $types)) { $objectTypes = null; if ($opts->getOption("objectTypes")) { $objectTypes = explode(",", $opts->getOption("objectTypes")); } $classes = null; if ($opts->getOption("classes")) { $classes = explode(",", $opts->getOption("classes")); } Warmer::objects($objectTypes, $classes); } // disable maintenance mode if requested if ($opts->getOption("maintenanceMode")) { \Pimcore\Tool\Admin::deactivateMaintenanceMode(); }
protected function execute(InputInterface $input, OutputInterface $output) { $currentRevision = null; if ($input->getOption("source-build")) { $currentRevision = $input->getOption("source-build"); } $availableUpdates = Update::getAvailableUpdates($currentRevision); if ($input->getOption("list")) { if (count($availableUpdates["releases"])) { $rows = []; foreach ($availableUpdates["releases"] as $release) { $rows[] = [$release["version"], date("Y-m-d", $release["date"]), $release["id"]]; } $table = new Table($output); $table->setHeaders(['Version', 'Date', 'Build'])->setRows($rows); $table->render(); } if (count($availableUpdates["revisions"])) { $this->output->writeln("The latest available build is: <comment>" . $availableUpdates["revisions"][0]["id"] . "</comment> (" . date("Y-m-d", $availableUpdates["revisions"][0]["date"]) . ")"); } if (!count($availableUpdates["releases"]) && !count($availableUpdates["revisions"])) { $this->output->writeln("<info>No updates available</info>"); } } if ($input->getOption("update")) { $returnMessages = []; $build = null; $updateInfo = trim($input->getOption("update")); if (is_numeric($updateInfo)) { $build = $updateInfo; } else { // get build nr. by version number foreach ($availableUpdates["releases"] as $release) { if ($release["version"] == $updateInfo) { $build = $release["id"]; break; } } } if (!$build) { $this->writeError("Update with build / version " . $updateInfo . " not found."); exit; } if (!Update::isWriteable()) { $this->writeError(PIMCORE_PATH . " is not recursivly writable, please check!"); exit; } if (!Update::isComposerAvailable()) { $this->writeError("Composer is not installed properly, please ensure composer is in your PATH variable."); exit; } $helper = $this->getHelper('question'); $question = new ConfirmationQuestion("You are going to update to build {$build}! Continue with this action? (y/n)", false); if (!$helper->ask($input, $output, $question)) { return; } $this->output->writeln("Starting the update process ..."); if ($input->getOption("dry-run")) { $this->output->writeln("<info>---------- DRY-RUN ----------</info>"); } $jobs = Update::getJobs($build, $currentRevision); $steps = count($jobs["parallel"]) + count($jobs["procedural"]); $progress = new ProgressBar($output, $steps); $progress->start(); foreach ($jobs["parallel"] as $job) { if ($job["type"] == "download") { Update::downloadData($job["revision"], $job["url"]); } $progress->advance(); } $maintenanceModeId = 'cache-warming-dummy-session-id'; Admin::activateMaintenanceMode($maintenanceModeId); $stoppedByError = false; foreach ($jobs["procedural"] as $job) { if ($input->getOption("dry-run")) { $job["dry-run"] = true; } $script = realpath(PIMCORE_PATH . DIRECTORY_SEPARATOR . "cli" . DIRECTORY_SEPARATOR . "console.php"); $return = Console::runPhpScript($script, "internal:update-processor " . escapeshellarg(json_encode($job))); $return = trim($return); $returnData = @json_decode($return, true); if (is_array($returnData)) { if (trim($returnData["message"])) { $returnMessages[] = [$job["revision"], strip_tags($returnData["message"])]; } if (!$returnData["success"]) { $stoppedByError = true; break; } } else { $stoppedByError = true; break; } $progress->advance(); } $progress->finish(); Update::composerDumpAutoload(); Admin::deactivateMaintenanceMode(); $this->output->writeln("\n"); if ($stoppedByError) { $this->output->writeln("<error>Update stopped by error! Please check your logs</error>"); $this->output->writeln("Last return value was: " . $return); } else { $this->output->writeln("<info>Update done!</info>"); if (count($returnMessages)) { $table = new Table($output); $table->setHeaders(['Build', 'Message'])->setRows($returnMessages); $table->render(); } } } }