PerfMigrate.objet_update.inc 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * PerfGroupeNodeMigration
  4. *
  5. */
  6. class PerfObjetNodeUpdateMigration extends PerfApiMigration {
  7. public function __construct() {
  8. $this->description = t('Update Objects Class');
  9. parent::__construct();
  10. $this->systemOfRecord = Migration::DESTINATION;
  11. $fields = array(
  12. 'ID' => t('id'),
  13. 'images' => t('images'),
  14. 'images_title' => t('images title'),
  15. 'images_alt' => t('images alt'),
  16. );
  17. // The source ID here is the one retrieved from the XML listing file, and
  18. // used to identify the specific item's file
  19. $this->map = new MigrateSQLMap($this->machineName,
  20. array(
  21. 'ID' => array(
  22. 'type' => 'varchar',
  23. 'length' => 255,
  24. 'not null' => TRUE,
  25. )
  26. ),
  27. MigrateDestinationNode::getKeySchema()
  28. );
  29. // This can also be an URL instead of a file path.
  30. $xml_folder = DRUPAL_ROOT . '/' . drupal_get_path('module', 'PerfMigrate') . '/xml/';
  31. $items_url = $xml_folder . 'baseperf-objets.xml';
  32. // We use the MigrateSourceMultiItems class for any source where we obtain the list
  33. // of IDs to process and the data for each item from the same file. Typically the data
  34. // for an item is not contained in a single line within the source file. Examples include
  35. // multiple items defined in a single xml file or a single json file where in both cases
  36. // the id is part of the item.
  37. $item_xpath = '/ROOT/ITEMS/OBJET'; // relative to document
  38. $item_ID_xpath = '@ID'; // relative to item_xpath and gets assembled
  39. // into full path /producers/producer/sourceid
  40. $items_class = new MigrateItemsXML($items_url, $item_xpath, $item_ID_xpath); //
  41. $this->source = new MigrateSourceMultiItems($items_class, $fields);
  42. $this->destination = new MigrateDestinationNode('object');
  43. $this->addFieldMapping('nid', 'ID')
  44. ->sourceMigration('PerfObjetNode');
  45. #images
  46. $this->addFieldMapping('field_images', 'images');
  47. $this->addFieldMapping('field_images:source_dir')->defaultValue('public://SRC_IMAGES');
  48. $this->addFieldMapping('field_images:file_replace')->defaultValue(FILE_EXISTS_REPLACE);
  49. $this->addFieldMapping('field_images:title', 'images_title');
  50. $this->addFieldMapping('field_images:alt', 'images_alt');
  51. }
  52. public function prepareRow($row){
  53. // dsm($row , '--- $row ---');
  54. $xml = $row->xml;
  55. #images
  56. $images = array();
  57. $titles = array();
  58. $alts = array();
  59. foreach ($xml->xpath('IMAGE_CONSULTABLE') as $xml_image) {
  60. $images[] = $this->getAttribute($xml_image, 'SRC');
  61. $alts[] = $this->getAttribute($xml_image, 'ALT');
  62. $titles[] = $this->getAttribute($xml_image, 'TITLE');
  63. }
  64. $row->images = $images;
  65. $row->images_title = $titles;
  66. $row->images_alt = $alts;
  67. }
  68. public function prepare($node, stdClass $row) {
  69. $node->name = 'migration';
  70. $node->workflow = 2;
  71. }
  72. }