PerfMigrate.docs_update.inc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * PerfGroupeNodeMigration
  4. *
  5. */
  6. abstract class PerfDocsNodeUpdateMigration extends PerfApiMigration {
  7. public function __construct() {
  8. parent::__construct();
  9. $this->systemOfRecord = Migration::DESTINATION;
  10. $this->fields += array(
  11. 'ID' => t('id'),
  12. 'images' => t('images'),
  13. 'images_title' => t('images title'),
  14. 'images_alt' => t('images alt'),
  15. );
  16. // The source ID here is the one retrieved from the XML listing file, and
  17. // used to identify the specific item's file
  18. $this->map = new MigrateSQLMap($this->machineName,
  19. array(
  20. 'ID' => array(
  21. 'type' => 'varchar',
  22. 'length' => 255,
  23. 'not null' => TRUE,
  24. )
  25. ),
  26. MigrateDestinationNode::getKeySchema()
  27. );
  28. // This can also be an URL instead of a file path.
  29. $xml_folder = DRUPAL_ROOT . '/' . drupal_get_path('module', 'PerfMigrate') . '/xml/';
  30. $items_url = $xml_folder . $this->itemsfile;
  31. $item_ID_xpath = '@ID'; // relative to item_xpath and gets assembled
  32. // into full path /producers/producer/sourceid
  33. $items_class = new MigrateItemsXML($items_url, $this->item_xpath, $item_ID_xpath); //
  34. $this->source = new MigrateSourceMultiItems($items_class, $this->fields);
  35. $this->destination = new MigrateDestinationNode('document');
  36. #images
  37. $this->addFieldMapping('field_images', 'images');
  38. $this->addFieldMapping('field_images:source_dir')->defaultValue('public://SRC_IMAGES');
  39. $this->addFieldMapping('field_images:file_replace')->defaultValue(FILE_EXISTS_REPLACE);
  40. $this->addFieldMapping('field_images:title', 'images_title');
  41. $this->addFieldMapping('field_images:alt', 'images_alt');
  42. }
  43. public function prepareRow($row){
  44. // dsm($row , '--- $row ---');
  45. $xml = $row->xml;
  46. #images
  47. $images = array();
  48. $titles = array();
  49. $alts = array();
  50. foreach ($xml->xpath('IMAGE_CONSULTABLE') as $xml_image) {
  51. $images[] = $this->getAttribute($xml_image, 'SRC');
  52. $alts[] = $this->getAttribute($xml_image, 'ALT');
  53. $titles[] = $this->getAttribute($xml_image, 'TITLE');
  54. }
  55. $row->images = $images;
  56. $row->images_title = $titles;
  57. $row->images_alt = $alts;
  58. }
  59. // public function prepare($node, stdClass $row) {
  60. // }
  61. }