flaglists migration is ok, but flood drupal

This commit is contained in:
Bachir Soussi Chiadmi 2021-02-26 10:49:05 +01:00
parent 30998980ca
commit 9f4cf46822
4 changed files with 106 additions and 38 deletions

View File

@ -1,3 +1,5 @@
# idlist=43615,53523,53524,58332,58333,58681,58682,58683,69219,69221,69235,69236,69237,69238,70903,72618,72619
# This is the migrations file from Flag Lists D7
id: d7_flaglistitems
label: Materio Flag List Items D7
@ -8,41 +10,53 @@ migration_tags:
- Content
migration_dependencies:
required:
- d7_flaglists
- d7_users
- d7_node_article
- d7_node_materiau
- d7_flaglists
source:
plugin: d7_flaglistitems_materio
#
process:
id: fcid
# id: fcid
# user_id: uid
user_id:
plugin: migration_lookup
migration: d7_users
source: uid
type: entity_type
# flag_list: fid
flag_list:
plugin: migration_lookup
migration: d7_flaglists
source: fid
baseflag: relatedflag
# baseflag:
# plugin: skip_on_empty
# method: row
# source: relatedflag
# TODO: skip if article or enable flaging of articles on D8
entity_id:
plugin: migration_lookup
migration:
- d7_node_materiau
- d7_node_article
no_stub: true
source: entity_id
# TODO use the destination entity_id isnstead of the original id
name:
plugin: concat
source:
- title
- entity_id
- dest_entity_id
delimiter: ' '
baseflag: relatedflag
flag_list: fid
# entity_id: entity_id
entity_id:
-
plugin: skip_on_empty
method: process
source: linked_materials
-
plugin: migration_lookup
migration: d7_node_materiau
no_stub: true
# type: entity_type
#
destination:
plugin: entity:flag_list_item

View File

@ -1,3 +1,6 @@
# user test 55811
# dossier test 4009,5084,6008,6315
# This is the migrations file from Flag Lists D7
id: d7_flaglists
label: 'Materio Flagging Collections D7'
@ -17,8 +20,8 @@ source:
# key: migrate
#
process:
id: fid
vid: fid
# id: fid
# vid: fid
langcode:
plugin: default_value
default_value: en
@ -42,4 +45,4 @@ process:
#
destination:
plugin: entity:flagging_collection
default_bundle: dossier
default_bundle: flagging_collection_type

View File

@ -5,6 +5,8 @@ namespace Drupal\materio_migrate\Plugin\migrate\source;
use Drupal\user\Entity\User;
use Drupal\migrate\Plugin\migrate\source\SqlBase;
use Drupal\migrate\Row;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Plugin\migrate\process\MigrationLookup;
/**
* Minimalistic example for a SqlBase source plugin.
@ -87,26 +89,72 @@ class D7FlagListItemsMaterio extends SqlBase {
// $row->setSourceProperty('uid', $owner);
// Check if the flagging collection exist.
$found = FALSE;
$flagListsService = \Drupal::service('flaglists');
$baseFlags = $flagListsService->getAllFlaggingCollections();
foreach ($baseFlags as $flag) {
if ($found =
$flag->get('id')->value == $row->getSourceProperty('fid')) {
$relatedFlag = $flag->get('relatedflag')->getValue();
$relatedFlagList = $relatedFlag['0']['target_id'];
$row->setSourceProperty('relatedflag', $relatedFlagList);
// $found = FALSE;
$fid = $row->getSourceProperty('fid');
$database = \Drupal::database();
$fidquery = $database->select('migrate_map_d7_flaglists', 'm')
->condition('m.sourceid1', $fid)
->fields('m', ['sourceid1', 'destid1']);
$result = $fidquery->execute();
foreach ($result as $record) {
if($record){
$dfid = $record->destid1;
break;
}
}
if (!$found) {
$message = $this->t('The flagging collection "@collection" wasn\'t found');
$messenger->addError($message,
['@collection' => $row->getSourceProperty('relatedflag')]);
$logger->error($message,
['@collection' => $row->getSourceProperty('relatedflag')]);
// if flag_collection already imported
if($dfid){
$flagListsService = \Drupal::service('flaglists');
$baseFlags = $flagListsService->getAllFlaggingCollections();
foreach ($baseFlags as $flag) {
if ($flag->get('id')->value == $dfid) {
$relatedFlag = $flag->get('relatedflag')->getValue();
$relatedFlagList = $relatedFlag['0']['target_id'];
$row->setSourceProperty('relatedflag', $relatedFlagList);
break;
}
}
}
// TODO: dest_entity_id (for name composition)
$entity_id = $row->getSourceProperty('entity_id');
// $database = \Drupal::database();
$query_entityid = $database->select('migrate_map_d7_node_materiau', 'm')
->condition('m.sourceid1', $entity_id)
->fields('m', ['sourceid1', 'destid1']);
$result = $query_entityid->execute();
foreach ($result as $record) {
if($record){
$dest_entity_id = $record->destid1;
break;
}
}
if(!$dest_entity_id){
$query_entityid = $database->select('migrate_map_d7_node_article', 'm')
->condition('m.sourceid1', $entity_id)
->fields('m', ['sourceid1', 'destid1']);
$result = $query_entityid->execute();
foreach ($result as $record) {
if($record){
$dest_entity_id = $record->destid1;
break;
}
}
}
if($dest_entity_id){
$row->setSourceProperty('dest_entity_id', $dest_entity_id);
}else{
$row->setSourceProperty('dest_entity_id', $entity_id);
}
// if (!$found) {
// $message = $this->t('The flagging collection "@collection" wasn\'t found');
// $messenger->addError($message,
// ['@collection' => $row->getSourceProperty('relatedflag')]);
// $logger->error($message,
// ['@collection' => $row->getSourceProperty('relatedflag')]);
// }
// Check if the entity exists.
// $entity_id = $row->getSourceProperty('entity_id');
// $entity = \Drupal::entityTypeManager()->getStorage($row->getSourceProperty('entity_type'))->load($entity_id);

View File

@ -110,13 +110,16 @@ class D7FlagListsMaterio extends SqlBase {
// [error] Drupal\Core\Config\Entity\Exception\ConfigEntityIdLengthException: Attempt to create a bundle with an ID longer than 32 characters: prototypage_rapide_grandes_dimensions(). in Drupal\Core\Entity\EntityBase->preSave() (line 439 of /var/www/html/d8.materio.com/public_html/web/core/lib/Drupal/Core/Entity/EntityBase.php).
// [error] Attempt to create a bundle with an ID longer than 32 characters: prototypage_rapide_grandes_dimensions(). (/var/www/html/d8.materio.com/public_html/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php:846)
// limit folder name to 32 characters
// limit folder name to 32 characters (32 bytes, special chars like é use 2 bytes)
$title = $row->getSourceProperty('title');
if (strlen($title) > 32) {
$title = substr($title, 0, 29).'...';
$title = $row->setSourceProperty('title', $title);
if (mb_strlen($title) > 32) {
$title = mb_strcut($title, 0 , 28).'...';
}
$row->setSourceProperty('title', $title);
return parent::prepareRow($row);
}