flaglists migration is ok, but flood drupal
This commit is contained in:
parent
30998980ca
commit
9f4cf46822
|
@ -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
|
# This is the migrations file from Flag Lists D7
|
||||||
id: d7_flaglistitems
|
id: d7_flaglistitems
|
||||||
label: Materio Flag List Items D7
|
label: Materio Flag List Items D7
|
||||||
|
@ -8,41 +10,53 @@ migration_tags:
|
||||||
- Content
|
- Content
|
||||||
migration_dependencies:
|
migration_dependencies:
|
||||||
required:
|
required:
|
||||||
- d7_flaglists
|
|
||||||
- d7_users
|
- d7_users
|
||||||
- d7_node_article
|
- d7_node_article
|
||||||
- d7_node_materiau
|
- d7_node_materiau
|
||||||
|
- d7_flaglists
|
||||||
source:
|
source:
|
||||||
plugin: d7_flaglistitems_materio
|
plugin: d7_flaglistitems_materio
|
||||||
#
|
#
|
||||||
process:
|
process:
|
||||||
id: fcid
|
# id: fcid
|
||||||
# user_id: uid
|
# user_id: uid
|
||||||
user_id:
|
user_id:
|
||||||
plugin: migration_lookup
|
plugin: migration_lookup
|
||||||
migration: d7_users
|
migration: d7_users
|
||||||
source: uid
|
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:
|
name:
|
||||||
plugin: concat
|
plugin: concat
|
||||||
source:
|
source:
|
||||||
- title
|
- title
|
||||||
- entity_id
|
- dest_entity_id
|
||||||
delimiter: ' '
|
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:
|
destination:
|
||||||
plugin: entity:flag_list_item
|
plugin: entity:flag_list_item
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
# user test 55811
|
||||||
|
# dossier test 4009,5084,6008,6315
|
||||||
|
|
||||||
# This is the migrations file from Flag Lists D7
|
# This is the migrations file from Flag Lists D7
|
||||||
id: d7_flaglists
|
id: d7_flaglists
|
||||||
label: 'Materio Flagging Collections D7'
|
label: 'Materio Flagging Collections D7'
|
||||||
|
@ -17,8 +20,8 @@ source:
|
||||||
# key: migrate
|
# key: migrate
|
||||||
#
|
#
|
||||||
process:
|
process:
|
||||||
id: fid
|
# id: fid
|
||||||
vid: fid
|
# vid: fid
|
||||||
langcode:
|
langcode:
|
||||||
plugin: default_value
|
plugin: default_value
|
||||||
default_value: en
|
default_value: en
|
||||||
|
@ -42,4 +45,4 @@ process:
|
||||||
#
|
#
|
||||||
destination:
|
destination:
|
||||||
plugin: entity:flagging_collection
|
plugin: entity:flagging_collection
|
||||||
default_bundle: dossier
|
default_bundle: flagging_collection_type
|
||||||
|
|
|
@ -5,6 +5,8 @@ namespace Drupal\materio_migrate\Plugin\migrate\source;
|
||||||
use Drupal\user\Entity\User;
|
use Drupal\user\Entity\User;
|
||||||
use Drupal\migrate\Plugin\migrate\source\SqlBase;
|
use Drupal\migrate\Plugin\migrate\source\SqlBase;
|
||||||
use Drupal\migrate\Row;
|
use Drupal\migrate\Row;
|
||||||
|
use Drupal\migrate\Plugin\MigrationInterface;
|
||||||
|
use Drupal\migrate\Plugin\migrate\process\MigrationLookup;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Minimalistic example for a SqlBase source plugin.
|
* Minimalistic example for a SqlBase source plugin.
|
||||||
|
@ -87,26 +89,72 @@ class D7FlagListItemsMaterio extends SqlBase {
|
||||||
// $row->setSourceProperty('uid', $owner);
|
// $row->setSourceProperty('uid', $owner);
|
||||||
|
|
||||||
// Check if the flagging collection exist.
|
// Check if the flagging collection exist.
|
||||||
$found = FALSE;
|
// $found = FALSE;
|
||||||
$flagListsService = \Drupal::service('flaglists');
|
$fid = $row->getSourceProperty('fid');
|
||||||
$baseFlags = $flagListsService->getAllFlaggingCollections();
|
$database = \Drupal::database();
|
||||||
foreach ($baseFlags as $flag) {
|
$fidquery = $database->select('migrate_map_d7_flaglists', 'm')
|
||||||
if ($found =
|
->condition('m.sourceid1', $fid)
|
||||||
$flag->get('id')->value == $row->getSourceProperty('fid')) {
|
->fields('m', ['sourceid1', 'destid1']);
|
||||||
$relatedFlag = $flag->get('relatedflag')->getValue();
|
$result = $fidquery->execute();
|
||||||
$relatedFlagList = $relatedFlag['0']['target_id'];
|
foreach ($result as $record) {
|
||||||
$row->setSourceProperty('relatedflag', $relatedFlagList);
|
if($record){
|
||||||
|
$dfid = $record->destid1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!$found) {
|
// if flag_collection already imported
|
||||||
$message = $this->t('The flagging collection "@collection" wasn\'t found');
|
if($dfid){
|
||||||
$messenger->addError($message,
|
$flagListsService = \Drupal::service('flaglists');
|
||||||
['@collection' => $row->getSourceProperty('relatedflag')]);
|
$baseFlags = $flagListsService->getAllFlaggingCollections();
|
||||||
$logger->error($message,
|
foreach ($baseFlags as $flag) {
|
||||||
['@collection' => $row->getSourceProperty('relatedflag')]);
|
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.
|
// Check if the entity exists.
|
||||||
// $entity_id = $row->getSourceProperty('entity_id');
|
// $entity_id = $row->getSourceProperty('entity_id');
|
||||||
// $entity = \Drupal::entityTypeManager()->getStorage($row->getSourceProperty('entity_type'))->load($entity_id);
|
// $entity = \Drupal::entityTypeManager()->getStorage($row->getSourceProperty('entity_type'))->load($entity_id);
|
||||||
|
|
|
@ -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] 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)
|
// [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');
|
$title = $row->getSourceProperty('title');
|
||||||
if (strlen($title) > 32) {
|
if (mb_strlen($title) > 32) {
|
||||||
$title = substr($title, 0, 29).'...';
|
$title = mb_strcut($title, 0 , 28).'...';
|
||||||
$title = $row->setSourceProperty('title', $title);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$row->setSourceProperty('title', $title);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return parent::prepareRow($row);
|
return parent::prepareRow($row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue