Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions Migrations/AnnotationsMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,51 @@

namespace Piwik\Plugins\Migration\Migrations;

use Piwik\Common;
use Piwik\Option;
use Piwik\Plugins\Annotations\AnnotationList;
use Piwik\Plugins\Migration\TargetDb;

class AnnotationsMigration extends BaseMigration
{
/**
* @param TargetDb $targetDb
* @return array
*/
public function validateStructure(TargetDb $targetDb)
{
return array();
// since Matomo 5.5.0, annotations are stored in their own table
// and the AnnotationList class had been removed
if (!class_exists(AnnotationList::class)) {
return $this->checkTablesHaveSameStructure($targetDb, 'annotations');
}

return [];
}

/**
* @param Request $request
* @param TargetDb $targetDb
* @return void
*/
public function migrate(Request $request, TargetDb $targetDb)
{
// since Matomo 5.5.0, annotations are stored in their own table
// and the AnnotationList class had been removed
if (!class_exists(AnnotationList::class)) {
$this->migrateEntities($request, $targetDb, 'annotations', 'annotations', 'id');

return;
}

// before Matomo 5.5.0, annotations were stored in the options table
$sourceName = AnnotationList::getAnnotationCollectionOptionName($request->sourceIdSite);
$targetName = AnnotationList::getAnnotationCollectionOptionName($request->targetIdSite);

$annotations = Option::get($sourceName);
if ($annotations) {
$this->log('Found annotations');
$annotationItems = Common::safe_unserialize($annotations) ?: [];
$this->log(sprintf('Found %d annotations', count($annotationItems)));

$targetDb->insert('option', array(
'option_name' => $targetName,
Expand Down
10 changes: 9 additions & 1 deletion tests/System/Commands/MigrateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function test_runMigration()
Found 2 segments at 2019-01-10 02:48:01
Processed SegmentsMigration at 2019-01-10 02:48:01
Processing AnnotationsMigration at 2019-01-10 02:48:01
Found annotations at 2019-01-10 02:48:01
Found 1 annotations at 2019-01-10 02:48:01
Processed AnnotationsMigration at 2019-01-10 02:48:01
Processing CustomDimensionMigration at 2019-01-10 02:48:01
Found 3 custom dimensions at 2019-01-10 02:48:01
Expand Down Expand Up @@ -138,6 +138,14 @@ public function test_runMigration_actuallyCopiesValues()
$archives = $targetDb->fetchAll('SELECT * FROM ' . self::$fixture->targetDb->prefixTable('archive_blob_2013_01'));
$this->assertGreaterThanOrEqual(195, count($archives));
$this->assertLessThanOrEqual(600, count($archives));

if (!class_exists('Piwik\Plugins\Annotations\AnnotationList')) {
$annotationsTable = self::$fixture->targetDb->prefixTable('annotations');
$this->assertContains($annotationsTable, $targetDb->listTables(), 'annotations table does not exist');

$annotationItems = $targetDb->fetchAll('SELECT * FROM ' . $annotationsTable);
$this->assertCount(1, $annotationItems);
}
Comment thread
snake14 marked this conversation as resolved.
}

/**
Expand Down