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

97 lines
2.9 KiB
PHP

<?php
/**
* PerfGroupeNodeMigration
*
*/
class PerfObjetNodeUpdateMigration extends PerfApiMigration {
public function __construct() {
$this->description = t('Update Objects Class');
parent::__construct();
$this->systemOfRecord = Migration::DESTINATION;
$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 . 'baseperf-objets.xml';
// We use the MigrateSourceMultiItems class for any source where we obtain the list
// of IDs to process and the data for each item from the same file. Typically the data
// for an item is not contained in a single line within the source file. Examples include
// multiple items defined in a single xml file or a single json file where in both cases
// the id is part of the item.
$item_xpath = '/ROOT/ITEMS/OBJET'; // relative to document
$item_ID_xpath = '@ID'; // relative to item_xpath and gets assembled
// into full path /producers/producer/sourceid
$items_class = new MigrateItemsXML($items_url, $item_xpath, $item_ID_xpath); //
$this->source = new MigrateSourceMultiItems($items_class, $fields);
$this->destination = new MigrateDestinationNode('object');
$this->addFieldMapping('nid', 'ID')
->sourceMigration('PerfObjetNode');
#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) {
$node->name = 'migration';
$node->workflow = 2;
}
}