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
1 month 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
1 month ago
4.11.0-b1.php
1 month ago
4.11.0-rc2.php
1 month ago
4.12.0-b1.php
1 month ago
4.12.0-b2.php
1 month ago
4.12.0-b3.php
1 month ago
4.12.0-b4.php
1 month 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
1 month ago
4.7.1-b1.php
1 month ago
5.0.0-b1.php
1 year ago
5.0.0-rc2.php
2 years ago
5.0.0-rc5.php
1 month 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
1 month ago
5.5.0-b2.php
1 month ago
5.6.0-b1.php
1 month 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
1 month ago
5.9.0-b2.php
1 month ago
5.2.0-b2.php
81 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\Common; |
| 12 | use Piwik\Config; |
| 13 | use Piwik\Container\StaticContainer; |
| 14 | use Piwik\DataAccess\ArchiveTableCreator; |
| 15 | use Piwik\Db; |
| 16 | use Piwik\Updater; |
| 17 | use Piwik\Updater\Migration\Factory as MigrationFactory; |
| 18 | use Piwik\Updates; |
| 19 | class Updates_5_2_0_b2 extends Updates |
| 20 | { |
| 21 | /** |
| 22 | * @var MigrationFactory |
| 23 | */ |
| 24 | private $migration; |
| 25 | public function __construct(MigrationFactory $factory) |
| 26 | { |
| 27 | $this->migration = $factory; |
| 28 | } |
| 29 | public function getMigrations(Updater $updater) |
| 30 | { |
| 31 | $migrations = []; |
| 32 | $config = Config::getInstance(); |
| 33 | $dbConfig = $config->database; |
| 34 | // only run migration if config is not set |
| 35 | if (empty($dbConfig['collation'])) { |
| 36 | $collation = $this->detectCollationForMigration(); |
| 37 | if (null !== $collation) { |
| 38 | $migrations[] = $this->migration->config->set('database', 'collation', $collation); |
| 39 | } |
| 40 | } |
| 41 | return $migrations; |
| 42 | } |
| 43 | public function doUpdate(Updater $updater) |
| 44 | { |
| 45 | $updater->executeMigrations(__FILE__, $this->getMigrations($updater)); |
| 46 | } |
| 47 | private function detectCollationForMigration() : ?string |
| 48 | { |
| 49 | try { |
| 50 | $db = Db::get(); |
| 51 | $metadataProvider = StaticContainer::get('Piwik\\Plugins\\DBStats\\MySQLMetadataProvider'); |
| 52 | $userTableStatus = $metadataProvider->getTableStatus('user'); |
| 53 | if (empty($userTableStatus['Collation'] ?? null)) { |
| 54 | // if there is no user table, or no collation for it, abort detection |
| 55 | // this table should always exist and something must be wrong in this case |
| 56 | return null; |
| 57 | } |
| 58 | $userTableCollation = $userTableStatus['Collation']; |
| 59 | $connectionCollation = $db->fetchOne('SELECT @@collation_connection'); |
| 60 | if ($userTableCollation === $connectionCollation) { |
| 61 | // if the connection is matching the user table |
| 62 | // we should be safe to assume we have already found a config value |
| 63 | return $userTableCollation; |
| 64 | } |
| 65 | $archiveTable = ArchiveTableCreator::getLatestArchiveTableInstalled(ArchiveTableCreator::NUMERIC_TABLE); |
| 66 | if (null === $archiveTable) { |
| 67 | return null; |
| 68 | } |
| 69 | $archiveTableStatus = $metadataProvider->getTableStatus(Common::unprefixTable($archiveTable)); |
| 70 | if (!empty($archiveTableStatus['Collation']) && $archiveTableStatus['Collation'] === $userTableCollation) { |
| 71 | // the most recent numeric archive table is matching the collation |
| 72 | // of the users table, should be a good config value to choose |
| 73 | return $userTableCollation; |
| 74 | } |
| 75 | } catch (\Exception $e) { |
| 76 | // rely on the system check if detection failed |
| 77 | } |
| 78 | return null; |
| 79 | } |
| 80 | } |
| 81 |