You are here

protected function MigrationBase::beginProcess in Migrate 6.2

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

Begin a process, ensuring only one process can be active at once on a given migration.

Parameters

int $newStatus: MigrationBase::STATUS_IMPORTING or MigrationBase::STATUS_ROLLING_BACK

3 calls to MigrationBase::beginProcess()
Migration::beginProcess in includes/migration.inc
Override MigrationBase::beginProcess, to make sure the map/message tables are present.
MigrationBase::processImport in includes/base.inc
Perform an operation during the import phase
MigrationBase::processRollback in includes/base.inc
Perform an operation during the rollback phase.
1 method overrides MigrationBase::beginProcess()
Migration::beginProcess in includes/migration.inc
Override MigrationBase::beginProcess, to make sure the map/message tables are present.

File

includes/base.inc, line 744
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

protected function beginProcess($newStatus) {

  // So hook_watchdog() knows what migration (if any) is running
  self::$currentMigration = $this;

  // Try to make the semaphore handling atomic (depends on DB support)
  $transaction = db_transaction();
  $this->starttime = microtime(TRUE);

  // Check to make sure there's no process already running for this migration
  $status = $this
    ->getStatus();
  if ($status != MigrationBase::STATUS_IDLE) {
    throw new MigrateException(t('There is already an active process on !machine_name', array(
      '!machine_name' => $this->machineName,
    )));
  }
  $this->processing = TRUE;
  $this->status = $newStatus;
  db_merge('migrate_status')
    ->key(array(
    'machine_name' => $this->machineName,
  ))
    ->fields(array(
    'class_name' => get_class($this),
    'status' => $newStatus,
  ))
    ->execute();

  // Set an error handler for imports
  if ($newStatus == MigrationBase::STATUS_IMPORTING) {
    $this->previousErrorHandler = set_error_handler(array(
      $this,
      'errorHandler',
    ));
  }

  // Save the initial history record
  if ($this->logHistory) {
    $this->logID = db_insert('migrate_log')
      ->fields(array(
      'machine_name' => $this->machineName,
      'process_type' => $newStatus,
      'starttime' => round(microtime(TRUE) * 1000),
      'initialHighwater' => $this
        ->getHighwater(),
    ))
      ->execute();
  }

  // And capture anything the DB tries to log to the watchdog
  // TODO: Broken by http://drupal.org/node/711108 - what to do?

  //Database::setLoggingCallback(array($this, 'loggingCallback'), WATCHDOG_NOTICE, WATCHDOG_ERROR);
}