PerfMigrate.docs.inc 4.3 KB

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