Skip to content

Commit

Permalink
Merge pull request #31 from jordandukart/dev_imt_70
Browse files Browse the repository at this point in the history
Add sleep and wakeup to avoid some serialization pitfalls.
  • Loading branch information
nchiasson-dgi authored Sep 9, 2021
2 parents d39a70f + 0681b77 commit b568f81
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion src/MigrateBatchExecutable.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
*/
class MigrateBatchExecutable extends MigrateExecutable {

use DependencySerializationTrait;
use DependencySerializationTrait {
__sleep as traitSleep;
__wakeup as traitWakeup;
}

// The name of our timer.
const TIMER = 'dgi_migrate_iteration_timer';
Expand Down Expand Up @@ -69,6 +72,38 @@ public function __construct(MigrationInterface $migration, MigrateMessageInterfa
}
}

/**
* {@inheritdoc}
*/
public function __sleep() {
$vars = $this->traitSleep();
$to_suppress = [
// XXX: Avoid serializing some things can't be natively serialized.
'source',
];
foreach ($to_suppress as $value) {
$key = array_search($value, $vars);
if ($key !== FALSE) {
unset($vars[$key]);
}
}
// XXX: This unsets the protected sourcePlugin variable to avoid having
// it be serialized to the DB.
$this->migration->set('source', $this->migration->getSourceConfiguration());
return $vars;
}

/**
* {@inheritdoc}
*/
public function __wakeup() {
$this->traitWakeup();
// XXX: Re-add the listeners because the services get re-initialized.
foreach ($this->listeners as $event => $listener) {
$this->getEventDispatcher()->addListener($event, $listener);
}
}

/**
* Prepare a batch array for execution for the given migration.
*
Expand Down

0 comments on commit b568f81

Please sign in to comment.