You are here

public function MigrateDestinationVariable::import in Migrate 7.2

Import a single row.

Parameters

$variable: Variable object to build. Prefilled with any fields mapped in the Migration.

$row: Raw source data object - passed through to prepare/complete handlers.

Return value

array Array of key fields of the object that was saved if successful. FALSE on failure.

Overrides MigrateDestination::import

File

plugins/destinations/variable.inc, line 65
Support for variable destinations.

Class

MigrateDestinationVariable
Destination class implementing migration into {variable}.

Code

public function import(stdClass $variable, stdClass $row) {

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

  // Check to see if this is a new variable.
  $update = FALSE;

  // We cannot just check against NULL because a variable might actually be
  // set to NULL. Attempt to use a unique variable default value that nothing
  // else would use.
  $default = 'migrate:' . REQUEST_TIME . ':' . drupal_random_key();
  if (variable_get($variable->name, $default) !== $default) {
    $update = TRUE;
  }

  // variable_set() provides no return callback, so we can't really test this
  // without running a variable_get() check.
  migrate_instrument_start('variable_set');
  variable_set($variable->name, $variable->value);
  migrate_instrument_stop('variable_set');

  // Return the new id or FALSE on failure.
  if (variable_get($variable->name, $default) === $variable->value) {

    // Increment the count if the save succeeded.
    if ($update) {
      $this->numUpdated++;
    }
    else {
      $this->numCreated++;
    }

    // Return the primary key to the mapping table.
    $return = array(
      $variable->name,
    );
  }
  else {
    $return = FALSE;
  }

  // Invoke migration complete handlers.
  $this
    ->complete($variable, $row);
  return $return;
}