示例#1
0
	static function update()
	{
		$sqlarray = array(
			'ALTER TABLE `'. Piwik::prefixTable('log_visit') .'`
				ADD `visit_goal_converted` VARCHAR( 1 ) NOT NULL AFTER `visit_total_time`' => false,
			// 0.2.27 [826]
			'ALTER IGNORE TABLE `'. Piwik::prefixTable('log_visit') .'`
				CHANGE `visit_goal_converted` `visit_goal_converted` TINYINT(1) NOT NULL' => false,
		);

		$tables = Piwik::getTablesCreateSql();
		$sqlarray[ $tables['log_conversion'] ] = false;
		$sqlarray[ $tables['goal'] ] = false;

		$tables = Piwik::getTablesInstalled();
		foreach($tables as $tableName)
		{
			if(preg_match('/archive_/', $tableName) == 1)
			{
				$sqlarray[ 'CREATE INDEX index_all ON '. $tableName .' (`idsite`,`date1`,`date2`,`name`,`ts_archived`)' ] = false;
			}
		}

		Piwik_Updater::updateDatabase(__FILE__, $sqlarray);
	}
示例#2
0
    static function getSql($schema = 'Myisam')
    {
        $sqlarray = array('ALTER TABLE `' . Piwik_Common::prefixTable('log_visit') . '`
				ADD `visit_goal_converted` VARCHAR( 1 ) NOT NULL AFTER `visit_total_time`' => false, 'ALTER IGNORE TABLE `' . Piwik_Common::prefixTable('log_visit') . '`
				CHANGE `visit_goal_converted` `visit_goal_converted` TINYINT(1) NOT NULL' => false, 'CREATE TABLE `' . Piwik_Common::prefixTable('goal') . "` (\n\t\t\t\t`idsite` int(11) NOT NULL,\n\t\t\t\t`idgoal` int(11) NOT NULL,\n\t\t\t\t`name` varchar(50) NOT NULL,\n\t\t\t\t`match_attribute` varchar(20) NOT NULL,\n\t\t\t\t`pattern` varchar(255) NOT NULL,\n\t\t\t\t`pattern_type` varchar(10) NOT NULL,\n\t\t\t\t`case_sensitive` tinyint(4) NOT NULL,\n\t\t\t\t`revenue` float NOT NULL,\n\t\t\t\t`deleted` tinyint(4) NOT NULL default '0',\n\t\t\t\tPRIMARY KEY  (`idsite`,`idgoal`)\n\t\t\t)" => false, 'CREATE TABLE `' . Piwik_Common::prefixTable('log_conversion') . '` (
				`idvisit` int(10) unsigned NOT NULL,
				`idsite` int(10) unsigned NOT NULL,
				`visitor_idcookie` char(32) NOT NULL,
				`server_time` datetime NOT NULL,
				`visit_server_date` date NOT NULL,
				`idaction` int(11) NOT NULL,
				`idlink_va` int(11) NOT NULL,
				`referer_idvisit` int(10) unsigned default NULL,
				`referer_visit_server_date` date default NULL,
				`referer_type` int(10) unsigned default NULL,
				`referer_name` varchar(70) default NULL,
				`referer_keyword` varchar(255) default NULL,
				`visitor_returning` tinyint(1) NOT NULL,
				`location_country` char(3) NOT NULL,
				`location_continent` char(3) NOT NULL,
				`url` text NOT NULL,
				`idgoal` int(10) unsigned NOT NULL,
				`revenue` float default NULL,
				PRIMARY KEY  (`idvisit`,`idgoal`),
				KEY `index_idsite_date` (`idsite`,`visit_server_date`)
			)' => false);
        $tables = Piwik::getTablesInstalled();
        foreach ($tables as $tableName) {
            if (preg_match('/archive_/', $tableName) == 1) {
                $sqlarray['CREATE INDEX index_all ON ' . $tableName . ' (`idsite`,`date1`,`date2`,`name`,`ts_archived`)'] = false;
            }
        }
        return $sqlarray;
    }
	protected function checkTableExists()
	{
		if(is_null(self::$tablesAlreadyInstalled))
		{
			self::$tablesAlreadyInstalled = Piwik::getTablesInstalled($forceReload = false);
		}
		
		if(!in_array($this->generatedTableName, self::$tablesAlreadyInstalled))
		{
			$db = Zend_Registry::get('db');
			$sql = Piwik::getTableCreateSql($this->tableName);
			
			$config = Zend_Registry::get('config');
			$prefixTables = $config->database->tables_prefix;
			$sql = str_replace( $prefixTables . $this->tableName, $this->generatedTableName, $sql);
			try {
				$db->query( $sql );
			} catch(Exception $e) {
				// mysql error 1050: table already exists
				if(! $db->isErrNo($e, '1050'))
				{
					// failed for some other reason
					throw $e;
				}
			}
			
			self::$tablesAlreadyInstalled[] = $this->generatedTableName;
		}
	}
