You are here

public function MigrateSourceOracle::performRewind in Migrate 6.2

Same name and namespace in other branches
  1. 7.2 plugins/sources/oracle.inc \MigrateSourceOracle::performRewind()

Implementation of MigrateSource::performRewind().

File

plugins/sources/oracle.inc, line 153
Define a MigrateSource class for importing from Oracle databases.

Class

MigrateSourceOracle
Implementation of MigrateSource, to handle imports from remote Oracle servers.

Code

public function performRewind() {
  $keys = array();
  foreach ($this->activeMap
    ->getSourceKey() as $field_name => $field_schema) {

    // Allow caller to provide an alias to table containing the primary key.
    if (!empty($field_schema['alias'])) {
      $field_name = $field_schema['alias'] . '.' . $field_name;
    }
    $keys[] = $field_name;
  }

  /*
   * Replace :criteria placeholder with idlist or highwater clauses. We
   * considered supporting both but it is not worth the complexity. Run twice
   * instead.
   */
  if (!empty($this->idList)) {

    // TODO: Sanitize. not critical as this is admin supplied data in drush.
    $this->query = str_replace(':criteria', $keys[0] . ' IN (' . implode(',', $this->idList) . ')', $this->query);
  }
  else {
    if (isset($this->highwaterField['name']) && ($highwater = $this->activeMigration
      ->getHighwater())) {
      if (empty($this->highwaterField['alias'])) {
        $highwater_name = $this->highwaterField['name'];
      }
      else {
        $highwater_name = $this->highwaterField['alias'] . '.' . $this->highwaterField['name'];
      }
      $this->query = str_replace(':criteria', "{$highwater_name} > '{$highwater}'", $this->query);
    }
    else {

      // No idlist or highwater. Replace :criteria placeholder with harmless WHERE
      // clause instead of empty since we don't know if an AND follows.
      $this->query = str_replace(':criteria', '1=1', $this->query);
    }
  }
  migrate_instrument_start('oracle_query');
  $this
    ->connect();
  $this->result = oci_parse($this->connection, $this->query);
  if (!$this->result) {
    $e = oci_error($this->connection);
    throw new Exception($e['message'] . "\n" . $e['sqltext']);
  }
  $status = oci_execute($this->result);
  if (!$status) {
    $e = oci_error($this->result);
    throw new Exception($e['message'] . "\n" . $e['sqltext']);
  }
  migrate_instrument_stop('oracle_query');
}