Called on Core install, update, plugin enable/disable
Will clear all cache that could be affected by the change in configuration being made
public static deleteAllCacheOnUpdate ( $pluginName = false ) |
public function dispatch() { $module = Common::getRequestVar('module', '', 'string'); $action = Common::getRequestVar('action', '', 'string'); if ($module == 'CoreUpdater' || $module == 'Proxy' || $module == 'Installation' || $module == 'LanguagesManager' && $action == 'saveLanguage') { return; } $updater = new PiwikCoreUpdater(); $updates = $updater->getComponentsWithNewVersion(array('core' => Version::VERSION)); if (!empty($updates)) { Filesystem::deleteAllCacheOnUpdate(); } if ($updater->getComponentUpdates() !== null) { if (FrontController::shouldRethrowException()) { throw new Exception("Piwik and/or some plugins have been upgraded to a new version. \n" . "--> Please run the update process first. See documentation: http://piwik.org/docs/update/ \n"); } elseif ($module === 'API') { $outputFormat = strtolower(Common::getRequestVar('format', 'xml', 'string', $_GET + $_POST)); $response = new ResponseBuilder($outputFormat); $e = new Exception('Database Upgrade Required. Your Piwik database is out-of-date, and must be upgraded before you can continue.'); echo $response->getResponseException($e); Common::sendResponseCode(503); exit; } else { Piwik::redirectToModule('CoreUpdater'); } } }
protected function execute(InputInterface $input, OutputInterface $output) { $commandName = $input->getFirstArgument(); $enable = false !== strpos($commandName, 'enable'); $full = $input->getOption('full'); $config = Config::getInstance(); $development = $config->Development; if ($enable) { $development['enabled'] = 1; if ($full) { $development['disable_merged_assets'] = 1; } $message = 'Development mode enabled'; } else { $development['enabled'] = 0; if ($full) { $development['disable_merged_assets'] = 0; } $message = 'Development mode disabled'; } $config->Development = $development; $config->forceSave(); Filesystem::deleteAllCacheOnUpdate(); $this->writeSuccessMessage($output, array($message)); }
/** * Installation Step 1: Welcome * * Can also display an error message when there is a failure early (eg. DB connection failed) */ function welcome() { // Delete merged js/css files to force regenerations based on updated activated plugin list Filesystem::deleteAllCacheOnUpdate(); $this->checkPiwikIsNotInstalled(); $view = new View('@Installation/welcome', $this->getInstallationSteps(), __FUNCTION__); $view->showNextStep = true; return $view->render(); }
/** * Installation Step 1: Welcome * * Can also display an error message when there is a failure early (eg. DB connection failed) * * @param string Optional error message */ function welcome($message = false) { // Delete merged js/css files to force regenerations based on updated activated plugin list Filesystem::deleteAllCacheOnUpdate(); if (empty($message)) { $this->checkPiwikIsNotInstalled(); } $view = new View('@Installation/welcome', $this->getInstallationSteps(), __FUNCTION__); $view->newInstall = !SettingsPiwik::isPiwikInstalled(); $view->errorMessage = $message; $view->showNextStep = $view->newInstall; return $view->render(); }
public function dispatch() { $module = Common::getRequestVar('module', '', 'string'); $action = Common::getRequestVar('action', '', 'string'); $updater = new PiwikCoreUpdater(); $updates = $updater->getComponentsWithNewVersion(array('core' => Version::VERSION)); if (!empty($updates)) { Filesystem::deleteAllCacheOnUpdate(); } if ($updater->getComponentUpdates() !== null && $module != 'CoreUpdater' && $module != 'Proxy' && $module != 'Installation' && !($module == 'LanguagesManager' && $action == 'saveLanguage')) { if (FrontController::shouldRethrowException()) { throw new Exception("Piwik and/or some plugins have been upgraded to a new version. \n" . "--> Please run the update process first. See documentation: http://piwik.org/docs/update/ \n"); } else { Piwik::redirectToModule('CoreUpdater'); } } }
public function installOrUpdatePluginFromFile($pathToZip) { $tmpPluginFolder = StaticContainer::get('path.tmp') . self::PATH_TO_DOWNLOAD . $this->pluginName; try { $this->makeSureFoldersAreWritable(); $this->extractPluginFiles($pathToZip, $tmpPluginFolder); $this->makeSurePluginJsonExists($tmpPluginFolder); $metadata = $this->getPluginMetadataIfValid($tmpPluginFolder); $this->makeSureThereAreNoMissingRequirements($metadata); $this->pluginName = $metadata->name; $this->fixPluginFolderIfNeeded($tmpPluginFolder); $this->copyPluginToDestination($tmpPluginFolder); Filesystem::deleteAllCacheOnUpdate($this->pluginName); } catch (\Exception $e) { $this->removeFileIfExists($pathToZip); $this->removeFolderIfExists($tmpPluginFolder); throw $e; } $this->removeFileIfExists($pathToZip); $this->removeFolderIfExists($tmpPluginFolder); return $metadata; }
/** * @param string $pluginName */ private function clearCache($pluginName) { $this->resetTransientCache(); Filesystem::deleteAllCacheOnUpdate($pluginName); }
/** * Updates multiple components, while capturing & returning errors and warnings. * * @param string[] $componentsWithUpdateFile Component names mapped with arrays of update files. Same structure * as the result of `getComponentsWithUpdateFile()`. * @return array Information about the update process, including: * * * **warnings**: The list of warnings that occurred during the update process. * * **errors**: The list of updater exceptions thrown during individual component updates. * * **coreError**: True if an exception was thrown while updating core. * * **deactivatedPlugins**: The list of plugins that were deactivated due to an error in the * update process. */ public function updateComponents($componentsWithUpdateFile) { $warnings = array(); $errors = array(); $deactivatedPlugins = array(); $coreError = false; if (!empty($componentsWithUpdateFile)) { $currentAccess = Access::getInstance(); $hasSuperUserAccess = $currentAccess->hasSuperUserAccess(); if (!$hasSuperUserAccess) { $currentAccess->setSuperUserAccess(true); } // if error in any core update, show message + help message + EXIT // if errors in any plugins updates, show them on screen, disable plugins that errored + CONTINUE // if warning in any core update or in any plugins update, show message + CONTINUE // if no error or warning, success message + CONTINUE foreach ($componentsWithUpdateFile as $name => $filenames) { try { $warnings = array_merge($warnings, $this->update($name)); } catch (UpdaterErrorException $e) { $errors[] = $e->getMessage(); if ($name == 'core') { $coreError = true; break; } elseif (\Piwik\Plugin\Manager::getInstance()->isPluginActivated($name)) { \Piwik\Plugin\Manager::getInstance()->deactivatePlugin($name); $deactivatedPlugins[] = $name; } } } if (!$hasSuperUserAccess) { $currentAccess->setSuperUserAccess(false); } } Filesystem::deleteAllCacheOnUpdate(); $result = array('warnings' => $warnings, 'errors' => $errors, 'coreError' => $coreError, 'deactivatedPlugins' => $deactivatedPlugins); /** * Triggered after Piwik has been updated. */ Piwik::postEvent('CoreUpdater.update.end'); return $result; }
/** * Execute command like: ./console core:clear-caches */ protected function execute(InputInterface $input, OutputInterface $output) { Filesystem::deleteAllCacheOnUpdate(); $this->writeSuccessMessage($output, array('Caches cleared')); }
/** * @param string $pluginName */ private function clearCache($pluginName) { Filesystem::deleteAllCacheOnUpdate($pluginName); }
/** * Installation Step 1: Welcome */ function welcome($message = false) { // Delete merged js/css files to force regenerations based on updated activated plugin list Filesystem::deleteAllCacheOnUpdate(); $view = new View('@Installation/welcome', $this->getInstallationSteps(), __FUNCTION__); $isConfigFileFound = file_exists(Config::getLocalConfigPath()); $view->newInstall = !$isConfigFileFound; $view->errorMessage = $message; $this->skipThisStep(__FUNCTION__); $view->showNextStep = $view->newInstall; $this->session->currentStepDone = __FUNCTION__; return $view->render(); }
public static function addHooks() { $testingEnvironment = new Piwik_TestingEnvironment(); if ($testingEnvironment->queryParamOverride) { foreach ($testingEnvironment->queryParamOverride as $key => $value) { $_GET[$key] = $value; } } if ($testingEnvironment->globalsOverride) { foreach ($testingEnvironment->globalsOverride as $key => $value) { $GLOBALS[$key] = $value; } } Config::setSingletonInstance(new Config($testingEnvironment->configFileGlobal, $testingEnvironment->configFileLocal, $testingEnvironment->configFileCommon)); \Piwik\CacheFile::$invalidateOpCacheBeforeRead = true; Piwik::addAction('Access.createAccessSingleton', function ($access) use($testingEnvironment) { if (!$testingEnvironment->testUseRegularAuth) { $access = new Piwik_MockAccess($access); \Piwik\Access::setSingletonInstance($access); } }); if (!$testingEnvironment->dontUseTestConfig) { Piwik::addAction('Config.createConfigSingleton', function (Config $config, &$cache, $local) use($testingEnvironment) { $config->setTestEnvironment($testingEnvironment->configFileLocal, $testingEnvironment->configFileGlobal, $testingEnvironment->configFileCommon); if ($testingEnvironment->configFileLocal) { unset($cache['General']); $config->General['session_save_handler'] = 'dbtable'; } $manager = \Piwik\Plugin\Manager::getInstance(); $pluginsToLoad = $manager->getPluginsToLoadDuringTests(); $config->Plugins = array('Plugins' => $pluginsToLoad); $trackerPluginsToLoad = array_filter($pluginsToLoad, function ($plugin) use($manager) { return $manager->isTrackerPlugin($manager->loadPlugin($plugin)); }); $config->Plugins_Tracker = array('Plugins_Tracker' => $trackerPluginsToLoad); $log = $config->log; $log['log_writers'] = array('file'); $config->log = $log; $manager->unloadPlugins(); // TODO: replace this and below w/ configOverride use if ($testingEnvironment->tablesPrefix) { $cache['database']['tables_prefix'] = $testingEnvironment->tablesPrefix; } if ($testingEnvironment->dbName) { $cache['database']['dbname'] = $testingEnvironment->dbName; } if ($testingEnvironment->configOverride) { $cache = $testingEnvironment->arrayMergeRecursiveDistinct($cache, $testingEnvironment->configOverride); } }); } Piwik::addAction('Request.dispatch', function () { \Piwik\Plugins\CoreVisualizations\Visualizations\Cloud::$debugDisableShuffle = true; \Piwik\Visualization\Sparkline::$enableSparklineImages = false; \Piwik\Plugins\ExampleUI\API::$disableRandomness = true; }); Piwik::addAction('AssetManager.getStylesheetFiles', function (&$stylesheets) { $stylesheets[] = 'tests/resources/screenshot-override/override.css'; }); Piwik::addAction('AssetManager.getJavaScriptFiles', function (&$jsFiles) { $jsFiles[] = 'tests/resources/screenshot-override/override.js'; }); self::addSendMailHook(); Piwik::addAction('Updater.checkForUpdates', function () { try { @\Piwik\Filesystem::deleteAllCacheOnUpdate(); } catch (Exception $ex) { // pass } }); $testingEnvironment->logVariables(); $testingEnvironment->executeSetupTestEnvHook(); }
public function test_trackingApiWithBulkRequests_viaCurl_withCorrectTokenAuth() { $token_auth = Fixture::getTokenAuth(); \Piwik\Filesystem::deleteAllCacheOnUpdate(); $this->issueBulkTrackingRequest($token_auth, $expectTrackingToSucceed = true); }
$access = new FakeAccess(); FakeAccess::$superUser = true; FakeAccess::$superUserLogin = '******'; return $access; } else { return $previous; } }), 'observers.global' => DI\add(array(array('AssetManager.getStylesheetFiles', function (&$stylesheets) { $useOverrideCss = \Piwik\Container\StaticContainer::get('test.vars.useOverrideCss'); if ($useOverrideCss) { $stylesheets[] = 'tests/resources/screenshot-override/override.css'; } }), array('AssetManager.getJavaScriptFiles', function (&$jsFiles) { $useOverrideJs = \Piwik\Container\StaticContainer::get('test.vars.useOverrideJs'); if ($useOverrideJs) { $jsFiles[] = 'tests/resources/screenshot-override/override.js'; } }), array('Updater.checkForUpdates', function () { try { @\Piwik\Filesystem::deleteAllCacheOnUpdate(); } catch (Exception $ex) { // pass } }), array('Test.Mail.send', function (\Zend_Mail $mail) { $outputFile = PIWIK_INCLUDE_PATH . '/tmp/' . Common::getRequestVar('module', '') . '.' . Common::getRequestVar('action', '') . '.mail.json'; $outputContent = str_replace("=\n", "", $mail->getBodyText($textOnly = true)); $outputContent = str_replace("=0A", "\n", $outputContent); $outputContent = str_replace("=3D", "=", $outputContent); $outputContents = array('from' => $mail->getFrom(), 'to' => $mail->getRecipients(), 'subject' => $mail->getSubject(), 'contents' => $outputContent); file_put_contents($outputFile, json_encode($outputContents)); }))));
private function doWelcomeUpdates($view, $componentsWithUpdateFile) { $view->new_piwik_version = Version::VERSION; $view->commandUpgradePiwik = "<br /><code>php " . Filesystem::getPathToPiwikRoot() . "/console core:update </code>"; $pluginNamesToUpdate = array(); $dimensionsToUpdate = array(); $coreToUpdate = false; // handle case of existing database with no tables if (!DbHelper::isInstalled()) { $this->errorMessages[] = Piwik::translate('CoreUpdater_EmptyDatabaseError', Config::getInstance()->database['dbname']); $this->coreError = true; $currentVersion = 'N/A'; } else { $this->errorMessages = array(); try { $currentVersion = Option::get('version_core'); } catch (Exception $e) { $currentVersion = '<= 0.2.9'; } foreach ($componentsWithUpdateFile as $name => $filenames) { if ($name == 'core') { $coreToUpdate = true; } elseif (0 === strpos($name, 'log_')) { $dimensionsToUpdate[] = $name; } else { $pluginNamesToUpdate[] = $name; } } } // check file integrity $integrityInfo = Filechecks::getFileIntegrityInformation(); if (isset($integrityInfo[1])) { if ($integrityInfo[0] == false) { $this->warningMessages[] = Piwik::translate('General_FileIntegrityWarningExplanation'); } $this->warningMessages = array_merge($this->warningMessages, array_slice($integrityInfo, 1)); } Filesystem::deleteAllCacheOnUpdate(); $view->coreError = $this->coreError; $view->warningMessages = $this->warningMessages; $view->errorMessages = $this->errorMessages; $view->current_piwik_version = $currentVersion; $view->pluginNamesToUpdate = $pluginNamesToUpdate; $view->dimensionsToUpdate = $dimensionsToUpdate; $view->coreToUpdate = $coreToUpdate; }
protected function executeClearCaches() { Filesystem::deleteAllCacheOnUpdate(); }
/** * Execute command like: ./console core:clear-caches */ protected function execute(InputInterface $input, OutputInterface $output) { // Note: the logic for this command must be refactored in this helper function below. Filesystem::deleteAllCacheOnUpdate(); $this->writeSuccessMessage($output, array('Caches cleared')); }
private function tryToRepairPiwik() { // in case any opcaches etc were not cleared after an update for instance. Might prevent from getting the // error again try { Filesystem::deleteAllCacheOnUpdate(); } catch (Exception $e) { } }
private function doExecuteUpdates($view, $updater, $componentsWithUpdateFile) { $this->loadAndExecuteUpdateFiles($updater, $componentsWithUpdateFile); Filesystem::deleteAllCacheOnUpdate(); $view->coreError = $this->coreError; $view->warningMessages = $this->warningMessages; $view->errorMessages = $this->errorMessages; $view->deactivatedPlugins = $this->deactivatedPlugins; }