class WordPressItemSource in WordPress Migrate 7
Same name and namespace in other branches
- 7.2 wordpress_item.inc \WordPressItemSource
Implementation of MigrateSource, to handle migrating items from WordPress XML dumps.
Hierarchy
- class \MigrateSource implements \Iterator
- class \WordPressSource
- class \WordPressItemSource
- class \WordPressSource
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 WordPressSource {
/**
* 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(
'title' => 'Item title',
'link' => 'WordPress URL of the item',
'pubDate' => 'Published date',
'creator' => 'WordPress username of the item author',
'guid' => 'Alternate URL of the item (?)',
'description' => '?',
'content' => 'Body of the item',
'excerpt' => 'Teaser for the item',
'post_id' => 'Unique ID of the item within the blog',
'post_date' => 'Date posted (author\\s timezone?)',
'post_date_gmt' => 'Date posted (GMT)',
'comment_status' => 'Whether comments may be posted to this item (open/closed)',
'ping_status' => '?',
'post_name' => 'Trailing component of link',
'status' => 'Item status (publish/draft/inherit)',
'post_parent' => 'Parent item ID (?)',
'menu_order' => 'Equivalent to Drupal weight?',
'post_type' => 'Item type (post/page/attachment)',
'post_password' => '?',
'is_sticky' => 'Equivalent to Drupal sticky flag',
'category' => 'Categories (as nicename) assigned to this item',
'tag' => 'Tags (as nicename) assigned to this item',
);
/**
* Simple initialization.
*
*/
public function __construct($filename, $post_type) {
parent::__construct($filename);
$this->postType = $post_type;
$this->xpath = '//channel/item';
}
/**
* Return a count of all available source records.
*
* @param boolean $refresh
* Not currently in use.
*/
public function count($refresh = FALSE) {
$post_types = $this->xml
->xpath("//channel/item[wp:post_type='{$this->postType}']");
$count = count($post_types);
return $count;
}
/**
* Parse the values out of the item element.
*
* @param SimpleXMLElement $item
* @return boolean
*/
protected function populateRow($item) {
// Pull non-namespaced items
foreach ($item as $name => $value) {
$this->currentRow->{$name} = (string) $value;
}
// Now check each namespace
$namespaces = $item
->getNameSpaces(TRUE);
foreach ($namespaces as $ns => $nsuri) {
$item_ns = $item
->children($namespaces[$ns]);
foreach ($item_ns as $name => $value) {
// Special-case content:encoded and excerpt:encoded, which otherwise
// would both be saved as "encoded"
if ($name == 'encoded') {
$this->currentRow->{$ns} = (string) $value;
}
else {
$this->currentRow->{$name} = (string) $value;
}
}
}
// Make sure this is the desired post type
if ($this->currentRow->post_type != $this->postType) {
$this->currentRow = NULL;
return FALSE;
}
// The category field is now the descriptive name, we want the nicename
$this->currentRow->category = array();
// The tag domain changed with WXR version 1.1
$migration = Migration::currentMigration();
$wxr_version = $this->xml
->xpath('//channel/wp:wxr_version');
$wxr_version = (double) reset($wxr_version);
if ($wxr_version < 1.1) {
$tag_domain = 'tag';
}
else {
$tag_domain = 'post_tag';
}
foreach ($item->category as $cat) {
$attributes = $cat
->attributes();
$domain = $attributes->domain;
$nicename = $attributes->nicename;
if ($nicename) {
$nicename = (string) $nicename[0];
if ($domain == 'category') {
$this->currentRow->category[] = $nicename;
}
if ($domain == $tag_domain) {
$this->currentRow->tag[] = $nicename;
}
}
}
$this->currentKey = array(
$this->currentRow->post_id,
);
return TRUE;
}
}
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 | 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 | 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:: |
protected | function | Generate a hash of the source row. | 3 |
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:: |
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::valid() - called at the top of the loop, returning TRUE to process the loop and FALSE to terminate it | |
WordPressItemSource:: |
protected | property | List of available source fields. | |
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 WordPressSource:: |
|
WordPressItemSource:: |
protected | function | Parse the values out of the item element. | |
WordPressItemSource:: |
public | function |
Simple initialization. Overrides WordPressSource:: |
1 |
WordPressSource:: |
protected | property | The domain name of this blog | |
WordPressSource:: |
protected | property | The WXR file being imported | |
WordPressSource:: |
protected | property | Number of items to be processed | |
WordPressSource:: |
protected | property | Track where we are within the items array | |
WordPressSource:: |
protected | property | Array of XML elements we're traversing for this source. | |
WordPressSource:: |
protected | property |
Number of eligible rows processed so far (used for itemlimit checking) Overrides MigrateSource:: |
|
WordPressSource:: |
protected | property | The parsed XML from the WXR file | |
WordPressSource:: |
protected | property | xpath for selecting the appropriate elements for this source. | |
WordPressSource:: |
public | function |
Returns a list of fields available to be mapped from the source. Overrides MigrateSource:: |
|
WordPressSource:: |
public | function | ||
WordPressSource:: |
public | function | ||
WordPressSource:: |
public | function |
Implementation of Iterator::next() - called at the bottom of the loop implicitly,
as well as explicitly from rewind(). Overrides MigrateSource:: |
|
WordPressSource:: |
public | function |
Implementation of Iterator::rewind() - called before beginning a foreach loop. Overrides MigrateSource:: |
|
WordPressSource:: |
public | function | Return a string representing the source. |