protected static function initCorePiwikInTrackerMode() { static $init = false; if (!empty($GLOBALS['PIWIK_TRACKER_MODE']) && $init === false) { $init = true; require_once PIWIK_INCLUDE_PATH . '/core/Loader.php'; require_once PIWIK_INCLUDE_PATH . '/core/Translate.php'; require_once PIWIK_INCLUDE_PATH . '/core/Option.php'; try { $access = Zend_Registry::get('access'); } catch (Exception $e) { Piwik::createAccessObject(); } try { $config = Zend_Registry::get('config'); } catch (Exception $e) { Piwik::createConfigObject(); } try { $db = Zend_Registry::get('db'); } catch (Exception $e) { Piwik::createDatabaseObject(); } $pluginsManager = Piwik_PluginsManager::getInstance(); $pluginsToLoad = Zend_Registry::get('config')->Plugins->Plugins->toArray(); $pluginsForcedNotToLoad = Piwik_Tracker::getPluginsNotToLoad(); $pluginsToLoad = array_diff($pluginsToLoad, $pluginsForcedNotToLoad); $pluginsManager->loadPlugins($pluginsToLoad); } }
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(); }
/** * 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; }
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()); }
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(); }
/** * 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(); }
/** * Must be called before dispatch() * - checks that directories are writable, * - loads the configuration file, * - loads the plugin, * - inits the DB connection, * - etc. */ function init() { static $initialized = false; if($initialized) { return; } $initialized = true; try { Zend_Registry::set('timer', new Piwik_Timer); $directoriesToCheck = array( '/tmp/', '/tmp/templates_c/', '/tmp/cache/', '/tmp/assets/' ); Piwik::checkDirectoriesWritableOrDie($directoriesToCheck); Piwik_Common::assignCliParametersToRequest(); Piwik_Translate::getInstance()->loadEnglishTranslation(); $exceptionToThrow = false; try { Piwik::createConfigObject(); } catch(Exception $e) { Piwik_PostEvent('FrontController.NoConfigurationFile', $e, $info = array(), $pending = true); $exceptionToThrow = $e; } if(Zend_Registry::get('config')->General->maintenance_mode == 1 && !Piwik_Common::isPhpCliMode()) { throw new Exception("Piwik is in scheduled maintenance. Please come back later."); } $pluginsManager = Piwik_PluginsManager::getInstance(); $pluginsManager->loadPlugins( Zend_Registry::get('config')->Plugins->Plugins->toArray() ); if($exceptionToThrow) { throw $exceptionToThrow; } try { Piwik::createDatabaseObject(); } catch(Exception $e) { Piwik_PostEvent('FrontController.badConfigurationFile', $e, $info = array(), $pending = true); throw $e; } Piwik::createLogObject(); // creating the access object, so that core/Updates/* can enforce Super User and use some APIs Piwik::createAccessObject(); Piwik_PostEvent('FrontController.dispatchCoreAndPluginUpdatesScreen'); Piwik_PluginsManager::getInstance()->installLoadedPlugins(); Piwik::install(); // ensure the current Piwik URL is known for later use if(method_exists('Piwik', 'getPiwikUrl')) { $host = Piwik::getPiwikUrl(); } Piwik_PostEvent('FrontController.initAuthenticationObject'); try { $authAdapter = Zend_Registry::get('auth'); } catch(Exception $e){ throw new Exception("Authentication object cannot be found in the Registry. Maybe the Login plugin is not activated? <br />You can activate the plugin by adding:<br /> <code>Plugins[] = Login</code><br /> under the <code>[Plugins]</code> section in your config/config.inc.php"); } Zend_Registry::get('access')->reloadAccess($authAdapter); Piwik_Translate::getInstance()->reloadLanguage(); Piwik::raiseMemoryLimitIfNecessary(); $pluginsManager->postLoadPlugins(); Piwik_PostEvent('FrontController.checkForUpdates'); } catch(Exception $e) { Piwik_ExitWithMessage($e->getMessage(), false, true); } Piwik::log('End FrontController->init() - Request: '. var_export($_REQUEST, true)); }
/** * Must be called before dispatch() * - checks that directories are writable, * - loads the configuration file, * - loads the plugin, * - inits the DB connection, * - etc. */ function init() { try { Zend_Registry::set('timer', new Piwik_Timer()); $directoriesToCheck = array('/tmp', '/tmp/templates_c', '/tmp/cache'); Piwik::checkDirectoriesWritableOrDie($directoriesToCheck); self::assignCliParametersToRequest(); Piwik_Translate::getInstance()->loadEnglishTranslation(); $exceptionToThrow = false; try { Piwik::createConfigObject(); } catch (Exception $e) { Piwik_PostEvent('FrontController.NoConfigurationFile', $e); $exceptionToThrow = $e; } $pluginsManager = Piwik_PluginsManager::getInstance(); $pluginsManager->setPluginsToLoad(Zend_Registry::get('config')->Plugins->Plugins->toArray()); if ($exceptionToThrow) { throw $exceptionToThrow; } Piwik_Translate::getInstance()->loadUserTranslation(); try { Piwik::createDatabaseObject(); } catch (Exception $e) { Piwik_PostEvent('FrontController.badConfigurationFile', $e); throw $e; } Piwik::createLogObject(); // creating the access object, so that core/Updates/* can enforce Super User and use some APIs Piwik::createAccessObject(); Piwik_PostEvent('FrontController.dispatchCoreAndPluginUpdatesScreen'); Piwik_PluginsManager::getInstance()->installLoadedPlugins(); Piwik::install(); Piwik_PostEvent('FrontController.initAuthenticationObject'); try { $authAdapter = Zend_Registry::get('auth'); } catch (Exception $e) { throw new Exception("Authentication object cannot be found in the Registry. Maybe the Login plugin is not activated?\n\t\t\t\t\t\t\t\t\t<br>You can activate the plugin by adding:<br>\n\t\t\t\t\t\t\t\t\t<code>Plugins[] = Login</code><br>\n\t\t\t\t\t\t\t\t\tunder the <code>[Plugins]</code> section in your config/config.inc.php"); } Zend_Registry::get('access')->reloadAccess($authAdapter); Piwik::raiseMemoryLimitIfNecessary(); $pluginsManager->setLanguageToLoad(Piwik_Translate::getInstance()->getLanguageToLoad()); $pluginsManager->postLoadPlugins(); Piwik_PostEvent('FrontController.checkForUpdates'); } catch (Exception $e) { Piwik_ExitWithMessage($e->getMessage(), $e->getTraceAsString(), true); } }
/** * Must be called before dispatch() * - checks that directories are writable, * - loads the configuration file, * - loads the plugin, * - inits the DB connection, * - etc. */ function init() { static $initialized = false; if ($initialized) { return; } $initialized = true; try { Zend_Registry::set('timer', new Piwik_Timer()); $directoriesToCheck = array('/tmp/', '/tmp/templates_c/', '/tmp/cache/', '/tmp/assets/', '/tmp/tcpdf/'); Piwik::checkDirectoriesWritableOrDie($directoriesToCheck); Piwik_Common::assignCliParametersToRequest(); Piwik_Translate::getInstance()->loadEnglishTranslation(); $exceptionToThrow = false; try { Piwik::createConfigObject(); } catch (Exception $e) { Piwik_PostEvent('FrontController.NoConfigurationFile', $e, $info = array(), $pending = true); $exceptionToThrow = $e; } if (Piwik_Session::isFileBasedSessions()) { Piwik_Session::start(); } if (Piwik_Config::getInstance()->General['maintenance_mode'] == 1 && !Piwik_Common::isPhpCliMode()) { $format = Piwik_Common::getRequestVar('format', ''); $exception = new Exception("Piwik is in scheduled maintenance. Please come back later."); if (empty($format)) { throw $exception; } $response = new Piwik_API_ResponseBuilder($format); echo $response->getResponseException($exception); exit; } if (!Piwik_Common::isPhpCliMode() && Piwik_Config::getInstance()->General['force_ssl'] == 1 && !Piwik::isHttps()) { $url = Piwik_Url::getCurrentUrl(); $url = str_replace("http://", "https://", $url); Piwik_Url::redirectToUrl($url); } $pluginsManager = Piwik_PluginsManager::getInstance(); $pluginsToLoad = Piwik_Config::getInstance()->Plugins['Plugins']; $pluginsManager->loadPlugins($pluginsToLoad); if ($exceptionToThrow) { throw $exceptionToThrow; } try { Piwik::createDatabaseObject(); } catch (Exception $e) { if (self::shouldRethrowException()) { throw $e; } Piwik_PostEvent('FrontController.badConfigurationFile', $e, $info = array(), $pending = true); throw $e; } Piwik::createLogObject(); // creating the access object, so that core/Updates/* can enforce Super User and use some APIs Piwik::createAccessObject(); Piwik_PostEvent('FrontController.dispatchCoreAndPluginUpdatesScreen'); Piwik_PluginsManager::getInstance()->installLoadedPlugins(); Piwik::install(); // ensure the current Piwik URL is known for later use if (method_exists('Piwik', 'getPiwikUrl')) { $host = Piwik::getPiwikUrl(); } Piwik_PostEvent('FrontController.initAuthenticationObject'); try { $authAdapter = Zend_Registry::get('auth'); } catch (Exception $e) { throw new Exception("Authentication object cannot be found in the Registry. Maybe the Login plugin is not activated?\n\t\t\t\t\t\t\t\t\t<br />You can activate the plugin by adding:<br />\n\t\t\t\t\t\t\t\t\t<code>Plugins[] = Login</code><br />\n\t\t\t\t\t\t\t\t\tunder the <code>[Plugins]</code> section in your config/config.ini.php"); } Zend_Registry::get('access')->reloadAccess($authAdapter); Piwik::raiseMemoryLimitIfNecessary(); Piwik_Translate::getInstance()->reloadLanguage(); $pluginsManager->postLoadPlugins(); Piwik_PostEvent('FrontController.checkForUpdates'); } catch (Exception $e) { if (self::shouldRethrowException()) { throw $e; } Piwik_ExitWithMessage($e->getMessage(), false, true); } // Piwik::log('End FrontController->init() - Request: '. var_export($_REQUEST, true)); }
/** * 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() { Piwik::createAccessObject(); }