You are here

class MigrateDestinationLineItem in MERCI (Manage Equipment Reservations, Checkout and Inventory) 7.3

Hierarchy

Expanded class hierarchy of MigrateDestinationLineItem

File

merci_migrate/merci_line_item.inc, line 72

View source
class MigrateDestinationLineItem extends MigrateDestinationEntity {
  protected $bypassDestIdCheck = FALSE;
  public static function getKeySchema() {
    return array(
      'line_item_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Primary Key: Unique ID.',
      ),
    );
  }
  public function __construct($bundle, array $options = array()) {
    parent::__construct('merci_line_item', $bundle, $options);
  }

  /**
   * Returns a list of fields available to be mapped for the node type (bundle)
   *
   * @param Migration $migration
   *  Optionally, the migration containing this destination.
   * @return array
   *  Keys: machine names of the fields (to be passed to addFieldMapping)
   *  Values: Human-friendly descriptions of the fields.
   */
  public function fields($migration = NULL) {
    $fields = array();

    // First the core (node table) properties
    $fields['line_item_id'] = t('Entity ID');
    $fields['type'] = t('Type');
    $fields['line_item_label'] = t('Title');
    $fields['entity_id'] = t('Parent ID');
    $fields['quantity'] = t('Quantity');
    $fields['created'] = t('Created');
    $fields['changed'] = t('Changed');

    // Then add in anything provided by handlers
    $fields += migrate_handler_invoke_all('Entity', 'fields', $this->entityType, $this->bundle, $migration);
    return $fields;
  }

  /**
   * Import a single node.
   *
   * @param $node
   *  Node 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 (nid only in this case) of the node that was saved if
   *  successful. FALSE on failure.
   */
  public function import(stdClass $object, stdClass $row) {

    // Updating previously-migrated content?
    $migration = Migration::currentMigration();
    if (!isset($object->type)) {

      // Default the type to our designated destination bundle (by doing this
      // conditionally, we permit some flexibility in terms of implementing
      // migrations which can affect more than one type).
      $object->type = $this->bundle;
    }

    // Invoke migration prepare handlers
    $this
      ->prepare($object, $row);

    // Validate field data prior to saving.
    MigrateDestinationEntity::fieldAttachValidate('merci_line_item', $object);
    migrate_instrument_start('merci_line_item_save');
    entity_save('merci_line_item', $object);
    migrate_instrument_stop('merci_line_item_save');
    if (isset($object->line_item_id)) {
      $this->numCreated++;
      $return = array(
        $object->line_item_id,
      );
    }
    else {
      $return = FALSE;
    }
    $this
      ->complete($object, $row);
    return $return;
  }
  public function rollback(array $id) {
    static $count = 0;
    migrate_instrument_start('merci_line_item_delete');
    $this
      ->prepareRollback($id);
    entity_delete('merci_line_item', reset($id));
    $this
      ->completeRollback($id);
    migrate_instrument_stop('merci_line_item_delete');
  }

}

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.
MigrateDestinationEntity::$bundle protected property The bundle (node type, vocabulary, etc.) of the destination.
MigrateDestinationEntity::$entityType protected property The entity type (node, user, taxonomy_term, etc.) of the destination.
MigrateDestinationEntity::$language protected property Default language for text fields in this destination.
MigrateDestinationEntity::$textFormat protected property Default input format for text fields in this destination.
MigrateDestinationEntity::array_flatten public static function Flattens an array of allowed values.
MigrateDestinationEntity::complete public function Give handlers a shot at modifying the object (or taking additional action) after saving it.
MigrateDestinationEntity::completeRollback public function Give handlers a shot at cleaning up after an entity has been rolled back.
MigrateDestinationEntity::fieldAttachValidate 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::getBundle public function
MigrateDestinationEntity::getEntityType public function
MigrateDestinationEntity::getLanguage public function
MigrateDestinationEntity::getTextFormat public function
MigrateDestinationEntity::prepare public function Give handlers a shot at modifying the object before saving it.
MigrateDestinationEntity::prepareRollback public function Give handlers a shot at cleaning up before an entity has been rolled back.
MigrateDestinationEntity::__toString public function Derived classes must implement __toString(). Overrides MigrateDestination::__toString
MigrateDestinationLineItem::$bypassDestIdCheck protected property
MigrateDestinationLineItem::fields public function Returns a list of fields available to be mapped for the node type (bundle) Overrides MigrateDestination::fields
MigrateDestinationLineItem::getKeySchema public static function
MigrateDestinationLineItem::import public function Import a single node. Overrides MigrateDestination::import
MigrateDestinationLineItem::rollback public function
MigrateDestinationLineItem::__construct public function Simply save the key schema. Overrides MigrateDestinationEntity::__construct