示例#4
0
 public static function getAllTablesStatus()
 {
     Piwik::checkUserIsSuperUser();
     $db = Zend_Registry::get('db');
     // http://dev.mysql.com/doc/refman/5.1/en/show-table-status.html
     $tablesPiwik = Piwik::getTablesInstalled();
     $total = array('Name' => 'Total', 'Data_length' => 0, 'Index_length' => 0, 'Rows' => 0);
     $table = array();
     foreach ($tablesPiwik as $tableName) {
         $t = self::getTableStatus($tableName);
         $total['Data_length'] += $t['Data_length'];
         $total['Index_length'] += $t['Index_length'];
         $total['Rows'] += $t['Rows'];
         $t['Total_length'] = Piwik::getPrettySizeFromBytes($t['Index_length'] + $t['Data_length']);
         $t['Data_length'] = Piwik::getPrettySizeFromBytes($t['Data_length']);
         $t['Index_length'] = Piwik::getPrettySizeFromBytes($t['Index_length']);
         $t['Rows'] = Piwik::getPrettySizeFromBytes($t['Rows']);
         $table[] = $t;
     }
     $total['Total_length'] = Piwik::getPrettySizeFromBytes($total['Data_length'] + $total['Index_length']);
     $total['Data_length'] = Piwik::getPrettySizeFromBytes($total['Data_length']);
     $total['Index_length'] = Piwik::getPrettySizeFromBytes($total['Index_length']);
     $total['TotalRows'] = Piwik::getPrettySizeFromBytes($total['Rows']);
     $table['Total'] = $total;
     return $table;
 }
