PerfMigrate.ldcs_update.inc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * PerfGroupeNodeMigration
  4. *
  5. */
  6. class PerfLDCNodeUpdateMigration extends PerfApiMigration {
  7. public function __construct() {
  8. $this->description = t('Update Lieu Date Contexte (effectuation) Class');
  9. parent::__construct();
  10. $this->systemOfRecord = Migration::DESTINATION;
  11. $fields = array(
  12. 'ID' => t('id'),
  13. );
  14. // The source ID here is the one retrieved from the XML listing file, and
  15. // used to identify the specific item's file
  16. $this->map = new MigrateSQLMap($this->machineName,
  17. array(
  18. 'ID' => array(
  19. 'type' => 'varchar',
  20. 'length' => 255,
  21. 'not null' => TRUE,
  22. )
  23. ),
  24. MigrateDestinationNode::getKeySchema()
  25. );
  26. // This can also be an URL instead of a file path.
  27. $xml_folder = DRUPAL_ROOT . '/' . drupal_get_path('module', 'PerfMigrate') . '/xml/';
  28. $items_url = $xml_folder . 'baseperf-ldcs.xml';
  29. // We use the MigrateSourceMultiItems class for any source where we obtain the list
  30. // of IDs to process and the data for each item from the same file. Typically the data
  31. // for an item is not contained in a single line within the source file. Examples include
  32. // multiple items defined in a single xml file or a single json file where in both cases
  33. // the id is part of the item.
  34. $item_xpath = '/ROOT/ITEMS/LIEU_DATE_CONTEXTE'; // relative to document
  35. $item_ID_xpath = '@ID'; // relative to item_xpath and gets assembled
  36. // into full path /producers/producer/sourceid
  37. $items_class = new MigrateItemsXML($items_url, $item_xpath, $item_ID_xpath); //
  38. $this->source = new MigrateSourceMultiItems($items_class, $fields);
  39. $this->destination = new MigrateDestinationNode('effectuation');
  40. $this->addFieldMapping('nid', 'ID')
  41. ->sourceMigration('PerfLDCNode');
  42. }
  43. public function prepareRow($row){
  44. }
  45. public function prepare($node, stdClass $row) {
  46. }
  47. public function complete($node, stdClass $row){
  48. $xml = $row->xml;
  49. # personnes
  50. $this->recordGroup($node, 'field_concepteur', $xml, 'CONCEPTEUR');
  51. $this->recordGroup($node, 'field_executant',$xml, 'EXECUTANT');
  52. $this->recordGroup($node, 'field_organisateur', $xml, 'ORGANISATEUR');
  53. $this->recordGroup($node, 'field_temoin', $xml, 'TEMOIN');
  54. node_save($node);
  55. # personnes
  56. $this->updatePersonneTerms($xml);
  57. }
  58. }