PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 5.0.3
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v5.0.3
5.13.0 5.12.1 5.12.0 5.11.1 5.11.0 5.10.2 5.10.1 trunk 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.3.2 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.10.0 4.11.0 4.12.0 4.13.0 4.13.2 4.13.3 4.13.4 4.13.5 4.14.0 4.14.1 4.14.2 4.15.0 4.15.1 4.15.2 4.15.3 4.2.0 4.3.0 4.3.1 4.4.1 4.4.2 4.5.0 4.6.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.10.0 5.2.0 5.2.1 5.2.2 5.3.0 5.3.1 5.3.2 5.3.3 5.6.0 5.6.1 5.7.0 5.7.1 5.8.0 5.8.1 5.8.2
matomo / app / core / DataAccess / ArchiveTableCreator.php
matomo / app / core / DataAccess Last commit date
LogQueryBuilder 2 years ago Actions.php 2 years ago ArchiveSelector.php 2 years ago ArchiveTableCreator.php 2 years ago ArchiveTableDao.php 2 years ago ArchiveWriter.php 2 years ago ArchivingDbAdapter.php 2 years ago LogAggregator.php 2 years ago LogQueryBuilder.php 2 years ago LogTableTemporary.php 2 years ago Model.php 2 years ago RawLogDao.php 2 years ago TableMetadata.php 2 years ago
ArchiveTableCreator.php
103 lines
1 <?php
2
3 /**
4 * Matomo - free/libre analytics platform
5 *
6 * @link https://matomo.org
7 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
8 *
9 */
10 namespace Piwik\DataAccess;
11
12 use Piwik\Common;
13 use Piwik\Date;
14 class ArchiveTableCreator
15 {
16 const NUMERIC_TABLE = "numeric";
17 const BLOB_TABLE = "blob";
18 public static $tablesAlreadyInstalled = null;
19 public static function getNumericTable(Date $date)
20 {
21 return self::getTable($date, self::NUMERIC_TABLE);
22 }
23 public static function getBlobTable(Date $date)
24 {
25 return self::getTable($date, self::BLOB_TABLE);
26 }
27 protected static function getTable(Date $date, $type)
28 {
29 $tableNamePrefix = "archive_" . $type;
30 $tableName = $tableNamePrefix . "_" . self::getTableMonthFromDate($date);
31 $tableName = Common::prefixTable($tableName);
32 self::createArchiveTablesIfAbsent($tableName, $tableNamePrefix);
33 return $tableName;
34 }
35 protected static function createArchiveTablesIfAbsent($tableName, $tableNamePrefix)
36 {
37 if (is_null(self::$tablesAlreadyInstalled)) {
38 self::refreshTableList();
39 }
40 if (!in_array($tableName, self::$tablesAlreadyInstalled)) {
41 self::getModel()->createArchiveTable($tableName, $tableNamePrefix);
42 self::$tablesAlreadyInstalled[] = $tableName;
43 }
44 }
45 private static function getModel()
46 {
47 return new \Piwik\DataAccess\Model();
48 }
49 public static function clear()
50 {
51 self::$tablesAlreadyInstalled = null;
52 }
53 public static function refreshTableList()
54 {
55 self::$tablesAlreadyInstalled = self::getModel()->getInstalledArchiveTables();
56 }
57 /**
58 * Returns all table names archive_*
59 *
60 * @param string $type The type of table to return. Either `self::NUMERIC_TABLE` or `self::BLOB_TABLE`.
61 * @param bool $forceReload
62 * @return array
63 */
64 public static function getTablesArchivesInstalled($type = null, $forceReload = false)
65 {
66 if (is_null(self::$tablesAlreadyInstalled) || $forceReload) {
67 self::refreshTableList();
68 }
69 if (empty($type)) {
70 return self::$tablesAlreadyInstalled;
71 } else {
72 $tableMatchRegex = '/archive_' . preg_quote($type) . '_/';
73 }
74 $archiveTables = array();
75 foreach (self::$tablesAlreadyInstalled as $table) {
76 if (preg_match($tableMatchRegex, $table)) {
77 $archiveTables[] = $table;
78 }
79 }
80 return $archiveTables;
81 }
82 public static function getDateFromTableName($tableName)
83 {
84 $tableName = Common::unprefixTable($tableName);
85 $date = str_replace(array('archive_numeric_', 'archive_blob_'), '', $tableName);
86 return $date;
87 }
88 public static function getTableMonthFromDate(Date $date)
89 {
90 return $date->toString('Y_m');
91 }
92 public static function getTypeFromTableName($tableName)
93 {
94 if (strpos($tableName, 'archive_numeric_') !== false) {
95 return self::NUMERIC_TABLE;
96 }
97 if (strpos($tableName, 'archive_blob_') !== false) {
98 return self::BLOB_TABLE;
99 }
100 return false;
101 }
102 }
103