You are here

abstract class MigrateMap in Migrate 7.2

Same name and namespace in other branches
  1. 6.2 includes/map.inc \MigrateMap

We implement the Iterator interface to support iteration over the map table for the purpose of rollback.

Hierarchy

Expanded class hierarchy of MigrateMap

File

includes/map.inc, line 12
Defines the framework for map and message handling.

View source
abstract class MigrateMap implements Iterator {

  /**
   * Codes reflecting the current status of a map row.
   */
  const STATUS_IMPORTED = 0;
  const STATUS_NEEDS_UPDATE = 1;
  const STATUS_IGNORED = 2;
  const STATUS_FAILED = 3;

  /**
   * Codes reflecting how to handle the destination item on rollback.
   *
   */
  const ROLLBACK_DELETE = 0;
  const ROLLBACK_PRESERVE = 1;

  /**
   * Arrays of key fields for the source and destination. Array keys are the
   * field names - array values are specific to the concrete map class.
   *
   * @var array
   */
  protected $sourceKey, $destinationKey;
  public abstract function getSourceKey();
  public abstract function getDestinationKey();

  /**
   * Mapping from field names to the map/message table key names (e.g.,
   * from input_field to sourceid1, or from nid to destid1)
   *
   * @var array
   */
  protected $sourceKeyMap, $destinationKeyMap;

  /**
   * Get the source key map.
   */
  public function getSourceKeyMap() {
    return $this->sourceKeyMap;
  }

  /**
   * Boolean determining whether to track last_imported times in map tables
   *
   * @var boolean
   */
  protected $trackLastImported = FALSE;
  public function getTrackLastImported() {
    return $this->trackLastImported;
  }
  public function setTrackLastImported($trackLastImported) {
    if (is_bool($trackLastImported)) {
      $this->trackLastImported = $trackLastImported;
    }
  }

  /**
   * Save a mapping from the key values in the source row to the destination
   * keys.
   *
   * @param $source_row
   * @param $dest_ids
   * @param $status
   * @param $rollback_action
   * @param $hash
   */
  public abstract function saveIDMapping(stdClass $source_row, array $dest_ids, $status = MigrateMap::STATUS_IMPORTED, $rollback_action = MigrateMap::ROLLBACK_DELETE, $hash = NULL);

  /**
   * Record a message related to a source record
   *
   * @param array $source_key
   *  Source ID of the record in error
   * @param string $message
   *  The message to record.
   * @param int $level
   *  Optional message severity (defaults to MESSAGE_ERROR).
   */
  public abstract function saveMessage($source_key, $message, $level = MigrationBase::MESSAGE_ERROR);

  /**
   * Prepare to run a full update - mark all previously-imported content as
   * ready to be re-imported.
   */
  public abstract function prepareUpdate();

  /**
   * Report the number of processed items in the map
   */
  public abstract function processedCount();

  /**
   * Report the number of imported items in the map
   */
  public abstract function importedCount();

  /**
   * Report the number of items that failed to import
   */
  public abstract function errorCount();

  /**
   * Report the number of messages
   */
  public abstract function messageCount();

  /**
   * Delete the map and message entries for a given source record
   *
   * @param array $source_key
   */
  public abstract function delete(array $source_key, $messages_only = FALSE);

  /**
   * Delete the map and message entries for a given destination record
   *
   * @param array $destination_key
   */
  public abstract function deleteDestination(array $destination_key);

  /**
   * Delete the map and message entries for a set of given source records.
   *
   * @param array $source_keys
   */
  public abstract function deleteBulk(array $source_keys);

  /**
   * Clear all messages from the map.
   */
  public abstract function clearMessages();

  /**
   * Retrieve map data for a given source or destination item
   */
  public abstract function getRowBySource(array $source_id);
  public abstract function getRowByDestination(array $destination_id);

  /**
   * Retrieve an array of map rows marked as needing update.
   */
  public abstract function getRowsNeedingUpdate($count);

  /**
   * Given a (possibly multi-field) destination key, return the (possibly
   * multi-field) source key mapped to it.
   *
   * @param array $destination_id
   *  Array of destination key values.
   *
   * @return array
   *  Array of source key values, or NULL on failure.
   */
  public abstract function lookupSourceID(array $destination_id);

  /**
   * Given a (possibly multi-field) source key, return the (possibly
   * multi-field) destination key it is mapped to.
   *
   * @param array $source_id
   *  Array of source key values.
   *
   * @return array
   *  Array of destination key values, or NULL on failure.
   */
  public abstract function lookupDestinationID(array $source_id);

  /**
   * Remove any persistent storage used by this map (e.g., map and message
   * tables)
   */
  public abstract function destroy();

}

Members

Namesort descending Modifiers Type Description Overrides
MigrateMap::$sourceKey protected property Arrays of key fields for the source and destination. Array keys are the field names - array values are specific to the concrete map class.
MigrateMap::$sourceKeyMap protected property Mapping from field names to the map/message table key names (e.g., from input_field to sourceid1, or from nid to destid1)
MigrateMap::$trackLastImported protected property Boolean determining whether to track last_imported times in map tables
MigrateMap::clearMessages abstract public function Clear all messages from the map. 1
MigrateMap::delete abstract public function Delete the map and message entries for a given source record 1
MigrateMap::deleteBulk abstract public function Delete the map and message entries for a set of given source records. 1
MigrateMap::deleteDestination abstract public function Delete the map and message entries for a given destination record 1
MigrateMap::destroy abstract public function Remove any persistent storage used by this map (e.g., map and message tables) 1
MigrateMap::errorCount abstract public function Report the number of items that failed to import 1
MigrateMap::getDestinationKey abstract public function 1
MigrateMap::getRowByDestination abstract public function 1
MigrateMap::getRowBySource abstract public function Retrieve map data for a given source or destination item 1
MigrateMap::getRowsNeedingUpdate abstract public function Retrieve an array of map rows marked as needing update. 1
MigrateMap::getSourceKey abstract public function 1
MigrateMap::getSourceKeyMap public function Get the source key map.
MigrateMap::getTrackLastImported public function
MigrateMap::importedCount abstract public function Report the number of imported items in the map 1
MigrateMap::lookupDestinationID abstract public function Given a (possibly multi-field) source key, return the (possibly multi-field) destination key it is mapped to. 1
MigrateMap::lookupSourceID abstract public function Given a (possibly multi-field) destination key, return the (possibly multi-field) source key mapped to it. 1
MigrateMap::messageCount abstract public function Report the number of messages 1
MigrateMap::prepareUpdate abstract public function Prepare to run a full update - mark all previously-imported content as ready to be re-imported. 1
MigrateMap::processedCount abstract public function Report the number of processed items in the map 1
MigrateMap::ROLLBACK_DELETE constant Codes reflecting how to handle the destination item on rollback.
MigrateMap::ROLLBACK_PRESERVE constant
MigrateMap::saveIDMapping abstract public function Save a mapping from the key values in the source row to the destination keys. 1
MigrateMap::saveMessage abstract public function Record a message related to a source record 1
MigrateMap::setTrackLastImported public function
MigrateMap::STATUS_FAILED constant
MigrateMap::STATUS_IGNORED constant
MigrateMap::STATUS_IMPORTED constant Codes reflecting the current status of a map row.
MigrateMap::STATUS_NEEDS_UPDATE constant