示例#1
0
 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);
     }
 }
示例#2
0
 /**
  * Setup the database and create the base tables for all tests
  */
 public function setUp()
 {
     parent::setUp();
     try {
         Piwik::createConfigObject();
         Piwik_Config::getInstance()->setTestEnvironment();
         $dbConfig = Piwik_Config::getInstance()->database;
         $dbName = $dbConfig['dbname'];
         $dbConfig['dbname'] = null;
         Piwik::createDatabaseObject($dbConfig);
         Piwik::dropDatabase();
         Piwik::createDatabase($dbName);
         Piwik::disconnectDatabase();
         Piwik::createDatabaseObject();
         Piwik::createTables();
         Piwik::createLogObject();
         Piwik_PluginsManager::getInstance()->loadPlugins(array());
     } catch (Exception $e) {
         $this->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";
 }
 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();
 }
 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());
 }
示例#5
0
 function __construct($title = '')
 {
     parent::__construct($title);
     print "The test class extends Test_Database: the test Piwik database is created once in the constructor, and all tables are truncated at the end of EACH unit test method.<br>";
     Piwik::createConfigObject();
     Piwik::createDatabaseObject();
     Zend_Registry::get('config')->setTestEnvironment();
     Zend_Registry::get('config')->disableSavingConfigurationFileUpdates();
     Piwik::createLogObject();
     Piwik::dropDatabase();
     Piwik::createDatabase();
     Piwik::disconnectDatabase();
     Piwik::createDatabaseObject();
     Piwik::createTables();
 }
示例#6
0
 function __construct($title = '')
 {
     parent::__construct($title);
     try {
         Piwik::createConfigObject();
         Piwik_Config::getInstance()->setTestEnvironment();
         Piwik::createDatabaseObject();
         Piwik::createLogObject();
         Piwik::dropDatabase();
         Piwik::createDatabase();
         Piwik::disconnectDatabase();
         Piwik::createDatabaseObject();
         Piwik::createTables();
         Piwik_PluginsManager::getInstance()->installLoadedPlugins();
     } catch (Exception $e) {
         echo $e->getMessage();
         echo "<br/><b>TEST INITIALIZATION FAILED!";
         throw $e;
     }
 }
 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();
 }
示例#8
0
 /**
  * Creates database object based on form data.
  * 
  * @return array The database connection info. Can be passed into Piwik::createDatabaseObject.
  */
 public function createDatabaseObject()
 {
     $dbname = $this->getSubmitValue('dbname');
     if (empty($dbname)) {
         throw new Exception("No database name");
     }
     $adapter = $this->getSubmitValue('adapter');
     $port = Piwik_Db_Adapter::getDefaultPortForAdapter($adapter);
     $dbInfos = array('host' => $this->getSubmitValue('host'), 'username' => $this->getSubmitValue('username'), 'password' => $this->getSubmitValue('password'), 'dbname' => $dbname, 'tables_prefix' => $this->getSubmitValue('tables_prefix'), 'adapter' => $adapter, 'port' => $port);
     if (($portIndex = strpos($dbInfos['host'], '/')) !== false) {
         // unix_socket=/path/sock.n
         $dbInfos['port'] = substr($dbInfos['host'], $portIndex);
         $dbInfos['host'] = '';
     } else {
         if (($portIndex = strpos($dbInfos['host'], ':')) !== false) {
             // host:port
             $dbInfos['port'] = substr($dbInfos['host'], $portIndex + 1);
             $dbInfos['host'] = substr($dbInfos['host'], 0, $portIndex);
         }
     }
     try {
         @Piwik::createDatabaseObject($dbInfos);
     } catch (Zend_Db_Adapter_Exception $e) {
         $db = Piwik_Db_Adapter::factory($adapter, $dbInfos, $connect = false);
         // database not found, we try to create  it
         if ($db->isErrNo($e, '1049')) {
             $dbInfosConnectOnly = $dbInfos;
             $dbInfosConnectOnly['dbname'] = null;
             @Piwik::createDatabaseObject($dbInfosConnectOnly);
             @Piwik::createDatabase($dbInfos['dbname']);
             // select the newly created database
             @Piwik::createDatabaseObject($dbInfos);
         } else {
             throw $e;
         }
     }
     return $dbInfos;
 }
示例#9
0
 /**
  * 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));
 }
示例#11
0
 /**
  * Must be called before dispatch()
  * - checks that directories are writable,
  * - loads the configuration file,
  * - loads the plugin,
  * - inits the DB connection,
  * - etc.
  * @throws Exception
  * @throws Exception
  * @throws bool|Exception
  * @return
  */
 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 = $this->createConfigObject();
         if (Piwik_Session::isFileBasedSessions()) {
             Piwik_Session::start();
         }
         $this->handleMaintenanceMode();
         $this->handleSSLRedirection();
         $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
         $this->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);
         // Force the auth to use the token_auth if specified, so that embed dashboard
         // and all other non widgetized controller methods works fine
         if (($token_auth = Piwik_Common::getRequestVar('token_auth', false, 'string')) !== false) {
             Piwik_API_Request::reloadAuthUsingTokenAuth();
         }
         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));
 }
 /**
  * Create database connection from session-store
  */
 protected function createDbFromSessionInformation()
 {
     $dbInfos = $this->session->db_infos;
     Piwik_Config::getInstance()->database = $dbInfos;
     Piwik::createDatabaseObject($dbInfos);
 }
