Skip to content

Commit

Permalink
NEW Add migration task from gorriecoe/silverstripe-link
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Apr 1, 2024
1 parent 38d2aa4 commit 2d0e3c8
Show file tree
Hide file tree
Showing 10 changed files with 2,305 additions and 418 deletions.
2 changes: 1 addition & 1 deletion docs/en/09_migrating/00_upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ For databases that support transactions, the full data migration is performed wi
> We strongly recommend running this task in a local development environment before trying it in production.
> There may be edge cases that the migration task doesn't account for which need to be resolved.
1. Prepare the task
1. Configure the migration task
- Enable the task:
```yml
Expand Down
294 changes: 294 additions & 0 deletions docs/en/09_migrating/02_gorriecoe-migration.md

Large diffs are not rendered by default.

669 changes: 669 additions & 0 deletions src/Tasks/GorriecoeMigrationTask.php

Large diffs are not rendered by default.

424 changes: 10 additions & 414 deletions src/Tasks/LinkFieldMigrationTask.php

Large diffs are not rendered by default.

443 changes: 443 additions & 0 deletions src/Tasks/MigrationTaskTrait.php

Large diffs are not rendered by default.

613 changes: 613 additions & 0 deletions tests/php/Tasks/GorriecoeMigrationTaskTest.php

Large diffs are not rendered by default.

230 changes: 230 additions & 0 deletions tests/php/Tasks/GorriecoeMigrationTaskTest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
SilverStripe\LinkField\Models\EmailLink:
email-link01:
LinkText: 'pre-existing link 01'
Email: '[email protected]'
email-link02:
LinkText: 'pre-existing link 02'
Email: '[email protected]'

SilverStripe\LinkField\Models\SiteTreeLink:
sitetree-link01:
LinkText: 'pre-existing link 01'
OpenInNew: 0
Anchor: 'an-anchor'
# Doesn't matter if this is a real page or not for our purposes
PageID: 7
sitetree-link02:
LinkText: 'pre-existing link 02'
OpenInNew: 1
PageID: 1

GorriecoeMigrationTaskTest_OldLinkTable:
url-link01:
Title: 'url link 01'
Created: '2019-12-02T12:21:12'
LastEdited: '2019-12-23T12:21:18'
Type: 'URL'
URL: null
OpenInNewWindow: true
MySort: 1
url-link02:
Title: 'url link 02'
Type: 'URL'
URL: '/some-relative-path/hahaha'
OpenInNewWindow: false
MySort: 2
url-link03:
Title: 'url link03'
Type: 'URL'
URL: 'https://www.example.com/'
MySort: 3
email-link01:
Title: 'email link 01'
Type: 'Email'
Email: null
OpenInNewWindow: true
email-link02:
Title: 'email link 02'
Type: 'Email'
Email: '[email protected]'
OpenInNewWindow: false
email-link03:
Title: 'email link03'
Type: 'Email'
Email: '[email protected]'
phone-link01:
Title: 'phone link 01'
Type: 'Phone'
Phone: null
OpenInNewWindow: true
phone-link02:
Title: 'phone link 02'
Type: 'Phone'
Phone: '123456789'
OpenInNewWindow: false
phone-link03:
Title: 'phone link03'
Type: 'Phone'
Phone: '04-555-call-me'
file-link01:
Title: 'file link 01'
Type: 'File'
FileID: 0
OpenInNewWindow: true
file-link02:
Title: 'file link 02'
Type: 'File'
FileID: 0
OpenInNewWindow: false
file-link03:
Title: 'file link03'
Type: 'File'
# Doesn't matter if this is a real file or not for our purposes
FileID: 1
sitetree-link01:
Title: 'sitetree link 01'
Type: 'SiteTree'
SiteTreeID: 0
OpenInNewWindow: true
Anchor: null
sitetree-link02:
Title: 'sitetree link 02'
Type: 'SiteTree'
SiteTreeID: 0
OpenInNewWindow: false
Anchor: 'this-will-be?treated&like-just-an-anchor=1#okiedoke'
sitetree-link03:
Title: 'sitetree link03'
Type: 'SiteTree'
# Doesn't matter if this is a real page or not for our purposes
SiteTreeID: 1
Anchor: '#anchor-first?querystring=second&awesome'
sitetree-link04:
Title: 'sitetree link04'
Type: 'SiteTree'
Anchor: '?querystring=first&awesome#anchor-second'
custom-link01:
Title: 'custom link 01'
Type: 'Custom'
CustomField: null
OpenInNewWindow: true
custom-link02:
Title: 'custom link 02'
Type: 'Custom'
CustomField: 'Some value'
OpenInNewWindow: false
custom-link03:
Title: 'custom link03'
Type: 'Custom'
CustomField: 'another value'

SilverStripe\LinkField\Tests\Tasks\LinkFieldMigrationTaskTest\HasManyLinkOwner:
# We can't add the relations here, because that would set them against a real has_one, but we want
# them to be added against columns that aren't added through the regular ORM to simulate legacy data
legacy-relations:

# many_many relation migrations
SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner:
manymany-owner1:
Title: 'Owner 1'
manymany-owner2:
Title: 'Owner 2'
manymany-owner3:
Title: 'Owner 3'

LinkFieldTest_Tasks_WasManyManyOwner_NormalManyMany:
join1:
LinkFieldTest_Tasks_WasManyManyOwnerID: =>SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner.manymany-owner1
GorriecoeMigrationTaskTest_OldLinkTableID: =>SilverStripe\LinkField\Models\EmailLink.email-link01
CustomSort: 1
join2:
LinkFieldTest_Tasks_WasManyManyOwnerID: =>SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner.manymany-owner1
GorriecoeMigrationTaskTest_OldLinkTableID: =>SilverStripe\LinkField\Models\EmailLink.email-link02
CustomSort: 2
join3:
LinkFieldTest_Tasks_WasManyManyOwnerID: =>SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner.manymany-owner1
GorriecoeMigrationTaskTest_OldLinkTableID: =>SilverStripe\LinkField\Models\SiteTreeLink.sitetree-link01
CustomSort: 3
join4:
LinkFieldTest_Tasks_WasManyManyOwnerID: =>SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner.manymany-owner2
GorriecoeMigrationTaskTest_OldLinkTableID: =>SilverStripe\LinkField\Models\EmailLink.email-link01
CustomSort: 3
join5:
LinkFieldTest_Tasks_WasManyManyOwnerID: =>SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner.manymany-owner2
GorriecoeMigrationTaskTest_OldLinkTableID: =>SilverStripe\LinkField\Models\SiteTreeLink.sitetree-link02
CustomSort: 2
join6:
LinkFieldTest_Tasks_WasManyManyOwnerID: =>SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner.manymany-owner2
GorriecoeMigrationTaskTest_OldLinkTableID: =>SilverStripe\LinkField\Models\EmailLink.email-link02
CustomSort: 1
join7:
LinkFieldTest_Tasks_WasManyManyOwnerID: =>SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner.manymany-owner3
GorriecoeMigrationTaskTest_OldLinkTableID: =>SilverStripe\LinkField\Models\EmailLink.email-link01
CustomSort: 4

GorriecoeMigrationTaskTest_manymany_through:
join1:
OldOwnerID: =>SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner.manymany-owner1
OldLinkID: =>SilverStripe\LinkField\Models\EmailLink.email-link01
CustomSort: 1
join2:
OldOwnerID: =>SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner.manymany-owner1
OldLinkID: =>SilverStripe\LinkField\Models\EmailLink.email-link02
CustomSort: 2
join3:
OldOwnerID: =>SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner.manymany-owner1
OldLinkID: =>SilverStripe\LinkField\Models\SiteTreeLink.sitetree-link01
CustomSort: 3
join4:
OldOwnerID: =>SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner.manymany-owner2
OldLinkID: =>SilverStripe\LinkField\Models\EmailLink.email-link01
CustomSort: 3
join5:
OldOwnerID: =>SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner.manymany-owner2
OldLinkID: =>SilverStripe\LinkField\Models\SiteTreeLink.sitetree-link02
CustomSort: 2
join6:
OldOwnerID: =>SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner.manymany-owner2
OldLinkID: =>SilverStripe\LinkField\Models\EmailLink.email-link02
CustomSort: 1
join7:
OldOwnerID: =>SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner.manymany-owner3
OldLinkID: =>SilverStripe\LinkField\Models\EmailLink.email-link01
CustomSort: 4

GorriecoeMigrationTaskTest_manymany_throughpoly:
poly-join1:
OldOwnerID: =>SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner.manymany-owner1
OldOwnerClass: 'SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner'
OldLinkID: =>SilverStripe\LinkField\Models\EmailLink.email-link01
CustomSort: 1
poly-join2:
OldOwnerID: =>SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner.manymany-owner1
OldOwnerClass: 'SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner'
OldLinkID: =>SilverStripe\LinkField\Models\EmailLink.email-link02
CustomSort: 2
poly-join3:
OldOwnerID: =>SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner.manymany-owner1
OldOwnerClass: 'SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner'
OldLinkID: =>SilverStripe\LinkField\Models\SiteTreeLink.sitetree-link01
CustomSort: 3
poly-join4:
OldOwnerID: =>SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner.manymany-owner2
OldOwnerClass: 'SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner'
OldLinkID: =>SilverStripe\LinkField\Models\EmailLink.email-link01
CustomSort: 3
poly-join5:
OldOwnerID: =>SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner.manymany-owner2
OldOwnerClass: 'SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner'
OldLinkID: =>SilverStripe\LinkField\Models\SiteTreeLink.sitetree-link02
CustomSort: 2
poly-join6:
OldOwnerID: =>SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner.manymany-owner2
OldOwnerClass: 'SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner'
OldLinkID: =>SilverStripe\LinkField\Models\EmailLink.email-link02
CustomSort: 1
poly-join7:
OldOwnerID: =>SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner.manymany-owner3
OldOwnerClass: 'SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest\WasManyManyOwner'
OldLinkID: =>SilverStripe\LinkField\Models\EmailLink.email-link01
CustomSort: 4
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest;

use SilverStripe\Dev\TestOnly;
use SilverStripe\LinkField\Models\Link;
use SilverStripe\ORM\DataObject;

class WasManyManyJoinModel extends DataObject implements TestOnly
{
private static string $table_name = 'LinkFieldTest_Tasks_WasManyManyJoinModel';

private static array $has_one = [
'Owner' => WasManyManyOwner::class,
'Link' => Link::class,
];
}
26 changes: 26 additions & 0 deletions tests/php/Tasks/GorriecoeMigrationTaskTest/WasManyManyOwner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace SilverStripe\LinkField\Tests\Tasks\GorriecoeMigrationTaskTest;

use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Dev\TestOnly;
use SilverStripe\LinkField\Models\Link;
use SilverStripe\ORM\DataObject;

class WasManyManyOwner extends DataObject implements TestOnly
{
private static string $table_name = 'LinkFieldTest_Tasks_WasManyManyOwner';

private static array $db = [
'Title' => 'Varchar',
];

private static array $has_many = [
'NormalManyMany' => Link::class . '.Owner',
'ManyManyThrough' => Link::class . '.Owner',
'ManyManyThroughPolymorphic' => Link::class . '.Owner',
// These two are here just as a sanity check that additional relationships don't affect the task
'LinkButNotIncluded' => Link::class . '.Owner',
'NotLink' => SiteTree::class,
];
}
5 changes: 2 additions & 3 deletions tests/php/Tasks/LinkFieldMigrationTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use SilverStripe\Core\Convert;
use SilverStripe\Core\Environment;
use SilverStripe\Core\Manifest\ClassLoader;
use SilverStripe\Dev\Deprecation;
use SilverStripe\Dev\SapphireTest;
use SilverStripe\LinkField\Models\EmailLink;
use SilverStripe\LinkField\Models\ExternalLink;
Expand Down Expand Up @@ -174,7 +173,7 @@ public function testGetNeedsMigration(bool $hasTitleColumn, bool $hasLinkTextCol
OverrideMigrationStepsExtension::$needsMigration = $extensionOverride;

$this->startCapturingOutput();
$needsMigration = $this->callPrivateMethod('getNeedsMigration', [$baseTable]);
$needsMigration = $this->callPrivateMethod('getNeedsMigration');
$output = $this->stopCapturingOutput();

$this->assertSame($expected, $needsMigration);
Expand Down Expand Up @@ -1117,7 +1116,7 @@ private function stopCapturingOutput(): string

private function callPrivateMethod(string $methodName, array $args = []): mixed
{
$task = Deprecation::withNoReplacement(fn() => new LinkFieldMigrationTask());
$task = new LinkFieldMigrationTask();
$reflectionMethod = new ReflectionMethod($task, $methodName);
$reflectionMethod->setAccessible(true);
return $reflectionMethod->invoke($task, ...$args);
Expand Down

0 comments on commit 2d0e3c8

Please sign in to comment.