public function WordPressAttachment::postImport in WordPress Migrate 7
Same name and namespace in other branches
- 7.2 wordpress_attachment.inc \WordPressAttachment::postImport()
Called after all attachments are imported - fix up references to the imported attachments in node bodies.
Overrides Migration::postImport
File
- ./
wordpress_attachment.inc, line 235
Class
- WordPressAttachment
- Implementation of WordPressMigration, for attachments
Code
public function postImport() {
parent::postImport();
migrate_instrument_start('WordPressAttachment postImport');
$source_migrations = array(
$this
->generateMachineName('WordPressBlogEntry'),
$this
->generateMachineName('WordPressPage'),
);
foreach ($source_migrations as $source_migration) {
$migration = MigrationBase::getInstance($source_migration);
$map = $migration
->getMap();
foreach ($map as $map_row) {
$nid = $map_row->destid1;
$node = node_load($nid);
$body = $node->body[LANGUAGE_NONE][0]['value'];
$result = db_select('wordpress_migrate_attachment', 'a')
->fields('a', array(
'original_url',
'new_uri',
))
->condition('filename', $this->wxrFile)
->execute();
foreach ($result as $row) {
$body = str_replace($row->original_url, $row->new_uri, $body);
}
$node->body[LANGUAGE_NONE][0]['value'] = $body;
node_save($node);
}
}
migrate_instrument_stop('WordPressAttachment postImport');
}