Set maximum script execution time.
public static setMaxExecutionTime ( integer $executionTime ) | ||
$executionTime | integer | max execution time in seconds (0 = no limit) |
/** * Update Piwik codebase by downloading and installing the latest version. * * @param bool $https Whether to use HTTPS if supported of not. If false, will use HTTP. * @return string[] Return an array of messages for the user. * @throws ArchiveDownloadException * @throws UpdaterException * @throws Exception */ public function updatePiwik($https = true) { if (!$this->isNewVersionAvailable()) { throw new Exception($this->translator->translate('CoreUpdater_ExceptionAlreadyLatestVersion', Version::VERSION)); } SettingsServer::setMaxExecutionTime(0); $newVersion = $this->getLatestVersion(); $url = $this->getArchiveUrl($newVersion, $https); $messages = array(); try { $archiveFile = $this->downloadArchive($newVersion, $url); $messages[] = $this->translator->translate('CoreUpdater_DownloadingUpdateFromX', $url); $extractedArchiveDirectory = $this->decompressArchive($archiveFile); $messages[] = $this->translator->translate('CoreUpdater_UnpackingTheUpdate'); $this->verifyDecompressedArchive($extractedArchiveDirectory); $messages[] = $this->translator->translate('CoreUpdater_VerifyingUnpackedFiles'); $disabledPluginNames = $this->disableIncompatiblePlugins($newVersion); if (!empty($disabledPluginNames)) { $messages[] = $this->translator->translate('CoreUpdater_DisablingIncompatiblePlugins', implode(', ', $disabledPluginNames)); } $this->installNewFiles($extractedArchiveDirectory); $messages[] = $this->translator->translate('CoreUpdater_InstallingTheLatestVersion'); } catch (ArchiveDownloadException $e) { throw $e; } catch (Exception $e) { throw new UpdaterException($e, $messages); } return $messages; }
public function runUpdaterAndExit($doDryRun = null) { $updater = new Updater(); $componentsWithUpdateFile = CoreUpdater::getComponentUpdates($updater); if (empty($componentsWithUpdateFile)) { throw new NoUpdatesFoundException("Everything is already up to date."); } SettingsServer::setMaxExecutionTime(0); $cli = Common::isPhpCliMode() ? '_cli' : ''; $welcomeTemplate = '@CoreUpdater/runUpdaterAndExit_welcome' . $cli; $doneTemplate = '@CoreUpdater/runUpdaterAndExit_done' . $cli; $viewWelcome = new View($welcomeTemplate); $this->addCustomLogoInfo($viewWelcome); $viewDone = new View($doneTemplate); $this->addCustomLogoInfo($viewDone); $doExecuteUpdates = Common::getRequestVar('updateCorePlugins', 0, 'integer') == 1; if (is_null($doDryRun)) { $doDryRun = !$doExecuteUpdates; } if ($doDryRun) { $viewWelcome->queries = $updater->getSqlQueriesToExecute(); $viewWelcome->isMajor = $updater->hasMajorDbUpdate(); $this->doWelcomeUpdates($viewWelcome, $componentsWithUpdateFile); return $viewWelcome->render(); } // CLI if (Common::isPhpCliMode()) { $this->doWelcomeUpdates($viewWelcome, $componentsWithUpdateFile); $output = $viewWelcome->render(); // Proceed with upgrade in CLI only if user specifically asked for it, or if running console command $isUpdateRequested = Common::isRunningConsoleCommand() || Piwik::getModule() == 'CoreUpdater'; if (!$this->coreError && $isUpdateRequested) { $this->doExecuteUpdates($viewDone, $updater, $componentsWithUpdateFile); $output .= $viewDone->render(); } return $output; } // Web if ($doExecuteUpdates) { $this->warningMessages = array(); $this->doExecuteUpdates($viewDone, $updater, $componentsWithUpdateFile); $this->redirectToDashboardWhenNoError($updater); return $viewDone->render(); } exit; }
public function init() { SettingsServer::setMaxExecutionTime(0); $this->archivingStartingTime = time(); // Note: the order of methods call matters here. $this->initStateFromParameters(); $this->logInitInfo(); $this->logArchiveTimeoutInfo(); // record archiving start time Option::set(self::OPTION_ARCHIVING_STARTED_TS, time()); $this->segments = $this->initSegmentsToArchive(); $this->allWebsites = APISitesManager::getInstance()->getAllSitesId(); if (!empty($this->shouldArchiveOnlySpecificPeriods)) { $this->logger->info("- Will only process the following periods: " . implode(", ", $this->shouldArchiveOnlySpecificPeriods) . " (--force-periods)"); } $this->invalidateArchivedReportsForSitesThatNeedToBeArchivedAgain(); $websitesIds = $this->initWebsiteIds(); $this->filterWebsiteIds($websitesIds); $this->websites = $this->createSitesToArchiveQueue($websitesIds); if ($this->websites->getInitialSiteIds() != $websitesIds) { $this->logger->info('Will ignore websites and help finish a previous started queue instead. IDs: ' . implode(', ', $this->websites->getInitialSiteIds())); } $this->logForcedSegmentInfo(); /** * This event is triggered after a CronArchive instance is initialized. * * @param array $websiteIds The list of website IDs this CronArchive instance is processing. * This will be the entire list of IDs regardless of whether some have * already been processed. */ Piwik::postEvent('CronArchive.init.finish', array($this->websites->getInitialSiteIds())); }
public function runUpdaterAndExit($doDryRun = null) { $updater = new DbUpdater(); $componentsWithUpdateFile = $updater->getComponentUpdates(); if (empty($componentsWithUpdateFile)) { throw new NoUpdatesFoundException("Everything is already up to date."); } SettingsServer::setMaxExecutionTime(0); $welcomeTemplate = '@CoreUpdater/runUpdaterAndExit_welcome'; $doneTemplate = '@CoreUpdater/runUpdaterAndExit_done'; $viewWelcome = new View($welcomeTemplate); $this->addCustomLogoInfo($viewWelcome); $this->setBasicVariablesView($viewWelcome); $viewDone = new View($doneTemplate); $this->addCustomLogoInfo($viewDone); $this->setBasicVariablesView($viewDone); $doExecuteUpdates = Common::getRequestVar('updateCorePlugins', 0, 'integer') == 1; if (is_null($doDryRun)) { $doDryRun = !$doExecuteUpdates; } if ($doDryRun) { $viewWelcome->queries = $updater->getSqlQueriesToExecute(); $viewWelcome->isMajor = $updater->hasMajorDbUpdate(); $this->doWelcomeUpdates($viewWelcome, $componentsWithUpdateFile); return $viewWelcome->render(); } // Web if ($doExecuteUpdates) { $this->warningMessages = array(); $this->doExecuteUpdates($viewDone, $updater, $componentsWithUpdateFile); $this->redirectToDashboardWhenNoError($updater); return $viewDone->render(); } exit; }
/** * Fetches a file located at `$url` and saves it to `$destinationPath`. * * @param string $url The URL of the file to download. * @param string $destinationPath The path to download the file to. * @param int $tries (deprecated) * @param int $timeout The amount of seconds to wait before aborting the HTTP request. * @throws Exception if the response cannot be saved to `$destinationPath`, if the HTTP response cannot be sent, * if there are more than 5 redirects or if the request times out. * @return bool `true` on success, throws Exception on failure * @api */ public static function fetchRemoteFile($url, $destinationPath = null, $tries = 0, $timeout = 10) { @ignore_user_abort(true); SettingsServer::setMaxExecutionTime(0); return self::sendHttpRequest($url, $timeout, 'Update', $destinationPath); }
protected function runUpdaterAndExit() { $updater = new Updater(); $componentsWithUpdateFile = CoreUpdater::getComponentUpdates($updater); if (empty($componentsWithUpdateFile)) { Piwik::redirectToModule('CoreHome'); } SettingsServer::setMaxExecutionTime(0); $cli = Common::isPhpCliMode() ? '_cli' : ''; $welcomeTemplate = '@CoreUpdater/runUpdaterAndExit_welcome' . $cli; $doneTemplate = '@CoreUpdater/runUpdaterAndExit_done' . $cli; $viewWelcome = new View($welcomeTemplate); $viewDone = new View($doneTemplate); if (Common::isPhpCliMode()) { $this->doWelcomeUpdates($viewWelcome, $componentsWithUpdateFile); $output = $viewWelcome->render(); if (!$this->coreError && Piwik::getModule() == 'CoreUpdater') { $this->doExecuteUpdates($viewDone, $updater, $componentsWithUpdateFile); $output .= $viewDone->render(); } return $output; } else { if (Common::getRequestVar('updateCorePlugins', 0, 'integer') == 1) { $this->warningMessages = array(); $this->doExecuteUpdates($viewDone, $updater, $componentsWithUpdateFile); $this->redirectToDashboardWhenNoError($updater); return $viewDone->render(); } else { $viewWelcome->queries = $updater->getSqlQueriesToExecute(); $viewWelcome->isMajor = $updater->hasMajorDbUpdate(); $this->doWelcomeUpdates($viewWelcome, $componentsWithUpdateFile); return $viewWelcome->render(); } } exit; }
<?php // Good old test proxy endpoints have some commons if (!defined('PIWIK_INCLUDE_PATH')) { define('PIWIK_INCLUDE_PATH', realpath(dirname(__FILE__)) . '/../../../'); } if (!defined('PIWIK_USER_PATH')) { define('PIWIK_USER_PATH', PIWIK_INCLUDE_PATH); } require_once file_exists(PIWIK_INCLUDE_PATH . '/vendor/autoload.php') ? PIWIK_INCLUDE_PATH . '/vendor/autoload.php' : PIWIK_INCLUDE_PATH . '/../../autoload.php'; // Piwik is installed as a dependency require_once PIWIK_INCLUDE_PATH . '/core/EventDispatcher.php'; require_once PIWIK_INCLUDE_PATH . '/core/Piwik.php'; require_once PIWIK_INCLUDE_PATH . '/libs/upgradephp/upgrade.php'; require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/TestingEnvironment.php'; if (file_exists(PIWIK_INCLUDE_PATH . '/vendor/autoload.php')) { $vendorDirectory = PIWIK_INCLUDE_PATH . '/vendor'; } else { $vendorDirectory = PIWIK_INCLUDE_PATH . '/../..'; } require_once $vendorDirectory . '/autoload.php'; require_once $vendorDirectory . '/mustangostang/spyc/Spyc.php'; require_once $vendorDirectory . '/piwik/device-detector/DeviceDetector.php'; \Piwik\SettingsServer::setMaxExecutionTime(0); // Make sure Data processed in cron core:archive command is not being purged instantly (useful for: Integration/ArchiveCronTest) if (\Piwik\SettingsServer::isArchivePhpTriggered()) { \Piwik\ArchiveProcessor\Rules::disablePurgeOutdatedArchives(); }
public function download($pluginOrThemeName) { @ignore_user_abort(true); SettingsServer::setMaxExecutionTime(0); $downloadUrl = $this->getDownloadUrl($pluginOrThemeName); if (empty($downloadUrl)) { return false; } // in the beginning we allowed to specify a download path but this way we make sure security is always taken // care of and we always generate a random download filename. $target = $this->getRandomTmpPluginDownloadFilename(); Filesystem::deleteFileIfExists($target); $success = $this->service->download($downloadUrl, $target, static::HTTP_REQUEST_TIMEOUT); if ($success) { return $target; } return false; }
/** * Update Piwik codebase by downloading and installing the latest version. * * @param bool $https Whether to use HTTPS if supported of not. If false, will use HTTP. * @return string[] Return an array of messages for the user. * @throws ArchiveDownloadException * @throws UpdaterException * @throws Exception */ public function updatePiwik($https = true) { if (!$this->isNewVersionAvailable()) { throw new Exception($this->translator->translate('CoreUpdater_ExceptionAlreadyLatestVersion', Version::VERSION)); } SettingsServer::setMaxExecutionTime(0); $newVersion = $this->getLatestVersion(); $url = $this->getArchiveUrl($newVersion, $https); $messages = array(); try { $archiveFile = $this->downloadArchive($newVersion, $url); $messages[] = $this->translator->translate('CoreUpdater_DownloadingUpdateFromX', $url); $extractedArchiveDirectory = $this->decompressArchive($archiveFile); $messages[] = $this->translator->translate('CoreUpdater_UnpackingTheUpdate'); $this->verifyDecompressedArchive($extractedArchiveDirectory); $messages[] = $this->translator->translate('CoreUpdater_VerifyingUnpackedFiles'); if (Marketplace::isMarketplaceEnabled()) { // we need to load the marketplace already here, otherwise it will use the new, updated file in Piwik 3 // we also need to make sure to create a new instance here as otherwise we would change the "global" // environment, but we only want to change piwik version temporarily for this task here $environment = StaticContainer::getContainer()->make('Piwik\\Plugins\\Marketplace\\Environment'); $environment->setPiwikVersion($newVersion); /** @var \Piwik\Plugins\Marketplace\Api\Client $marketplaceClient */ $marketplaceClient = StaticContainer::getContainer()->make('Piwik\\Plugins\\Marketplace\\Api\\Client', array('environment' => $environment)); require_once PIWIK_DOCUMENT_ROOT . '/plugins/CorePluginsAdmin/PluginInstaller.php'; require_once PIWIK_DOCUMENT_ROOT . '/plugins/Marketplace/Api/Exception.php'; } $this->installNewFiles($extractedArchiveDirectory); $messages[] = $this->translator->translate('CoreUpdater_InstallingTheLatestVersion'); } catch (ArchiveDownloadException $e) { throw $e; } catch (Exception $e) { throw new UpdaterException($e, $messages); } try { if (Marketplace::isMarketplaceEnabled() && !empty($marketplaceClient)) { $messages[] = $this->translator->translate('CoreUpdater_CheckingForPluginUpdates'); $pluginManager = PluginManager::getInstance(); $pluginManager->loadAllPluginsAndGetTheirInfo(); $loadedPlugins = $pluginManager->getLoadedPlugins(); $marketplaceClient->clearAllCacheEntries(); $pluginsWithUpdate = $marketplaceClient->checkUpdates($loadedPlugins); foreach ($pluginsWithUpdate as $pluginWithUpdate) { $pluginName = $pluginWithUpdate['name']; $messages[] = $this->translator->translate('CoreUpdater_UpdatingPluginXToVersionY', array($pluginName, $pluginWithUpdate['version'])); $pluginInstaller = new PluginInstaller($marketplaceClient); $pluginInstaller->installOrUpdatePluginFromMarketplace($pluginName); } } } catch (MarketplaceApi\Exception $e) { // there is a problem with the connection to the server, ignore for now } catch (Exception $e) { throw new UpdaterException($e, $messages); } try { $disabledPluginNames = $this->disableIncompatiblePlugins($newVersion); if (!empty($disabledPluginNames)) { $messages[] = $this->translator->translate('CoreUpdater_DisablingIncompatiblePlugins', implode(', ', $disabledPluginNames)); } } catch (Exception $e) { throw new UpdaterException($e, $messages); } return $messages; }