PluginProbe ʕ •ᴥ•ʔ
Matomo Analytics – Powerful, Privacy-First Insights for WordPress / 4.3.0
Matomo Analytics – Powerful, Privacy-First Insights for WordPress v4.3.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 5 years ago Actions.php 5 years ago ArchiveSelector.php 5 years ago ArchiveTableCreator.php 5 years ago ArchiveTableDao.php 5 years ago ArchiveWriter.php 5 years ago ArchivingDbAdapter.php 5 years ago LogAggregator.php 5 years ago LogQueryBuilder.php 5 years ago LogTableTemporary.php 5 years ago Model.php 5 years ago RawLogDao.php 5 years ago TableMetadata.php 5 years ago
ArchiveTableCreator.php
126 lines
1 <?php
2 /**
3 * Matomo - free/libre analytics platform
4 *
5 * @link https://matomo.org
6 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
7 *
8 */
9
10 namespace Piwik\DataAccess;
11
12 use Piwik\Common;
13 use Piwik\Date;
14
15 class ArchiveTableCreator
16 {
17 const NUMERIC_TABLE = "numeric";
18 const BLOB_TABLE = "blob";
19
20 public static $tablesAlreadyInstalled = null;
21
22 public static function getNumericTable(Date $date)
23 {
24 return self::getTable($date, self::NUMERIC_TABLE);
25 }
26
27 public static function getBlobTable(Date $date)
28 {
29 return self::getTable($date, self::BLOB_TABLE);
30 }
31
32 protected static function getTable(Date $date, $type)
33 {
34 $tableNamePrefix = "archive_" . $type;
35 $tableName = $tableNamePrefix . "_" . self::getTableMonthFromDate($date);
36 $tableName = Common::prefixTable($tableName);
37
38 self::createArchiveTablesIfAbsent($tableName, $tableNamePrefix);
39
40 return $tableName;
41 }
42
43 protected static function createArchiveTablesIfAbsent($tableName, $tableNamePrefix)
44 {
45 if (is_null(self::$tablesAlreadyInstalled)) {
46 self::refreshTableList();
47 }
48
49 if (!in_array($tableName, self::$tablesAlreadyInstalled)) {
50 self::getModel()->createArchiveTable($tableName, $tableNamePrefix);
51 self::$tablesAlreadyInstalled[] = $tableName;
52 }
53 }
54
55 private static function getModel()
56 {
57 return new Model();
58 }
59
60 public static function clear()
61 {
62 self::$tablesAlreadyInstalled = null;
63 }
64
65 public static function refreshTableList()
66 {
67 self::$tablesAlreadyInstalled = self::getModel()->getInstalledArchiveTables();
68 }
69
70 /**
71 * Returns all table names archive_*
72 *
73 * @param string $type The type of table to return. Either `self::NUMERIC_TABLE` or `self::BLOB_TABLE`.
74 * @param bool $forceReload
75 * @return array
76 */
77 public static function getTablesArchivesInstalled($type = null, $forceReload = false)
78 {
79 if (is_null(self::$tablesAlreadyInstalled)
80 || $forceReload
81 ) {
82 self::refreshTableList();
83 }
84
85 if (empty($type)) {
86 return self::$tablesAlreadyInstalled;
87 } else {
88 $tableMatchRegex = '/archive_' . preg_quote($type) . '_/';
89 }
90
91 $archiveTables = array();
92 foreach (self::$tablesAlreadyInstalled as $table) {
93 if (preg_match($tableMatchRegex, $table)) {
94 $archiveTables[] = $table;
95 }
96 }
97 return $archiveTables;
98 }
99
100 public static function getDateFromTableName($tableName)
101 {
102 $tableName = Common::unprefixTable($tableName);
103 $date = str_replace(array('archive_numeric_', 'archive_blob_'), '', $tableName);
104
105 return $date;
106 }
107
108 public static function getTableMonthFromDate(Date $date)
109 {
110 return $date->toString('Y_m');
111 }
112
113 public static function getTypeFromTableName($tableName)
114 {
115 if (strpos($tableName, 'archive_numeric_') !== false) {
116 return self::NUMERIC_TABLE;
117 }
118
119 if (strpos($tableName, 'archive_blob_') !== false) {
120 return self::BLOB_TABLE;
121 }
122
123 return false;
124 }
125 }
126