/** * Returns all available archive blob tables * * @return array */ public static function getAllArchiveBlobTables() { if (empty(self::$archiveBlobTables)) { $archiveTables = ArchiveTableCreator::getTablesArchivesInstalled(); self::$archiveBlobTables = array_filter($archiveTables, function ($name) { return ArchiveTableCreator::getTypeFromTableName($name) == ArchiveTableCreator::BLOB_TABLE; }); // sort tables so we have them in order of their date rsort(self::$archiveBlobTables); } return (array) self::$archiveBlobTables; }
public function getMigrations(Updater $updater) { $migrations = array(); $archiveTables = ArchiveTableCreator::getTablesArchivesInstalled(); $archiveBlobTables = array_filter($archiveTables, function ($name) { return ArchiveTableCreator::getTypeFromTableName($name) == ArchiveTableCreator::BLOB_TABLE; }); foreach ($archiveBlobTables as $table) { $migrations[] = $this->migration->db->sql("UPDATE {$table} SET name = 'DevicePlugins_plugin' WHERE name = 'UserSettings_plugin'"); } return $migrations; }
public function getMigrationQueries(Updater $updater) { $sqls = array(); $archiveTables = ArchiveTableCreator::getTablesArchivesInstalled(); $archiveBlobTables = array_filter($archiveTables, function ($name) { return ArchiveTableCreator::getTypeFromTableName($name) == ArchiveTableCreator::BLOB_TABLE; }); foreach ($archiveBlobTables as $table) { $sqls["UPDATE " . $table . " SET name = 'UserLanguage_language' WHERE name = 'UserSettings_language'"] = false; } return $sqls; }
public static function getSql() { $sqls = array(); $archiveTables = ArchiveTableCreator::getTablesArchivesInstalled(); $archiveBlobTables = array_filter($archiveTables, function ($name) { return ArchiveTableCreator::getTypeFromTableName($name) == ArchiveTableCreator::BLOB_TABLE; }); foreach ($archiveBlobTables as $table) { $sqls["UPDATE " . $table . " SET name = 'DevicePlugins_plugin' WHERE name = 'UserSettings_plugin'"] = false; } return $sqls; }
private function addArchivingIdMigrationQueries($sql) { $tables = ArchiveTableCreator::getTablesArchivesInstalled(); foreach ($tables as $table) { $type = ArchiveTableCreator::getTypeFromTableName($table); if ($type === ArchiveTableCreator::NUMERIC_TABLE) { $maxId = Db::fetchOne('SELECT MAX(idarchive) FROM ' . $table); if (!empty($maxId)) { $maxId = (int) $maxId + 500; } else { $maxId = 1; } $sql[] = $this->migration->db->insert($this->sequenceTable, array('name' => $table, 'value' => $maxId)); } } return $sql; }
private static function addArchivingIdMigrationQueries($sql) { $tables = ArchiveTableCreator::getTablesArchivesInstalled(); foreach ($tables as $table) { $type = ArchiveTableCreator::getTypeFromTableName($table); if ($type === ArchiveTableCreator::NUMERIC_TABLE) { $maxId = Db::fetchOne('SELECT MAX(idarchive) FROM ' . $table); if (!empty($maxId)) { $maxId = (int) $maxId + 500; } else { $maxId = 1; } $query = self::getQueryToCreateSequence($table, $maxId); // refs #6696, ignores Integrity constraint violation: 1062 Duplicate entry 'piwik_archive_numeric_2010_01' for key 'PRIMARY' $sql[$query] = '1062'; } } return $sql; }
public function createArchiveTable($tableName, $tableNamePrefix) { $db = Db::get(); $sql = DbHelper::getTableCreateSql($tableNamePrefix); // replace table name template by real name $tableNamePrefix = Common::prefixTable($tableNamePrefix); $sql = str_replace($tableNamePrefix, $tableName, $sql); try { $db->query($sql); } catch (Exception $e) { // accept mysql error 1050: table already exists, throw otherwise if (!$db->isErrNo($e, '1050')) { throw $e; } } try { if (ArchiveTableCreator::NUMERIC_TABLE === ArchiveTableCreator::getTypeFromTableName($tableName)) { $sequence = new Sequence($tableName); $sequence->create(); } } catch (Exception $e) { } }
/** * @param $idSites * @param $period string * @param $datesByMonth array * @throws \Exception */ private function markArchivesInvalidatedFor($idSites, $period, $datesByMonth) { $invalidateForPeriodId = $this->getPeriodId($period); // In each table, invalidate day/week/month/year containing this date $archiveTables = ArchiveTableCreator::getTablesArchivesInstalled(); $archiveNumericTables = array_filter($archiveTables, function ($name) { return ArchiveTableCreator::getTypeFromTableName($name) == ArchiveTableCreator::NUMERIC_TABLE; }); foreach ($archiveNumericTables as $table) { // Extract Y_m from table name $suffix = ArchiveTableCreator::getDateFromTableName($table); if (!isset($datesByMonth[$suffix])) { continue; } // Dates which are to be deleted from this table $datesToDelete = $datesByMonth[$suffix]; self::getModel()->updateArchiveAsInvalidated($table, $idSites, $invalidateForPeriodId, $datesToDelete); } }
/** * 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 = Date::factory('today')->subMonth(1 + $this->deleteReportsOlderThan); // find all archive tables that are older than N months $oldNumericTables = array(); $oldBlobTables = array(); foreach (DbHelper::getTablesInstalled() as $table) { $type = ArchiveTableCreator::getTypeFromTableName($table); if ($type === false) { continue; } $date = ArchiveTableCreator::getDateFromTableName($table); list($year, $month) = explode('_', $date); if (self::shouldReportBePurged($year, $month, $toRemoveDate)) { if ($type == ArchiveTableCreator::NUMERIC_TABLE) { $oldNumericTables[] = $table; } else { $oldBlobTables[] = $table; } } } return array($oldNumericTables, $oldBlobTables); }