cforge-2.0.x-dev/cforge.migrate.inc
cforge.migrate.inc
<?php
use Drupal\migrate\MigrateSkipRowException;
use Drupal\cforge\EventSubscriber\MigrationSubscriber;
use Drupal\user\Entity\User;
use Drupal\migrate\Row;
/**
* Implements hook_migration_plugins_alter().
*/
function _cforge_migration_plugins_alter(array &$definitions) {
// When this runs a subsequent time, previously exported items are counted twice.
foreach (array_keys($definitions) as $key) {
if (substr($key, 0, 8) == 'upgrade_') {
unset($definitions[$key]);
}
}
unset($definitions['d7_menu_link_translation']);
$definitions['d7_block']['process']['region']['map']['sky_seldulac']['sky_seldulac'] = [
'help' => 'top',
'headerright' => null, // this isn't a region any more. see menu "topright"
'navigation' => 'top',
'contentbottom' => 'content',
'contentfooter' => 'footer',
'footer' => 'footer'
];
$definitions['d7_filter_format']['process']['filters']['id']['map'] = MigrationSubscriber::FILTER_FORMATS;
$definitions['d7_filter_format']['process']['filters']['id']['default_value'] = 'plain_text';
$definitions['d7_block']['process']['plugin'][0]['map']['cforge']['cf_training'] = 'hamlets_vid';
$definitions['d7_block']['process']['plugin'][0]['map']['cforge']['decouvrir'] = 'hamlets_vid';
$definitions['d7_block']['process']['plugin'][0]['map']['cforge']['nitin'] = 'hamlets_vid';
$definitions['d7_block']['process']['plugin'][0]['map']['cforge']['sel_promo'] = 'sel_promo_block';
// This is missing from the poll module
$definitions['d7_block']['process']['plugin'][0]['map']['poll']['recent'] = 'poll_recent_block';
// Change the name of the d7 'event_date' field to 'date'
foreach ($definitions as &$def) {
if (isset($def['process']['event_date'])) {
$def['process']['date'] = $def['process']['event_date'];
$def['process']['date']['process']['value']['to_format'] = 'Y-m-d\TH:i:s';
unset($def['process']['event_date']);
}
}
$definitions['d7_menu']['process']['id']['map']['secondary-menu'] = 'topright';
$definitions['d7_menu']['process']['id']['map']['main'] = 'visitors';
$definitions['d7_user']['migration_dependencies']['required'][] = 'd7_cf_neighbourhoods';
// Try to make this last
$definitions['d7_menu_links']['migration_dependencies']['required'][] = 'd7_cforge_settings';
$skip = [
'action_settings',
'user_profile_field',
'user_profile_field_instance',
'user_profile_entity_display',
'user_profile_entity_form_display',
'd7_view_mode',
'd7_search_settings',
'd7_search_page',
'd7_comment_entity_form_display',
'd7_comment_entity_display',
'd7_comment_field_instance',
'd7_system_file',
'd7_system_mail',
'd7_theme_settings',
'd7_system_authorize',
'd7_node:webform',
'd7_filter_format'
];
foreach ($skip as $mig) {
unset($definitions[$mig]);
}
unset(
$definitions['d7_filter_format']['process']['filters']['id']['bypass'],
// After a week of trying I'm working around this. See MigrationSubsriber::migratePostRowSave
$definitions['d7_user']['process']['user_picture']
);
}
/**
* Implements hook_migrate_prepare_row().
*/
function cforge_migrate_d7_filter_format_prepare_row(Row $row, $source, $migration) {
$ignore = array_keys(MigrationSubscriber::FILTER_FORMATS);
if (in_array($row->getSourceProperty('format'), $ignore)) {
throw new MigrateSkipRowException("Ignoring unknown filter format");
}
}
/**
* Implements hook_migrate_prepare_row().
*/
function cforge_migrate_d7_comment_prepare_row(Row $row, $source, $migration) {
// Skip comments where the user has been deleted.
$uid = $row->getSourceProperty('uid');
if (!User::load($uid)) {
throw new MigrateSkipRowException("User $uid no longer exists");
}
}
/**
* Implements hook_migrate_prepare_row().
*/
function cforge_migrate_d7_menu_prepare_row(Row $row, $source, $migration) {
if ($row->getSourceProperty('menu_name') == 'visitors') {
throw new MigrateSkipRowException("Not migrating visitors menu");
}
}
/**
* Implements hook_migrate_prepare_row().
*/
function cforge_migrate_d7_menu_links_prepare_row(Row $row, $source, $migration) {
// Only migrate menu links which are not already in the menu tree.
// Use the title to identify menu links.
$dont_mig_paths = ['offers', 'wants', 'members', 'transactions', 'news', 'community-tasks', 'user/logout', 'user'];
if (in_array($row->getSourceProperty('link_path'), $dont_mig_paths)) {
throw new MigrateSkipRowException("Menu link titled '".$row->getSourceProperty('link_path')."': ".$row->getSourceProperty('link_path')." already exists.");
}
if (in_array($row->getSourceProperty('menu_name'), ['setup', 'account'])) {
throw new MigrateSkipRowException("Not migrating links in ".$row->getSourceProperty('menu_name')." menu.");
}
if ($row->getSourceProperty('router_path') == 'admin/structure/taxonomy/%') {
if ($row->getSourceProperty('link_title')) {
$vocab = end(explode('/', $row->getSourceProperty('link_path')));
$row->setSourceProperty('link_path', 'admin/structure/taxonomy/manage/'.$vocab.'/overview');
\Drupal::messenger()->addStatus('Upgrading menu link_path: '.$row->getSourceProperty('link_path'));
}
}
if ($row->getSourceProperty('link_path') == 'hamlets_helpdesk') {
throw new MigrateSkipRowException("hamlets_helpdesk menu link Has been replaced");
}
if ($row->getSourceProperty('link_path') == 'admin/config/system/backup_migrate/export') {
throw new MigrateSkipRowException("Not migrating this link.");
}
}
/**
* Implements hook_migrate_prepare_row().
*/
function cforge_migrate_d7_theme_settings_prepare_row(Row $row, $source, $migration) {
$active_theme_name = \Drupal::theme()->getActiveTheme()->getName();
if ($row->getSourceProperty('name') != 'theme_'.$active_theme_name.'_settings') {
throw new MigrateSkipRowException("Active theme is $active_theme_name; Not migrating ".$row->getSourceProperty('name'));
}
}
/**
* Implements hook_migrate_prepare_row().
*/
function cforge_migrate_d7_contact_category_prepare_row(Row $row, $source, $migration) {
// The category is a machine name taken from the localised d7 category name.
if (strlen($row->getSourceProperty('category')) > 32) {
throw new MigrateSkipRowException('Skipping contact category '.$row->id());
}
}
/**
* Implements hook_migrate_prepare_row().
*/
function cforge_migrate_d7_block_prepare_row(Row $row, $source, $migration) {
if ($row->getSourceProperty('module') == 'views') {
throw new MigrateSkipRowException('Skipping block');
}
if ($row->getSourceProperty('theme') <> 'sky_seldulac') {
throw new MigrateSkipRowException('Skipping block');
}
// don't migrate some blocks.
elseif (in_array($row->getSourceProperty('delta'), ['visitors', 'form', 'online'])) {
throw new MigrateSkipRowException('Skipping block');
}
elseif ($row->getSourceProperty('module') == 'aggregator' and $row->getSourceProperty('delta') < 3) {
throw new MigrateSkipRowException('Aggregator block not migrated');
}
if (in_array($row->getSourceProperty('theme'), ['bartik', 'seven'])) {
throw new MigrateSkipRowException('Skipping block in theme '.$row->getSourceProperty('theme'));
}
}
/**
* Implements hook_migrate_prepare_row().
*/
function cforge_migrate_d7_action_prepare_row(Row $row, $source, $migration) {
$callback = $row->getSourceProperty('callback');
if (substr($callback, 0, 22) == 'views_bulk_operations_') {
if (!\Drupal::moduleHandler()->moduleExists('views_bulk_operations')) {
throw new MigrateSkipRowException();
}
}
elseif (!is_callable($callback)) {
throw new MigrateSkipRowException('Callback not found: '.$callback);
}
$skip = [
'mcapi_transaction_mail_action',
'og_set_state_action',
'og_membership_delete_action',
'system_block_ip_action',
'views_bulk_operations_user_roles_action',
'views_bulk_operations_archive_action',
'views_bulk_operations_argument_selector_action',
'views_bulk_operations_delete_item',
'views_bulk_operations_delete_revision',
'views_bulk_operations_modify_action',
'views_bulk_operations_remove_from_book_action'
];
if (in_array($row->id(), $skip)) {
throw new MigrateSkipRowException('Skipping action '.$row->id());
}
}
/**
* Implements hook_migrate_prepare_row().
* Don't migrate certain roles
*/
function cforge_migrate_d7_user_role_prepare_row(Row $row, $source, $migration) {
if (in_array($row->getSourceProperty('rid'), [3, 4, 6])) {
throw new MigrateSkipRowException("Role is already installed.");
}
}
/**
* Implements hook_migrate_prepare_row().
*/
function cforge_migrate_d7_node_type_prepare_row(Row $row, $source, $migration) {
$type = $row->getSourceProperty('field_name');
if (in_array($type, ['page', 'story'])) {
throw new MigrateSkipRowException("Type is already installed.");
}
}
