getLogger(), $this->getServiceLocator()->get(UpdateLogger::SERVICE_ID) ]; $this->setLogger(new LoggerAggregator($loggers)); } catch (ServiceNotFoundException $e) { // update script to add update logger hasn't run yet, ignore } $report = parent::__invoke($params); $migrationsReport = $this->getServiceLocator()->get(MigrationsService::class)->migrate(); $this->logInfo(\helpers_Report::renderToCommandline($migrationsReport, false)); $report->add($migrationsReport); // regenerate locales $files = \tao_models_classes_LanguageService::singleton()->generateAll(); if (count($files) > 0) { $report->add(new Report(Report::TYPE_SUCCESS, __('Successfully updated %s client translation bundles', count($files)))); } else { $report->add(new Report(Report::TYPE_ERROR, __('No client translation bundles updated'))); } $updateId = $this->generateUpdateId(); $this->updateCacheBuster($report, $updateId); $postUpdateReport = $this->runPostUpdateScripts(); $report->add($postUpdateReport); $report->add(new Report(Report::TYPE_INFO, __('Update ID : %s', $updateId))); $this->getEventManager()->trigger(new TaoUpdateEvent($report)); return $report; } /** * Generate a unique ID per update * @return string the new id */ protected function generateUpdateId() { return uniqid(); } /** * Update the asset service to save the cache buster value (the update id) * * @param Report $report * @param string $updateid */ private function updateCacheBuster(Report $report, $updateid) { try { $assetService = $this->getServiceLocator()->get(AssetService::SERVICE_ID); $assetService->setCacheBuster($updateid); $this->getServiceLocator()->register(AssetService::SERVICE_ID, $assetService); } catch (\Exception $e) { \common_Logger::e($e->getMessage()); $report->add( new Report(Report::TYPE_WARNING, __('Unable to update the asset service'))); } } /** * @throws \common_exception_Error */ private function runPostUpdateScripts() { $report = new Report(Report::TYPE_INFO, 'Post update actions:'); $extManager = $this->getServiceLocator()->get(ExtensionManager::SERVICE_ID); $sorted = \helpers_ExtensionHelper::sortByDependencies($extManager->getInstalledExtensions()); foreach ($sorted as $ext) { $postUpdateExtensionReport = $this->runPostUpdateScript($ext); if ($postUpdateExtensionReport !== null) { $report->add($postUpdateExtensionReport); } } if (!$report->hasChildren()) { $report->add( new Report(Report::TYPE_INFO, 'No actions to be executed')); } return $report; } /** * @param Extension $ext * * @return Report|null */ private function runPostUpdateScript(Extension $ext): ?Report { try { return $ext->getUpdater()->postUpdate(); } catch (UpdaterNotFoundException $e) { return Report::createSuccess(sprintf('No postprocessing defined for %s', $ext->getName())); } catch (ManifestException $e) { return new Report(Report::TYPE_WARNING, $e->getMessage()); } } }