class MigrateDestinationTermMachineName in Taxonomy Machine Name 7
Class MigrateDestinationTermMachineName
Hierarchy
- class \MigrateDestination
- class \MigrateDestinationEntity
- class \MigrateDestinationTerm
- class \MigrateDestinationEntity
Expanded class hierarchy of MigrateDestinationTermMachineName
File
- ./
taxonomy_machine_name.migrate.inc, line 81 - Taxonomy Machine Name Migrate Module File.
View source
class MigrateDestinationTermMachineName extends MigrateDestinationTerm {
/**
* @var array
*/
protected $deferred;
/**
* Constructor for MigrateDestinationTermMachineName.
*
* @param string $bundle
* The machine name of the taxonomy vocabulary.
*
* @param array $options
* An optional array of options to control the import process.
*/
public function __construct($bundle, array $options = array()) {
parent::__construct($bundle, $options);
$this->deferred = array();
}
/**
* Returns the fields that are exposed by this migration destination.
*
* The only additional field is "Parent (by machine name)".
*
* @param Migration $migration
* Migration instance.
*
* @return array
* Destination fields.
*/
public function fields($migration = NULL) {
$fields = parent::fields();
$fields['parent_machine_name'] = t('Parent (by machine name).');
return $fields;
}
/**
* Attempt to find a term that has the same machine name.
*
* @param object $term
* A taxonomy term object with at least the machine
* name and vid properties defined.
*
* @return object
* A matching taxonomy term object if found, otherwise FALSE.
*/
public function findMatchingTerm($term) {
$candidate = taxonomy_term_machine_name_load(trim($term->machine_name), $term->vid);
if (is_object($candidate)) {
return $candidate;
}
else {
return FALSE;
}
}
/**
* Import the provided term, using information from the provided row.
*
* @param stdclass $term
* Term object to build. Prefilled with any fields mapped in the Migration.
* @param stdclass $row
* Raw source data object - passed through to prepare/complete handlers.
*
* @return array
* Array of key fields (tid only in this case) of the term that was saved if
* successful. FALSE on failure.
*
* @throws \MigrateException
*/
public function import(stdClass $term, stdClass $row) {
// Look up parent name if provided.
if (isset($term->parent_machine_name)) {
$parent_machine_name = trim($term->parent_machine_name);
if (!empty($parent_machine_name)) {
// Default to bundle if no vocabulary machine name provided.
if (!isset($term->vocabulary_machine_name)) {
$term->vocabulary_machine_name = $this->bundle;
}
$parent_tid = taxonomy_term_machine_name_load($parent_machine_name, $term->vocabulary_machine_name);
if (!empty($parent_tid)) {
$term->parent = $parent_tid->tid;
}
else {
// Store aside for post import process once parent will be created.
$deferred_import = new stdClass();
$deferred_import->term = clone $term;
$deferred_import->row = clone $row;
$this->deferred[] = $deferred_import;
}
}
}
$tid = parent::import($term, $row);
return $tid;
}
/**
* Check whether or not this destination has terms for which the import was.
*
* "deferred" because their parent term could not be found.
*
* @return bool
* TRUE if there are terms for which import was deferred, FALSE otherwise.
*/
public function hasDeferredImports() {
return count($this->deferred) > 0;
}
/**
* Return the machine names of any terms for which import was deferred.
*
* @return array
* An array of machine names for all deferred term imports.
*/
public function getDeferredImportKeys() {
$keys = array();
foreach ($this->deferred as $import) {
$keys[] = $import->term->machine_name;
}
return $keys;
}
/**
* Attempt to import any terms for which import was previously deferred.
*
* This will run import() again for each term and row, which will again
* attempt to match up each term with its parent term.
*
* Any term for which a parent term is still not found will be returned to
* the set of deferred imports. If the import is a multi-level hierarchy,
* this method can be invoked multiple times until every level of the
* hierarchy has been successfully imported.
*/
public function runDeferredImports() {
$current = $this->deferred;
// Clear the list of deferred imports, to be rebuilt during the import.
$this->deferred = array();
foreach ($current as $import) {
// This will automatically re-queue any imports that
// still need to be deferred.
$this
->import($import->term, $import->row);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MigrateDestination:: |
protected | property | Maintain stats on the number of destination objects created or updated. | |
MigrateDestination:: |
protected | property | ||
MigrateDestination:: |
public | function | ||
MigrateDestination:: |
public | function | ||
MigrateDestination:: |
public | function | Reset numCreated and numUpdated back to 0. | |
MigrateDestinationEntity:: |
protected | property | The bundle (node type, vocabulary, etc.) of the destination. | |
MigrateDestinationEntity:: |
protected | property | The entity type (node, user, taxonomy_term, etc.) of the destination. | |
MigrateDestinationEntity:: |
protected | property | Default language for text fields in this destination. | |
MigrateDestinationEntity:: |
protected | property | Default input format for text fields in this destination. | |
MigrateDestinationEntity:: |
public static | function | Flattens an array of allowed values. | |
MigrateDestinationEntity:: |
public | function | Give handlers a shot at modifying the object (or taking additional action) after saving it. | |
MigrateDestinationEntity:: |
public | function | Give handlers a shot at cleaning up after an entity has been rolled back. | |
MigrateDestinationEntity:: |
public static | function | Perform field validation against the field data in an entity. Wraps field_attach_validate to handle exceptions cleanly and provide maximum information for identifying the cause of validation errors. | |
MigrateDestinationEntity:: |
public | function | ||
MigrateDestinationEntity:: |
public | function | ||
MigrateDestinationEntity:: |
public | function | ||
MigrateDestinationEntity:: |
public | function | ||
MigrateDestinationEntity:: |
public | function | Give handlers a shot at modifying the object before saving it. | |
MigrateDestinationEntity:: |
public | function | Give handlers a shot at cleaning up before an entity has been rolled back. | |
MigrateDestinationEntity:: |
public | function |
Derived classes must implement __toString(). Overrides MigrateDestination:: |
|
MigrateDestinationTerm:: |
protected | property | Boolean indicating whether to permit duplicate terms to be created. | |
MigrateDestinationTerm:: |
public static | function | ||
MigrateDestinationTerm:: |
public static | function | Return an options array for term destinations. | |
MigrateDestinationTerm:: |
public | function | Delete a migrated term | |
MigrateDestinationTermMachineName:: |
protected | property | ||
MigrateDestinationTermMachineName:: |
public | function |
Returns the fields that are exposed by this migration destination. Overrides MigrateDestinationTerm:: |
|
MigrateDestinationTermMachineName:: |
public | function |
Attempt to find a term that has the same machine name. Overrides MigrateDestinationTerm:: |
|
MigrateDestinationTermMachineName:: |
public | function | Return the machine names of any terms for which import was deferred. | |
MigrateDestinationTermMachineName:: |
public | function | Check whether or not this destination has terms for which the import was. | |
MigrateDestinationTermMachineName:: |
public | function |
Import the provided term, using information from the provided row. Overrides MigrateDestinationTerm:: |
|
MigrateDestinationTermMachineName:: |
public | function | Attempt to import any terms for which import was previously deferred. | |
MigrateDestinationTermMachineName:: |
public | function |
Constructor for MigrateDestinationTermMachineName. Overrides MigrateDestinationTerm:: |