示例#13
0
 protected function createDbFromSessionInformation()
 {
     $session = new Zend_Session_Namespace("Installation");
     $dbInfos = $session->db_infos;
     Zend_Registry::get('config')->disableSavingConfigurationFileUpdates();
     Zend_Registry::get('config')->database = $dbInfos;
     Piwik::createDatabaseObject($dbInfos);
 }
示例#14
0
 public function isTestDatabasePresent()
 {
     try {
         Piwik::createConfigObject();
         Piwik_Config::getInstance()->setTestEnvironment();
         Piwik::createDatabaseObject();
         Piwik::disconnectDatabase();
         return true;
     } catch (Exception $e) {
         return false;
     }
 }
示例#15
0
 /**
  * Overwrite the global GET/POST/COOKIE variables and set the fake ones @see setFakeRequest()
  * Reads the configuration file but disables write to this file
  * Creates the database object & enable profiling by default (@see disableProfiler())
  *
  */
 public function __construct()
 {
     $_COOKIE = $_GET = $_POST = array();
     // init GET and REQUEST to the empty array
     $this->setFakeRequest();
     Piwik::createConfigObject(PIWIK_INCLUDE_PATH . '/config/config.ini.php');
     Zend_Registry::get('config')->disableSavingConfigurationFileUpdates();
     // setup database
     Piwik::createDatabaseObject();
     Piwik_Tracker_Db::enableProfiling();
     $this->timestampToUse = time();
 }
	/**
	 * 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));
	}
示例#17
0
 /**
  * Overwrite the global GET/POST/COOKIE variables and set the fake ones @see setFakeRequest()
  * Reads the configuration file but disables write to this file
  * Creates the database object & enable profiling by default (@see disableProfiler())
  *
  */
 public function __construct()
 {
     $_COOKIE = $_GET = $_REQUEST = $_POST = array();
     // init GET and REQUEST to the empty array
     $this->setFakeRequest();
     require_once "modules/Piwik.php";
     Piwik::createConfigObject('../config/config.ini.php');
     Zend_Registry::get('config')->doWriteFileWhenUpdated = false;
     // setup database
     Piwik::createDatabaseObject();
     Piwik_LogStats_Db::enableProfiling();
     $this->timestampToUse = time();
 }
示例#18
0
	/**
	 * Create database connection from session-store
	 */
	protected function createDbFromSessionInformation()
	{
		$dbInfos = $this->session->db_infos;
		Zend_Registry::get('config')->disableSavingConfigurationFileUpdates();
		Zend_Registry::get('config')->database = $dbInfos;
		Piwik::createDatabaseObject($dbInfos);
	}
示例#19
0
 /**
  * Must be called before dispatch()
  * - checks that directories are writable,
  * - loads the configuration file,
  * - loads the plugin, 
  * - inits the DB connection,
  * - etc.
  * 
  * @return void 
  */
 function init()
 {
     Zend_Registry::set('timer', new Piwik_Timer());
     $this->checkDirectoriesWritableOrDie();
     $this->assignCliParametersToRequest();
     $exceptionToThrow = false;
     //move into a init() method
     try {
         Piwik::createConfigObject();
     } catch (Exception $e) {
         Piwik_PostEvent('FrontController.NoConfigurationFile', $e);
         $exceptionToThrow = $e;
     }
     Piwik::loadPlugins();
     if ($exceptionToThrow) {
         throw $exceptionToThrow;
     }
     // database object
     Piwik::createDatabaseObject();
     // Create the log objects
     Piwik::createLogObject();
     Piwik::terminateLoadPlugins();
     Piwik::install();
     //		Piwik::printMemoryUsage('Start program');
     // can be used for debug purpose
     $doNotDrop = array(Piwik::prefixTable('access'), Piwik::prefixTable('user'), Piwik::prefixTable('site'), Piwik::prefixTable('archive'), Piwik::prefixTable('logger_api_call'), Piwik::prefixTable('logger_error'), Piwik::prefixTable('logger_exception'), Piwik::prefixTable('logger_message'), Piwik::prefixTable('log_visit'), Piwik::prefixTable('log_link_visit_action'), Piwik::prefixTable('log_action'), Piwik::prefixTable('log_profiling'));
     // Setup the auth object
     Piwik_PostEvent('FrontController.authSetCredentials');
     try {
         $authAdapter = Zend_Registry::get('auth');
     } catch (Exception $e) {
         throw new Exception("Object 'auth' cannot be found in the Registry. Maybe the Login plugin is not enabled?\r\n\t\t\t\t\t\t\t\t<br>You can enable the plugin by adding:<br>\r\n\t\t\t\t\t\t\t\t<code>Plugins[] = Login</code><br>\r\n\t\t\t\t\t\t\t\tunder the <code>[Plugins]</code> section in your config/config.inc.php");
     }
     // Perform the authentication query, saving the result
     $access = new Piwik_Access($authAdapter);
     Zend_Registry::set('access', $access);
     Zend_Registry::get('access')->loadAccess();
     Piwik::raiseMemoryLimitIfNecessary();
 }