PerfMigrate.basic_update.inc 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. abstract class PerfBasicUpdateMigration extends PerfApiMigration {
  3. public function __construct(){
  4. $this->description = t('Migrate Update Performance Basic Class');
  5. parent::__construct();
  6. $this->systemOfRecord = Migration::DESTINATION;
  7. // There isn't a consistent way to automatically identify appropriate "fields"
  8. // from an XML feed, so we pass an explicit list of source fields
  9. $fields = array(
  10. 'treeline_id' => t('Treeline id'),
  11. 'language'=>t('language'),
  12. // 'title' => t('title'),
  13. 'site_internet' => t('Site internet'),
  14. // 'images' => t('Images'),
  15. 'images_alt' => t('Images Alt'),
  16. 'images_title' => t('Images Title'),
  17. 'sources_bibliographiques' => t('Sources bibliographiques'), // BIBLIOGRAPHIE
  18. );
  19. // The source ID here is the one retrieved from the XML listing file, and
  20. // used to identify the specific item's file
  21. $this->map = new MigrateSQLMap($this->machineName,
  22. array(
  23. 'treeline_id' => array(
  24. 'type' => 'varchar',
  25. 'length' => 255,
  26. 'not null' => TRUE,
  27. )
  28. ),
  29. MigrateDestinationNode::getKeySchema()
  30. );
  31. // This can also be an URL instead of a file path.
  32. $xml_folder = DRUPAL_ROOT . '/' . drupal_get_path('module', 'PerfMigrate') . '/xml/';
  33. $items_url = $xml_folder . 'baseperf-parsed.xml';
  34. // We use the MigrateSourceMultiItems class for any source where we obtain the list
  35. // of IDs to process and the data for each item from the same file. Typically the data
  36. // for an item is not contained in a single line within the source file. Examples include
  37. // multiple items defined in a single xml file or a single json file where in both cases
  38. // the id is part of the item.
  39. $item_ID_xpath = '@ID'; // relative to item_xpath and gets assembled
  40. // into full path /producers/producer/sourceid
  41. $items_class = new MigrateItemsXML($items_url, $this->item_xpath, $item_ID_xpath); //
  42. $this->source = new MigrateSourceMultiItems($items_class, $fields);
  43. $this->destination = new MigrateDestinationNode('performance');
  44. #site internet
  45. $this->addFieldMapping('field_site_internet', 'site_internet');
  46. #images
  47. $this->addFieldMapping('field_images', 'images');
  48. $this->addFieldMapping('field_images:source_dir')->defaultValue('public://SRC_IMAGES');
  49. $this->addFieldMapping('field_images:file_replace')->defaultValue(FILE_EXISTS_REPLACE);
  50. $this->addFieldMapping('field_images:title', 'images_title');
  51. $this->addFieldMapping('field_images:alt', 'images_alt');
  52. $this->addFieldMapping('field_sources_bibliographiques', 'sources_bibliographiques')
  53. ->xpath('BIBLIOGRAPHIE/@BIBLIOGRAPHIE');
  54. $this->addUnmigratedDestinations(array());
  55. }
  56. public function prepareRow($row){
  57. // dsm($row , '--- $row ---');
  58. $xml = $row->xml;
  59. #site internet
  60. $row->site_internet = array();
  61. foreach ($xml->xpath('SITE_INTERNET') as $xml_site){
  62. $row->site_internet[] = trim($this->getAttribute($xml_site, 'URL'));
  63. }
  64. #images
  65. $images = array();
  66. $titles = array();
  67. $alts = array();
  68. //drush_log(dt('start images import : !images', array('!images'=>count($xml->IMAGE_CONSULTABLE))), 'status');
  69. foreach ($xml->IMAGE_CONSULTABLE as $xml_image) { //IMAGE_CONSULTABLE
  70. $images[] = $this->getAttribute($xml_image, 'SRC');
  71. $alts[] = $this->getAttribute($xml_image, 'ALT');
  72. $titles[] = $this->getAttribute($xml_image, 'TITLE');
  73. }
  74. $row->images = $images;
  75. $row->images_title = $titles;
  76. $row->images_alt = $alts;
  77. }
  78. // public function prepare($node, stdClass $row) {
  79. // // $xml = $row->xml;
  80. // }
  81. public function complete($node, stdClass $row){
  82. $xml = $row->xml;
  83. # images
  84. # this script only update title and alt field of image files that already exists
  85. # but i sa that some files are missing after the first import …
  86. // $delta = 0;
  87. // foreach ($xml->IMAGE_CONSULTABLE as $xml_image) { //IMAGE_CONSULTABLE
  88. // if(isset($node->field_images['und'][$delta])){
  89. // $node->field_images['und'][$delta]['title'] = $this->getAttribute($xml_image, 'TITLE');
  90. // $node->field_images['und'][$delta]['alt'] = $this->getAttribute($xml_image, 'ALT');
  91. // }
  92. // $delta ++;
  93. // }
  94. # personnes
  95. $this->recordGroup($node, 'field_concepteur', $xml, 'CONCEPTEUR');
  96. $this->recordGroup($node, 'field_executant',$xml, 'EXECUTANT');
  97. $this->recordGroup($node, 'field_organisateur', $xml, 'ORGANISATEUR');
  98. $this->recordGroup($node, 'field_temoin', $xml, 'TEMOIN');
  99. node_save($node);
  100. # personnes
  101. $this->updatePersonneTerms($xml);
  102. }
  103. }