Files
2020-09-23 15:50:29 +02:00

81 lines
2.3 KiB
PHP

<?php
/**
* PerfGroupeNodeMigration
*
*/
abstract class PerfDocsNodeUpdateMigration extends PerfApiMigration {
public function __construct() {
parent::__construct();
$this->systemOfRecord = Migration::DESTINATION;
$this->fields += array(
'ID' => t('id'),
'images' => t('images'),
'images_title' => t('images title'),
'images_alt' => t('images alt'),
);
// The source ID here is the one retrieved from the XML listing file, and
// used to identify the specific item's file
$this->map = new MigrateSQLMap($this->machineName,
array(
'ID' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
)
),
MigrateDestinationNode::getKeySchema()
);
// This can also be an URL instead of a file path.
$xml_folder = DRUPAL_ROOT . '/' . drupal_get_path('module', 'PerfMigrate') . '/xml/';
$items_url = $xml_folder . $this->itemsfile;
$item_ID_xpath = '@ID'; // relative to item_xpath and gets assembled
// into full path /producers/producer/sourceid
$items_class = new MigrateItemsXML($items_url, $this->item_xpath, $item_ID_xpath); //
$this->source = new MigrateSourceMultiItems($items_class, $this->fields);
$this->destination = new MigrateDestinationNode('document');
#images
$this->addFieldMapping('field_images', 'images');
$this->addFieldMapping('field_images:source_dir')->defaultValue('public://SRC_IMAGES');
$this->addFieldMapping('field_images:file_replace')->defaultValue(FILE_EXISTS_REPLACE);
$this->addFieldMapping('field_images:title', 'images_title');
$this->addFieldMapping('field_images:alt', 'images_alt');
}
public function prepareRow($row){
// dsm($row , '--- $row ---');
$xml = $row->xml;
#images
$images = array();
$titles = array();
$alts = array();
foreach ($xml->xpath('IMAGE_CONSULTABLE') as $xml_image) {
$images[] = $this->getAttribute($xml_image, 'SRC');
$alts[] = $this->getAttribute($xml_image, 'ALT');
$titles[] = $this->getAttribute($xml_image, 'TITLE');
}
$row->images = $images;
$row->images_title = $titles;
$row->images_alt = $alts;
}
// public function prepare($node, stdClass $row) {
// }
}