You are here

class WordPressCommentSource in WordPress Migrate 7

Implementation of MigrateSource, to handle migrating comments from WordPress XML dumps.

Hierarchy

Expanded class hierarchy of WordPressCommentSource

File

./wordpress_comment.inc, line 12
Support for migrating comments from a WordPress blog into Drupal.

View source
class WordPressCommentSource extends WordPressSource {

  /**
   * List of available source fields.
   *
   * @var array
   */
  protected $fields = array(
    'post_id' => 'Unique ID of the item the comment is attached to',
    'comment_id' => 'Unique ID of the comment',
    'comment_author' => 'Name of comment author',
    'comment_author_email' => 'Email address of comment author',
    'comment_author_url' => 'URL of comment author',
    'comment_author_IP' => 'IP address from which comment was posted',
    'comment_date' => 'Date of comment (what timezone?)',
    'comment_date_gmt' => 'Date of comment (GMT)',
    'comment_content' => 'Body of comment',
    'comment_approved' => '1/0/spam - spam comments will not be imported',
    'comment_type' => '?',
    'comment_parent' => 'comment_id (?) of parent comment',
    'comment_user_id' => 'WordPress user ID of commenter (?)',
  );

  /**
   * Simple initialization.
   *
   */
  public function __construct($filename) {
    parent::__construct($filename);
    $this->xpath = '//channel/item/wp:comment';
  }

  /**
   * Parse the values out of the wp:comment element.
   *
   * @param SimpleXMLElement $item
   * @return boolean
   */
  protected function populateRow($item) {

    // All the stuff we want is in the wp namespace
    $namespaces = $item
      ->getNameSpaces(TRUE);
    $item_ns = $item
      ->children($namespaces['wp']);
    foreach ($item_ns as $name => $value) {
      $this->currentRow->{$name} = (string) $value;
    }

    // Find the containing item
    $post_id = $this->xml
      ->xpath("//channel/item[wp:comment/wp:comment_id='" . $this->currentRow->comment_id . "']/wp:post_id");
    $this->currentRow->post_id = (string) $post_id[0];
    $this->currentKey = array(
      $this->currentRow->comment_id,
    );
    return TRUE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MigrateSource::$activeMap protected property The MigrateMap class for the current migration.
MigrateSource::$activeMigration protected property The Migration class currently invoking us, during rewind() and next().
MigrateSource::$cacheCounts protected property Whether this instance should cache the source count.
MigrateSource::$cacheKey protected property Key to use for caching counts.
MigrateSource::$currentKey protected property The primary key of the current row
MigrateSource::$currentRow protected property The current row from the quey
MigrateSource::$highwaterField protected property Information on the highwater mark for the current migration, if any.
MigrateSource::$idList protected property List of source IDs to process.
MigrateSource::$mapRowAdded protected property By default, next() will directly read the map row and add it to the data row. A source plugin implementation may do this itself (in particular, the SQL source can incorporate the map table into the query) - if so, it should set this TRUE so we…
MigrateSource::$multikeySeparator protected property Used in the case of multiple key sources that need to use idlist.
MigrateSource::$numIgnored protected property Number of rows intentionally ignored (prepareRow() returned FALSE)
MigrateSource::$originalHighwater protected property The highwater mark at the beginning of the import operation.
MigrateSource::$skipCount protected property Whether this instance should not attempt to count the source.
MigrateSource::$trackChanges protected property If TRUE, we will maintain hashed source rows to determine whether incoming data has changed.
MigrateSource::current public function Implementation of Iterator::current() - called when entering a loop iteration, returning the current row
MigrateSource::dataChanged protected function Determine whether this row has changed, and therefore whether it should be processed.
MigrateSource::getCurrentKey public function
MigrateSource::getIgnored public function
MigrateSource::getProcessed public function
MigrateSource::hash protected function Generate a hash of the source row. 3
MigrateSource::key public function Implementation of Iterator::key - called when entering a loop iteration, returning the key of the current row. It must be a scalar - we will serialize to fulfill the requirement, but using getCurrentKey() is preferable.
MigrateSource::prepareRow protected function Give the calling migration a shot at manipulating, and possibly rejecting, the source row.
MigrateSource::resetStats public function Reset numIgnored back to 0.
MigrateSource::valid public function Implementation of Iterator::valid() - called at the top of the loop, returning TRUE to process the loop and FALSE to terminate it
WordPressCommentSource::$fields protected property List of available source fields.
WordPressCommentSource::populateRow protected function Parse the values out of the wp:comment element.
WordPressCommentSource::__construct public function Simple initialization. Overrides WordPressSource::__construct
WordPressSource::$baseBlogUrl protected property The domain name of this blog
WordPressSource::$filename protected property The WXR file being imported
WordPressSource::$itemCount protected property Number of items to be processed
WordPressSource::$itemIndex protected property Track where we are within the items array
WordPressSource::$items protected property Array of XML elements we're traversing for this source.
WordPressSource::$numProcessed protected property Number of eligible rows processed so far (used for itemlimit checking) Overrides MigrateSource::$numProcessed
WordPressSource::$xml protected property The parsed XML from the WXR file
WordPressSource::$xpath protected property xpath for selecting the appropriate elements for this source.
WordPressSource::count public function Return a count of all available source records. Overrides MigrateSource::count 1
WordPressSource::fields public function Returns a list of fields available to be mapped from the source. Overrides MigrateSource::fields
WordPressSource::getBaseBlogUrl public function
WordPressSource::getXml public function
WordPressSource::next public function Implementation of Iterator::next() - called at the bottom of the loop implicitly, as well as explicitly from rewind(). Overrides MigrateSource::next
WordPressSource::rewind public function Implementation of Iterator::rewind() - called before beginning a foreach loop. Overrides MigrateSource::rewind
WordPressSource::__toString public function Return a string representing the source.