Skip to content

Commit

Permalink
Update Migrate to 7.x-2.12
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Hunt committed Feb 11, 2023
1 parent 10b6b96 commit 4485d78
Show file tree
Hide file tree
Showing 22 changed files with 508 additions and 159 deletions.
16 changes: 14 additions & 2 deletions docroot/sites/all/modules/contrib/migrate/includes/base.inc
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ abstract class MigrationBase {
* An array that points to the active symbol table at the point the error
* occurred.
*/
public function errorHandler($error_level, $message, $filename, $line, $context) {
public function errorHandler($error_level, $message, $filename, $line, $context = array()) {
if ($error_level & error_reporting()) {
$message .= "\n" . t('File !file, line !line',
array('!line' => $line, '!file' => $filename));
Expand Down Expand Up @@ -806,10 +806,11 @@ abstract class MigrationBase {
->condition('machine_name', $this->machineName)
->isNotNull('endtime')
->orderBy('endtime', 'DESC')
->range(0, 1)
->execute()
->fetchField();
if ($last_imported) {
$last_imported = date('Y-m-d H:i:s', $last_imported / 1000);
$last_imported = date('Y-m-d H:i:s', (int) ($last_imported / 1000));
}
else {
$last_imported = '';
Expand Down Expand Up @@ -1050,6 +1051,17 @@ abstract class MigrationBase {
$this->processing = FALSE;
}
self::$currentMigration = NULL;

// If we're disabling any hooks, reset the static module_implements cache so
// it is rebuilt again and the specified hooks removed by our
// hook_module_implements_alter() is recollected. By setting #write_cache to
// FALSE, we ensure that our munged version of the hooks array does not get
// written to the persistent cache and interfere with other Drupal processes.
if (!empty($this->disableHooks)) {
$implementations = &drupal_static('module_implements');
$implementations = array();
$implementations['#write_cache'] = FALSE;
}
}

/**
Expand Down
100 changes: 76 additions & 24 deletions docroot/sites/all/modules/contrib/migrate/includes/migration.inc
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ abstract class Migration extends MigrationBase {
*/
protected $queuedMessages = array();

protected $subfieldDelimiter = ':';

/**
* General initialization of a Migration object.
*/
Expand Down Expand Up @@ -749,33 +751,17 @@ abstract class Migration extends MigrationBase {
$ids = $this->destination->import($this->destinationValues, $this->sourceValues);
migrate_instrument_stop('destination import');
if ($ids) {
$this->map->saveIDMapping($this->sourceValues, $ids,
$this->needsUpdate, $this->rollbackAction,
$data_row->migrate_map_hash);
$this->successes_since_feedback++;
$this->total_successes++;
$this->onSuccess($data_row, $ids);
}
else {
$this->map->saveIDMapping($this->sourceValues, array(),
MigrateMap::STATUS_FAILED, $this->rollbackAction,
NULL);
if ($this->map->messageCount() == 0) {
$message = t('New object was not saved, no error provided');
$this->saveMessage($message);
self::displayMessage($message);
}
$this->onEmptyDestination($data_row, $ids);
}
} catch (MigrateException $e) {
$this->map->saveIDMapping($this->sourceValues, array(),
$e->getStatus(), $this->rollbackAction, $data_row->migrate_map_hash);
$this->saveMessage($e->getMessage(), $e->getLevel());
self::displayMessage($e->getMessage());
$this->onMigrateException($e, $data_row);
} catch (Exception $e) {
$this->map->saveIDMapping($this->sourceValues, array(),
MigrateMap::STATUS_FAILED, $this->rollbackAction,
NULL);
$this->handleException($e);
$this->onException($e);
}

$this->total_processed++;
$this->processed_since_feedback++;
if ($this->highwaterField) {
Expand Down Expand Up @@ -821,6 +807,68 @@ abstract class Migration extends MigrationBase {
return $return;
}

/**
* React when the migration has been successful.
*
* @param object $data_row
* Data.
* @param array $ids
* Destination ids.
*/
protected function onSuccess($data_row, $ids) {
$this->map->saveIDMapping($this->sourceValues, $ids,
$this->needsUpdate, $this->rollbackAction,
$data_row->migrate_map_hash);
$this->successes_since_feedback++;
$this->total_successes++;
}

/**
* React when migration didn't failed but destination ids are empty.
*
* @param object $data_row
* Data.
* @param array $ids
* Destination ids.
*/
protected function onEmptyDestination($data_row, $ids) {
$this->map->saveIDMapping($this->sourceValues, array(),
MigrateMap::STATUS_FAILED, $this->rollbackAction,
NULL);
if ($this->map->messageCount() == 0) {
$message = t('New object was not saved, no error provided');
$this->saveMessage($message);
self::displayMessage($message);
}
}

/**
* React when there is a migrate exception
*
* @param \MigrateException $e
* Exception.
*
*/
protected function onMigrateException(\MigrateException $e, $data_row) {
$this->map->saveIDMapping($this->sourceValues, array(),
$e->getStatus(), $this->rollbackAction, $data_row->migrate_map_hash);
$this->saveMessage($e->getMessage(), $e->getLevel());
self::displayMessage($e->getMessage());
}

/**
* React when there is an exception
*
* @param \Exception $e
* Exception.
*/
protected function onException(\Exception $e) {
$this->map->saveIDMapping($this->sourceValues, array(),
MigrateMap::STATUS_FAILED, $this->rollbackAction,
NULL);
$this->handleException($e);
}

/**
* Perform an analysis operation - report on field values in the source.
*
Expand Down Expand Up @@ -1328,7 +1376,7 @@ abstract class Migration extends MigrationBase {

// Are we dealing with the primary value of the destination field, or a
// subfield?
$destination = explode(':', $destination);
$destination = explode($this->subfieldDelimiter, $destination);
// Count how many levels of fields are in the mapping. We'll use the
// last one.
$destination_count = count($destination);
Expand Down Expand Up @@ -1358,7 +1406,11 @@ abstract class Migration extends MigrationBase {
elseif (!is_array($this->destinationValues->{$destination_field})) {
$this->destinationValues->{$destination_field} = array($this->destinationValues->{$destination_field});
}
if (!is_array($this->destinationValues->{$destination_field}['arguments'][$destination[1]])) {
// Additional check for case when first subfield doesn't exist.
if (!isset($this->destinationValues->{$destination_field}['arguments'][$destination[1]])) {
$this->destinationValues->{$destination_field}['arguments'][$destination[1]] = array();
}
elseif (!is_array($this->destinationValues->{$destination_field}['arguments'][$destination[1]])) {
// Convert first subfield level to an array so we can add to it.
$this->destinationValues->{$destination_field}['arguments'][$destination[1]] = array($this->destinationValues->{$destination_field}['arguments'][$destination[1]]);
}
Expand Down Expand Up @@ -1449,7 +1501,7 @@ abstract class Migration extends MigrationBase {
}
}
// Occasionally $source_key comes through with an empty string.
$sanity_check = array_filter($source_key);
$sanity_check = array_filter($source_key, 'strlen');
if ($continue || empty($source_key) || empty($sanity_check)) {
continue;
}
Expand Down
5 changes: 5 additions & 0 deletions docroot/sites/all/modules/contrib/migrate/includes/source.inc
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ abstract class MigrateSource implements Iterator {
* Implementation of Iterator::current() - called when entering a loop
* iteration, returning the current row
*/
#[\ReturnTypeWillChange]
public function current() {
return $this->currentRow;
}
Expand All @@ -236,6 +237,7 @@ abstract class MigrateSource implements Iterator {
* serialize to fulfill the requirement, but using getCurrentKey() is
* preferable.
*/
#[\ReturnTypeWillChange]
public function key() {
return serialize($this->currentKey);
}
Expand All @@ -244,6 +246,7 @@ abstract class MigrateSource implements Iterator {
* Implementation of Iterator::valid() - called at the top of the loop,
* returning TRUE to process the loop and FALSE to terminate it
*/
#[\ReturnTypeWillChange]
public function valid() {
return !is_null($this->currentRow);
}
Expand All @@ -253,6 +256,7 @@ abstract class MigrateSource implements Iterator {
* implement performRewind() to do any class-specific setup for iterating
* source records.
*/
#[\ReturnTypeWillChange]
public function rewind() {
$this->activeMigration = Migration::currentMigration();
$this->activeMap = $this->activeMigration->getMap();
Expand All @@ -278,6 +282,7 @@ abstract class MigrateSource implements Iterator {
* Implementation of Iterator::next() - subclasses of MigrateSource should
* implement getNextRow() to retrieve the next valid source rocord to process.
*/
#[\ReturnTypeWillChange]
public function next() {
$this->currentKey = NULL;
$this->currentRow = NULL;
Expand Down
17 changes: 13 additions & 4 deletions docroot/sites/all/modules/contrib/migrate/migrate.drush.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,13 @@ function drush_migrate_import($args = NULL) {
}
if (drush_get_option('needs-update')) {
$map_rows = $migration->getMap()->getRowsNeedingUpdate(10000);

if (empty($map_rows)) {
drush_set_error(NULL, dt("Not found records to update for '!name' migration.",
array('!name' => get_class($migration))));
return;
}

$idlist = array();
foreach ($map_rows as $row) {
$idlist[] = $row->sourceid1;
Expand Down Expand Up @@ -1431,7 +1438,7 @@ function drush_migrate_deregister($args = NULL) {
$migrations = explode(',', $args);
}
foreach ($migrations as $machine_name) {
drush_migrate_deregister_migration(drupal_strtolower($machine_name));
drush_migrate_deregister_migration($machine_name);
drush_log(dt("Deregistered '!description' migration",
array('!description' => $machine_name)), 'success');
}
Expand All @@ -1445,13 +1452,15 @@ function drush_migrate_deregister($args = NULL) {
/**
* Given a migration machine name, remove its tracking from the database.
*
* @param $machine_name
* @param string $machine_name
* Migration machine name.
*/
function drush_migrate_deregister_migration($machine_name) {
$machine_name_lowered = drupal_strtolower($machine_name);
// The class is gone, so we'll manually clear migrate_status, and make
// the default assumptions about the map/message tables.
db_drop_table('migrate_map_' . $machine_name);
db_drop_table('migrate_message_' . $machine_name);
db_drop_table('migrate_map_' . $machine_name_lowered);
db_drop_table('migrate_message_' . $machine_name_lowered);
db_delete('migrate_status')
->condition('machine_name', $machine_name)
->execute();
Expand Down
8 changes: 4 additions & 4 deletions docroot/sites/all/modules/contrib/migrate/migrate.info
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ files[] = plugins/sources/mongodb.inc
files[] = plugins/sources/multiitems.inc
files[] = plugins/sources/sql.inc
files[] = plugins/sources/sqlmap.inc
files[] = plugins/sources/mssql.inc
files[] = plugins/sources/sqlsrv.inc
files[] = plugins/sources/oracle.inc
files[] = plugins/sources/spreadsheet.inc
files[] = plugins/sources/xml.inc
Expand All @@ -51,8 +51,8 @@ files[] = tests/plugins/destinations/term.test
files[] = tests/plugins/destinations/user.test
files[] = tests/plugins/sources/xml.test

; Information added by Drupal.org packaging script on 2018-06-10
version = "7.x-2.11"
; Information added by Drupal.org packaging script on 2023-01-15
version = "7.x-2.12"
core = "7.x"
project = "migrate"
datestamp = "1528674486"
datestamp = "1673814412"
37 changes: 30 additions & 7 deletions docroot/sites/all/modules/contrib/migrate/migrate.module
Original file line number Diff line number Diff line change
Expand Up @@ -191,17 +191,40 @@ function migrate_handler_invoke_all($destination, $method) {
* @param $method
* Handler method to call (defaults to prepare()).
*/
function migrate_field_handler_invoke_all($entity, array $field_info,
array $instance, array $values, $method = 'prepare') {
function migrate_field_handler_invoke_all($entity, array $field_info, array $instance, array $values, $method = 'prepare') {
static $types_handled = array();
static $methods_handled = array();
static $disabled = null;
$return = array();
$type = $field_info['type'];
$class_list = _migrate_class_list('MigrateFieldHandler');
$disabled = unserialize(variable_get('migrate_disabled_handlers',
serialize(array())));
static $class_list = null;
if (!$class_list) {
$class_list = _migrate_class_list('MigrateFieldHandler');
}
// No need to do this unserialize/variable_get/serialize so often,
// it never changes.
if(!is_array($disabled)){
$disabled = unserialize(variable_get('migrate_disabled_handlers',
serialize(array())));
}
// This function is called a lot. Rather than determine if the field type is
// handled once for every record, the value should be determined once per
// execution.
// The same can go for whether the handler/method pair exists
if(!isset($types_handled[$type])){
foreach($class_list as $class_name => $handler) {
$types_handled[$type][$class_name] = $handler->handlesType($type);
}
}
if(!isset($methods_handled[$method])){
foreach($class_list as $class_name => $handler) {
$methods_handled[$method][$class_name] = method_exists($handler, $method);
}
}

$handler_called = FALSE;
foreach ($class_list as $class_name => $handler) {
if (!in_array($class_name, $disabled) && $handler->handlesType($type)
&& method_exists($handler, $method)) {
if (!in_array($class_name, $disabled) && $types_handled[$type][$class_name] && $methods_handled[$method][$class_name]) {
migrate_instrument_start($class_name . '->' . $method);
$result = call_user_func_array(array($handler, $method),
array($entity, $field_info, $instance, $values));
Expand Down
Loading

0 comments on commit 4485d78

Please sign in to comment.