示例#5
0
文件: 0.2.33.php 项目: ntulip/piwik
    static function update()
    {
        // alter table to set the utf8 collation
        $tablesToAlter = Piwik::getTablesInstalled(true);
        foreach ($tablesToAlter as $table) {
            $sqlarray['ALTER TABLE `' . $table . '`
				CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci '] = false;
        }
        Piwik_Updater::updateDatabase(__FILE__, $sqlarray);
    }
示例#6
0
 function optimizeArchiveTable()
 {
     $tablesPiwik = Piwik::getTablesInstalled();
     $archiveTables = array_filter($tablesPiwik, array("Piwik_CoreAdminHome", "isArchiveTable"));
     if (empty($archiveTables)) {
         return;
     }
     $query = "OPTIMIZE TABLE " . implode(",", $archiveTables);
     Piwik_Query($query);
 }
示例#7
0
    static function getSql($schema = 'Myisam')
    {
        $sqlarray = array('ALTER TABLE `' . Piwik_Common::prefixTable('user_dashboard') . '`
				CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci ' => '1146', 'ALTER TABLE `' . Piwik_Common::prefixTable('user_language') . '`
				CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci ' => '1146');
        // alter table to set the utf8 collation
        $tablesToAlter = Piwik::getTablesInstalled(true);
        foreach ($tablesToAlter as $table) {
            $sqlarray['ALTER TABLE `' . $table . '`
				CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci '] = false;
        }
        return $sqlarray;
    }
 /**
  * test daily
  * @group Core
  * @group TablePartitioning
  */
 public function testDailyPartition()
 {
     $tableName = 'archive_numeric';
     $p = new Piwik_TablePartitioning_Daily($tableName);
     $timestamp = strtotime("10 September 2000");
     $suffixShouldBe = "_2000_09_10";
     $prefixTables = Piwik_Config::getInstance()->database['tables_prefix'];
     $tablename = $prefixTables . $tableName . $suffixShouldBe;
     $p->setTimestamp($timestamp);
     $allTablesInstalled = Piwik::getTablesInstalled();
     $this->assertContains($tablename, $allTablesInstalled);
     $this->assertEquals($tablename, $p->getTableName());
     $this->assertEquals($tablename, (string) $p->__toString());
 }
示例#9
0
 static function getSql()
 {
     $sqlarray = array('DROP INDEX index_idsite_date ON ' . Piwik::prefixTable('log_visit') => '1091', 'CREATE INDEX index_idsite_date_config ON ' . Piwik::prefixTable('log_visit') . ' (idsite, visit_server_date, config_md5config(8))' => '1061');
     $tables = Piwik::getTablesInstalled();
     foreach ($tables as $tableName) {
         if (preg_match('/archive_/', $tableName) == 1) {
             $sqlarray['DROP INDEX index_all ON ' . $tableName] = '1091';
         }
         if (preg_match('/archive_numeric_/', $tableName) == 1) {
             $sqlarray['CREATE INDEX index_idsite_dates_period ON ' . $tableName . ' (idsite, date1, date2, period)'] = '1061';
         }
     }
     return $sqlarray;
 }
示例#10
0
 protected function checkTableExists()
 {
     if (is_null(self::$tablesAlreadyInstalled)) {
         self::$tablesAlreadyInstalled = Piwik::getTablesInstalled($forceReload = false);
     }
     if (!in_array($this->generatedTableName, self::$tablesAlreadyInstalled)) {
         $db = Zend_Registry::get('db');
         $sql = Piwik::getTableCreateSql($this->tableName);
         $config = Zend_Registry::get('config');
         $prefixTables = $config->database->tables_prefix;
         $sql = str_replace($prefixTables . $this->tableName, $this->generatedTableName, $sql);
         $db->query($sql);
         self::$tablesAlreadyInstalled[] = $this->generatedTableName;
     }
 }
示例#11
0
 function test_dailyPartition()
 {
     $tableName = 'archive_numeric';
     $p = new Piwik_TablePartitioning_Daily($tableName);
     $timestamp = strtotime("10 September 2000");
     $suffixShouldBe = "_2000_09_10";
     $config = Zend_Registry::get('config');
     $prefixTables = $config->database->tables_prefix;
     $tablename = $prefixTables . $tableName . $suffixShouldBe;
     $p->setTimestamp($timestamp);
     $allTablesInstalled = Piwik::getTablesInstalled();
     $this->assertTrue(in_array($tablename, $allTablesInstalled));
     $this->assertTrue($tablename, $p->getTableName());
     $this->assertEqual($tablename, (string) $p);
 }
示例#12
0
    static function getSql($schema = 'Myisam')
    {
        $sqlarray = array('ALTER TABLE `' . Piwik_Common::prefixTable('log_visit') . '`
				ADD `visit_goal_converted` VARCHAR( 1 ) NOT NULL AFTER `visit_total_time`' => false, 'ALTER IGNORE TABLE `' . Piwik_Common::prefixTable('log_visit') . '`
				CHANGE `visit_goal_converted` `visit_goal_converted` TINYINT(1) NOT NULL' => false);
        $tables = Piwik::getTablesCreateSql();
        $sqlarray[$tables['log_conversion']] = false;
        $sqlarray[$tables['goal']] = false;
        $tables = Piwik::getTablesInstalled();
        foreach ($tables as $tableName) {
            if (preg_match('/archive_/', $tableName) == 1) {
                $sqlarray['CREATE INDEX index_all ON ' . $tableName . ' (`idsite`,`date1`,`date2`,`name`,`ts_archived`)'] = false;
            }
        }
        return $sqlarray;
    }
示例#13
0
 public function tearDown()
 {
     parent::tearDown();
     Piwik::$lockPrivilegeGranted = null;
     // remove archive tables (integration test teardown will only truncate)
     $archiveTables = $this->getArchiveTableNames();
     $archiveTables = array_merge($archiveTables['numeric'], $archiveTables['blob']);
     foreach ($archiveTables as $table) {
         Piwik_Query("DROP TABLE IF EXISTS " . Piwik_Common::prefixTable($table));
     }
     // refresh table name caches so next test will pass
     Piwik_TablePartitioning::$tablesAlreadyInstalled = null;
     Piwik::getTablesInstalled(true);
     // drop temporary tables
     $tempTableName = Piwik_PrivacyManager_LogDataPurger::TEMP_TABLE_NAME;
     Piwik_Query("DROP TABLE IF EXISTS " . Piwik_Common::prefixTable($tempTableName));
 }
示例#14
0
	static function update()
	{
		$sqlarray = array(
			// 0.2.33 [1020]
			'ALTER TABLE `'. Piwik::prefixTable('user_dashboard') .'`
				CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci ' => '1146',
			'ALTER TABLE `'. Piwik::prefixTable('user_language') .'`
				CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci ' => '1146',
		);

		// alter table to set the utf8 collation
		$tablesToAlter = Piwik::getTablesInstalled(true);
		foreach($tablesToAlter as $table) {
			$sqlarray[ 'ALTER TABLE `'. $table .'`
				CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci ' ] = false;
		}

		Piwik_Updater::updateDatabase(__FILE__, $sqlarray);
	}
示例#15
0
 /**
  * Gets the result of a SHOW TABLE STATUS query for every Piwik table in the DB.
  * Non-piwik tables are ignored.
  * 
  * @param string $matchingRegex Regex used to filter out tables whose name doesn't
  *                              match it.
  * @return array The table information. See http://dev.mysql.com/doc/refman/5.5/en/show-table-status.html
  *               for specifics.
  */
 public function getAllTablesStatus($matchingRegex = null)
 {
     if (is_null($this->tableStatuses)) {
         $tablesPiwik = Piwik::getTablesInstalled();
         $this->tableStatuses = array();
         foreach (Piwik_FetchAll("SHOW TABLE STATUS") as $t) {
             if (in_array($t['Name'], $tablesPiwik)) {
                 $this->tableStatuses[$t['Name']] = $t;
             }
         }
     }
     if (is_null($matchingRegex)) {
         return $this->tableStatuses;
     }
     $result = array();
     foreach ($this->tableStatuses as $status) {
         if (preg_match($matchingRegex, $status['Name'])) {
             $result[] = $status;
         }
     }
     return $result;
 }
示例#16
0
 /**
  * Utility function that finds every archive table whose reports are considered
  * old.
  * 
  * @return array An array of two arrays. The first holds the numeric archive table
  *               names, and the second holds the blob archive table names.
  */
 private function getArchiveTablesToPurge()
 {
     // get month for which reports as old or older than, should be deleted
     // reports whose creation date <= this month will be deleted
     // (NOTE: we ignore how far we are in the current month)
     $toRemoveDate = Piwik_Date::factory('today')->subMonth(1 + $this->deleteReportsOlderThan);
     $toRemoveYear = (int) $toRemoveDate->toString('Y');
     $toRemoveMonth = (int) $toRemoveDate->toString('m');
     // find all archive tables that are older than N months
     $oldNumericTables = array();
     $oldBlobTables = array();
     foreach (Piwik::getTablesInstalled() as $table) {
         if (preg_match("/archive_(numeric|blob)_([0-9]+)_([0-9]+)/", $table, $matches)) {
             $type = $matches[1];
             $year = (int) $matches[2];
             $month = (int) $matches[3];
             if (self::shouldReportBePurged($year, $month, $toRemoveDate)) {
                 if ($type == "numeric") {
                     $oldNumericTables[] = $table;
                 } else {
                     $oldBlobTables[] = $table;
                 }
             }
         }
     }
     return array($oldNumericTables, $oldBlobTables);
 }
示例#17
0
 function tablesCreation()
 {
     $this->checkPreviousStepIsValid(__FUNCTION__);
     $view = new Piwik_Installation_View($this->pathView . 'tablesCreation.tpl', $this->getInstallationSteps(), __FUNCTION__);
     $session = new Zend_Session_Namespace("Installation");
     $this->skipThisStep(__FUNCTION__);
     $this->createDbFromSessionInformation();
     if (Piwik_Common::getRequestVar('deleteTables', 0, 'int') == 1) {
         Piwik::dropTables();
         $view->existingTablesDeleted = true;
         // when the user decides to drop the tables then we dont skip the next steps anymore
         $session->skipThisStep['firstWebsiteSetup'] = false;
         $session->skipThisStep['displayJavascriptCode'] = false;
     }
     $tablesInstalled = Piwik::getTablesInstalled();
     $tablesToInstall = Piwik::getTablesNames();
     $view->tablesInstalled = '';
     if (count($tablesInstalled) > 0) {
         $view->tablesInstalled = implode(", ", $tablesInstalled);
         $view->someTablesInstalled = true;
         $minimumCountPiwikTables = 14;
         if (count($tablesInstalled) >= $minimumCountPiwikTables) {
             $view->showReuseExistingTables = true;
             // when the user reuses the same tables we skip the website creation step
             $session->skipThisStep['firstWebsiteSetup'] = true;
             $session->skipThisStep['displayJavascriptCode'] = true;
         }
     } else {
         Piwik::createTables();
         Piwik::createAnonymousUser();
         require_once "Updater.php";
         $updater = new Piwik_Updater();
         $updater->recordComponentSuccessfullyUpdated('core', Piwik_Version::VERSION);
         $view->tablesCreated = true;
         $view->showNextStep = true;
     }
     if (isset($session->databaseCreated) && $session->databaseCreated === true) {
         $view->databaseName = $session->db_infos['dbname'];
         $view->databaseCreated = true;
         unset($session->databaseCreated);
     }
     $session->currentStepDone = __FUNCTION__;
     echo $view->render();
 }
示例#18
0
	/**
	 * Installation Step 5: Table Creation
	 */
	function tablesCreation()
	{
		$this->checkPreviousStepIsValid( __FUNCTION__ );

		$view = new Piwik_Installation_View(
						$this->pathView . 'tablesCreation.tpl',
						$this->getInstallationSteps(),
						__FUNCTION__
					);
		$this->skipThisStep( __FUNCTION__ );
		$this->createDbFromSessionInformation();

		if(Piwik_Common::getRequestVar('deleteTables', 0, 'int') == 1)
		{
			Piwik::dropTables();
			$view->existingTablesDeleted = true;

			// when the user decides to drop the tables then we dont skip the next steps anymore
			// workaround ZF-1743
			$tmp = $this->session->skipThisStep;
			$tmp['firstWebsiteSetup'] = false;
			$tmp['displayJavascriptCode'] = false;
			$this->session->skipThisStep = $tmp;
		}

		$tablesInstalled = Piwik::getTablesInstalled();
		$tablesToInstall = Piwik::getTablesNames();
		$view->tablesInstalled = '';
		if(count($tablesInstalled) > 0)
		{
			// we have existing tables
			$view->tablesInstalled = implode(', ', $tablesInstalled);
			$view->someTablesInstalled = true;

			$minimumCountPiwikTables = 18;
			$baseTablesInstalled = preg_grep('/archive_numeric|archive_blob/', $tablesInstalled, PREG_GREP_INVERT);

			Piwik::createAccessObject();
			Piwik::setUserIsSuperUser();

			if(count($baseTablesInstalled) >= $minimumCountPiwikTables &&
				count(Piwik_SitesManager_API::getInstance()->getAllSitesId()) > 0 &&
				count(Piwik_UsersManager_API::getInstance()->getUsers()) > 0)
			{
				$view->showReuseExistingTables = true;
				// when the user reuses the same tables we skip the website creation step
				// workaround ZF-1743
				$tmp = $this->session->skipThisStep;
				$tmp['firstWebsiteSetup'] = true;
				$tmp['displayJavascriptCode'] = true;
				$this->session->skipThisStep = $tmp;
			}
		}
		else
		{
			Piwik::createTables();
			Piwik::createAnonymousUser();

			$updater = new Piwik_Updater();
			$updater->recordComponentSuccessfullyUpdated('core', Piwik_Version::VERSION);
			$view->tablesCreated = true;
			$view->showNextStep = true;
		}

		$this->session->currentStepDone = __FUNCTION__;
		echo $view->render();
	}
示例#19
0
 private function doWelcomeUpdates($view, $componentsWithUpdateFile)
 {
     $view->new_piwik_version = Piwik_Version::VERSION;
     $pluginNamesToUpdate = array();
     $coreToUpdate = false;
     // handle case of existing database with no tables
     $tablesInstalled = Piwik::getTablesInstalled();
     if (count($tablesInstalled) == 0) {
         $this->errorMessages[] = Piwik_Translate('CoreUpdater_EmptyDatabaseError', Zend_Registry::get('config')->database->dbname);
         $this->coreError = true;
         $currentVersion = 'N/A';
     } else {
         $this->errorMessages = array();
         try {
             $currentVersion = Piwik_GetOption('version_core');
         } catch (Exception $e) {
             $currentVersion = '<= 0.2.9';
         }
         foreach ($componentsWithUpdateFile as $name => $filenames) {
             if ($name == 'core') {
                 $coreToUpdate = true;
             } else {
                 $pluginNamesToUpdate[] = $name;
             }
         }
     }
     $view->coreError = $this->coreError;
     $view->errorMessages = $this->errorMessages;
     $view->current_piwik_version = $currentVersion;
     $view->pluginNamesToUpdate = $pluginNamesToUpdate;
     $view->coreToUpdate = $coreToUpdate;
     $view->clearCompiledTemplates();
     echo $view->render();
 }
示例#20
0
 /**
  * Truncates all tables then inserts the data in $tables into each
  * mapped table.
  * 
  * @param array $tables Array mapping table names with arrays of row data.
  */
 protected static function restoreDbTables($tables)
 {
     // truncate existing tables
     Piwik::truncateAllTables();
     // insert data
     $existingTables = Piwik::getTablesInstalled();
     foreach ($tables as $table => $rows) {
         // create table if it's an archive table
         if (strpos($table, 'archive_') !== false && !in_array($table, $existingTables)) {
             $tableType = strpos($table, 'archive_numeric') !== false ? 'archive_numeric' : 'archive_blob';
             $createSql = Piwik::getTableCreateSql($tableType);
             $createSql = str_replace(Piwik_Common::prefixTable($tableType), $table, $createSql);
             Piwik_Query($createSql);
         }
         if (empty($rows)) {
             continue;
         }
         $rowsSql = array();
         foreach ($rows as $row) {
             $values = array();
             foreach ($row as $name => $value) {
                 if (is_null($value)) {
                     $values[] = 'NULL';
                 } else {
                     if (is_numeric($value)) {
                         $values[] = $value;
                     } else {
                         if (!ctype_print($value)) {
                             $values[] = "x'" . bin2hex(substr($value, 1)) . "'";
                         } else {
                             $values[] = "'{$value}'";
                         }
                     }
                 }
             }
             $rowsSql[] = "(" . implode(',', $values) . ")";
         }
         $sql = "INSERT INTO {$table} VALUES " . implode(',', $rowsSql);
         Piwik_Query($sql);
     }
 }
示例#21
0
<?php

Piwik_Query("ALTER TABLE `" . Piwik::prefixTable('log_visit') . "` \n\t\t\tADD `visit_goal_converted` VARCHAR( 1 ) NOT NULL AFTER `visit_total_time` ;");
$tables = Piwik::getTablesCreateSql();
Piwik_Query($tables['log_conversion']);
Piwik_Query($tables['goal']);
$allTablesInstalled = Piwik::getTablesInstalled();
foreach ($allTablesInstalled as $tableName) {
    if (preg_match('/archive_/', $tableName) == 1) {
        Piwik_Query('CREATE INDEX index_all 
				ON ' . $tableName . ' (`idsite`,`date1`,`date2`,`name`,`ts_archived`)');
    }
}
示例#22
0
 /**
  * When tracking data in the past (using Tracking API), this function
  * can be used to invalidate reports for the idSites and dates where new data
  * was added. 
  * DEV: If you call this API, the UI should display the data correctly, but will process
  *      in real time, which could be very slow after large data imports. 
  *      After calling this function via REST, you can manually force all data 
  *      to be reprocessed by visiting the script as the Super User:
  *      http://example.net/piwik/misc/cron/archive.php?token_auth=$SUPER_USER_TOKEN_AUTH_HERE 
  * REQUIREMENTS: On large piwik setups, you will need in PHP configuration: max_execution_time = 0
  * 	We recommend to use an hourly schedule of the script at misc/cron/archive.php 
  * 	More information: http://piwik.org/setup-auto-archiving/
  * 
  * @param string $idSites Comma separated list of idSite that have had data imported for the specified dates
  * @param string $dates Comma separated list of dates to invalidate for all these websites
  * @return array
  */
 public function invalidateArchivedReports($idSites, $dates)
 {
     $idSites = Piwik_Site::getIdSitesFromIdSitesString($idSites);
     if (empty($idSites)) {
         throw new Exception("Specify a value for &idSites= as a comma separated list of website IDs, for which your token_auth has 'admin' permission");
     }
     Piwik::checkUserHasAdminAccess($idSites);
     // Ensure the specified dates are valid
     $toInvalidate = $invalidDates = array();
     $dates = explode(',', $dates);
     $dates = array_unique($dates);
     foreach ($dates as $theDate) {
         try {
             $date = Piwik_Date::factory($theDate);
         } catch (Exception $e) {
             $invalidDates[] = $theDate;
             continue;
         }
         if ($date->toString() == $theDate) {
             $toInvalidate[] = $date;
         } else {
             $invalidDates[] = $theDate;
         }
     }
     // Lookup archive tables
     $tables = Piwik::getTablesInstalled();
     $archiveTables = Piwik::getTablesArchivesInstalled();
     // If using the feature "Delete logs older than N days"...
     $logsAreDeletedBeforeThisDate = Piwik_Config::getInstance()->Deletelogs['delete_logs_schedule_lowest_interval'];
     $logsDeleteEnabled = Piwik_Config::getInstance()->Deletelogs['delete_logs_enable'];
     $minimumDateWithLogs = false;
     if ($logsDeleteEnabled && $logsAreDeletedBeforeThisDate) {
         $minimumDateWithLogs = Piwik_Date::factory('today')->subDay($logsAreDeletedBeforeThisDate);
     }
     // Given the list of dates, process which tables they should be deleted from
     $minDate = false;
     $warningDates = $processedDates = array();
     /* @var $date Piwik_Date */
     foreach ($toInvalidate as $date) {
         // we should only delete reports for dates that are more recent than N days
         if ($minimumDateWithLogs && $date->isEarlier($minimumDateWithLogs)) {
             $warningDates[] = $date->toString();
         } else {
             $processedDates[] = $date->toString();
         }
         $month = $date->toString('Y_m');
         // For a given date, we must invalidate in the monthly archive table
         $datesByMonth[$month][] = $date->toString();
         // But also the year stored in January
         $year = $date->toString('Y_01');
         $datesByMonth[$year][] = $date->toString();
         // but also weeks overlapping several months stored in the month where the week is starting
         /* @var $week Piwik_Period_Week */
         $week = Piwik_Period::factory('week', $date);
         $week = $week->getDateStart()->toString('Y_m');
         $datesByMonth[$week][] = $date->toString();
         // Keep track of the minimum date for each website
         if ($minDate === false || $date->isEarlier($minDate)) {
             $minDate = $date;
         }
     }
     // In each table, invalidate day/week/month/year containing this date
     $sqlIdSites = implode(",", $idSites);
     foreach ($archiveTables as $table) {
         // Extract Y_m from table name
         $suffix = str_replace(array('archive_numeric_', 'archive_blob_'), '', Piwik_Common::unprefixTable($table));
         if (!isset($datesByMonth[$suffix])) {
             continue;
         }
         // Dates which are to be deleted from this table
         $datesToDeleteInTable = $datesByMonth[$suffix];
         // Build one statement to delete all dates from the given table
         $sql = $bind = array();
         $datesToDeleteInTable = array_unique($datesToDeleteInTable);
         foreach ($datesToDeleteInTable as $dateToDelete) {
             $sql[] = '(date1 <= ? AND ? <= date2)';
             $bind[] = $dateToDelete;
             $bind[] = $dateToDelete;
         }
         $sql = implode(" OR ", $sql);
         $query = "DELETE FROM {$table} " . " WHERE ( {$sql} ) " . " AND idsite IN (" . $sqlIdSites . ")";
         Piwik_Query($query, $bind);
         //			var_dump($query);var_dump($bind);
     }
     // Update piwik_site.ts_created
     $query = "UPDATE " . Piwik_Common::prefixTable("site") . " SET ts_created = ?" . " WHERE idsite IN ( {$sqlIdSites} )\n\t\t\t\t\tAND ts_created > ?";
     $minDateSql = $minDate->subDay(1)->getDatetime();
     $bind = array($minDateSql, $minDateSql);
     Piwik_Query($query, $bind);
     //		var_dump($query);var_dump($bind);
     // Force to re-process data for these websites in the next archive.php cron run
     $invalidatedIdSites = Piwik_CoreAdminHome_API::getWebsiteIdsToInvalidate();
     $invalidatedIdSites = array_merge($invalidatedIdSites, $idSites);
     $invalidatedIdSites = array_unique($invalidatedIdSites);
     $invalidatedIdSites = array_values($invalidatedIdSites);
     Piwik_SetOption(self::OPTION_INVALIDATED_IDSITES, serialize($invalidatedIdSites));
     Piwik_Site::clearCache();
     $output = array();
     // output logs
     if ($warningDates) {
         $output[] = 'Warning: the following Dates have not been invalidated, because they are earlier than your Log Deletion limit: ' . implode(", ", $warningDates) . "\n The last day with logs is " . $minimumDateWithLogs . ". " . "\n Please disable 'Delete old Logs' or set it to a higher deletion threshold (eg. 180 days or 365 years).'.";
     }
     $output[] = "Success. The following dates were invalidated successfully: " . implode(", ", $processedDates);
     return $output;
 }
示例#23
0
 private function doWelcomeUpdates($view, $componentsWithUpdateFile)
 {
     $view->new_piwik_version = Piwik_Version::VERSION;
     $view->commandUpgradePiwik = "<br/><code>php " . Piwik_Common::getPathToPiwikRoot() . "/index.php  -- \"module=CoreUpdater\" </code>";
     $pluginNamesToUpdate = array();
     $coreToUpdate = false;
     // handle case of existing database with no tables
     $tablesInstalled = Piwik::getTablesInstalled();
     if (count($tablesInstalled) == 0) {
         $this->errorMessages[] = Piwik_Translate('CoreUpdater_EmptyDatabaseError', Zend_Registry::get('config')->database->dbname);
         $this->coreError = true;
         $currentVersion = 'N/A';
     } else {
         $this->errorMessages = array();
         try {
             $currentVersion = Piwik_GetOption('version_core');
         } catch (Exception $e) {
             $currentVersion = '<= 0.2.9';
         }
         foreach ($componentsWithUpdateFile as $name => $filenames) {
             if ($name == 'core') {
                 $coreToUpdate = true;
             } else {
                 $pluginNamesToUpdate[] = $name;
             }
         }
     }
     // check file integrity
     $integrityInfo = Piwik::getFileIntegrityInformation();
     if (isset($integrityInfo[1])) {
         $this->warningMessages[] = '<b>' . Piwik_Translate('General_FileIntegrityWarningExplanation') . '</b>';
         $this->warningMessages += array_splice($integrityInfo, 1);
     }
     $view->coreError = $this->coreError;
     $view->warningMessages = $this->warningMessages;
     $view->errorMessages = $this->errorMessages;
     $view->current_piwik_version = $currentVersion;
     $view->pluginNamesToUpdate = $pluginNamesToUpdate;
     $view->coreToUpdate = $coreToUpdate;
     $view->clearCompiledTemplates();
     echo $view->render();
 }
 /**
  * Drops all archive tables.
  */
 public static function deleteArchiveTables()
 {
     foreach (Piwik::getTablesArchivesInstalled() as $table) {
         Piwik_Query("DROP TABLE IF EXISTS {$table}");
     }
     Piwik_TablePartitioning::$tablesAlreadyInstalled = Piwik::getTablesInstalled($forceReload = true);
 }
示例#25
0
 /**
  * Returns all table names archive_*
  * 
  * @return array 
  */
 public static function getTablesArchivesInstalled()
 {
     $archiveTables = array();
     $tables = Piwik::getTablesInstalled();
     foreach ($tables as $table) {
         if (strpos($table, 'archive_') !== false) {
             $archiveTables[] = $table;
         }
     }
     return $archiveTables;
 }
示例#26
0
<?php

require_once "SitesManager/API.php";
// alter table to set the utf8 collation
$tablesToAlter = Piwik::getTablesInstalled(true);
foreach ($tablesToAlter as $table) {
    Piwik_Query("ALTER TABLE `" . $table . "` \n\t\t\t\t CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci ");
}
// force regeneration of cache files as we add 'hosts' entry in it
Piwik::setUserIsSuperUser();
$allSiteIds = Piwik_SitesManager_API::getAllSitesId();
Piwik_Common::regenerateCacheWebsiteAttributes($allSiteIds);