Commit 85042d01 authored by catch's avatar catch

Revert "Issue #2500513 by svendecabooter, phenaproxima: Upgrade path for Shortcut 7.x"

This reverts commit 33608908.
parent 8691e08f
......@@ -9964,60 +9964,8 @@ public function load() {
'p8' => '0',
'p9' => '0',
'updated' => '0',
))->values(array(
'menu_name' => 'shortcut-set-2',
'mlid' => '472',
'plid' => '0',
'link_path' => 'admin/help',
'router_path' => 'admin/help',
'link_title' => 'Help',
'options' => 'a:0:{}',
'module' => 'menu',
'hidden' => '0',
'external' => '0',
'has_children' => '0',
'expanded' => '0',
'weight' => '-49',
'depth' => '1',
'customized' => '0',
'p1' => '472',
'p2' => '0',
'p3' => '0',
'p4' => '0',
'p5' => '0',
'p6' => '0',
'p7' => '0',
'p8' => '0',
'p9' => '0',
'updated' => '0',
))->values(array(
'menu_name' => 'shortcut-set-2',
'mlid' => '473',
'plid' => '0',
'link_path' => 'admin/people',
'router_path' => 'admin/people',
'link_title' => 'People',
'options' => 'a:0:{}',
'module' => 'menu',
'hidden' => '0',
'external' => '0',
'has_children' => '0',
'expanded' => '0',
'weight' => '-50',
'depth' => '1',
'customized' => '0',
'p1' => '473',
'p2' => '0',
'p3' => '0',
'p4' => '0',
'p5' => '0',
'p6' => '0',
'p7' => '0',
'p8' => '0',
'p9' => '0',
'updated' => '0',
))->execute();
}
}
#f486477d40296da58f59a61204fa5370
#8e0b0e21959e36a659b7ac2c4206fecd
......@@ -47,11 +47,8 @@ public function load() {
->values(array(
'set_name' => 'shortcut-set-1',
'title' => 'Default',
))->values(array(
'set_name' => 'shortcut-set-2',
'title' => 'Alternative shortcut set',
))->execute();
}
}
#65b4e1b8c85fc2c4232ce4bdb50a15ab
#b3fff732e065eff0eff212928ce45a0c
......@@ -45,11 +45,8 @@ public function load() {
'uid',
'set_name',
))
->values(array(
'uid' => '2',
'set_name' => 'shortcut-set-2',
))->execute();
->execute();
}
}
#ee87e7f17ab09f7cdf72e64b5a66aca2
#56b71631616c8eae6cc71b0ae443426a
id: d7_shortcut
label: Shortcut links
migration_tags:
- Drupal 7
source:
plugin: d7_shortcut
constants:
uri_scheme: 'internal:/'
process:
shortcut_set:
plugin: migration
migration: d7_shortcut_set
source: menu_name
title: link_title
weight: weight
link:
plugin: concat
source:
- 'constants/uri_scheme'
- link_path
destination:
plugin: entity:shortcut
migration_dependencies:
required:
- d7_shortcut_set
- d7_menu_links
id: d7_shortcut_set
label: Shortcut sets
migration_tags:
- Drupal 7
source:
plugin: d7_shortcut_set
process:
id:
-
plugin: static_map
bypass: true
source: set_name
map:
shortcut-set-1: default
-
plugin: machine_name
field: id
label: title
destination:
plugin: entity:shortcut_set
id: d7_shortcut_set_users
label: Shortcut set user mapping
migration_tags:
- Drupal 7
source:
plugin: d7_shortcut_set_users
process:
uid:
-
plugin: migration
migration: d7_user
source: uid
-
plugin: skip_on_empty
method: row
set_name:
plugin: migration
migration: d7_shortcut_set
source: set_name
destination:
plugin: shortcut_set_users
migration_dependencies:
required:
- d7_shortcut_set
- d7_user
<?php
/**
* @file
* Contains \Drupal\shortcut\Plugin\migrate\destination\EntityShortcutSet.
*/
namespace Drupal\shortcut\Plugin\migrate\destination;
use Drupal\migrate\Row;
use Drupal\Core\Entity\EntityInterface;
use Drupal\migrate\Plugin\migrate\destination\EntityConfigBase;
/**
* @MigrateDestination(
* id = "entity:shortcut_set"
* )
*/
class EntityShortcutSet extends EntityConfigBase {
/**
* {@inheritdoc}
*/
protected function getEntity(Row $row, array $old_destination_id_values) {
$entity = parent::getEntity($row, $old_destination_id_values);
// Set the "syncing" flag to TRUE, to avoid duplication of default
// shortcut links
$entity->setSyncing(TRUE);
return $entity;
}
}
<?php
/**
* @file
* Contains \Drupal\shortcut\Plugin\migrate\destination\ShortcutSetUsers.
*/
namespace Drupal\shortcut\Plugin\migrate\destination;
use Drupal\shortcut\ShortcutSetStorageInterface;
use Drupal\user\Entity\User;
use Drupal\migrate\Entity\MigrationInterface;
use Drupal\migrate\Row;
use Drupal\migrate\Plugin\migrate\destination\DestinationBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
/**
* @MigrateDestination(
* id = "shortcut_set_users"
* )
*/
class ShortcutSetUsers extends DestinationBase implements ContainerFactoryPluginInterface {
/**
* The shortcut set storage handler.
*
* @var \Drupal\shortcut\ShortcutSetStorageInterface
*/
protected $shortcutSetStorage;
/**
* Constructs an entity destination plugin.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param MigrationInterface $migration
* The migration.
* @param \Drupal\shortcut\ShortcutSetStorageInterface $shortcut_set_storage
* The shortcut_set entity storage handler.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration, ShortcutSetStorageInterface $shortcut_set_storage) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $migration);
$this->shortcutSetStorage = $shortcut_set_storage;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition, MigrationInterface $migration = NULL) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$migration,
$container->get('entity.manager')->getStorage('shortcut_set')
);
}
/**
* {@inheritdoc}
*/
public function getIds() {
return array(
'set_name' => array(
'type' => 'string',
),
'uid' => array(
'type' => 'integer',
),
);
}
/**
* {@inheritdoc}
*/
public function fields(MigrationInterface $migration = NULL) {
return [
'uid' => 'The users.uid for this set.',
'source' => 'The shortcut_set.set_name that will be displayed for this user.',
];
}
/**
* {@inheritdoc}
*/
public function import(Row $row, array $old_destination_id_values = array()) {
/** @var \Drupal\shortcut\ShortcutSetInterface $set */
$set = $this->shortcutSetStorage->load($row->getDestinationProperty('set_name'));
/** @var \Drupal\user\UserInterface $account */
$account = User::load($row->getDestinationProperty('uid'));
$this->shortcutSetStorage->assignUser($set, $account);
return array($set->id(), $account->id());
}
}
<?php
/**
* @file
* Contains \Drupal\shortcut\Plugin\migrate\source\d7\Shortcut.
*/
namespace Drupal\shortcut\Plugin\migrate\source\d7;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal 7 shortcut links source from database.
*
* @MigrateSource(
* id = "d7_shortcut",
* source_provider = "shortcut"
* )
*/
class Shortcut extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
return $this->select('menu_links', 'ml')
->fields('ml', array('mlid', 'menu_name', 'link_path', 'link_title', 'weight'))
->condition('hidden', '0')
->condition('menu_name', 'shortcut-set-%', 'LIKE');
}
/**
* {@inheritdoc}
*/
public function fields() {
return array(
'mlid' => $this->t("The menu.mlid primary key for this menu item (= shortcut link)."),
'menu_name' => $this->t("The menu_name (= set name) for this shortcut link."),
'link_path' => $this->t("The link for this shortcut."),
'link_title' => $this->t("The title for this shortcut."),
'weight' => $this->t("The weight for this shortcut"),
);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['mlid']['type'] = 'integer';
return $ids;
}
}
<?php
/**
* @file
* Contains \Drupal\shortcut\Plugin\migrate\source\d7\ShortcutSet.
*/
namespace Drupal\shortcut\Plugin\migrate\source\d7;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal 7 shortcut_set source from database.
*
* @MigrateSource(
* id = "d7_shortcut_set",
* source_provider = "shortcut"
* )
*/
class ShortcutSet extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
return $this->select('shortcut_set', 'ss')->fields('ss');
}
/**
* {@inheritdoc}
*/
public function fields() {
return array(
'set_name' => $this->t("The name under which the set's links are stored."),
'title' => $this->t("The title of the set."),
);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['set_name']['type'] = 'string';
return $ids;
}
}
<?php
/**
* @file
* Contains \Drupal\shortcut\Plugin\migrate\source\d7\ShortcutSetUsers.
*/
namespace Drupal\shortcut\Plugin\migrate\source\d7;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal 7 shortcut_set_users source from database.
*
* @MigrateSource(
* id = "d7_shortcut_set_users",
* source_provider = "shortcut"
* )
*/
class ShortcutSetUsers extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
return $this->select('shortcut_set_users', 'ssu')->fields('ssu');
}
/**
* {@inheritdoc}
*/
public function fields() {
return array(
'uid' => $this->t('The users.uid for this set.'),
'set_name' => $this->t('The shortcut_set.set_name that will be displayed for this user.'),
);
}
/**
* {@inheritdoc}
*/
public function getIds() {
return array(
'set_name' => array(
'type' => 'string',
),
'uid' => array(
'type' => 'integer',
),
);
}
}
<?php
/**
* @file
* Contains \Drupal\shortcut\Tests\Migrate\d7\MigrateShortcutSetTest.
*/
namespace Drupal\shortcut\Tests\Migrate\d7;
use Drupal\shortcut\Entity\ShortcutSet;
use Drupal\shortcut\ShortcutSetInterface;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
/**
* Test shortcut_set migration to ShortcutSet entities.
*
* @group shortcut
*/
class MigrateShortcutSetTest extends MigrateDrupal7TestBase {
/**
* Modules to enable.
*
* @var array
*/
static $modules = array(
'link',
'field',
'shortcut',
'menu_link_content',
);
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installSchema('system', array('router'));
$this->installEntitySchema('shortcut');
$this->installEntitySchema('menu_link_content');
$this->executeMigration('d7_shortcut_set');
$this->executeMigration('menu');
$this->executeMigration('d7_menu_links');
$this->executeMigration('d7_shortcut');
}
/**
* Test the shortcut set migration.
*/
public function testShortcutSetMigration() {
$this->assertEntity('default', 'Default', 2);
$this->assertEntity('shortcut_set_2', 'Alternative shortcut set', 2);
}
/**
* Asserts various aspects of a shortcut set entity.
*
* @param string $id
* The expected shortcut set ID.
* @param string $label
* The expected shortcut set label.
* @param int $expected_size
* The number of shortcuts expected to be in the set.
*/
protected function assertEntity($id, $label, $expected_size) {
$shortcut_set = ShortcutSet::load($id);
$this->assertTrue($shortcut_set instanceof ShortcutSetInterface);
/** @var \Drupal\shortcut\ShortcutSetInterface $shortcut_set */
$this->assertIdentical($id, $shortcut_set->id());
$this->assertIdentical($label, $shortcut_set->label());
// Check the number of shortcuts in the set.
$shortcuts = $shortcut_set->getShortcuts();
$this->assertIdentical(count($shortcuts), $expected_size);
}
}
<?php
/**
* @file
* Contains \Drupal\shortcut\Tests\Migrate\d7\MigrateShortcutSetUsersTest.
*/
namespace Drupal\shortcut\Tests\Migrate\d7;
use Drupal\user\Entity\User;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
/**
* Test shortcut_set_users migration.
*
* @group shortcut
*/
class MigrateShortcutSetUsersTest extends MigrateDrupal7TestBase {
/**
* Modules to enable.
*
* @var array
*/
static $modules = array(
'link',
'field',
'shortcut',
'menu_link_content',
);
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installSchema('system', array('router'));
$this->installEntitySchema('shortcut');
$this->installEntitySchema('menu_link_content');
$this->installSchema('shortcut', ['shortcut_set_users']);
$this->executeMigration('d7_user_role');
$this->executeMigration('d7_user');
$this->executeMigration('d7_shortcut_set');
$this->executeMigration('menu');
$this->executeMigration('d7_menu_links');
$this->executeMigration('d7_shortcut');
$this->executeMigration('d7_shortcut_set_users');
}
/**
* Test the shortcut set migration.
*/
public function testShortcutSetUsersMigration() {
// Check if migrated user has correct migrated shortcut set assigned.
$account = User::load(2);
$shortcut_set = shortcut_current_displayed_set($account);
/** @var \Drupal\shortcut\ShortcutSetInterface $shortcut_set */
$this->assertIdentical('shortcut_set_2', $shortcut_set->id());
}
}
<?php
/**
* @file
* Contains \Drupal\shortcut\Tests\Migrate\d7\MigrateShortcutTest.
*/
namespace Drupal\shortcut\Tests\Migrate\d7;
use Drupal\shortcut\Entity\Shortcut;
use Drupal\shortcut\ShortcutInterface;
use Drupal\migrate_drupal\Tests\d7\MigrateDrupal7TestBase;
/**
* Test shortcut menu links migration to Shortcut entities.
*
* @group shortcut
*/
class MigrateShortcutTest extends MigrateDrupal7TestBase {
/**
* Modules to enable.
*
* @var array
*/
static $modules = array(
'link',
'field',
'shortcut',
'menu_link_content',
);
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installSchema('system', array('router'));
$this->installEntitySchema('shortcut');
$this->installEntitySchema('menu_link_content');
$this->executeMigration('d7_shortcut_set');
$this->executeMigration('menu');
$this->executeMigration('d7_menu_links');
$this->executeMigration('d7_shortcut');
}
/**
* Asserts various aspects of a shortcut entity.
*
* @param int $id
* The shortcut ID.
* @param string $title
* The expected title of the shortcut.
* @param int $weight
* The expected weight of the shortcut.
* @param string $url
* The expected URL of the shortcut.
*/
protected function assertEntity($id, $title, $weight, $url) {
$shortcut = Shortcut::load($id);
$this->assertTrue($shortcut instanceof ShortcutInterface);
/** @var \Drupal\shortcut\ShortcutInterface $shortcut */
$this->assertIdentical($title, $shortcut->getTitle());
$this->assertIdentical($weight, $shortcut->getWeight());
$this->assertIdentical($url, $shortcut->getUrl()->toString());
}
/**
* Test the shortcut migration.
*/
public function testShortcutMigration() {
// Check if the 4 shortcuts were migrated correctly.
$this->assertEntity(1, 'Add content', '-20', '/node/add');
$this->assertEntity(2, 'Find content', '-19', '/admin/content');
$this->assertEntity(3, 'Help', '-49', '/admin/help');
$this->assertEntity(4, 'People', '-50', '/admin/people');
}
}
<?php
/**
* @file
* Contains \Drupal\Tests\shortcut\Unit\Plugin\migrate\source\d7\ShortcutSetTest.
*/
namespace Drupal\Tests\shortcut\Unit\Plugin\migrate\source\d7;
use Drupal\Tests\migrate\Unit\MigrateSqlSourceTestCase;
/**
* Tests D7 ShortcutSet source plugin.
*
* @group shortcut
*/
class ShortcutSetTest extends MigrateSqlSourceTestCase {
const PLUGIN_CLASS = 'Drupal\shortcut\Plugin\migrate\source\d7\ShortcutSet';
protected $migrationConfiguration = [
'id' => 'test',
'source' => [
'plugin' => 'd7_shortcut_set',
],
];
protected $expectedResults = [
[
'set_name' => 'shortcut-set-2',
'title' => 'Alternative shortcut set',
],