public function testWebArchiving() { if (self::isMysqli() && self::isTravisCI()) { $this->markTestSkipped('Skipping on Mysqli as it randomly fails.'); } $host = Fixture::getRootUrl(); $token = Fixture::getTokenAuth(); $urlTmp = Option::get('piwikUrl'); Option::set('piwikUrl', $host . 'tests/PHPUnit/proxy/index.php'); $url = $host . 'tests/PHPUnit/proxy/archive.php?token_auth=' . $token; $output = Http::sendHttpRequest($url, 600); // ignore random build issues if (empty($output) || strpos($output, \Piwik\CronArchive::NO_ERROR) === false) { $message = "This test has failed. Because it sometimes randomly fails, we skip the test, and ignore this failure.\n"; $message .= "If you see this message often, or in every build, please investigate as this should only be a random and rare occurence!\n"; $message .= "\n\narchive web failed: " . $output . "\n\nurl used: {$url}"; $this->markTestSkipped($message); } if (!empty($urlTmp)) { Option::set('piwikUrl', $urlTmp); } else { Option::delete('piwikUrl'); } $this->assertContains('Starting Piwik reports archiving...', $output); $this->assertContains('Archived website id = 1', $output); $this->assertContains('Done archiving!', $output); $this->compareArchivePhpOutputAgainstExpected($output); }
public static function setUpBeforeClass() { $dbName = false; if (!empty($GLOBALS['PIWIK_BENCHMARK_DATABASE'])) { $dbName = $GLOBALS['PIWIK_BENCHMARK_DATABASE']; } // connect to database self::createTestConfig(); self::connectWithoutDatabase(); // create specified fixture (global var not set, use default no-data fixture (see end of this file)) if (empty($GLOBALS['PIWIK_BENCHMARK_FIXTURE'])) { $fixtureName = 'Piwik_Test_Fixture_EmptyOneSite'; } else { $fixtureName = 'Piwik_Test_Fixture_' . $GLOBALS['PIWIK_BENCHMARK_FIXTURE']; } self::$fixture = new $fixtureName(); // figure out if the desired fixture has already been setup, and if not empty the database $installedFixture = false; try { if (isset(self::$fixture->tablesPrefix)) { Config::getInstance()->database['tables_prefix'] = self::$fixture->tablesPrefix; } Db::query("USE " . $dbName); $installedFixture = \Piwik\Option::get('benchmark_fixture_name'); } catch (Exception $ex) { // ignore } $createEmptyDatabase = $fixtureName != $installedFixture; parent::_setUpBeforeClass($dbName, $createEmptyDatabase); // if we created an empty database, setup the fixture if ($createEmptyDatabase) { self::$fixture->setUp(); \Piwik\Option::set('benchmark_fixture_name', $fixtureName); } }
public function index() { Piwik::checkUserHasSuperUserAccess(); $view = new View('@TasksTimetable/index.twig'); $this->setGeneralVariablesView($view); $tasks = Option::get('TaskScheduler.timetable'); if (!empty($tasks)) { $tasks = unserialize($tasks); } if (empty($tasks)) { $tasks = array(); } else { asort($tasks); } $tsNow = Date::now()->getTimestamp(); $dateFormat = Piwik::translate(Date::DATE_FORMAT_LONG) . ' h:mm:ss'; $formatter = new Formatter(); $tasksFormatted = array(); foreach ($tasks as $name => $timestamp) { $tasksFormatted[] = array('name' => $name, 'executionDate' => Date::factory($timestamp)->getLocalized($dateFormat), 'ts_difference' => $formatter->getPrettyTimeFromSeconds($timestamp - $tsNow)); } $view->currentTime = Date::now()->getLocalized($dateFormat); $view->tasks = $tasksFormatted; return $view->render(); }
public function test_rememberToInvalidateArchivedReportsLater_shouldCreateAnEntryInCaseThereIsNoneYet() { $key = 'report_to_invalidate_2_2014-04-05'; $this->assertFalse(Option::get($key)); $this->rememberReport(2, '2014-04-05'); $this->assertSame('1', Option::get($key)); }
/** * @depends testMarkComponentSuccessfullyUpdated_ShouldCreateAnOptionEntry */ public function testMarkComponentSuccessfullyUninstalled_ShouldCreateAnOptionEntry() { $updater = $this->createUpdater(); $updater->markComponentSuccessfullyUninstalled('test_entry'); $value = Option::get('version_test_entry'); $this->assertFalse($value); }
/** * Returns version number of a newer Piwik release. * * @return string|bool false if current version is the latest available, * or the latest version number if a newest release is available */ public static function isNewestVersionAvailable() { $latestVersion = Option::get(self::LATEST_VERSION); if (!empty($latestVersion) && version_compare(Version::VERSION, $latestVersion) == -1) { return $latestVersion; } return false; }
public function getAllSiteIdsToArchive() { Option::clearCachedOption('SharedSiteIdsToArchive'); $siteIdsToArchive = Option::get('SharedSiteIdsToArchive'); if (empty($siteIdsToArchive)) { return array(); } return explode(',', trim($siteIdsToArchive)); }
private function migratePluginEmailUpdateSetting() { $isEnabled = Option::get('enableUpdateCommunicationPlugins'); Access::doAsSuperUser(function () use($isEnabled) { $settings = StaticContainer::get('Piwik\\Plugins\\CoreUpdater\\SystemSettings'); $settings->sendPluginUpdateEmail->setValue(!empty($isEnabled)); $settings->save(); }); }
public function test_UpdateCommand_DoesNotExecuteUpdate_IfPiwikUpToDate() { Option::set('version_core', Version::VERSION); $result = $this->applicationTester->run(array('command' => 'core:update', '--yes' => true)); $this->assertEquals(0, $result, $this->getCommandDisplayOutputErrorMessage()); // check no update occurred $this->assertContains("Everything is already up to date.", $this->applicationTester->getDisplay()); $this->assertEquals(Version::VERSION, Option::get('version_core')); }
private static function updateIPAnonymizationSettings() { $optionName = 'PrivacyManager.ipAnonymizerEnabled'; $value = Option::get($optionName); if ($value !== false) { // If the config is defined, nothing to do return; } // We disable IP anonymization if it wasn't configured (because by default it has gone from disabled to enabled) Option::set($optionName, '0'); }
public function rememberToInvalidateArchivedReportsLater($idSite, Date $date) { $key = $this->buildRememberArchivedReportId($idSite, $date->toString()); $value = Option::get($key); // we do not really have to get the value first. we could simply always try to call set() and it would update or // insert the record if needed but we do not want to lock the table (especially since there are still some // MyISAM installations) if (false === $value) { Option::set($key, '1'); } }
private function getFromOption($name, $config) { $name = $this->prefix($name); $value = Option::get($name); if (false !== $value) { settype($value, $config['type']); } else { $value = $config['default']; } return $value; }
public function test_getAll_ReturnsValueInOption_IfOptionCacheHasSeparateValue() { // get option so cache is loaded Option::get(self::TEST_OPTION_NAME); // set option value to something else $newList = array('1', '2', '3'); $this->initOptionValue($newList); // test option is now different $list = $this->distributedList->getAll(); $this->assertEquals($newList, $list); }
/** * Retrieve the current version of a recorded component * @param string $name * @return false|string * @throws \Exception */ public static function getCurrentRecordedComponentVersion($name) { try { $currentVersion = Option::get(self::getNameInOptionTable($name)); } catch (\Exception $e) { // mysql error 1146: table doesn't exist if (Db::get()->isErrNo($e, '1146')) { // case when the option table is not yet created (before 0.2.10) $currentVersion = false; } else { // failed for some other reason throw $e; } } return $currentVersion; }
private function loadSpammerList() { if ($this->spammerList !== null) { return $this->spammerList; } // Read first from the auto-updated list in database $list = Option::get(self::OPTION_STORAGE_NAME); if ($list) { $this->spammerList = unserialize($list); } else { // Fallback to reading the bundled list $file = PIWIK_VENDOR_PATH . '/piwik/referrer-spam-blacklist/spammers.txt'; $this->spammerList = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); } return $this->spammerList; }
public function performSetUp($setupEnvironmentOnly = false) { parent::performSetUp($setupEnvironmentOnly); $this->createSegments(); $this->setupDashboards(); $visitorIdDeterministic = bin2hex(Db::fetchOne("SELECT idvisitor FROM " . Common::prefixTable('log_visit') . " WHERE idsite = 2 AND location_latitude IS NOT NULL LIMIT 1")); $this->testEnvironment->forcedIdVisitor = $visitorIdDeterministic; $this->testEnvironment->overlayUrl = $this->getLocalTestSiteUrl(); $this->createOverlayTestSite(); $forcedNowTimestamp = Option::get("Tests.forcedNowTimestamp"); if ($forcedNowTimestamp == false) { throw new Exception("Incorrect fixture setup, Tests.forcedNowTimestamp option does not exist! Run the setup again."); } $this->testEnvironment->forcedNowTimestamp = $forcedNowTimestamp; $this->testEnvironment->save(); }
private function loadDefinitions() { if ($this->definitionList === null) { // Read first from the auto-updated list in database $list = Option::get(self::OPTION_STORAGE_NAME); if ($list) { $this->definitionList = unserialize(base64_decode($list)); } else { // Fallback to reading the bundled list $yml = file_get_contents(PIWIK_INCLUDE_PATH . self::DEFINITION_FILE); $this->definitionList = $this->loadYmlData($yml); Option::set(self::OPTION_STORAGE_NAME, base64_encode(serialize($this->definitionList))); } } Piwik::postEvent('Referrer.addSocialUrls', array(&$this->definitionList)); return $this->definitionList; }
public function test_WebArchiving() { if (self::isMysqli() && self::isTravisCI()) { $this->markTestSkipped('Skipping on Mysqli as it randomly fails.'); } $host = Fixture::getRootUrl(); $token = Fixture::getTokenAuth(); $urlTmp = Option::get('piwikUrl'); Option::set('piwikUrl', $host . 'tests/PHPUnit/proxy/index.php'); $url = $host . 'tests/PHPUnit/proxy/archive.php?token_auth=' . $token; $output = Http::sendHttpRequest($url, 600); // ignore random build issues if (empty($output) || strpos($output, \Piwik\CronArchive::NO_ERROR) === false) { $this->fail("archive web failed: " . $output . "\n\nurl used: {$url}"); } if (!empty($urlTmp)) { Option::set('piwikUrl', $urlTmp); } else { Option::delete('piwikUrl'); } $this->assertWebArchivingDone($output); }
private function loadSpammerList() { if ($this->spammerList !== null) { return $this->spammerList; } // Read first from the auto-updated list in database $list = Option::get(self::OPTION_STORAGE_NAME); if ($list) { $this->spammerList = unserialize($list); } else { // Fallback to reading the bundled list if (file_exists(PIWIK_INCLUDE_PATH . '/vendor/piwik/referrer-spam-blacklist/spammers.txt')) { $file = PIWIK_INCLUDE_PATH . '/vendor/piwik/referrer-spam-blacklist/spammers.txt'; // Piwik is the main project } else { $file = PIWIK_INCLUDE_PATH . '/../../piwik/referrer-spam-blacklist/spammers.txt'; // Piwik is installed as a dependency } $this->spammerList = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); } return $this->spammerList; }
public function performSetUp($setupEnvironmentOnly = false) { $this->extraTestEnvVars = array('loadRealTranslations' => 1); parent::performSetUp($setupEnvironmentOnly); $this->createSegments(); $this->setupDashboards(); $visitorIdDeterministic = bin2hex(Db::fetchOne("SELECT idvisitor FROM " . Common::prefixTable('log_visit') . " WHERE idsite = 2 AND location_latitude IS NOT NULL LIMIT 1")); $this->testEnvironment->forcedIdVisitor = $visitorIdDeterministic; $this->testEnvironment->overlayUrl = $this->getLocalTestSiteUrl(); $this->createOverlayTestSite(); $forcedNowTimestamp = Option::get("Tests.forcedNowTimestamp"); if ($forcedNowTimestamp == false) { throw new Exception("Incorrect fixture setup, Tests.forcedNowTimestamp option does not exist! Run the setup again."); } $this->testEnvironment->forcedNowTimestamp = $forcedNowTimestamp; $this->testEnvironment->save(); // launch archiving so tests don't run out of time print "Archiving in fixture set up..."; VisitsSummaryAPI::getInstance()->get('all', 'year', '2012-08-09'); VisitsSummaryAPI::getInstance()->get('all', 'year', '2012-08-09', urlencode(OmniFixture::DEFAULT_SEGMENT)); print "Done."; }
private static function migrateExistingMobileMessagingOptions() { if (Option::get(MobileMessaging::DELEGATED_MANAGEMENT_OPTION) == 'true') { return; } // copy $superUserLogin_MobileMessagingSettings -> _MobileMessagingSettings as settings are managed globally $optionName = MobileMessaging::USER_SETTINGS_POSTFIX_OPTION; $superUsers = UsersManagerApi::getInstance()->getUsersHavingSuperUserAccess(); if (empty($superUsers)) { return; } $firstSuperUser = array_shift($superUsers); if (empty($firstSuperUser)) { return; } $superUserLogin = $firstSuperUser['login']; $optionPrefixed = $superUserLogin . $optionName; // $superUserLogin_MobileMessagingSettings $value = Option::get($optionPrefixed); if (false !== $value) { // _MobileMessagingSettings Option::set($optionName, $value); } }
/** * @return string */ public function admin() { Piwik::checkUserHasSuperUserAccess(); $view = new View('@LoginLdap/index'); ControllerAdmin::setBasicVariablesAdminView($view); if (!function_exists('ldap_connect')) { $notification = new Notification(Piwik::translate('LoginLdap_LdapFunctionsMissing')); $notification->context = Notification::CONTEXT_ERROR; $notification->type = Notification::TYPE_PERSISTENT; Notification\Manager::notify('LoginLdap_LdapFunctionsMissing', $notification); } $this->setBasicVariablesView($view); $serverNames = Config::getServerNameList() ?: array(); $view->servers = array(); if (empty($serverNames)) { try { $serverInfo = ServerInfo::makeFromOldConfig()->getProperties(); $serverInfo['name'] = 'server'; $view->servers[] = $serverInfo; } catch (Exception $ex) { // ignore } } else { foreach ($serverNames as $server) { $serverConfig = Config::getServerConfig($server); if (!empty($serverConfig)) { $serverConfig['name'] = $server; $view->servers[] = $serverConfig; } } } $view->ldapConfig = Config::getPluginOptionValuesWithDefaults(); $view->isLoginControllerActivated = PluginManager::getInstance()->isPluginActivated('Login'); $view->updatedFromPre30 = Option::get('LoginLdap_updatedFromPre3_0'); return $view->render(); }
/** * Determine if normal users can manage their own SMS API credential * * @return bool false if SMS API credential only manageable by super admin, true otherwise */ public function getDelegatedManagement() { Piwik::checkUserHasSomeViewAccess(); return Option::get(MobileMessaging::DELEGATED_MANAGEMENT_OPTION) == 'true'; }
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; }
private function getLastSentVersion() { return Option::get('last_update_communication_sent_core'); }
/** * @return false|string */ private function getLastSuccessRunTimestamp() { $timestamp = Option::get(self::OPTION_ARCHIVING_FINISHED_TS); return $this->sanitiseTimestamp($timestamp); }
/** * Returns the URL to this Piwik instance, eg. **http://demo.piwik.org/** or **http://example.org/piwik/**. * * @return string * @api */ public static function getPiwikUrl() { $url = Option::get(self::OPTION_PIWIK_URL); $isPiwikCoreDispatching = defined('PIWIK_ENABLE_DISPATCH') && PIWIK_ENABLE_DISPATCH; if (Common::isPhpCliMode() || SettingsServer::isArchivePhpTriggered() || !$isPiwikCoreDispatching) { return $url; } $currentUrl = Common::sanitizeInputValue(Url::getCurrentUrlWithoutFileName()); // when script is called from /misc/cron/archive.php, Piwik URL is /index.php $currentUrl = str_replace("/misc/cron", "", $currentUrl); if (empty($url) || $currentUrl != $url) { if (strlen($currentUrl) >= strlen('http://a/')) { self::overwritePiwikUrl($currentUrl); } $url = $currentUrl; } if (ProxyHttp::isHttps()) { $url = str_replace("http://", "https://", $url); } return $url; }
private function getLatestVersionSent($plugin) { return Option::get($this->getNotificationSentOptionName($plugin)); }
function reuseTables() { $this->checkPiwikIsNotInstalled(); $steps = $this->getInstallationSteps(); $steps['tablesCreation'] = 'Installation_ReusingTables'; $view = new View('@Installation/reuseTables', $steps, 'tablesCreation'); $result = $this->updateComponents(); if ($result === false) { $this->redirectToNextStep('tablesCreation'); } $oldVersion = Option::get('version_core'); $view->coreError = $result['coreError']; $view->warningMessages = $result['warnings']; $view->errorMessages = $result['errors']; $view->deactivatedPlugins = $result['deactivatedPlugins']; $view->currentVersion = Version::VERSION; $view->oldVersion = $oldVersion; $view->showNextStep = true; return $view->render(); }
private function reportAlreadySent($report, Period $period) { $key = self::OPTION_KEY_LAST_SENT_DATERANGE . $report['idreport']; $previousDate = Option::get($key); return $previousDate === $period->getRangeString(); }