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.6.0-b4.php
100 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\ArchiveProcessor\Rules; |
| 12 | use Piwik\Common; |
| 13 | use Piwik\DataAccess\ArchiveTableCreator; |
| 14 | use Piwik\Db; |
| 15 | use Piwik\Plugins\SitesManager\Model; |
| 16 | use Piwik\Plugins\VisitFrequency\API as VisitFrequencyAPI; |
| 17 | use Piwik\Segment; |
| 18 | use Piwik\Segment\SegmentExpression; |
| 19 | use Piwik\Updater; |
| 20 | use Piwik\Updates as PiwikUpdates; |
| 21 | use Piwik\Updater\Migration; |
| 22 | use Piwik\Updater\Migration\Factory as MigrationFactory; |
| 23 | /** |
| 24 | * Update for version 4.6.0-b2. |
| 25 | */ |
| 26 | class Updates_4_6_0_b4 extends PiwikUpdates |
| 27 | { |
| 28 | /** |
| 29 | * @var MigrationFactory |
| 30 | */ |
| 31 | private $migration; |
| 32 | public function __construct(MigrationFactory $factory) |
| 33 | { |
| 34 | $this->migration = $factory; |
| 35 | } |
| 36 | /** |
| 37 | * @return Migration\Db[] |
| 38 | */ |
| 39 | public function getMigrations(Updater $updater) |
| 40 | { |
| 41 | $migrations = []; |
| 42 | $sites = new Model(); |
| 43 | $idSites = $sites->getSitesId(); |
| 44 | $doneFlagsToMigrate = []; |
| 45 | foreach ($idSites as $idSite) { |
| 46 | $segmentStrings = Rules::getSegmentsToProcess([$idSite]); |
| 47 | foreach ($segmentStrings as $segmentString) { |
| 48 | try { |
| 49 | $segment = new Segment($segmentString, [$idSite]); |
| 50 | } catch (\Exception $e) { |
| 51 | continue; |
| 52 | } |
| 53 | if ($segment->getOriginalString() === $segment->getString()) { |
| 54 | continue; |
| 55 | } |
| 56 | $segmentsToAppend = [VisitFrequencyAPI::NEW_VISITOR_SEGMENT, VisitFrequencyAPI::RETURNING_VISITOR_SEGMENT]; |
| 57 | foreach ($segmentsToAppend as $segmentToAppend) { |
| 58 | // we need to migrate the existing archive |
| 59 | $oldSegmentString = Segment::combine($segment->getString(), SegmentExpression::AND_DELIMITER, $segmentToAppend); |
| 60 | $newSegmentString = Segment::combine($segment->getOriginalString(), SegmentExpression::AND_DELIMITER, $segmentToAppend); |
| 61 | $oldSegmentHash = Segment::getSegmentHash($oldSegmentString); |
| 62 | $newSegmentHash = Segment::getSegmentHash($newSegmentString); |
| 63 | if ($oldSegmentHash === $newSegmentHash) { |
| 64 | continue; |
| 65 | } |
| 66 | $doneFlagsToMigrate['done' . $oldSegmentHash . '.Goals'] = 'done' . $newSegmentHash . '.Goals'; |
| 67 | $doneFlagsToMigrate['done' . $oldSegmentHash . '.VisitsSummary'] = 'done' . $newSegmentHash . '.VisitsSummary'; |
| 68 | $doneFlagsToMigrate['done' . $oldSegmentHash . '.UserCountry'] = 'done' . $newSegmentHash . '.UserCountry'; |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | if (!empty($doneFlagsToMigrate)) { |
| 73 | foreach (ArchiveTableCreator::getTablesArchivesInstalled() as $table) { |
| 74 | if (strpos($table, 'numeric') === \false) { |
| 75 | continue; |
| 76 | } |
| 77 | $sqlPlaceholders = Common::getSqlStringFieldsArray($doneFlagsToMigrate); |
| 78 | $bind = array_keys($doneFlagsToMigrate); |
| 79 | $selectSql = sprintf('SELECT 1 FROM `%s` where `name` in (%s) LIMIT 1', $table, $sqlPlaceholders); |
| 80 | $archiveTableHasDoneFlags = Db::fetchOne($selectSql, $bind); |
| 81 | if (!$archiveTableHasDoneFlags) { |
| 82 | continue; |
| 83 | } |
| 84 | $sql = 'update ' . $table . ' set `name` = (case'; |
| 85 | foreach ($doneFlagsToMigrate as $oldDoneFlag => $newDoneFlag) { |
| 86 | $sql .= " when `name` = '{$oldDoneFlag}' then '{$newDoneFlag}' "; |
| 87 | } |
| 88 | $sql .= ' else `name` end) where `name` in (' . $sqlPlaceholders . ')'; |
| 89 | Db::query($sql, $bind); |
| 90 | $migrations[] = $this->migration->db->boundSql($sql, $bind, [Migration\Db\Sql::ERROR_CODE_DUPLICATE_ENTRY]); |
| 91 | } |
| 92 | } |
| 93 | return $migrations; |
| 94 | } |
| 95 | public function doUpdate(Updater $updater) |
| 96 | { |
| 97 | $updater->executeMigrations(__FILE__, $this->getMigrations($updater)); |
| 98 | } |
| 99 | } |
| 100 |