class WordPressItemSource in WordPress Migrate 7.2
Same name and namespace in other branches
- 7 wordpress_item.inc \WordPressItemSource
Implementation of MigrateSource, to handle migrating items from WordPress XML dumps.
Hierarchy
- class \MigrateSource implements \Iterator
- class \MigrateSourceXML
- class \WordPressItemSource
- class \MigrateSourceXML
Expanded class hierarchy of WordPressItemSource
File
- ./
wordpress_item.inc, line 12 - Support for migrating posts and pages from a WordPress blog into Drupal.
View source
class WordPressItemSource extends MigrateSourceXML {
/**
* The <wp:post_type> value we're looking for in this migration
* (post/page/attachment).
*
* @var string
*/
protected $postType;
/**
* List of available source fields.
*
* @var array
*/
protected $fields = array();
/**
* Simple initialization.
*/
public function __construct($filename, $post_type, $cache_key, $namespaces = array()) {
$source_options = array(
'reader_class' => 'MigrateXMLReader',
'cache_counts' => TRUE,
'cache_key' => $cache_key,
);
$this->fields = $this
->fields();
parent::__construct($filename, '/rss/channel/item', 'wp:post_id', $this->fields, $source_options, $namespaces);
$this->postType = $post_type;
}
/**
* Provides a list of available source fields, keyed by the field name
* as it appears in the source data, with descriptions as the values.
*
* @return array
*/
public function fields() {
return array(
'title' => 'Item title',
'link' => 'WordPress URL of the item',
'pubDate' => 'Published date',
'dc:creator' => 'WordPress username of the item author',
'guid' => 'Alternate URL of the item (?)',
'description' => '?',
'content:encoded' => 'Body of the item',
'excerpt:encoded' => 'Teaser for the item',
'wp:post_id' => 'Unique ID of the item within the blog',
'wp:post_date' => 'Date posted (author\\s timezone?)',
'wp:post_date_gmt' => 'Date posted (GMT)',
'wp:comment_status' => 'Whether comments may be posted to this item (open/closed)',
'wp:ping_status' => '?',
'wp:post_name' => 'Trailing component of link',
'wp:status' => 'Item status (publish/draft/inherit)',
'wp:post_parent' => 'Parent item ID (?)',
'wp:menu_order' => 'Equivalent to Drupal weight?',
'wp:post_type' => 'Item type (post/page/attachment)',
'wp:post_password' => '?',
'wp:is_sticky' => 'Equivalent to Drupal sticky flag',
'category' => 'Categories (as nicename) assigned to this item',
'tag' => 'Tags (as nicename) assigned to this item',
'content' => 'Extracted from Wordpress content:encoded',
'status' => 'Extracted from Wordpress status',
);
}
/**
* Return a count of all available source records.
*/
public function computeCount() {
$count = 0;
foreach ($this->sourceUrls as $url) {
$reader = new $this->readerClass($url, $this->elementQuery, $this->idQuery);
foreach ($reader as $element) {
// Only count relevant postType
$field = 'wp:post_type';
$post_type = current($element
->xpath($field));
if ($post_type == $this->postType) {
$count++;
}
}
}
return $count;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MigrateSource:: |
protected | property | The MigrateMap class for the current migration. | |
MigrateSource:: |
protected | property | The Migration class currently invoking us, during rewind() and next(). | |
MigrateSource:: |
protected | property | Whether this instance should cache the source count. | |
MigrateSource:: |
protected | property | Key to use for caching counts. | |
MigrateSource:: |
protected | property | The primary key of the current row | |
MigrateSource:: |
protected | property | The current row from the quey | |
MigrateSource:: |
protected | property | Information on the highwater mark for the current migration, if any. | |
MigrateSource:: |
protected | property | List of source IDs to process. | |
MigrateSource:: |
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:: |
protected | property | Used in the case of multiple key sources that need to use idlist. | |
MigrateSource:: |
protected | property | Number of rows intentionally ignored (prepareRow() returned FALSE) | |
MigrateSource:: |
protected | property | Number of rows we've at least looked at. | 1 |
MigrateSource:: |
protected | property | The highwater mark at the beginning of the import operation. | |
MigrateSource:: |
protected | property | Whether this instance should not attempt to count the source. | |
MigrateSource:: |
protected | property | If TRUE, we will maintain hashed source rows to determine whether incoming data has changed. | |
MigrateSource:: |
public | function | Return a count of available source records, from the cache if appropriate. Returns -1 if the source is not countable. | |
MigrateSource:: |
public | function | Implementation of Iterator::current() - called when entering a loop iteration, returning the current row | |
MigrateSource:: |
protected | function | Determine whether this row has changed, and therefore whether it should be processed. | |
MigrateSource:: |
public | function | ||
MigrateSource:: |
public | function | ||
MigrateSource:: |
public | function | ||
MigrateSource:: |
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:: |
public | function | Implementation of Iterator::next() - subclasses of MigrateSource should implement getNextRow() to retrieve the next valid source rocord to process. | |
MigrateSource:: |
protected | function | Give the calling migration a shot at manipulating, and possibly rejecting, the source row. | |
MigrateSource:: |
public | function | Reset numIgnored back to 0. | |
MigrateSource:: |
public | function | Implementation of Iterator::rewind() - subclasses of MigrateSource should implement performRewind() to do any class-specific setup for iterating source records. | |
MigrateSource:: |
public | function | Implementation of Iterator::valid() - called at the top of the loop, returning TRUE to process the loop and FALSE to terminate it | |
MigrateSourceXML:: |
protected | property | Holds our current position within the $source_urls array | |
MigrateSourceXML:: |
protected | property | Store the query string used to recognize elements being iterated so we can create reader objects on the fly. | |
MigrateSourceXML:: |
protected | property | Store the query string used to retrieve the primary key value from each element so we can create reader objects on the fly. | |
MigrateSourceXML:: |
protected | property | An array of namespaces to explicitly register before Xpath queries. | |
MigrateSourceXML:: |
protected | property | ||
MigrateSourceXML:: |
protected | property | Store the reader class used to query XML so we can create reader objects on the fly. | |
MigrateSourceXML:: |
protected | property | The source URLs to load XML from | |
MigrateSourceXML:: |
public | function | Returns the active Url. | |
MigrateSourceXML:: |
public | function | Implementation of MigrationSource::getNextRow(). | |
MigrateSourceXML:: |
public | function | Advances the reader to the next source from source_urls. | |
MigrateSourceXML:: |
public | function | The MigrateXMLReader object serving as a cursor over the XML source. | |
MigrateSourceXML:: |
protected | function |
Generate a hash of the source row. Overrides MigrateSource:: |
|
MigrateSourceXML:: |
public | function | Implementation of MigrateSource::performRewind(). | |
MigrateSourceXML:: |
protected | function | Explicitly register namespaces on an XML element. | |
MigrateSourceXML:: |
public | function | Return a string representing the source query. | |
WordPressItemSource:: |
protected | property |
List of available source fields. Overrides MigrateSourceXML:: |
|
WordPressItemSource:: |
protected | property | The <wp:post_type> value we're looking for in this migration (post/page/attachment). | |
WordPressItemSource:: |
public | function |
Return a count of all available source records. Overrides MigrateSourceXML:: |
|
WordPressItemSource:: |
public | function |
Provides a list of available source fields, keyed by the field name
as it appears in the source data, with descriptions as the values. Overrides MigrateSourceXML:: |
|
WordPressItemSource:: |
public | function |
Simple initialization. Overrides MigrateSourceXML:: |
1 |