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 / Updates / 5.0.0-b1.php
matomo / app / core / Updates Last commit date
3.12.0-b1.php 2 years ago 3.12.0-b7.php 2 years ago 4.0.0-b1.php 2 years ago 4.0.0-b3.php 2 years ago 4.0.0-rc3.php 2 years ago 4.0.0-rc4.php 2 years ago 4.0.1-b1.php 2 years ago 4.0.4-b1.php 2 years ago 4.1.2-b1.php 2 years ago 4.1.2-b2.php 2 years ago 4.10.0-b1.php 2 years ago 4.11.0-b1.php 2 years ago 4.11.0-rc2.php 2 years ago 4.12.0-b1.php 2 years ago 4.12.0-b2.php 2 years ago 4.12.0-b3.php 2 years ago 4.12.0-b4.php 2 years ago 4.3.0-b3.php 2 years ago 4.3.0-b4.php 2 years ago 4.3.0-rc2.php 2 years ago 4.4.0-b1.php 2 years ago 4.5.0-b1.php 2 years ago 4.6.0-b1.php 2 years ago 4.6.0-b4.php 2 years ago 4.6.2-rc2.php 2 years ago 4.7.0-b2.php 2 years ago 4.7.1-b1.php 2 years ago 5.0.0-b1.php 2 years ago 5.0.0-rc2.php 2 years ago 5.0.0-rc5.php 2 years ago
5.0.0-b1.php
122 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\Updates;
11
12 use Piwik\DataAccess\ArchiveTableCreator;
13 use Piwik\Db;
14 use Piwik\Common;
15 use Piwik\DbHelper;
16 use Piwik\SettingsPiwik;
17 use Piwik\Updater;
18 use Piwik\Updater\Migration\Db as DbAlias;
19 use Piwik\Updater\Migration\Factory;
20 use Piwik\Updates as PiwikUpdates;
21 use Piwik\Updater\Migration\Custom as CustomMigration;
22 use Piwik\Plugins\Goals\Commands\CalculateConversionPages;
23 /**
24 * Update for version 5.0.0-b1
25 */
26 class Updates_5_0_0_b1 extends PiwikUpdates
27 {
28 /**
29 * @var Factory
30 */
31 private $migration;
32 private $tableName;
33 private $indexName;
34 private $newIndexName;
35 public function __construct(Factory $factory)
36 {
37 $this->migration = $factory;
38 $this->tableName = Common::prefixTable('log_visit');
39 $this->indexName = 'index_idsite_idvisitor';
40 $this->newIndexName = 'index_idsite_idvisitor_time';
41 }
42 public function doUpdate(Updater $updater)
43 {
44 $updater->executeMigrations(__FILE__, $this->getMigrations($updater));
45 }
46 public function getMigrations(Updater $updater)
47 {
48 $migrations = $this->getUpdateArchiveIndexMigrations();
49 $migrations[] = $this->migration->db->addColumns('user_token_auth', ['post_only' => "TINYINT(2) UNSIGNED NOT NULL DEFAULT '0'"]);
50 $migrations[] = $this->migration->db->addColumns('log_conversion', ['pageviews_before' => "SMALLINT UNSIGNED DEFAULT NULL"]);
51 $instanceId = SettingsPiwik::getPiwikInstanceId();
52 if (strpos($instanceId, '.matomo.cloud') === false && strpos($instanceId, '.innocraft.cloud') === false) {
53 $commandString = './console core:calculate-conversion-pages --dates=yesterday,today';
54 $populatePagesBefore = new CustomMigration([CalculateConversionPages::class, 'calculateYesterdayAndToday'], $commandString);
55 $migrations[] = $populatePagesBefore;
56 }
57 return $this->appendLogVisitTableMigrations($migrations);
58 }
59 private function getUpdateArchiveIndexMigrations()
60 {
61 $migrations = [];
62 $tables = ArchiveTableCreator::getTablesArchivesInstalled('numeric');
63 foreach ($tables as $table) {
64 $migrations[] = $this->migration->db->sql(sprintf('DELETE FROM `%s` WHERE ts_archived is null', $table));
65 $hasPrefix = strpos($table, 'archive') !== 0;
66 if ($hasPrefix) {
67 $table = Common::unprefixTable($table);
68 }
69 $migrations[] = $this->migration->db->dropIndex($table, 'index_idsite_dates_period');
70 $migrations[] = $this->migration->db->addIndex($table, ['idsite', 'date1', 'date2', 'period', 'name(6)'], 'index_idsite_dates_period');
71 }
72 return $migrations;
73 }
74 private function appendLogVisitTableMigrations($migrations)
75 {
76 if ($this->hasNewIndex()) {
77 // correct index already exists, so don't perform anything
78 return $migrations;
79 }
80 if ($this->hasCorrectlySetOldIndex()) {
81 // already existing index has the correct fields. Try renaming, but ignore syntax error thrown if rename command does not exist
82 $migrations[] = $this->migration->db->sql("ALTER TABLE `{$this->tableName}` RENAME INDEX `{$this->indexName}` TO `{$this->newIndexName}`", [DbAlias::ERROR_CODE_SYNTAX_ERROR]);
83 }
84 // create the new index if it does not yet exist and drop the old one
85 if ($this->isTableInnoDb()) {
86 // Only InnoDB does support descending indexes as of MySQL 8
87 $migrations[] = $this->migration->db->sql("ALTER TABLE `{$this->tableName}` ADD INDEX `{$this->newIndexName}` (`idsite`, `idvisitor`, `visit_last_action_time` DESC)", [DbAlias::ERROR_CODE_DUPLICATE_KEY, DbAlias::ERROR_CODE_KEY_COLUMN_NOT_EXISTS]);
88 } else {
89 $migrations[] = $this->migration->db->sql("ALTER TABLE `{$this->tableName}` ADD INDEX `{$this->newIndexName}` (`idsite`, `idvisitor`, `visit_last_action_time`)", [DbAlias::ERROR_CODE_DUPLICATE_KEY, DbAlias::ERROR_CODE_KEY_COLUMN_NOT_EXISTS]);
90 }
91 $migrations[] = $this->migration->db->dropIndex('log_visit', $this->indexName);
92 return $migrations;
93 }
94 private function hasCorrectlySetOldIndex() : bool
95 {
96 $sql = "SHOW INDEX FROM `{$this->tableName}` WHERE Key_name = '{$this->indexName}'";
97 $result = Db::fetchAll($sql);
98 if (empty($result)) {
99 // No index present
100 return false;
101 }
102 // Check that the $result contains all the required column names. This is required as there was a previous index
103 // with the same name that only consisted of two columns. We want to check this index is built with all three.
104 // $diff will be empty if all three columns are found, meaning that the index already exists.
105 $diff = array_diff(['idsite', 'idvisitor', 'visit_last_action_time'], array_column($result, 'Column_name'));
106 if (!$diff) {
107 return true;
108 }
109 return false;
110 }
111 private function hasNewIndex() : bool
112 {
113 return DbHelper::tableHasIndex($this->tableName, $this->newIndexName);
114 }
115 private function isTableInnoDb() : bool
116 {
117 $sql = "SHOW TABLE STATUS WHERE NAME='{$this->tableName}'";
118 $result = Db::fetchRow($sql);
119 return strtolower($result['Engine'] ?? '') === 'innodb';
120 }
121 }
122