You are here

class MigrateDestinationFlagSimple in Migrate Extras 6.2

Same name and namespace in other branches
  1. 7.2 flag.inc \MigrateDestinationFlagSimple

Destination class implementing when you want just an insert into flag_content table.

Hierarchy

Expanded class hierarchy of MigrateDestinationFlagSimple

File

./flag.inc, line 11
Flag module integration

View source
class MigrateDestinationFlagSimple extends MigrateDestination {
  public function __construct($fid) {
    parent::__construct();
    $this->fid = $fid;
  }
  public function __toString() {
    $flag = flag_get_flag(NULL, $this->fid);
    return t('flag (!flag)', array(
      '!flag' => $flag->name,
    ));
  }
  public static function getKeySchema() {
    return array(
      'fcid' => array(
        'type' => 'int',
        'not null' => TRUE,
      ),
    );
  }

  /**
   * Delete a membership.
   *
   * @param $id
   *  IDs to be deleted.
   */
  public function bulkRollback(array $ids) {
    migrate_instrument_start(__METHOD__);
    db_delete('flag_content')
      ->condition('fcid', $ids, 'IN')
      ->execute();
    migrate_instrument_stop(__METHOD__);
  }

  /**
   * Import a single flag_content.
   *
   * @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) {
    if (isset($entity->timestamp)) {
      $entity->timestamp = Migration::timestamp($entity->timestamp);
    }
    $entity->fid = $this->fid;
    if (!empty($entity->fcid)) {
      $return = drupal_write_record('flag_content', $entity, 'fcid');
    }
    else {
      $return = drupal_write_record('flag_content', $entity);
    }
    if ($return) {
      return array(
        $entity->fcid,
      );
    }
  }
  public function fields() {
    return array(
      'fcid' => 'Flag content ID',
      'fid' => 'Flag ID',
      'content_type' => '',
      'content_id' => '',
      'uid' => 'User ID',
      'timestamp' => '',
    );
  }

}

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.
MigrateDestinationFlagSimple::bulkRollback public function Delete a membership.
MigrateDestinationFlagSimple::fields public function Derived classes must implement fields(), returning a list of available destination fields. Overrides MigrateDestination::fields
MigrateDestinationFlagSimple::getKeySchema public static function
MigrateDestinationFlagSimple::import public function Import a single flag_content. Overrides MigrateDestination::import
MigrateDestinationFlagSimple::__construct public function Null constructor Overrides MigrateDestination::__construct
MigrateDestinationFlagSimple::__toString public function Derived classes must implement __toString(). Overrides MigrateDestination::__toString