You are here

class MigrateDestinationRole in Migrate 7.2

Same name and namespace in other branches
  1. 6.2 plugins/destinations/user.inc \MigrateDestinationRole

Hierarchy

Expanded class hierarchy of MigrateDestinationRole

File

plugins/destinations/user.inc, line 294
Support for user destinations.

View source
class MigrateDestinationRole extends MigrateDestinationTable {
  public function __construct() {
    parent::__construct('role');
  }

  /**
   * Get the key definition for the role table.
   *
   * @param $dummy
   *  PHP is picky - it throws E_STRICT notices if we don't have a parameter
   *  because MigrateDestinationTable has one.
   */
  public static function getKeySchema($dummy = NULL) {
    return MigrateDestinationTable::getKeySchema('role');
  }

  /**
   * Delete a single row.
   *
   * @param $id
   *  Primary key values.
   */
  public function rollback(array $id) {
    migrate_instrument_start('role rollback');
    $rid = reset($id);
    user_role_delete((int) $rid);
    migrate_instrument_stop('role rollback');
  }

  /**
   * Import a single row.
   *
   * @param $entity
   *  Object object to build. Prefilled with any fields mapped in the Migration.
   * @param $row
   *  Raw source data object - passed through to prepare/complete handlers.
   *
   * @return array
   *  Array of key fields of the object that was saved if
   *  successful. FALSE on failure.
   */
  public function import(stdClass $entity, stdClass $row) {
    $migration = Migration::currentMigration();
    $updating = FALSE;

    // Updating previously-migrated content?
    if (isset($row->migrate_map_destid1)) {
      $updating = TRUE;
      if (isset($entity->rid)) {
        if ($entity->rid != $row->migrate_map_destid1) {
          throw new MigrateException(t("Incoming id !id and map destination id !destid don't match", array(
            '!id' => $entity->rid,
            '!destid' => $row->migrate_map_destid1,
          )));
        }
      }
      else {
        $entity->rid = $row->migrate_map_destid1;
      }
    }
    if ($migration
      ->getSystemOfRecord() == Migration::DESTINATION) {
      $updating = TRUE;
      if (!isset($entity->rid)) {
        throw new MigrateException(t('System-of-record is DESTINATION, but no destination id provided'));
      }
      $old_entity = user_role_load($entity->rid);
      foreach ($entity as $field => $value) {
        $old_entity->{$field} = $entity->{$field};
      }
      $entity = $old_entity;
    }
    $this
      ->prepare($entity, $row);
    user_role_save($entity);
    $this
      ->complete($entity, $row);
    if (!empty($entity->rid)) {
      $id = array(
        $entity->rid,
      );
      if ($updating) {
        $this->numUpdated++;
      }
      else {
        $this->numCreated++;
      }
    }
    else {
      $id = FALSE;
    }
    return $id;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MigrateDestination::$numCreated protected property Maintain stats on the number of destination objects created or updated.
MigrateDestination::$numUpdated protected property
MigrateDestination::getCreated public function
MigrateDestination::getUpdated public function
MigrateDestination::resetStats public function Reset numCreated and numUpdated back to 0.
MigrateDestinationRole::getKeySchema public static function Get the key definition for the role table. Overrides MigrateDestinationTable::getKeySchema
MigrateDestinationRole::import public function Import a single row. Overrides MigrateDestinationTable::import
MigrateDestinationRole::rollback public function Delete a single row. Overrides MigrateDestinationTable::rollback
MigrateDestinationRole::__construct public function Null constructor Overrides MigrateDestinationTable::__construct
MigrateDestinationTable::$schema protected property The schema of the current table.
MigrateDestinationTable::$tableName protected property The name of the current table.
MigrateDestinationTable::complete public function Give handlers a shot at modifying the object (or taking additional action) after saving it.
MigrateDestinationTable::completeRollback public function Give handlers a shot at cleaning up after a row has been rolled back.
MigrateDestinationTable::fields public function Returns a list of fields available to be mapped. Overrides MigrateDestination::fields
MigrateDestinationTable::prepare public function Give handlers a shot at modifying the object before saving it.
MigrateDestinationTable::prepareRollback public function Give handlers a shot at cleaning up before the row has been rolled back.
MigrateDestinationTable::__toString public function Derived classes must implement __toString(). Overrides MigrateDestination::__toString