Skip to content

Commit d6ad606

Browse files
authored
Handle old format state files
There was an intermediate serialisation format that may be saved in some instances. Detect and handle.
1 parent 04c1e4c commit d6ad606

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/StateMachine/AEventProcessor.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Evenement\EventEmitterTrait;
1818
use Exception;
1919
use RuntimeException;
20+
use function array_key_exists;
2021
use function count;
2122
use function in_array;
2223
use function array_key_first;
@@ -423,6 +424,12 @@ public function unserialize($data)
423424
* @throws Exception
424425
*/
425426
public function __unserialize(array $data) {
427+
//Detect old serialisation format
428+
if (count($data) === 1 && array_key_exists('data', $data)) {
429+
$this->unserialize($data['data']);
430+
return;
431+
}
432+
426433
$this->unresolved_events = $data['events'];
427434

428435
$this->instanceId = $data['instanceId'] ?? $this->generateInstanceId(); //Generate a new ID if we don't have one serialized
@@ -442,4 +449,4 @@ public function resolveEvents($events)
442449
$this->consumedEvents = array_map(function($event_id) use ($events) { return $events[$event_id]; } , $this->unresolved_events);
443450
unset($this->unresolved_events);
444451
}
445-
}
452+
}

0 commit comments

Comments
 (0)