<?php
|
|
|
|
/**
|
|
* @file
|
|
* Contains sample_migration.module.
|
|
*/
|
|
|
|
use Drupal\Core\Routing\RouteMatchInterface;
|
|
|
|
/**
|
|
* Implements hook_help().
|
|
*/
|
|
function sample_migration_help($route_name, RouteMatchInterface $route_match) {
|
|
switch ($route_name) {
|
|
// Main module help for the sample_migration module.
|
|
case 'help.page.sample_migration':
|
|
$output = '';
|
|
$output .= '<h3>' . t('About') . '</h3>';
|
|
$output .= '<p>' . t('Sample Migrations') . '</p>';
|
|
return $output;
|
|
|
|
default:
|
|
}
|
|
}
|
|
|
|
function sample_migration_title_body_paragraphs(&$context) {
|
|
$entity_type_manager = \Drupal::service('entity_type.manager');
|
|
|
|
/* @var NodeStorage $node_storage */
|
|
$node_storage = $entity_type_manager->getStorage('node');
|
|
$media_storage = $entity_type_manager->getStorage('media');
|
|
$file_storage = $entity_type_manager->getStorage('file');
|
|
|
|
if (empty($context['sandbox'])) {
|
|
$context['sandbox'] = [];
|
|
}
|
|
|
|
if (!isset($context['sandbox']['progress'])) {
|
|
$context['sandbox']['progress'] = 0;
|
|
$context['sandbox']['current_index'] = 0;
|
|
$all_arm_pages = $node_storage->loadByProperties([
|
|
'type' => 'arm_page'
|
|
]);
|
|
$context['sandbox']['arm_content'] = array_values($all_arm_pages);
|
|
$context['sandbox']['arm_map'] = _get_arm_map();
|
|
$context['sandbox']['file_map'] = _get_file_map();
|
|
$context['sandbox']['d7_files'] = _get_d7_arm_files();
|
|
|
|
$context['sandbox']['index'] = array_values($context['sandbox']['arm_content']);
|
|
$context['sandbox']['max'] = count($context['sandbox']['arm_content']);
|
|
}
|
|
|
|
$limit = 10;
|
|
$indexes = range($context['sandbox']['current_index'], $context['sandbox']['current_index'] + $limit);
|
|
|
|
foreach ($indexes as $index) {
|
|
$node = $context['sandbox']['arm_content'][$index];
|
|
|
|
if (!is_null($node)) {
|
|
$context['results'][] = $node->title->value;
|
|
$d7nid = $context['sandbox']['arm_map'][$node->id()];
|
|
$d7file = $context['sandbox']['d7_files'][$d7nid->sourceid1];
|
|
|
|
if ($d7file) {
|
|
$d8file = $context['sandbox']['file_map'][$d7file->field_armpage_pdf_fid];
|
|
$current_file = $file_storage->load($d8file->destid1);
|
|
|
|
if ($d8file) {
|
|
$node->set('field_armpage_pdf', $current_file->id());
|
|
$node->save();
|
|
}
|
|
}
|
|
}
|
|
|
|
$context['sandbox']['progress']++;
|
|
$context['sandbox']['current_index'] = $index;
|
|
$context['message'] = t('Now processing Reviews');
|
|
}
|
|
|
|
// Update batch on our progress.
|
|
if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
|
|
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
|
|
}
|
|
else {
|
|
$context['sandbox']['finished'] = 1;
|
|
}
|
|
}
|
|
|
|
function sample_migration_title_body_paragraphs_finished() {
|
|
$messenger = \Drupal::messenger();
|
|
if ($success) {
|
|
$message = t('@count Reviews were added to Groups', ['@count' => count($results)]);
|
|
$messenger->addMessage($message);
|
|
}
|
|
else {
|
|
// Something went wrong
|
|
$error_operation = reset($operations);
|
|
$messenger->addMessage(
|
|
t('An error occurred while processing @operation with arguments : @args',
|
|
[
|
|
'@operation' => $error_operation[0],
|
|
'@args' => print_r($error_operation[0], TRUE)
|
|
]
|
|
)
|
|
);
|
|
}
|
|
}
|
|
|
|
function sample_migration_get_title_body_field_collections() {
|
|
Database::setActiveConnection('drupal7');
|
|
$drupal7db = Database::getConnection();
|
|
$query = $drupal7db->select('field_collection_item', 'fci')
|
|
->fields('fci', [
|
|
'item_id',
|
|
'field_name',
|
|
'revision_id'
|
|
]);
|
|
$query->innerJoin('field_data_' . $field_name, 'fd', 'fd.' . $field_name . '_value = fci.item_id');
|
|
$query->fields('fd', [
|
|
'entity_type',
|
|
'bundle',
|
|
'entity_id',
|
|
$field_name . '_revision_id'
|
|
]);
|
|
$query->condition('fci.field_name', $field_name);
|
|
|
|
$query->leftJoin('field_data_field_usingpage_block_image', 'fdfubi', 'fdfubi.entity_id = fci.item_id');
|
|
$query->fields('fdfubi', [
|
|
'entity_id',
|
|
'revision_id',
|
|
'field_usingpage_block_image_fid'
|
|
]);
|
|
|
|
$results = $query->execute()->fetchAll();
|
|
Database::setActiveConnection('default');
|
|
if (count($results)) {
|
|
$drupal8db = Database::getConnection();
|
|
$query = $drupal8db->select('migrate_map_upgrade_d7_node_using_library_page', 'mm');
|
|
$query->fields('mm', [
|
|
'sourceid1',
|
|
'destid1'
|
|
]);
|
|
$map_results = $query->execute()->fetchAllAssoc('sourceid1');
|
|
}
|
|
}
|
|
|
|
function sample_migration_get_test_paragraph_content_map() {
|
|
$drupal8db = Database::getConnection();
|
|
$query = $drupal8db->select('migrate_map_upgrade_d7_node_using_library_page', 'mm');
|
|
$query->fields('mm', [
|
|
'sourceid1',
|
|
'destid1'
|
|
]);
|
|
$map_results = $query->execute()->fetchAllAssoc('sourceid1');
|
|
}
|