static function update() { // force regeneration of cache files following #648 Piwik::setUserIsSuperUser(); $allSiteIds = Piwik_SitesManager_API::getAllSitesId(); Piwik_Common::regenerateCacheWebsiteAttributes($allSiteIds); }
/** * Returns array containing data about the website: goals, URLs, etc. * * @param int $idSite * @return array */ static function getCacheWebsiteAttributes($idSite) { require_once PIWIK_INCLUDE_PATH . '/core/Loader.php'; static $cache = null; if (is_null($cache)) { $cache = new Piwik_CacheFile('tracker'); } $filename = $idSite; $cacheContent = $cache->get($filename); if ($cacheContent !== false) { return $cacheContent; } if (defined('PIWIK_TRACKER_MODE') && PIWIK_TRACKER_MODE) { require_once PIWIK_INCLUDE_PATH . '/core/PluginsManager.php'; require_once PIWIK_INCLUDE_PATH . '/core/Translate.php'; require_once PIWIK_INCLUDE_PATH . '/core/Option.php'; Zend_Registry::set('db', Piwik_Tracker::getDatabase()); Piwik::createAccessObject(); Piwik::createConfigObject(); Piwik::setUserIsSuperUser(); $pluginsManager = Piwik_PluginsManager::getInstance(); $pluginsManager->setPluginsToLoad(Zend_Registry::get('config')->Plugins->Plugins->toArray()); } $content = array(); Piwik_PostEvent('Common.fetchWebsiteAttributes', $content, $idSite); // if nothing is returned from the plugins, we don't save the content // this is not expected: all websites are expected to have at least one URL if (!empty($content)) { $cache->set($filename, $content); } return $content; }
function test_callableApiMethods_doNotFail() { Piwik::createConfigObject(); Piwik_Config::getInstance()->setTestEnvironment(); Piwik::createLogObject(); Piwik::createAccessObject(); Piwik::createDatabaseObject(); Piwik::setUserIsSuperUser(); Piwik_Translate::getInstance()->loadEnglishTranslation(); $pluginsManager = Piwik_PluginsManager::getInstance(); $pluginsManager->loadPlugins(Piwik_Config::getInstance()->Plugins['Plugins']); Piwik_SitesManager_API::getInstance()->addSite("name", "http://example.org"); $apiGenerator = new Piwik_API_DocumentationGenerator_CallAllMethods(); $requestUrls = $apiGenerator->getAllRequestsWithParameters(); $this->assertTrue(count($requestUrls) > 20); foreach ($requestUrls as $url) { $call = new Piwik_API_Request($url); $output = $call->process(); // var_dump($url); // var_dump($output); $this->assertTrue(!empty($output)); } Piwik_Translate::getInstance()->unloadEnglishTranslation(); $this->pass(); }
static function update() { $obsoleteFiles = array( PIWIK_INCLUDE_PATH . '/core/Db/Mysqli.php', ); foreach($obsoleteFiles as $obsoleteFile) { if(file_exists($obsoleteFile)) { @unlink($obsoleteFile); } } $obsoleteDirectories = array( PIWIK_INCLUDE_PATH . '/core/Db/Pdo', ); foreach($obsoleteDirectories as $dir) { if(file_exists($dir)) { Piwik::unlinkRecursive($dir, true); } } // force regeneration of cache files Piwik::setUserIsSuperUser(); $allSiteIds = Piwik_SitesManager_API::getInstance()->getAllSitesId(); Piwik_Common::regenerateCacheWebsiteAttributes($allSiteIds); }
public static function setUpBeforeClass($dbName = false, $createEmptyDatabase = true, $createConfig = true) { try { Piwik::$piwikUrlCache = ''; if ($createConfig) { self::createTestConfig(); } if ($dbName === false) { $dbName = Piwik_Config::getInstance()->database['dbname']; } self::connectWithoutDatabase(); if ($createEmptyDatabase) { Piwik::dropDatabase(); } Piwik::createDatabase($dbName); Piwik::disconnectDatabase(); // reconnect once we're sure the database exists Piwik_Config::getInstance()->database['dbname'] = $dbName; Piwik::createDatabaseObject(); Piwik::createTables(); Piwik::createLogObject(); Piwik_PluginsManager::getInstance()->loadPlugins(array()); } catch (Exception $e) { self::fail("TEST INITIALIZATION FAILED: " . $e->getMessage()); } include "DataFiles/SearchEngines.php"; include "DataFiles/Languages.php"; include "DataFiles/Countries.php"; include "DataFiles/Currencies.php"; include "DataFiles/LanguageToCountry.php"; Piwik::createAccessObject(); Piwik_PostEvent('FrontController.initAuthenticationObject'); // We need to be SU to create websites for tests Piwik::setUserIsSuperUser(); // Load and install plugins $pluginsManager = Piwik_PluginsManager::getInstance(); $plugins = $pluginsManager->readPluginsDirectory(); $pluginsManager->loadPlugins($plugins); if ($createEmptyDatabase) { $pluginsManager->installLoadedPlugins(); } $_GET = $_REQUEST = array(); $_SERVER['HTTP_REFERER'] = ''; // Make sure translations are loaded to check messages in English Piwik_Translate::getInstance()->loadEnglishTranslation(); Piwik_LanguagesManager_API::getInstance()->setLanguageForUser('superUserLogin', 'en'); // List of Modules, or Module.Method that should not be called as part of the XML output compare // Usually these modules either return random changing data, or are already tested in specific unit tests. self::setApiNotToCall(self::$defaultApiNotToCall); self::setApiToCall(array()); }
public function init() { $this->initCore(); $this->initTokenAuth(); $this->initCheckCli(); $this->initLog(); $this->displayHelp(); $this->initPiwikHost(); $this->initStateFromParameters(); Piwik::setUserIsSuperUser(true); $this->logSection("INIT"); $this->log("Querying Piwik API at: {$this->piwikUrl}"); $this->log("Running as Super User: "******"accept-invalid-ssl-certificate"); // Test the specified piwik URL is valid $response = $this->request("?module=API&method=API.getDefaultMetricTranslations&format=php"); $responseUnserialized = @unserialize($response); if ($response === false || !is_array($responseUnserialized)) { $this->logFatalError("The Piwik URL {$this->piwikUrl} does not seem to be pointing to a Piwik server. Response was '{$response}'."); } $this->log("Notes"); // Information about timeout $this->todayArchiveTimeToLive = Piwik_ArchiveProcessing::getTodayArchiveTimeToLive(); $this->log("- Reports for today will be processed at most every " . Piwik_ArchiveProcessing::getTodayArchiveTimeToLive() . " seconds. You can change this value in Piwik UI > Settings > General Settings."); $this->log("- Reports for the current week/month/year will be refreshed at most every " . $this->processPeriodsMaximumEverySeconds . " seconds."); // Fetching segments to process $this->segments = Piwik_CoreAdminHome_API::getInstance()->getKnownSegmentsToArchive(); if (empty($this->segments)) { $this->segments = array(); } if (!empty($this->segments)) { $this->log("- Segments to pre-process for each website and each period: " . implode(", ", $this->segments)); } // Try and not request older data we know is already archived if ($this->timeLastCompleted !== false) { $dateLast = time() - $this->timeLastCompleted; $this->log("- Archiving was last executed without error " . Piwik::getPrettyTimeFromSeconds($dateLast, true, $isHtml = false) . " ago"); } $this->initWebsitesToProcess(); flush(); }
function test_callableApiMethods_doNotFail() { Piwik::createConfigObject(); Piwik::createLogObject(); Piwik::createAccessObject(); Piwik::createDatabaseObject(); Piwik::setUserIsSuperUser(); $pluginsManager = Piwik_PluginsManager::getInstance(); $pluginsManager->setPluginsToLoad(Zend_Registry::get('config')->Plugins->Plugins->toArray()); $apiGenerator = new Piwik_API_DocumentationGenerator_CallAllMethods(); $requestUrls = $apiGenerator->getAllRequestsWithParameters(); $this->assertTrue(count($requestUrls) > 20); foreach ($requestUrls as $url) { $call = new Piwik_API_Request($url); $output = $call->process(); // var_dump($url); // var_dump($output); $this->assertTrue(!empty($output)); } $this->pass(); }
<?php // force regeneration of cache files following #648 Piwik::setUserIsSuperUser(); $allSiteIds = Piwik_SitesManager_API::getAllSitesId(); Piwik_Common::regenerateCacheWebsiteAttributes($allSiteIds);
/** * Tracker requests will automatically trigger the Scheduled tasks. * This is useful for users who don't setup the cron, * but still want daily/weekly/monthly PDF reports emailed automatically. * * This is similar to calling the API CoreAdminHome.runScheduledTasks (see misc/cron/archive.sh) * * @param int $now Current timestamp */ public static function runScheduledTasks($now) { // Currently, there is no hourly tasks. When there are some, // this could be too agressive minimum interval (some hours would be skipped in case of low traffic) $minimumInterval = Piwik_Config::getInstance()->Tracker['scheduled_tasks_min_interval']; // If the user disabled browser archiving, he has already setup a cron // To avoid parallel requests triggering the Scheduled Tasks, // Get last time tasks started executing $cache = Piwik_Common::getCacheGeneral(); if ($minimumInterval <= 0 || empty($cache['isBrowserTriggerArchivingEnabled'])) { printDebug("-> Scheduled tasks not running in Tracker: Browser archiving is disabled."); return; } $nextRunTime = $cache['lastTrackerCronRun'] + $minimumInterval; if (isset($GLOBALS['PIWIK_TRACKER_DEBUG_FORCE_SCHEDULED_TASKS']) && $GLOBALS['PIWIK_TRACKER_DEBUG_FORCE_SCHEDULED_TASKS'] || $cache['lastTrackerCronRun'] === false || $nextRunTime < $now) { $cache['lastTrackerCronRun'] = $now; Piwik_Common::setCacheGeneral($cache); Piwik_Common::initCorePiwikInTrackerMode(); Piwik_SetOption('lastTrackerCronRun', $cache['lastTrackerCronRun']); printDebug('-> Scheduled Tasks: Starting...'); // save current user privilege and temporarily assume super user privilege $isSuperUser = Piwik::isUserIsSuperUser(); // Scheduled tasks assume Super User is running Piwik::setUserIsSuperUser(); // While each plugins should ensure that necessary languages are loaded, // we ensure English translations at least are loaded Piwik_Translate::getInstance()->loadEnglishTranslation(); $resultTasks = Piwik_TaskScheduler::runTasks(); // restore original user privilege Piwik::setUserIsSuperUser($isSuperUser); printDebug($resultTasks); printDebug('Finished Scheduled Tasks.'); } else { printDebug("-> Scheduled tasks not triggered."); } printDebug("Next run will be from: " . date('Y-m-d H:i:s', $nextRunTime) . ' UTC'); }
/** * Instantiate access and log objects */ protected function initObjectsToCallAPI() { // connect to the database using the DB infos currently in the session $this->createDbFromSessionInformation(); Piwik::createAccessObject(); Piwik::setUserIsSuperUser(); Piwik::createLogObject(); }
/** * Get user information * * @param string $loginMail (user login or email address) * @return array ("login" => '...', "email" => '...', "password" => '...') or null, if user not found */ protected function getUserInformation($loginMail) { Piwik::setUserIsSuperUser(); $user = null; if ($loginMail == Zend_Registry::get('config')->superuser->email || $loginMail == Zend_Registry::get('config')->superuser->login) { $user = array('login' => Zend_Registry::get('config')->superuser->login, 'email' => Zend_Registry::get('config')->superuser->email, 'password' => Zend_Registry::get('config')->superuser->password); } else { if (Piwik_UsersManager_API::getInstance()->userExists($loginMail)) { $user = Piwik_UsersManager_API::getInstance()->getUser($loginMail); } else { if (Piwik_UsersManager_API::getInstance()->userEmailExists($loginMail)) { $user = Piwik_UsersManager_API::getInstance()->getUserByEmail($loginMail); } } } return $user; }
/** * Get user information * * @param string $loginMail user login or email address * @return array ("login" => '...', "email" => '...', "password" => '...') or null, if user not found */ protected function getUserInformation($loginMail) { Piwik::setUserIsSuperUser(); $user = null; if ($loginMail == Piwik::getSuperUserEmail() || $loginMail == Piwik_Config::getInstance()->superuser['login']) { $user = array('login' => Piwik_Config::getInstance()->superuser['login'], 'email' => Piwik::getSuperUserEmail(), 'password' => Piwik_Config::getInstance()->superuser['password']); } else { if (Piwik_UsersManager_API::getInstance()->userExists($loginMail)) { $user = Piwik_UsersManager_API::getInstance()->getUser($loginMail); } else { if (Piwik_UsersManager_API::getInstance()->userEmailExists($loginMail)) { $user = Piwik_UsersManager_API::getInstance()->getUserByEmail($loginMail); } } } return $user; }
protected function lostPasswordFormValidated($loginMail, $urlToRedirect) { Piwik::setUserIsSuperUser(); $user = null; $isSuperUser = false; if ($loginMail == Zend_Registry::get('config')->superuser->email || $loginMail == Zend_Registry::get('config')->superuser->login) { $isSuperUser = true; $user = array('login' => Zend_Registry::get('config')->superuser->login, 'email' => Zend_Registry::get('config')->superuser->email); } else { if (Piwik_UsersManager_API::userExists($loginMail)) { $user = Piwik_UsersManager_API::getUser($loginMail); } else { if (Piwik_UsersManager_API::userEmailExists($loginMail)) { $user = Piwik_UsersManager_API::getUserByEmail($loginMail); } } } if ($user === null) { $messageNoAccess = Piwik_Translate('Login_InvalidUsernameEmail'); } else { $view = new Piwik_View('Login/templates/passwordsent.tpl'); $login = $user['login']; $email = $user['email']; $randomPassword = Piwik_Common::getRandomString(8); if ($isSuperUser) { $user['password'] = md5($randomPassword); Zend_Registry::get('config')->superuser = $user; } else { Piwik_UsersManager_API::updateUser($login, $randomPassword); } // send email with new password try { $mail = new Piwik_Mail(); $mail->addTo($email, $login); $mail->setSubject(Piwik_Translate('Login_MailTopicPasswordRecovery')); $mail->setBodyText(str_replace('\\n', "\n", sprintf(Piwik_Translate('Login_MailPasswordRecoveryBody'), $login, $randomPassword, Piwik_Url::getCurrentUrlWithoutQueryString()))); $piwikHost = $_SERVER['HTTP_HOST']; if (strlen($piwikHost) == 0) { $piwikHost = 'piwik.org'; } $fromEmailName = Zend_Registry::get('config')->General->login_password_recovery_email_name; $fromEmailAddress = Zend_Registry::get('config')->General->login_password_recovery_email_address; $fromEmailAddress = str_replace('{DOMAIN}', $piwikHost, $fromEmailAddress); $mail->setFrom($fromEmailAddress, $fromEmailName); @$mail->send(); } catch (Exception $e) { $view->ErrorString = $e->getMessage(); } $view->linkTitle = Piwik::getRandomTitle(); $view->urlToRedirect = $urlToRedirect; echo $view->render(); } }
/** * Initializes the test * @param $title * @return void */ function __construct($title = '') { parent::__construct($title); if (Test_Integration::$widgetTestingLevel != self::NO_WIDGET_TESTING) { self::initializeControllerTesting(); } Piwik::createAccessObject(); Piwik_PostEvent('FrontController.initAuthenticationObject'); // We need to be SU to create websites for tests Piwik::setUserIsSuperUser(); // Load and install plugins $pluginsManager = Piwik_PluginsManager::getInstance(); $plugins = Piwik_Config::getInstance()->Plugins['Plugins']; $pluginsManager->loadPlugins($plugins); $pluginsManager->installLoadedPlugins(); }
/** * Returns array containing data about the website: goals, URLs, etc. * * @param int $idSite * @return array */ static function getCacheWebsiteAttributes($idSite) { static $cache = null; if (is_null($cache)) { require_once "CacheFile.php"; $cache = new Piwik_CacheFile('tracker'); } $filename = $idSite; $cacheContent = $cache->get($filename); if ($cacheContent !== false) { return $cacheContent; } if (defined('PIWIK_TRACKER_MODE') && PIWIK_TRACKER_MODE) { //TODO we can remove these includes when #620 is done require_once "Zend/Exception.php"; require_once "Zend/Loader.php"; require_once "Zend/Auth.php"; require_once "Timer.php"; require_once "PluginsManager.php"; require_once "Piwik.php"; require_once "Access.php"; require_once "Auth.php"; require_once "API/Proxy.php"; require_once "Archive.php"; require_once "Site.php"; require_once "Date.php"; require_once "DataTable.php"; require_once "Translate.php"; require_once "Mail.php"; require_once "Url.php"; require_once "Controller.php"; require_once "Option.php"; require_once "View.php"; require_once "UpdateCheck.php"; Zend_Registry::set('db', Piwik_Tracker::getDatabase()); Piwik::createAccessObject(); Piwik::createConfigObject(); Piwik::setUserIsSuperUser(); $pluginsManager = Piwik_PluginsManager::getInstance(); $pluginsManager->setPluginsToLoad(Zend_Registry::get('config')->Plugins->Plugins->toArray()); } $content = array(); Piwik_PostEvent('Common.fetchWebsiteAttributes', $content, $idSite); // if nothing is returned from the plugins, we don't save the content // this is not expected: all websites are expected to have at least one URL if (!empty($content)) { $cache->set($filename, $content); } return $content; }
protected function createAccessObject() { parent::createAccessObject(); Piwik::setUserIsSuperUser(true); }