3.12.0-b1.php
2 years ago
3.12.0-b7.php
2 years ago
4.0.0-b1.php
7 months ago
4.0.0-b3.php
2 years ago
4.0.0-rc3.php
2 years ago
4.0.0-rc4.php
2 months 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 months ago
4.11.0-b1.php
2 months ago
4.11.0-rc2.php
2 months ago
4.12.0-b1.php
2 months ago
4.12.0-b2.php
2 months ago
4.12.0-b3.php
2 months ago
4.12.0-b4.php
2 months ago
4.3.0-b3.php
2 years ago
4.3.0-b4.php
7 months 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
3 months ago
4.6.2-rc2.php
3 months ago
4.7.0-b2.php
2 months ago
4.7.1-b1.php
2 months ago
5.0.0-b1.php
1 year ago
5.0.0-rc2.php
2 years ago
5.0.0-rc5.php
2 months ago
5.11.0-b1.php
2 weeks ago
5.2.0-b2.php
1 year ago
5.2.0-b6.php
1 year ago
5.3.0-b1.php
1 year ago
5.3.0-rc1.php
1 year ago
5.4.0-b1.php
7 months ago
5.4.0-b3.php
7 months ago
5.4.0-b4.php
2 months ago
5.5.0-b2.php
2 months ago
5.6.0-b1.php
2 months ago
5.7.0-b1.php
4 months ago
5.7.0-b2.php
3 months ago
5.7.0-b3.php
4 months ago
5.8.0-b1.php
3 months ago
5.8.0-b2.php
3 months ago
5.9.0-b1.php
2 months ago
5.9.0-b2.php
2 months ago
4.0.0-b1.php
233 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Matomo - free/libre analytics platform |
| 5 | * |
| 6 | * @link https://matomo.org |
| 7 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 8 | */ |
| 9 | namespace Piwik\Updates; |
| 10 | |
| 11 | use Piwik\DataAccess\TableMetadata; |
| 12 | use Piwik\Updater\Migration\Custom as CustomMigration; |
| 13 | use Piwik\Db; |
| 14 | use Piwik\DbHelper; |
| 15 | use Piwik\Plugin\Manager; |
| 16 | use Piwik\Plugins\CoreAdminHome\Commands\MigrateTokenAuths; |
| 17 | use Piwik\Plugins\CoreHome\Columns\Profilable; |
| 18 | use Piwik\Plugins\CoreHome\Columns\VisitorSecondsSinceFirst; |
| 19 | use Piwik\Plugins\CoreHome\Columns\VisitorSecondsSinceOrder; |
| 20 | use Piwik\Plugins\Installation\ServerFilesGenerator; |
| 21 | use Piwik\Plugins\PagePerformance\Columns\TimeDomCompletion; |
| 22 | use Piwik\Plugins\PagePerformance\Columns\TimeDomProcessing; |
| 23 | use Piwik\Plugins\PagePerformance\Columns\TimeNetwork; |
| 24 | use Piwik\Plugins\PagePerformance\Columns\TimeOnLoad; |
| 25 | use Piwik\Plugins\PagePerformance\Columns\TimeServer; |
| 26 | use Piwik\Plugins\PagePerformance\Columns\TimeTransfer; |
| 27 | use Piwik\Common; |
| 28 | use Piwik\Config; |
| 29 | use Piwik\Plugins\UserCountry\LocationProvider; |
| 30 | use Piwik\Plugins\VisitorInterest\Columns\VisitorSecondsSinceLast; |
| 31 | use Piwik\SettingsPiwik; |
| 32 | use Piwik\Updater; |
| 33 | use Piwik\Updates as PiwikUpdates; |
| 34 | use Piwik\Updater\Migration\Factory as MigrationFactory; |
| 35 | /** |
| 36 | * Update for version 4.0.0-b1. |
| 37 | */ |
| 38 | class Updates_4_0_0_b1 extends PiwikUpdates |
| 39 | { |
| 40 | /** |
| 41 | * @var MigrationFactory |
| 42 | */ |
| 43 | private $migration; |
| 44 | public function __construct(MigrationFactory $factory) |
| 45 | { |
| 46 | $this->migration = $factory; |
| 47 | } |
| 48 | public function getMigrations(Updater $updater) |
| 49 | { |
| 50 | $tableMetadata = new TableMetadata(); |
| 51 | $columnsToAdd = []; |
| 52 | $migrations = []; |
| 53 | $domain = Config::getLocalConfigPath() === Config::getDefaultLocalConfigPath() ? '' : Config::getHostname(); |
| 54 | $domainArg = !empty($domain) ? "--matomo-domain=" . escapeshellarg($domain) . " " : ''; |
| 55 | $toString = sprintf('./console %score:matomo4-migrate-token-auths', $domainArg); |
| 56 | $custom = new CustomMigration(array(MigrateTokenAuths::class, 'migrate'), $toString); |
| 57 | $migrations[] = $custom; |
| 58 | // invalidations table |
| 59 | $migrations[] = $this->migration->db->createTable('archive_invalidations', ['idinvalidation' => 'BIGINT UNSIGNED NOT NULL AUTO_INCREMENT', 'idarchive' => 'INTEGER UNSIGNED NULL', 'name' => 'VARCHAR(255) NOT NULL', 'idsite' => 'INTEGER NOT NULL', 'date1' => 'DATE NOT NULL', 'date2' => 'DATE NOT NULL', 'period' => 'TINYINT UNSIGNED NOT NULL', 'ts_invalidated' => 'DATETIME NOT NULL', 'status' => 'TINYINT(1) UNSIGNED DEFAULT 0', 'report' => 'VARCHAR(255) NULL'], ['idinvalidation']); |
| 60 | $migrations[] = $this->migration->db->addIndex('archive_invalidations', ['idsite', 'date1', 'period'], 'index_idsite_dates_period_name'); |
| 61 | $migrations[] = $this->migration->db->dropColumn('user', 'alias'); |
| 62 | // prevent possible duplicates when shorting session id |
| 63 | $migrations[] = $this->migration->db->sql('DELETE FROM `' . Common::prefixTable('session') . '` WHERE length(id) > 190'); |
| 64 | $migrations[] = $this->migration->db->changeColumnType('session', 'id', 'VARCHAR(191)'); |
| 65 | $migrations[] = $this->migration->db->changeColumnType('site_url', 'url', 'VARCHAR(190)'); |
| 66 | $migrations[] = $this->migration->db->changeColumnType('option', 'option_name', 'VARCHAR(191)'); |
| 67 | $migrations[] = $this->migration->db->changeColumnType('log_action', 'name', 'VARCHAR(4096)'); |
| 68 | $migrations[] = $this->migration->db->changeColumnType('log_conversion', 'url', 'VARCHAR(4096)'); |
| 69 | $migrations[] = $this->migration->db->changeColumn('log_link_visit_action', 'interaction_position', 'pageview_position', 'MEDIUMINT UNSIGNED DEFAULT NULL'); |
| 70 | $customTrackerPluginActive = \false; |
| 71 | if (in_array('CustomPiwikJs', Config::getInstance()->Plugins['Plugins'])) { |
| 72 | $customTrackerPluginActive = \true; |
| 73 | } |
| 74 | $migrations[] = $this->migration->plugin->activate('BulkTracking'); |
| 75 | $migrations[] = $this->migration->plugin->deactivate('CustomPiwikJs'); |
| 76 | $migrations[] = $this->migration->plugin->uninstall('CustomPiwikJs'); |
| 77 | if ($customTrackerPluginActive) { |
| 78 | $migrations[] = $this->migration->plugin->activate('CustomJsTracker'); |
| 79 | } |
| 80 | // Prepare all installed tables for utf8mb4 conversions. e.g. make some indexed fields smaller so they don't exceed the maximum key length |
| 81 | $allTables = DbHelper::getTablesInstalled(); |
| 82 | foreach ($allTables as $table) { |
| 83 | if (preg_match('/archive_/', $table) == 1) { |
| 84 | $tableNameUnprefixed = Common::unprefixTable($table); |
| 85 | $migrations[] = $this->migration->db->changeColumnType($tableNameUnprefixed, 'name', 'VARCHAR(190)'); |
| 86 | } |
| 87 | } |
| 88 | // Move the site search fields of log_visit out of custom variables into their own fields |
| 89 | $columnsToAdd['log_link_visit_action']['search_cat'] = 'VARCHAR(200) NULL'; |
| 90 | $columnsToAdd['log_link_visit_action']['search_count'] = 'INTEGER(10) UNSIGNED NULL'; |
| 91 | // replace days to ... dimensions w/ seconds dimensions |
| 92 | foreach (['log_visit', 'log_conversion'] as $table) { |
| 93 | $columnsToAdd[$table]['visitor_seconds_since_first'] = VisitorSecondsSinceFirst::COLUMN_TYPE; |
| 94 | $columnsToAdd[$table]['visitor_seconds_since_order'] = VisitorSecondsSinceOrder::COLUMN_TYPE; |
| 95 | } |
| 96 | $columnsToAdd['log_visit']['visitor_seconds_since_last'] = VisitorSecondsSinceLast::COLUMN_TYPE; |
| 97 | $columnsToAdd['log_visit']['profilable'] = Profilable::COLUMN_TYPE; |
| 98 | $columnsToAdd['log_link_visit_action'][TimeDomCompletion::COLUMN_NAME] = TimeDomCompletion::COLUMN_TYPE; |
| 99 | $columnsToAdd['log_link_visit_action'][TimeDomProcessing::COLUMN_NAME] = TimeDomProcessing::COLUMN_TYPE; |
| 100 | $columnsToAdd['log_link_visit_action'][TimeNetwork::COLUMN_NAME] = TimeNetwork::COLUMN_TYPE; |
| 101 | $columnsToAdd['log_link_visit_action'][TimeOnLoad::COLUMN_NAME] = TimeOnLoad::COLUMN_TYPE; |
| 102 | $columnsToAdd['log_link_visit_action'][TimeServer::COLUMN_NAME] = TimeServer::COLUMN_TYPE; |
| 103 | $columnsToAdd['log_link_visit_action'][TimeTransfer::COLUMN_NAME] = TimeTransfer::COLUMN_TYPE; |
| 104 | $columnsToMaybeAdd = ['revenue', 'revenue_discount', 'revenue_shipping', 'revenue_subtotal', 'revenue_tax']; |
| 105 | $columnsLogConversion = $tableMetadata->getColumns(Common::prefixTable('log_conversion')); |
| 106 | foreach ($columnsToMaybeAdd as $columnToMaybeAdd) { |
| 107 | if (!in_array($columnToMaybeAdd, $columnsLogConversion, \true)) { |
| 108 | $columnsToAdd['log_conversion'][$columnToMaybeAdd] = 'DOUBLE NULL DEFAULT NULL'; |
| 109 | } |
| 110 | } |
| 111 | foreach ($columnsToAdd as $table => $columns) { |
| 112 | $migrations[] = $this->migration->db->addColumns($table, $columns); |
| 113 | foreach ($columns as $columnName => $columnType) { |
| 114 | $optionKey = 'version_' . $table . '.' . $columnName; |
| 115 | $optionValue = $columnType; |
| 116 | if ($table == 'log_visit' && isset($columnsToAdd['log_conversion'][$columnName])) { |
| 117 | $optionValue .= '1'; |
| 118 | // column is in log_conversion too |
| 119 | } |
| 120 | $migrations[] = $this->migration->db->sql("INSERT IGNORE INTO `" . Common::prefixTable('option') . "` (option_name, option_value) VALUES ('{$optionKey}', '{$optionValue}')"); |
| 121 | } |
| 122 | } |
| 123 | if (Manager::getInstance()->isPluginInstalled('CustomVariables')) { |
| 124 | $visitActionTable = Common::prefixTable('log_link_visit_action'); |
| 125 | $migrations[] = $this->migration->db->sql("UPDATE {$visitActionTable} SET search_cat = if(custom_var_k4 = '_pk_scat', custom_var_v4, search_cat), search_count = if(custom_var_k5 = '_pk_scount', custom_var_v5, search_count) WHERE custom_var_k4 = '_pk_scat' or custom_var_k5 = '_pk_scount'"); |
| 126 | } |
| 127 | if ($this->usesGeoIpLegacyLocationProvider()) { |
| 128 | // activate GeoIp2 plugin for users still using GeoIp2 Legacy (others might have it disabled on purpose) |
| 129 | $migrations[] = $this->migration->plugin->activate('GeoIp2'); |
| 130 | } |
| 131 | // remove old options |
| 132 | $migrations[] = $this->migration->db->sql('DELETE FROM `' . Common::prefixTable('option') . '` WHERE option_name IN ("geoip.updater_period", "geoip.loc_db_url", "geoip.isp_db_url", "geoip.org_db_url")'); |
| 133 | // init seconds_to_... columns |
| 134 | $logVisitColumns = $tableMetadata->getColumns(Common::prefixTable('log_visit')); |
| 135 | $hasDaysColumnInVisit = in_array('visitor_days_since_first', $logVisitColumns); |
| 136 | if ($hasDaysColumnInVisit) { |
| 137 | $migrations[] = $this->migration->db->sql("UPDATE " . Common::prefixTable('log_visit') . " SET visitor_seconds_since_first = visitor_days_since_first * 86400, \n visitor_seconds_since_order = visitor_days_since_order * 86400,\n visitor_seconds_since_last = visitor_days_since_last * 86400"); |
| 138 | } |
| 139 | $logConvColumns = $tableMetadata->getColumns(Common::prefixTable('log_conversion')); |
| 140 | $hasDaysColumnInConv = in_array('visitor_days_since_first', $logConvColumns); |
| 141 | if ($hasDaysColumnInConv) { |
| 142 | $migrations[] = $this->migration->db->sql("UPDATE " . Common::prefixTable('log_conversion') . " SET visitor_seconds_since_first = visitor_days_since_first * 86400, \n visitor_seconds_since_order = visitor_days_since_order * 86400"); |
| 143 | } |
| 144 | // remove old days_to_... columns |
| 145 | $migrations[] = $this->migration->db->dropColumns('log_visit', ['config_gears', 'config_director', 'visitor_days_since_first', 'visitor_days_since_order', 'visitor_days_since_last']); |
| 146 | $migrations[] = $this->migration->db->dropColumns('log_conversion', ['visitor_days_since_first', 'visitor_days_since_order']); |
| 147 | $config = Config::getInstance(); |
| 148 | if (!empty($config->mail['type']) && $config->mail['type'] === 'Crammd5') { |
| 149 | $migrations[] = $this->migration->config->set('mail', 'type', 'Cram-md5'); |
| 150 | } |
| 151 | // keep piwik_ignore for existing installs |
| 152 | $migrations[] = $this->migration->config->set('Tracker', 'ignore_visits_cookie_name', 'piwik_ignore'); |
| 153 | $migrations[] = $this->migration->plugin->activate('PagePerformance'); |
| 154 | if (!Manager::getInstance()->isPluginActivated('CustomDimensions')) { |
| 155 | $migrations[] = $this->migration->plugin->activate('CustomDimensions'); |
| 156 | } |
| 157 | $configTableLimit = Config::getInstance()->getFromLocalConfig('General')['datatable_archiving_maximum_rows_custom_variables'] ?? null; |
| 158 | $configSubTableLimit = Config::getInstance()->getFromLocalConfig('General')['datatable_archiving_maximum_rows_subtable_custom_variables'] ?? null; |
| 159 | if ($configTableLimit) { |
| 160 | $migrations[] = $this->migration->config->set('General', 'datatable_archiving_maximum_rows_custom_dimensions', $configTableLimit); |
| 161 | } |
| 162 | if ($configSubTableLimit) { |
| 163 | $migrations[] = $this->migration->config->set('General', 'datatable_archiving_maximum_rows_subtable_custom_dimensions', $configSubTableLimit); |
| 164 | } |
| 165 | return $migrations; |
| 166 | } |
| 167 | public function doUpdate(Updater $updater) |
| 168 | { |
| 169 | $salt = SettingsPiwik::getSalt(); |
| 170 | $sessions = Db::fetchAll('SELECT id from `' . Common::prefixTable('session') . '`'); |
| 171 | foreach ($sessions as $session) { |
| 172 | if (!empty($session['id']) && mb_strlen($session['id']) != 128) { |
| 173 | $bind = [hash('sha512', $session['id'] . $salt), $session['id']]; |
| 174 | try { |
| 175 | Db::query(sprintf('UPDATE `%s` SET id = ? WHERE id = ?', Common::prefixTable('session')), $bind); |
| 176 | } catch (\Exception $e) { |
| 177 | // ignore possible duplicate key errors |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | $updater->executeMigrations(__FILE__, $this->getMigrations($updater)); |
| 182 | if ($this->usesGeoIpLegacyLocationProvider()) { |
| 183 | // switch to default provider if GeoIp Legacy was still in use |
| 184 | LocationProvider::setCurrentProvider(LocationProvider\DefaultProvider::ID); |
| 185 | } |
| 186 | // eg the case when not updating from most recent Matomo 3.X and when not using the UI updater |
| 187 | // afterwards the should receive a notification that the plugins are outdated |
| 188 | self::ensureCorePluginsThatWereMovedToMarketplaceCanBeUpdated(); |
| 189 | ServerFilesGenerator::createFilesForSecurity(); |
| 190 | } |
| 191 | public static function ensureCorePluginsThatWereMovedToMarketplaceCanBeUpdated() |
| 192 | { |
| 193 | $plugins = ['Provider', 'CustomVariables']; |
| 194 | $pluginManager = Manager::getInstance(); |
| 195 | foreach ($plugins as $plugin) { |
| 196 | if ($pluginManager->isPluginThirdPartyAndBogus($plugin)) { |
| 197 | $pluginDir = Manager::getPluginDirectory($plugin); |
| 198 | if (is_dir($pluginDir) && file_exists($pluginDir . '/' . $plugin . '.php') && !file_exists($pluginDir . '/plugin.json') && is_writable($pluginDir)) { |
| 199 | file_put_contents($pluginDir . '/plugin.json', '{ |
| 200 | "name": "' . $plugin . '", |
| 201 | "description": "' . $plugin . '", |
| 202 | "version": "3.14.1", |
| 203 | "theme": false, |
| 204 | "require": { |
| 205 | "piwik": ">=3.0.0,<4.0.0-b1" |
| 206 | }, |
| 207 | "authors": [ |
| 208 | { |
| 209 | "name": "Matomo", |
| 210 | "email": "hello@matomo.org", |
| 211 | "homepage": "https:\\/\\/matomo.org" |
| 212 | } |
| 213 | ], |
| 214 | "homepage": "https:\\/\\/matomo.org", |
| 215 | "license": "GPL v3+", |
| 216 | "keywords": ["' . $plugin . '"] |
| 217 | }'); |
| 218 | // otherwise cached information might be used and it won't be loaded otherwise within same request |
| 219 | $pluginObj = $pluginManager->loadPlugin($plugin); |
| 220 | $pluginObj->reloadPluginInformation(); |
| 221 | $pluginManager->unloadPlugin($pluginObj); |
| 222 | // prevent any events being posted to it somehow |
| 223 | } |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | protected function usesGeoIpLegacyLocationProvider() |
| 228 | { |
| 229 | $currentProvider = LocationProvider::getCurrentProviderId(); |
| 230 | return in_array($currentProvider, ['geoip_pecl', 'geoip_php', 'geoip_serverbased']); |
| 231 | } |
| 232 | } |
| 233 |