You are here

public function WordPressAttachment::prepareRow in WordPress Migrate 7.2

Same name and namespace in other branches
  1. 7 wordpress_attachment.inc \WordPressAttachment::prepareRow()

Data manipulations to be performed before migrate module applies mappings.

Parameters

stdClass $row:

Return value

string

Overrides Migration::prepareRow

File

./wordpress_attachment.inc, line 105

Class

WordPressAttachment
Implementation of WordPressMigration, for attachments

Code

public function prepareRow($row) {
  $wp_row = $row->xml
    ->children($this->arguments['namespaces']['wp']);

  // Skip any of the wrong post type
  if ($wp_row->post_type != 'attachment') {
    $this->skippedItems[] = $wp_row->post_id;
    return FALSE;
  }

  // If incoming date is zero (indicates unpublished content), use the current time
  if ($wp_row->post_date == '0000-00-00 00:00:00') {
    $wp_row->post_date = time();
  }

  // Sometimes URLs have doubled-up slashes - reduce to a single.
  $pieces = explode('://', $wp_row->{'attachment_url'});
  if (count($pieces) == 1) {
    $wp_row->attachment_url = str_replace('//', '/', $wp_row->attachment_url);
  }
  else {
    $wp_row->attachment_url = $pieces[0] . '://' . str_replace('//', '/', $pieces[1]);
  }

  // Make sure we actually have a URL
  if ($wp_row->attachment_url) {
    return TRUE;
  }
  else {
    return FALSE;
  }
}