| 
					
				 | 
			
			
				@@ -0,0 +1,123 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+<?php 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+namespace Drupal\materio_migrate\Plugin\migrate\source; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+use Drupal\migrate\Plugin\migrate\source\SqlBase; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+use Drupal\migrate\Row; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+use Drupal\user\Entity\User; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ * Minimalistic example for a SqlBase source plugin. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ * @MigrateSource( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ *   id = "d7_flaglists_materio", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ *   source_module = "flag_lists", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ * ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+class D7FlagListsMaterio extends SqlBase { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   * {@inheritdoc} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  public function query() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // Source data is queried from 'flag_lists_flags' table. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    $query = $this->select('flag_lists_flags', 'c'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    $query->join('flag', 'f', 'c.pfid = f.fid'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    $query->fields('c', [ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      'fid', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      'pfid', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      'uid', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      'entity_type', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      'title', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      'options', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ]) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      ->fields('f', [ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        'name', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      ]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return $query; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   * {@inheritdoc} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  public function fields() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    $fields = [ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      'fid' => $this->t('Flag List #'), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      'pfid' => $this->t('Parent flag id #'), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      'uid' => $this->t('Owner'), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      'entity_type' => $this->t('Entity type'), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      'name' => $this->t('Machine name of the related flag'), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      'title' => $this->t('Name of flag list'), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      'option' => $this->t('Serielized info'), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return $fields; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   * {@inheritdoc} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  public function getIds() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return [ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      'fid' => [ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        'type' => 'integer', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        'alias' => 'c', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      ], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   * {@inheritdoc} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+   */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  public function prepareRow(Row $row) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    # WE GOT THE USER FROM LOOKUP PLUGIN 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // Check if the user exists. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // $uid = $row->getSourceProperty('uid'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // $user = User::load($uid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // if (!empty($user)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //   $owner = $uid; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //   // Make the Administrator the owner. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //   $owner = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // $row->setSourceProperty('uid', $owner); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    # WE SET THE FLAG TEMPLATE DEFAULT "DOSSIER" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // Check if the template flag exist. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // $found = FALSE; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // $flagService = \Drupal::service('flag'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // $templateFlags = $flagService->getAllFlags( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //   $row->getSourceProperty('entity_type')); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // foreach ($templateFlags as $flag) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //   if ($found = 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //     $flag->get('id') == $row->getSourceProperty('name')) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //     break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // if (!$found) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //   $message = $this->t('The template flag "@flag" wasn\'t found. Using fallback.', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //     ['@flag' => $row->getSourceProperty('name')]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //   $messenger = \Drupal::messenger(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //   $logger = \Drupal::logger('flag_lists'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //   $messenger->addWarning($message); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //   $logger->warning($message); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //   // Fall back to known existing flag. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    //   $row->setSourceProperty('name', 'flag_list_template_1'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    // [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 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    $title = $row->getSourceProperty('title'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    if (strlen($title) > 32) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      $title = substr($title, 0, 29).'...'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      $title = $row->setSourceProperty('title', $title); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    return parent::prepareRow($row); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 |