You are here

public function MigrationBase::__construct in Migrate 7.2

Same name and namespace in other branches
  1. 6.2 includes/base.inc \MigrationBase::__construct()

Construction of a MigrationBase instance.

Parameters

array $arguments:

3 calls to MigrationBase::__construct()
Migration::__construct in includes/migration.inc
General initialization of a Migration object.
WineFinishMigration::__construct in migrate_example/wine.inc
Construction of a MigrationBase instance.
WinePrepMigration::__construct in migrate_example/wine.inc
Construction of a MigrationBase instance.
3 methods override MigrationBase::__construct()
Migration::__construct in includes/migration.inc
General initialization of a Migration object.
WineFinishMigration::__construct in migrate_example/wine.inc
Construction of a MigrationBase instance.
WinePrepMigration::__construct in migrate_example/wine.inc
Construction of a MigrationBase instance.

File

includes/base.inc, line 418
Defines the base class for migration processes.

Class

MigrationBase
The base class for all objects representing distinct steps in a migration process. Most commonly these will be Migration objects which actually import data from a source into a Drupal destination, but by deriving classes directly from MigrationBase…

Code

public function __construct($arguments = array()) {

  // Support for legacy code passing a group object as the first parameter.
  if (is_object($arguments) && is_a($arguments, 'MigrateGroup')) {
    $this->group = $arguments;
    $this->arguments['group_name'] = $arguments
      ->getName();
    if (!self::$groupArgumentWarning && variable_get('migrate_deprecation_warnings', 1)) {
      self::displayMessage(t('Passing a group object to a migration constructor is now deprecated - pass through the arguments array passed to the leaf class instead.'));
      self::$groupArgumentWarning = TRUE;
    }
  }
  else {
    if (empty($arguments)) {
      $this->arguments = array();
      if (!self::$emptyArgumentsWarning && variable_get('migrate_deprecation_warnings', 1)) {
        self::displayMessage(t('Passing an empty first parameter to a migration constructor is now deprecated - pass through the arguments array passed to the leaf class instead.'));
        self::$emptyArgumentsWarning = TRUE;
      }
    }
    else {
      $this->arguments = $arguments;
    }
    if (empty($this->arguments['group_name'])) {
      $this->arguments['group_name'] = 'default';
    }
    $this->group = MigrateGroup::getInstance($this->arguments['group_name']);
  }
  if (isset($this->arguments['machine_name'])) {
    $this->machineName = $this->arguments['machine_name'];
  }
  else {

    // Deprecated - this supports old code which does not pass the arguments
    // array through to the base constructor. Remove in the next version.
    $this->machineName = $this
      ->machineFromClass(get_class($this));
  }

  // Make any group arguments directly accessible to the specific migration,
  // other than group dependencies.
  $group_arguments = $this->group
    ->getArguments();
  unset($group_arguments['dependencies']);
  $this->arguments += $group_arguments;

  // Record the memory limit in bytes
  $limit = trim(ini_get('memory_limit'));
  if ($limit == '-1') {
    $this->memoryLimit = PHP_INT_MAX;
  }
  else {
    if (!is_numeric($limit)) {
      $last = drupal_strtolower($limit[strlen($limit) - 1]);
      $limit = substr($limit, 0, -1);
      switch ($last) {
        case 'g':
          $limit *= 1024;
        case 'm':
          $limit *= 1024;
        case 'k':
          $limit *= 1024;
          break;
        default:
          throw new Exception(t('Invalid PHP memory_limit !limit', array(
            '!limit' => $limit,
          )));
      }
    }
    $this->memoryLimit = $limit;
  }

  // Record the time limit
  $this->timeLimit = ini_get('max_execution_time');

  // Make sure we clear our semaphores in case of abrupt exit
  drupal_register_shutdown_function(array(
    $this,
    'endProcess',
  ));

  // Save any hook disablement information.
  if (isset($this->arguments['disable_hooks']) && is_array($this->arguments['disable_hooks'])) {
    $this->disableHooks = $this->arguments['disable_hooks'];
  }
}