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