-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split link migration for content and field
- Loading branch information
1 parent
708f08c
commit 9b0f638
Showing
22 changed files
with
912 additions
and
435 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
namespace verbb\hyper\console\controllers; | ||
|
||
use verbb\hyper\migrations\MigrateLinkitField; | ||
use verbb\hyper\migrations\MigrateLinkitContent; | ||
use verbb\hyper\migrations\MigrateTypedLinkField; | ||
use verbb\hyper\migrations\MigrateTypedLinkContent; | ||
use verbb\hyper\migrations\MigrateLinkField; | ||
use verbb\hyper\migrations\MigrateLinkContent; | ||
|
||
use Craft; | ||
use craft\helpers\App; | ||
|
||
use yii\console\Controller; | ||
use yii\console\ExitCode; | ||
|
||
class MigrateController extends Controller | ||
{ | ||
// Public Methods | ||
// ========================================================================= | ||
|
||
public function actionLinkitField(): int | ||
{ | ||
return $this->_migrate(MigrateLinkitField::class); | ||
} | ||
|
||
public function actionLinkitContent(): int | ||
{ | ||
return $this->_migrate(MigrateLinkitContent::class); | ||
} | ||
|
||
public function actionTypedLinkField(): int | ||
{ | ||
return $this->_migrate(MigrateTypedLinkField::class); | ||
} | ||
|
||
public function actionTypedLinkContent(): int | ||
{ | ||
return $this->_migrate(MigrateTypedLinkContent::class); | ||
} | ||
|
||
public function actionLinkField(): int | ||
{ | ||
return $this->_migrate(MigrateLinkField::class); | ||
} | ||
|
||
public function actionLinkContent(): int | ||
{ | ||
return $this->_migrate(MigrateLinkContent::class); | ||
} | ||
|
||
|
||
// Private Methods | ||
// ========================================================================= | ||
|
||
private function _migrate(string $migrationClass): int | ||
{ | ||
App::maxPowerCaptain(); | ||
|
||
Craft::$app->getDb()->backup(); | ||
|
||
$response = []; | ||
|
||
$migration = new $migrationClass(); | ||
$migration->setConsoleRequest($this); | ||
$migration->up(); | ||
|
||
return ExitCode::OK; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
namespace verbb\hyper\migrations; | ||
|
||
use verbb\hyper\fields\HyperField; | ||
use verbb\hyper\links as linkTypes; | ||
|
||
use craft\helpers\Console; | ||
|
||
use flipbox\craft\link\fields\Link; | ||
use flipbox\craft\link\types\Asset; | ||
use flipbox\craft\link\types\Category; | ||
use flipbox\craft\link\types\Email; | ||
use flipbox\craft\link\types\Entry; | ||
use flipbox\craft\link\types\Url; | ||
use flipbox\craft\link\types\User; | ||
|
||
class MigrateLinkContent extends PluginContentMigration | ||
{ | ||
// Properties | ||
// ========================================================================= | ||
|
||
public array $typeMap = [ | ||
Asset::class => linkTypes\Asset::class, | ||
Category::class => linkTypes\Category::class, | ||
Email::class => linkTypes\Email::class, | ||
Entry::class => linkTypes\Entry::class, | ||
Url::class => linkTypes\Url::class, | ||
User::class => linkTypes\User::class, | ||
]; | ||
|
||
public string $oldFieldTypeClass = Link::class; | ||
|
||
|
||
// Public Methods | ||
// ========================================================================= | ||
|
||
public function convertModel(HyperField $field, array $oldSettings): bool|array|null | ||
{ | ||
$identifier = $oldSettings['identifier'] ?? null; | ||
$linkTypeInfo = $field->migrationData[$identifier] ?? null; | ||
$linkTypeClass = $linkTypeInfo['class'] ?? null; | ||
$linkTypeHandle = $linkTypeInfo['handle'] ?? null; | ||
|
||
$hyperType = $oldSettings[0]['type'] ?? null; | ||
|
||
if (str_contains($hyperType, 'verbb\\hyper')) { | ||
$this->stdout(' > Content already migrated to Hyper content.', Console::FG_GREEN); | ||
|
||
return null; | ||
} | ||
|
||
// Return `null` for an empty field, or already migrated to Hyper. | ||
// `false` for when unable to find matching new type. | ||
if (!$linkTypeClass || !$linkTypeHandle) { | ||
return false; | ||
} | ||
|
||
$link = new $linkTypeClass(); | ||
$link->handle = $linkTypeHandle; | ||
$link->linkValue = $oldSettings['url'] ?? $oldSettings['email'] ?? $oldSettings['elementId'] ?? null; | ||
$link->linkText = $oldSettings['overrideText'] ?? null; | ||
$link->newWindow = ($oldSettings['target'] ?? '') === '_blank'; | ||
|
||
return [$link->getSerializedValues()]; | ||
} | ||
} |
Oops, something went wrong.