class MigrateListXML in Migrate 6.2
Same name and namespace in other branches
- 7.2 plugins/sources/xml.inc \MigrateListXML
Implementation of MigrateList, for retrieving a list of IDs to be migrated from an XML document.
Hierarchy
- class \MigrateList
- class \MigrateListXML
Expanded class hierarchy of MigrateListXML
File
- plugins/
sources/ xml.inc, line 27 - Support for migration from XML sources.
View source
class MigrateListXML extends MigrateList {
/**
* A URL pointing to an XML document containing a list of IDs to be processed.
*
* @var string
*/
protected $listUrl;
public function __construct($list_url) {
parent::__construct();
$this->listUrl = $list_url;
// Suppress errors during parsing, so we can pick them up after
libxml_use_internal_errors(TRUE);
}
/**
* Our public face is the URL we're getting items from
*
* @return string
*/
public function __toString() {
return $this->listUrl;
}
/**
* Load the XML at the given URL, and return an array of the IDs found within it.
*
* @return array
*/
public function getIdList() {
migrate_instrument_start("Retrieve {$this->listUrl}");
$xml = simplexml_load_file($this->listUrl);
migrate_instrument_stop("Retrieve {$this->listUrl}");
if ($xml !== FALSE) {
return $this
->getIDsFromXML($xml);
}
else {
Migration::displayMessage(t('Loading of !listUrl failed:', array(
'!listUrl' => $this->listUrl,
)));
foreach (libxml_get_errors() as $error) {
Migration::displayMessage(MigrateItemsXML::parseLibXMLError($error));
}
return NULL;
}
}
/**
* Given an XML object, parse out the IDs for processing and return them as an
* array. The default implementation assumes the IDs are simply the values of
* the top-level elements - in most cases, you will need to override this to
* reflect your particular XML structure.
*
* @param SimpleXMLElement $xml
*
* @return array
*/
protected function getIDsFromXML(SimpleXMLElement $xml) {
$ids = array();
foreach ($xml as $element) {
$ids[] = (string) $element;
}
return array_unique($ids);
}
/**
* Return a count of all available IDs from the source listing. The default
* implementation assumes the count of top-level elements reflects the number
* of IDs available - in many cases, you will need to override this to reflect
* your particular XML structure.
*/
public function computeCount() {
$xml = simplexml_load_file($this->listUrl);
// Number of sourceid elements beneath the top-level element
$count = count($xml);
return $count;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MigrateListXML:: |
protected | property | A URL pointing to an XML document containing a list of IDs to be processed. | |
MigrateListXML:: |
public | function |
Return a count of all available IDs from the source listing. The default
implementation assumes the count of top-level elements reflects the number
of IDs available - in many cases, you will need to override this to reflect
your particular XML structure. Overrides MigrateList:: |
|
MigrateListXML:: |
public | function |
Load the XML at the given URL, and return an array of the IDs found within it. Overrides MigrateList:: |
|
MigrateListXML:: |
protected | function | Given an XML object, parse out the IDs for processing and return them as an array. The default implementation assumes the IDs are simply the values of the top-level elements - in most cases, you will need to override this to reflect your particular… | |
MigrateListXML:: |
public | function |
Overrides MigrateList:: |
|
MigrateListXML:: |
public | function |
Our public face is the URL we're getting items from Overrides MigrateList:: |