protected function DrupalNode7Migration::remapMediaJson in Drupal-to-Drupal data migration 7.2
Rewrites the fids contained within media module text json.
Parameters
array $values: Incoming text values
Return value
array The values array.
File
- d7/
node.inc, line 134 - Implementation of DrupalNodeMigration for Drupal 7 sources.
Class
- DrupalNode7Migration
- Handling specific to a Drupal 7 source for nodes.
Code
protected function remapMediaJson($values) {
if (!is_array($values)) {
$values = array(
$values,
);
}
$media_regex = '#\\[\\[(.*?\\"type":"media".*?)\\]\\]#';
if (!isset($this->fileMigration)) {
$this->fileMigration = $this
->findFileMigration();
}
// By this point, if we don't know the file migration we have to bail.
if (empty($this->fileMigration)) {
return $values;
}
$map = $this->fileMigration
->getMap();
foreach ($values as &$value) {
preg_match_all($media_regex, $value, $matches);
if (empty($matches[1])) {
continue;
}
foreach ($matches[1] as $idx => $match) {
$media_item = json_decode($match, TRUE);
if (empty($media_item)) {
continue;
}
$fid = $media_item['fid'];
$destination = $map
->lookupDestinationID(array(
$fid,
));
if (empty($destination['destid1'])) {
continue;
}
$media_item['fid'] = $destination['destid1'];
$replace = '[[' . json_encode($media_item) . ']]';
$value = str_replace($matches[0][$idx], $replace, $value);
}
}
unset($value);
return $values;
}