PerfMigrate.objet.inc 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /**
  3. * PerfGroupeNodeMigration
  4. *
  5. */
  6. class PerfObjetNodeMigration extends PerfApiMigration {
  7. public function __construct() {
  8. $this->description = t('Migrate Objects Class');
  9. parent::__construct();
  10. $fields = array(
  11. 'ID' => t('id'),
  12. 'title' => t('title'),
  13. 'technique_description' => t('technique_description'),
  14. 'dimensions' => t('dimensions'),
  15. 'proprietaire' => t('proprietaire'),
  16. 'images' => t('images'),
  17. 'images_title' => t('images title'),
  18. 'images_alt' => t('images alt'),
  19. 'serie' => t('serie'),
  20. 'notes' => t('notes'),
  21. );
  22. // The source ID here is the one retrieved from the XML listing file, and
  23. // used to identify the specific item's file
  24. $this->map = new MigrateSQLMap($this->machineName,
  25. array(
  26. 'ID' => array(
  27. 'type' => 'varchar',
  28. 'length' => 255,
  29. 'not null' => TRUE,
  30. )
  31. ),
  32. MigrateDestinationNode::getKeySchema()
  33. );
  34. // This can also be an URL instead of a file path.
  35. $xml_folder = DRUPAL_ROOT . '/' . drupal_get_path('module', 'PerfMigrate') . '/xml/';
  36. $items_url = $xml_folder . 'baseperf-objets.xml';
  37. // We use the MigrateSourceMultiItems class for any source where we obtain the list
  38. // of IDs to process and the data for each item from the same file. Typically the data
  39. // for an item is not contained in a single line within the source file. Examples include
  40. // multiple items defined in a single xml file or a single json file where in both cases
  41. // the id is part of the item.
  42. $item_xpath = '/ROOT/ITEMS/OBJET'; // relative to document
  43. $item_ID_xpath = '@ID'; // relative to item_xpath and gets assembled
  44. // into full path /producers/producer/sourceid
  45. $items_class = new MigrateItemsXML($items_url, $item_xpath, $item_ID_xpath); //
  46. $this->source = new MigrateSourceMultiItems($items_class, $fields);
  47. $this->destination = new MigrateDestinationNode('object');
  48. $this->addFieldMapping('language')->defaultValue('fr');
  49. $this->addFieldMapping('is_new')->defaultValue(TRUE);
  50. // $this->addFieldMapping('created', 'date_creation');
  51. // $this->addFieldMapping('changed', 'date_modif');
  52. $this->addFieldMapping('status')->defaultValue(1);
  53. $this->addFieldMapping('promote')->defaultValue(0);
  54. $this->addFieldMapping('sticky')->defaultValue(0);
  55. $this->addFieldMapping('title', 'title');
  56. $this->addFieldMapping('field_technique_description', 'technique_description')
  57. ->xpath('@TECHNIQUE_DESCRIPTION_REFERENCE');
  58. $this->addFieldMapping('field_dimensions', 'dimensions')
  59. ->xpath('@DIMENSIONS_OBJET');
  60. $this->addFieldMapping('field_proprietaire', 'proprietaire')
  61. ->xpath('@ID_PROPRIETAIRE_OBJET');
  62. #images
  63. $this->addFieldMapping('field_images', 'images');
  64. $this->addFieldMapping('field_images:source_dir')->defaultValue('public://SRC_IMAGES');
  65. $this->addFieldMapping('field_images:title', 'images_title');
  66. $this->addFieldMapping('field_images:alt', 'images_alt');
  67. # serie
  68. $this->addFieldMapping('field_serie', 'serie')
  69. ->xpath('@SERIE');
  70. $this->addFieldMapping('field_serie:create_term')->defaultValue(TRUE);
  71. $this->addFieldMapping('field_notes', 'notes')
  72. ->xpath('@NOTES');
  73. $this->addUnmigratedDestinations(array('revision_uid', 'created', 'changed', 'revision', 'log', 'tnid','comment', 'uid','path', 'pathauto',
  74. 'field_technique_description:language', 'field_technique_description:format',
  75. 'field_dimensions:language', 'field_dimensions:format',
  76. 'field_proprietaire:language', 'field_proprietaire:format',
  77. 'field_images:file_class', 'field_images:language', 'field_images:destination_dir', 'field_images:destination_file', 'field_images:file_replace', 'field_images:preserve_files',
  78. // 'field_images:title', 'field_images:alt',
  79. 'field_serie:source_type',
  80. 'field_notes:language', 'field_notes:format',
  81. 'field_performances'
  82. ));
  83. }
  84. public function prepareRow($row){
  85. // dsm($row , '--- $row ---');
  86. $xml = $row->xml;
  87. $title = $this->getAttribute($xml, 'TITRE');
  88. if(strlen($title) > 255)
  89. $title = substr($title, 0, 250) . '...';
  90. $row->title = $title;
  91. #images
  92. $images = array();
  93. $titles = array();
  94. $alts = array();
  95. $i = 0;
  96. foreach ($xml->xpath('IMAGE_CONSULTABLE') as $xml_image) {
  97. $images[] = $this->getAttribute($xml_image, 'SRC');
  98. $alts[] = $this->getAttribute($xml_image, 'ALT');
  99. $titles[] = $this->getAttribute($xml_image, 'TITLE');
  100. $i++;
  101. }
  102. $row->images = $images;
  103. // $row->images_title = $alt;
  104. // $row->images_alt = $titles;
  105. // dsm($row->images, '$row->images');
  106. }
  107. public function prepare($node, stdClass $row) {
  108. $node->name = 'migration';
  109. $node->workflow = 2;
  110. }
  111. }