/** * Returns the idArchive if the archive is available in the database. * Returns false if the archive needs to be computed. * * An archive is available if * - for today, the archive was computed less than maxTimestampArchive seconds ago * - for any other day, if the archive was computed once this day was finished * - for other periods, if the archive was computed once the period was finished * * @return int|false */ protected function isArchived() { $bindSQL = array($this->idsite, $this->strDateStart, $this->strDateEnd, $this->periodId); $timeStampWhere = " AND UNIX_TIMESTAMP(ts_archived) >= ? "; $bindSQL[] = $this->maxTimestampArchive; $sqlQuery = "\tSELECT idarchive, value, name, UNIX_TIMESTAMP(date1) as timestamp\n\t\t\t\t\t\tFROM " . $this->tableArchiveNumeric->getTableName() . "\n\t\t\t\t\t\tWHERE idsite = ?\n\t\t\t\t\t\t\tAND date1 = ?\n\t\t\t\t\t\t\tAND date2 = ?\n\t\t\t\t\t\t\tAND period = ?\n\t\t\t\t\t\t\tAND ( (name = 'done' AND value = " . Piwik_ArchiveProcessing::DONE_OK . ")\n\t\t\t\t\t\t\t\t\tOR name = 'nb_visits')\n\t\t\t\t\t\t\t{$timeStampWhere}\n\t\t\t\t\t\tORDER BY ts_archived DESC"; $results = Piwik_FetchAll($sqlQuery, $bindSQL); if (empty($results)) { return false; } $idarchive = false; // we look for the more recent idarchive foreach ($results as $result) { if ($result['name'] == 'done') { $idarchive = $result['idarchive']; $this->timestampDateStart = $result['timestamp']; break; } } // case when we have a nb_visits entry in the archive, but the process is not finished yet or failed to finish // therefore we don't have the done=OK if ($idarchive === false) { return false; } // we look for the nb_visits result for this more recent archive foreach ($results as $result) { if ($result['name'] == 'nb_visits' && $result['idarchive'] == $idarchive) { $this->isThereSomeVisits = $result['value'] != 0; break; } } return $idarchive; }
function tearDown() { parent::tearDown(); $_GET = array(); $_POST = array(); $_REQUEST = array(); Piwik_TablePartitioning::$tablesAlreadyInstalled = null; }
public function tearDown() { parent::tearDown(); Piwik_DataTable_Manager::getInstance()->deleteAll(); Piwik_Option::getInstance()->clearCache(); Piwik_Common::deleteTrackerCache(); Piwik_Site::clearCache(); Piwik::truncateAllTables(); Piwik_TablePartitioning::$tablesAlreadyInstalled = null; }
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)); }
/** * Resets all caches and drops the database */ public function tearDown() { parent::tearDown(); try { $plugins = Piwik_PluginsManager::getInstance()->getLoadedPlugins(); foreach ($plugins as $plugin) { $plugin->uninstall(); } Piwik_PluginsManager::getInstance()->unloadPlugins(); } catch (Exception $e) { } Piwik::dropDatabase(); Piwik_DataTable_Manager::getInstance()->deleteAll(); Piwik_Option::getInstance()->clearCache(); Piwik_Site::clearCache(); Piwik_Common::deleteTrackerCache(); Piwik_Config::getInstance()->clear(); Piwik_TablePartitioning::$tablesAlreadyInstalled = null; Zend_Registry::_unsetInstance(); }
public static function tearDownAfterClass() { try { $plugins = Piwik_PluginsManager::getInstance()->getLoadedPlugins(); foreach ($plugins as $plugin) { $plugin->uninstall(); } Piwik_PluginsManager::getInstance()->unloadPlugins(); } catch (Exception $e) { } Piwik::dropDatabase(); Piwik_DataTable_Manager::getInstance()->deleteAll(); Piwik_Option::getInstance()->clearCache(); Piwik_Site::clearCache(); Piwik_Common::deleteTrackerCache(); Piwik_Config::getInstance()->clear(); Piwik_TablePartitioning::$tablesAlreadyInstalled = null; Zend_Registry::_unsetInstance(); $_GET = $_REQUEST = array(); Piwik_Translate::getInstance()->unloadEnglishTranslation(); // re-enable tag cloud shuffling Piwik_Visualization_Cloud::$debugDisableShuffle = true; }
public function setUp() { parent::setUp(); Piwik_TablePartitioning::$tablesAlreadyInstalled = null; }
public function __construct($tableName) { parent::__construct($tableName); }
/** * Returns the idArchive if the archive is available in the database. * Returns false if the archive needs to be computed. * * An archive is available if * - for today, the archive was computed less than minDatetimeArchiveProcessedUTC seconds ago * - for any other day, if the archive was computed once this day was finished * - for other periods, if the archive was computed once the period was finished * * @return int|false */ protected function isArchived() { $bindSQL = array($this->idsite, $this->period->getDateStart()->toString('Y-m-d'), $this->period->getDateEnd()->toString('Y-m-d'), $this->periodId); $timeStampWhere = ''; if ($this->minDatetimeArchiveProcessedUTC) { $timeStampWhere = " AND ts_archived >= ? "; $bindSQL[] = Piwik_Date::factory($this->minDatetimeArchiveProcessedUTC)->getDatetime(); } // When a Segment is specified, we try and only process the requested report in the archive // As a limitation, we don't know all the time which plugin should process which report // There is a catch all flag 'all' appended to archives containing all reports already // We look for this 'done.ABCDEFG.all', or for an archive that contains only our plugin data 'done.ABDCDEFG.Referers' $done = $this->getDoneStringFlag(); $doneAllPluginsProcessed = $this->getDoneStringFlag($flagArchiveAsAllPlugins = true); $sqlSegmentsFindArchiveAllPlugins = ''; if ($done != $doneAllPluginsProcessed) { $sqlSegmentsFindArchiveAllPlugins = "OR (name = '" . $doneAllPluginsProcessed . "' AND value = " . Piwik_ArchiveProcessing::DONE_OK . ")\n\t\t\t\t\tOR (name = '" . $doneAllPluginsProcessed . "' AND value = " . Piwik_ArchiveProcessing::DONE_OK_TEMPORARY . ")"; } $sqlQuery = "\tSELECT idarchive, value, name, date1 as startDate\n\t\t\t\t\t\tFROM " . $this->tableArchiveNumeric->getTableName() . "\n\t\t\t\t\t\tWHERE idsite = ?\n\t\t\t\t\t\t\tAND date1 = ?\n\t\t\t\t\t\t\tAND date2 = ?\n\t\t\t\t\t\t\tAND period = ?\n\t\t\t\t\t\t\tAND ( (name = '" . $done . "' AND value = " . Piwik_ArchiveProcessing::DONE_OK . ")\n\t\t\t\t\t\t\t\t\tOR (name = '" . $done . "' AND value = " . Piwik_ArchiveProcessing::DONE_OK_TEMPORARY . ")\n\t\t\t\t\t\t\t\t\t{$sqlSegmentsFindArchiveAllPlugins}\n\t\t\t\t\t\t\t\t\tOR name = 'nb_visits')\n\t\t\t\t\t\t\t{$timeStampWhere}\n\t\t\t\t\t\tORDER BY ts_archived DESC"; $results = Piwik_FetchAll($sqlQuery, $bindSQL); if (empty($results)) { return false; } $idarchive = false; // we look for the more recent idarchive foreach ($results as $result) { if ($result['name'] == $done || $result['name'] == $doneAllPluginsProcessed) { $idarchive = $result['idarchive']; $this->timestampDateStart = Piwik_Date::factory($result['startDate'])->getTimestamp(); break; } } // case when we have a nb_visits entry in the archive, but the process is not finished yet or failed to finish // therefore we don't have the done=OK if ($idarchive === false) { return false; } if ($this->getPluginBeingProcessed($this->getRequestedReport()) == 'VisitsSummary') { $this->isThereSomeVisits = false; } // we look for the nb_visits result for this most recent archive foreach ($results as $result) { if ($result['name'] == 'nb_visits' && $result['idarchive'] == $idarchive) { $this->isThereSomeVisits = $result['value'] > 0; $this->setNumberOfVisits($result['value']); break; } } return $idarchive; }
/** * 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); }
public function tearDown() { parent::tearDown(); Piwik_DataTable_Manager::getInstance()->deleteAll(); Piwik_Option::getInstance()->clearCache(); Piwik_Site::clearCache(); Piwik_Common::deleteTrackerCache(); Piwik_TablePartitioning::$tablesAlreadyInstalled = null; $tempTableName = Piwik_Common::prefixTable(Piwik_PrivacyManager_LogDataPurger::TEMP_TABLE_NAME); Piwik_Query("DROP TABLE IF EXISTS " . $tempTableName); }