public function WordPressItemMigration::prepareRow in WordPress Migrate 7
Same name and namespace in other branches
- 7.2 wordpress_item.inc \WordPressItemMigration::prepareRow()
Data manipulations to be performed before the migrate module applies mappings.
Parameters
stdClass $row:
Return value
string
Overrides Migration::prepareRow
File
- ./
wordpress_item.inc, line 317 - Support for migrating posts and pages from a WordPress blog into Drupal.
Class
- WordPressItemMigration
- Intermediate Migration class, implementing behavior common across different types (post_type) of items.
Code
public function prepareRow($row) {
// Only publish those with wp:status == 'publish'
if (isset($row->status) && $row->status == 'publish') {
$row->status = NODE_PUBLISHED;
}
else {
$row->status = NODE_NOT_PUBLISHED;
}
// If incoming date is zero (indicates unpublished content), use the current time
if ($row->post_date == '0000-00-00 00:00:00') {
$row->post_date = time();
}
// If the link has a query string, don't produce a path
if (strpos($row->link, '?')) {
unset($row->link);
}
else {
// Otherwise, strip the domain portion of the URL
$matches = array();
if (preg_match('|http://[^/]+/(.*)|', $row->link, $matches)) {
$row->link = $matches[1];
// Strip the last slash off of the URL (the Path module can't handle this)
$row->link = rtrim($row->link, '/');
}
else {
unset($row->link);
}
}
// Translate WordPress comment_status to Drupal values
if ($row->comment_status == 'open') {
$row->comment_status = COMMENT_NODE_OPEN;
}
else {
$row->comment_status = COMMENT_NODE_CLOSED;
}
// Interpret the [caption] tags
$row->content = preg_replace_callback('|(\\[caption.*?\\])(.*?)(\\[/caption\\])|i', array(
$this,
'replaceCaptions',
), $row->content);
// Rewrite embedded video references to media tags (TODO: YouTube only for now)
if (module_exists('media_youtube')) {
$row->content = preg_replace_callback('|<object [^>]*>.*?(<embed [^>]*>).*?</object>|i', array(
$this,
'replaceEmbeds',
), $row->content);
}
// Rewrite (or remember to rewrite) links of the form
// http://example.wordpress.com/?p=19 to local links of the form /node/35
$row->content = $this
->fixLocalLinks($row->content);
return TRUE;
}