PerfMigrate.ldcs.inc 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <?php
  2. /**
  3. * PerfGroupeNodeMigration
  4. *
  5. */
  6. class PerfLDCNodeMigration extends PerfApiMigration {
  7. public function __construct() {
  8. $this->description = t('Migrate Lieu Date Contexte (effectuation) Class');
  9. parent::__construct();
  10. $fields = array(
  11. 'language' => t('Lanuguage'),
  12. 'ID' => t('id'),
  13. 'title' => t('title'),
  14. 'structure_organisatrice' => t('Structure organisatrice'), // STRUCTURE_ORGANISATRICE
  15. 'topologie' => t('Topologie'),
  16. 'date_de_debut' => t('date debut'),
  17. 'date_de_fin' => t('date fin'),
  18. 'duree' => t('duree'), //'UNITE_DUREE' => t('UNITE_DUREE'),
  19. 'contexte' => t('contexte'), // CONTEXTE- TRADUCTION_CONTEXTE
  20. 'lieu' => t('lieu'),
  21. 'adresse' => t('adresse'),
  22. 'precision'=> t('precision'),
  23. 'ville' => t('ville'),
  24. 'pays' => t('pays'),
  25. 'executant'=> t('executant'),
  26. 'concepteur'=> t('concepteur'),
  27. 'organisateur'=> t('organisateur'),
  28. 'notes' => t('notes'),
  29. );
  30. // The source ID here is the one retrieved from the XML listing file, and
  31. // used to identify the specific item's file
  32. $this->map = new MigrateSQLMap($this->machineName,
  33. array(
  34. 'ID' => array(
  35. 'type' => 'varchar',
  36. 'length' => 255,
  37. 'not null' => TRUE,
  38. )
  39. ),
  40. MigrateDestinationNode::getKeySchema()
  41. );
  42. // This can also be an URL instead of a file path.
  43. $xml_folder = DRUPAL_ROOT . '/' . drupal_get_path('module', 'PerfMigrate') . '/xml/';
  44. $items_url = $xml_folder . 'baseperf-ldcs.xml';
  45. // We use the MigrateSourceMultiItems class for any source where we obtain the list
  46. // of IDs to process and the data for each item from the same file. Typically the data
  47. // for an item is not contained in a single line within the source file. Examples include
  48. // multiple items defined in a single xml file or a single json file where in both cases
  49. // the id is part of the item.
  50. $item_xpath = '/ROOT/ITEMS/LIEU_DATE_CONTEXTE'; // relative to document
  51. $item_ID_xpath = '@ID'; // relative to item_xpath and gets assembled
  52. // into full path /producers/producer/sourceid
  53. $items_class = new MigrateItemsXML($items_url, $item_xpath, $item_ID_xpath); //
  54. $this->source = new MigrateSourceMultiItems($items_class, $fields);
  55. $this->destination = new MigrateDestinationNode('effectuation');
  56. $this->addFieldMapping('language')->defaultValue('fr');
  57. $this->addFieldMapping('is_new')->defaultValue(TRUE);
  58. // $this->addFieldMapping('created', 'date_creation');
  59. // $this->addFieldMapping('changed', 'date_modif');
  60. $this->addFieldMapping('status')->defaultValue(1);
  61. $this->addFieldMapping('promote')->defaultValue(0);
  62. $this->addFieldMapping('sticky')->defaultValue(0);
  63. $this->addFieldMapping('title', 'title');
  64. # temps
  65. $this->addFieldMapping('field_date_de_debut', 'date_de_debut');
  66. $this->addFieldMapping('field_date_de_fin', 'date_de_fin');
  67. $this->addFieldMapping('field_duree', 'duree');
  68. # lieu
  69. $this->addFieldMapping('field_lieu', 'lieu')
  70. ->xpath('@NOM_LIEU');
  71. $this->addFieldMapping('field_lieu:create_term')->defaultValue(TRUE);
  72. # topologie
  73. $this->addFieldMapping('field_topologie', 'topologie')
  74. ->xpath('@TYPE');
  75. $this->addFieldMapping('field_topologie:create_term')->defaultValue(TRUE);
  76. # structure_organisatrice
  77. $this->addFieldMapping('field_structure', 'structure_organisatrice');
  78. $this->addFieldMapping('field_structure:create_term')->defaultValue(TRUE);
  79. # contexte
  80. $this->addFieldMapping('field_contexte', 'contexte');
  81. $this->addFieldMapping('field_contexte:format')->defaultValue('filtred_html');
  82. $this->addFieldMapping('field_contexte:language', 'language');
  83. # personnes
  84. $this->addFieldMapping('field_concepteur', 'concepteur');
  85. $this->addFieldMapping('field_concepteur:create_term')->defaultValue(TRUE);
  86. $this->addFieldMapping('field_executant', 'executant');
  87. $this->addFieldMapping('field_executant:create_term')->defaultValue(TRUE);
  88. $this->addFieldMapping('field_organisateur', 'organisateur');
  89. $this->addFieldMapping('field_organisateur:create_term')->defaultValue(TRUE);
  90. # note
  91. $this->addFieldMapping('field_note', 'notes')
  92. ->xpath('@NOTES');
  93. # addresse
  94. // $this->addFieldMapping('field_precision', 'precision')
  95. // ->xpath('@PRECISION');
  96. // $this->addFieldMapping('field_precision:format')->defaultValue('filtred_html');
  97. // $this->addFieldMapping('field_precision:language')->defaultValue('fr');
  98. $arguments = array(
  99. 'thoroughfare' => array('source_field' => 'adresse'),
  100. 'premise' => array('source_field' => 'precision'),
  101. // 'sub_premise' => array('source_field' => 'sub_premise'),
  102. 'locality' => array('source_field' => 'ville'),
  103. // 'postal_code' => array('source_field' => 'zip'),
  104. );
  105. $this->addFieldMapping('field_address', 'pays')
  106. ->arguments($arguments);
  107. $this->addFieldMapping(NULL, 'adresse');
  108. $this->addFieldMapping(NULL, 'precision');
  109. $this->addFieldMapping(NULL, 'ville');
  110. $this->addUnmigratedDestinations(array('revision_uid', 'created', 'changed', 'revision', 'log', 'tnid','comment', 'uid','path', 'pathauto',
  111. 'field_date_de_debut:format', 'field_date_de_debut:language', 'field_date_de_fin:format', 'field_date_de_fin:language',
  112. 'field_dure:format', 'field_dure:language',
  113. 'field_lieu:source_type', 'field_topologie:source_type', 'field_structure:source_type',
  114. 'field_concepteur:source_type','field_executant:source_type','field_organisateur:source_type',
  115. 'field_note:format', "field_note:language",
  116. ));
  117. }
  118. public function prepareRow($row){
  119. // dsm($row , '--- $row ---');
  120. $xml = $row->xml;
  121. $row->language = array('fr', 'en');
  122. $title = $this->getAttribute($xml, 'TITLE');
  123. if(strlen($title) > 255)
  124. $title = substr($title, 0, 250) . '...';
  125. $row->title = $title;
  126. # temps
  127. $row->date_de_debut = $this->getDate($xml, 'DEBUT');
  128. $row->date_de_fin = $this->getDate($xml, 'FIN');
  129. $row->duree = $this->getAttribute($xml, 'DUREE') .' '. $this->getAttribute($xml, 'UNITE_DUREE');
  130. # espace
  131. $row->lieu = $this->getAttribute($xml, 'NOM_LIEU');
  132. # structure
  133. $structure = array();
  134. foreach ($xml->xpath('STRUCTURE_ORGANISATRICE') as $xml_strucrture)
  135. $structure[] = $this->getAttribute($xml_strucrture, 'NOM');
  136. $row->structure_organisatrice = $structure;
  137. # contexte
  138. $row->contexte = array(
  139. $this->getAttribute($xml, "CONTEXTE"),
  140. $this->getAttribute($xml, "TRADUCTION_CONTEXTE"),
  141. );
  142. # personnes
  143. $concepteurs = array();
  144. foreach ($xml->xpath('PERSONNE[@CONCEPTEUR="oui"]') as $xml_concepteur)
  145. $concepteurs[] = $this->getPersonne($xml_concepteur);
  146. $row->concepteur = $concepteurs;
  147. $executants = array();
  148. foreach ($xml->xpath('PERSONNE[@EXECUTANT="oui"]') as $xml_executant)
  149. $executants[] = $this->getPersonne($xml_executant);
  150. $row->executant = $executants;
  151. $organisateurs = array();
  152. foreach ($xml->xpath('PERSONNE[@ORGANISATEUR="oui"]') as $xml_organisateur)
  153. $organisateurs[] = $this->getPersonne($xml_organisateur);
  154. $row->organisateur = $organisateurs;
  155. #address
  156. $row->adresse = $this->getAttribute($xml, 'ADRESSE');
  157. $row->precision = $this->getAttribute($xml, 'PRECISION');
  158. $row->ville = $this->getAttribute($xml, 'VILLE');
  159. $pays = $this->getAttribute($xml, 'PAYS');
  160. if($pays == 'France' || $pays == 'france' || $pays = ''){
  161. $pays = 'FR';
  162. }else if($pays == 'Allemagne' || $pays == 'RFA'){
  163. $pays = 'DE';
  164. }else if($pays == 'Monaco' || $pays == "Principauté de Monaco"){
  165. $pays = 'MC';
  166. }else if($pays == 'Canada'){
  167. $pays = 'CA';
  168. }else if($pays == 'Italie'){
  169. $pays = 'IT';
  170. }else if($pays == 'USA'){
  171. $pays = 'US';
  172. }else{
  173. // dsm($pays, '$pays');
  174. $pays = '';
  175. }
  176. $row->pays = $pays;
  177. }
  178. public function prepare($node, stdClass $row) {
  179. $node->name = 'migration';
  180. $node->workflow = 2;
  181. $node->language = 'fr';
  182. }
  183. }