PerfMigrate.basic.inc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <?php
  2. abstract class PerfBasicMigration extends PerfApiMigration {
  3. public function __construct(){
  4. $this->description = t('Migrate Performance Basic Class');
  5. parent::__construct();
  6. // There isn't a consistent way to automatically identify appropriate "fields"
  7. // from an XML feed, so we pass an explicit list of source fields
  8. $fields = array(
  9. 'treeline_id' => t('Treeline id'),
  10. 'title' => t('title'),
  11. 'sous_titre' => t('Sous-titre'),
  12. 'language' => t('Language'),
  13. 'description' => t('description'),
  14. 'auteur_description' => t('Auteur description'),
  15. 'language_description' => t('Language description'),
  16. 'intention' => t('Intention'),
  17. 'auteur_intention' => t('Auteur intention'),
  18. 'language_intention' => t('Language intention'),
  19. 'serie' => t('Série'),
  20. 'typologie_performance' => t('Typologie performance'),
  21. 'tags_libre' => t('Tags libres'),
  22. 'concepteur' => t('Concepteur'),
  23. 'executant' => t('Executant'),
  24. 'organisateur' => t('Organisateur'),
  25. 'contexte_theorique' => t('contexte_theorique'),
  26. 'auteur_contexte_theorique' => t('auteur_contexte_theorique'),
  27. 'language_contexte_theorique' => t('Language contexte'),
  28. // 'date_de_debut' => t('Date de debut'),
  29. // 'date_de_fin' => t('Date de fin'),
  30. // 'lieu' => t('Lieu'),
  31. // 'duree' => t('Durée'),
  32. // 'topologie' => t('Topologie'),
  33. 'effectuations_id' => t('effectuations id'),
  34. 'temoin' => t('Temoin'),
  35. 'site_internet' => t('Site internet'),
  36. 'images' => t('Images'),
  37. 'images_alt' => t('Images Alt'),
  38. 'images_title' => t('Images Title'),
  39. 'recherche' => t('recherche'),
  40. 'sources_bibliographiques' => t('Sources bibliographiques'), // BIBLIOGRAPHIE
  41. 'docs_audiovisuels' => t('docs audio visuel'), // DOC_AUDIOVISUEL
  42. 'docs_sonor' => t('docs sonor'),//DOC_SONORE
  43. 'documents' => t('documents'), // DOC_IMPRIME
  44. 'objects' => t('Objets'), // OBJET
  45. // 'docs_press' => t('doc press'), // DOC_PRESSE
  46. // 'docs_manuscrit' => t('doc manuscrits'), // DOC_MANUSCRITS
  47. );
  48. // The source ID here is the one retrieved from the XML listing file, and
  49. // used to identify the specific item's file
  50. $this->map = new MigrateSQLMap($this->machineName,
  51. array(
  52. 'treeline_id' => array(
  53. 'type' => 'varchar',
  54. 'length' => 255,
  55. 'not null' => TRUE,
  56. )
  57. ),
  58. MigrateDestinationNode::getKeySchema()
  59. );
  60. // This can also be an URL instead of a file path.
  61. $xml_folder = DRUPAL_ROOT . '/' . drupal_get_path('module', 'PerfMigrate') . '/xml/';
  62. $items_url = $xml_folder . 'baseperf-parsed.xml';
  63. // We use the MigrateSourceMultiItems class for any source where we obtain the list
  64. // of IDs to process and the data for each item from the same file. Typically the data
  65. // for an item is not contained in a single line within the source file. Examples include
  66. // multiple items defined in a single xml file or a single json file where in both cases
  67. // the id is part of the item.
  68. $item_ID_xpath = '@ID'; // relative to item_xpath and gets assembled
  69. // into full path /producers/producer/sourceid
  70. $items_class = new MigrateItemsXML($items_url, $this->item_xpath, $item_ID_xpath); //
  71. $this->source = new MigrateSourceMultiItems($items_class, $fields);
  72. $this->destination = new MigrateDestinationNode('performance');
  73. $this->addFieldMapping('language')->defaultValue('fr');
  74. $this->addFieldMapping('is_new')->defaultValue(TRUE);
  75. // $this->addFieldMapping('created', 'date_creation');
  76. // $this->addFieldMapping('changed', 'date_modif');
  77. $this->addFieldMapping('status')->defaultValue(1);
  78. $this->addFieldMapping('promote')->defaultValue(0);
  79. $this->addFieldMapping('sticky')->defaultValue(0);
  80. # titre & sous titre
  81. // $this->addFieldMapping('title', 'title')
  82. // ->xpath('@TITRE');
  83. $this->addFieldMapping('title_field', 'title');
  84. $this->addFieldMapping('title_field:language', 'language');
  85. $this->addFieldMapping('field_sous_titre', 'sous_titre')
  86. ->xpath('@SOUS_TITRE');
  87. # description
  88. $this->addFieldMapping('field_description', 'description');
  89. $this->addFieldMapping('field_description:format')->defaultValue('filtred_html');
  90. $this->addFieldMapping('field_description:language', 'language_description');
  91. $this->addFieldMapping('field_description:author', 'auteur_description');
  92. # intention (nexiste pas dans la base xml)
  93. $this->addFieldMapping('field_intention', 'intention');
  94. $this->addFieldMapping('field_intention:format')->defaultValue('filtred_html');
  95. $this->addFieldMapping('field_intention:language', 'language_intention');
  96. $this->addFieldMapping('field_intention:author', 'auteur_intention');
  97. # contexte theorique
  98. $this->addFieldMapping('field_contexte_theorique', 'contexte_theorique');
  99. $this->addFieldMapping('field_contexte_theorique:format')->defaultValue('filtred_html');
  100. $this->addFieldMapping('field_contexte_theorique:language', 'language_contexte_theorique');
  101. $this->addFieldMapping('field_contexte_theorique:author', 'auteur_contexte_theorique');
  102. # typologie perf
  103. $this->addFieldMapping('field_type_de_performance', 'typologie_performance')
  104. ->xpath('TYPOLOGIE_PERFORMANCE/@TYPOLOGIE_PERFORMANCE');
  105. $this->addFieldMapping('field_type_de_performance:create_term')->defaultValue(TRUE);
  106. # serie
  107. $this->addFieldMapping('field_serie', 'serie')
  108. ->xpath('SERIE/@NOM_SERIE');
  109. $this->addFieldMapping('field_serie:create_term')->defaultValue(TRUE);
  110. # tags libre perf
  111. $this->addFieldMapping('field_tags_libre', 'tags_libre');
  112. $this->addFieldMapping('field_tags_libre:create_term')->defaultValue(TRUE);
  113. # personnes
  114. $this->addFieldMapping('field_concepteur', 'concepteur');
  115. $this->addFieldMapping('field_concepteur:create_term')->defaultValue(TRUE);
  116. $this->addFieldMapping('field_executant', 'executant');
  117. $this->addFieldMapping('field_executant:create_term')->defaultValue(TRUE);
  118. $this->addFieldMapping('field_organisateur', 'organisateur');
  119. $this->addFieldMapping('field_organisateur:create_term')->defaultValue(TRUE);
  120. $this->addFieldMapping('field_temoin', 'temoin');
  121. $this->addFieldMapping('field_temoin:create_term')->defaultValue(TRUE);
  122. # lieu date contexte
  123. // $this->addFieldMapping('field_date_de_debut', 'date_de_debut');
  124. // $this->addFieldMapping('field_date_de_fin', 'date_de_fin');
  125. // $this->addFieldMapping('field_dure', 'duree');
  126. // $this->addFieldMapping('field_lieu', 'lieu')
  127. // ->xpath('LIEU_DATE_CONTEXTE/@NOM_LIEU');
  128. // $this->addFieldMapping('field_lieu:create_term')->defaultValue(TRUE);
  129. // $this->addFieldMapping('field_topologie', 'topologie')
  130. // ->xpath('LIEU_DATE_CONTEXTE/@TYPE');
  131. // $this->addFieldMapping('field_topologie:create_term')->defaultValue(TRUE);
  132. $this->addFieldMapping('field_effectuations', 'effectuations_id')
  133. ->sourceMigration('PerfLDCNode');
  134. #site internet
  135. $this->addFieldMapping('field_site_internet', 'site_internet');
  136. #images
  137. $this->addFieldMapping('field_images', 'images');
  138. $this->addFieldMapping('field_images:source_dir')->defaultValue('public://SRC_IMAGES');
  139. // $this->addFieldMapping('field_images:destination_file', 'images');
  140. // $this->addFieldMapping('field_images:alt', 'images_alt');
  141. $this->addFieldMapping('field_images:title', 'images_title');
  142. $this->addFieldMapping('field_images:alt', 'images_alt');
  143. $this->addFieldMapping('field_recherche', 'recherche')
  144. ->xpath('/RECHERCHE/@NOTES');
  145. $this->addFieldMapping('field_sources_bibliographiques', 'sources_bibliographiques')
  146. ->xpath('/BIBLIOGRAPHIE/@BIBLIOGRAPHIE');
  147. $this->addFieldMapping('field_documents_videos', 'docs_audiovisuels')
  148. ->sourceMigration('PerfDvidsNode');
  149. $this->addFieldMapping('field_documents_sonor', 'docs_sonor')
  150. ->sourceMigration('PerfDsonsNode');
  151. $this->addFieldMapping('field_documents', 'documents')
  152. ->sourceMigration(array('PerfDimpNode', 'PerfDpressNode', 'PerfDmanuNode')); // ?????
  153. $this->addFieldMapping('field_objects', 'objects')
  154. ->sourceMigration('PerfObjetNode');
  155. $this->addUnmigratedDestinations(array('revision_uid', 'created', 'changed', 'revision', 'log', 'tnid','comment', 'uid','path', 'pathauto',
  156. 'title',
  157. 'title_field:format',
  158. 'field_sous_titre:format', 'field_sous_titre:language',
  159. 'field_performances_associees',
  160. // 'body:summary',
  161. // 'field_auteur_description:source_type',
  162. // 'field_auteur_intention:source_type',
  163. // 'field_auteur_contexte:source_type',
  164. 'field_serie:source_type', 'field_type_de_performance:source_type', 'field_tags_libre:source_type',
  165. 'field_concepteur:source_type','field_executant:source_type','field_organisateur:source_type','field_temoin:source_type',
  166. // 'field_date_de_debut:format', 'field_date_de_debut:language', 'field_date_de_fin:format', 'field_date_de_fin:language',
  167. // 'field_dure:format', 'field_dure:language',
  168. // 'field_lieu:source_type', 'field_topologie:source_type'
  169. 'field_images:file_class', 'field_images:language', 'field_images:destination_dir', 'field_images:destination_file', 'field_images:file_replace', 'field_images:preserve_files',
  170. 'field_recherche:language', 'field_recherche:format',
  171. 'field_sources_bibliographiques:language', 'field_sources_bibliographiques:format',
  172. //'field_images:alt', //'field_images:title',
  173. ));
  174. }
  175. public function prepareRow($row){
  176. // dsm($row , '--- $row ---');
  177. $xml = $row->xml;
  178. $row->language = array('fr', 'en');
  179. $titre = $this->getAttribute($xml, 'TITRE');
  180. $traduction_titre = $this->getAttribute($xml, 'TRADUCTION_TITRE');
  181. $traduction_titre = $traduction_titre != '' ? $traduction_titre : $titre;
  182. $row->title = array(
  183. $titre,
  184. $traduction_titre,
  185. );
  186. # description
  187. $results = $this->getTextsAuthors($xml->xpath('DESCRIPTION'), 'DESCRIPTION', $row->language);
  188. $row->description = $results['values'];
  189. $row->auteur_description = $results['authors'];
  190. $row->language_description = $results['language'];
  191. # intention
  192. $results = $this->getTextsAuthors($xml->xpath('INTENTION'), 'INTENTION', $row->language);
  193. $row->intention = $results['values'];
  194. $row->auteur_intention = $results['authors'];
  195. $row->language_intention = $results['language'];
  196. # Contexte theorique
  197. $results = $this->getTextsAuthors($xml->xpath('CONTEXTE_THEORIQUE'), 'CONTEXTE_THEORIQUE', $row->language);
  198. $row->contexte_theorique = $results['values'];
  199. $row->auteur_contexte_theorique = $results['authors'];
  200. $row->language_contexte_theorique = $results['language'];
  201. #tags libres
  202. $tags = array();
  203. foreach ($xml->xpath('MOTS_CLE') as $xml_mot_clef)
  204. $tags[] = $this->getAttribute($xml_mot_clef, 'MOT_CLE');
  205. $row->tags_libre = $tags;
  206. # personnes
  207. $concepteurs = array();
  208. foreach ($xml->xpath('PERSONNE[@CONCEPTEUR="oui"]') as $xml_concepteur)
  209. $concepteurs[] = $this->getPersonne($xml_concepteur);
  210. $row->concepteur = $concepteurs;
  211. $executants = array();
  212. foreach ($xml->xpath('PERSONNE[@EXECUTANT="oui"]') as $xml_executant)
  213. $executants[] = $this->getPersonne($xml_executant);
  214. $row->executant = $executants;
  215. $organisateurs = array();
  216. foreach ($xml->xpath('PERSONNE[@ORGANISATEUR="oui"]') as $xml_organisateur)
  217. $organisateurs[] = $this->getPersonne($xml_organisateur);
  218. $row->organisateur = $organisateurs;
  219. $temoins = array();
  220. foreach ($xml->xpath('TEMOIN') as $xml_temoin)
  221. $temoins[] = $this->getPersonne($xml_temoin, '_TEMOIN');
  222. $row->temoin = $temoins;
  223. # lieu date contexte
  224. // $ldc = $xml->LIEU_DATE_CONTEXTE;
  225. // $row->date_de_debut = $this->getDate($ldc, 'DEBUT');
  226. // $row->date_de_fin = $this->getDate($ldc, 'FIN');
  227. // $row->duree = $this->getAttribute($ldc, 'DUREE') .' '. $this->getAttribute($ldc, 'UNITE_DUREE');
  228. // $row->lieu = $this->getAttribute($ldc, 'NOM_LIEU');
  229. $effectuations_id = array();
  230. foreach ($xml->xpath('LIEU_DATE_CONTEXTE') as $ldc)
  231. $effectuations_id[] = $this->getAttribute($ldc, 'ID');
  232. $row->effectuations_id = count($effectuations_id) ? $effectuations_id : NULL;
  233. # doc audiovisuel
  234. $docs = array();
  235. foreach ($xml->xpath('DOC_AUDIOVISUEL') as $doc)
  236. $docs[] = $this->getAttribute($doc, 'ID');
  237. $row->docs_audiovisuels = count($docs) ? $docs : NULL;
  238. # doc sonor
  239. $docs = array();
  240. foreach ($xml->xpath('DOC_SONORE') as $doc)
  241. $docs[] = $this->getAttribute($doc, 'ID');
  242. $row->docs_sonor = count($docs) ? $docs : NULL;
  243. # doc imprime
  244. $docs = array();
  245. foreach ($xml->xpath('DOC_IMPRIME') as $doc)
  246. $docs[] = $this->getAttribute($doc, 'ID');
  247. foreach ($xml->xpath('DOC_PRESSE') as $doc)
  248. $docs[] = $this->getAttribute($doc, 'ID');
  249. foreach ($xml->xpath('DOC_MANUSCRITS') as $doc)
  250. $docs[] = $this->getAttribute($doc, 'ID');
  251. $row->documents = count($docs) ? $docs : NULL;
  252. # objet
  253. $docs = array();
  254. foreach ($xml->xpath('OBJET') as $doc)
  255. $docs[] = $this->getAttribute($doc, 'ID');
  256. $row->objects = count($docs) ? $docs : NULL;
  257. #site internet
  258. // $sites = array();
  259. // foreach ($xml->xpath('SITE_INTERNET') as $xml)
  260. // $sites[] = str_replace('http://', '', $this->getAttribute($xml, 'URL'));
  261. // $row->site_internet = $sites;
  262. // dsm($row->site_internet)
  263. /*
  264. TODO site internet ne marche pas !!!
  265. */
  266. // $row->site_internet = '';
  267. foreach ($xml->xpath('SITE_INTERNET') as $xml_site)
  268. //$row->site_internet = array('url'=>str_replace('http://', '', $this->getAttribute($xml_site, 'URL')));
  269. $row->site_internet = str_replace('http://', '', $this->getAttribute($xml_site, 'URL'));
  270. // dsm($row->site_internet, '$row->site_internet');
  271. // drush_log(dt('web : !url', array('!url'=>$row->site_internet)), 'status');
  272. #images
  273. $images = array();
  274. $titles = array();
  275. $alts = array();
  276. // $i = 0;
  277. $str_xml = print_r($xml, true);
  278. //drush_log(dt('xml : !xml', array('!xml'=>$str_xml)), 'status');
  279. //drush_log(dt('start images import : !images', array('!images'=>count($xml->IMAGE_CONSULTABLE))), 'status');
  280. foreach ($xml->IMAGE_CONSULTABLE as $xml_image) { //IMAGE_CONSULTABLE
  281. // drush_log(dt('image'), 'status');
  282. $images[] = $this->getAttribute($xml_image, 'SRC');
  283. $alts[] = $this->getAttribute($xml_image, 'ALT');
  284. $titles[] = $this->getAttribute($xml_image, 'TITLE');
  285. // $i++;
  286. }
  287. $row->images = $images;
  288. $row->images_title = $titles;
  289. $row->images_alt = $alts;
  290. // dsm($row->images, '$row->images');
  291. }
  292. public function prepare($node, stdClass $row) {
  293. $node->name = 'migration';
  294. $node->workflow = 2;
  295. }
  296. public function complete($node, stdClass $row){
  297. $handler = entity_translation_get_handler('node', $node);
  298. $translation = array(
  299. 'translate' => 0,
  300. 'status' => 1,
  301. 'language' => 'en',
  302. 'source' => $node->language,
  303. );
  304. $handler->setTranslation($translation, $node);
  305. node_save($node);
  306. }
  307. }