From 178b17897ceffb1061b8a45a69f4e022251d8668 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Sun, 9 Nov 2014 16:01:02 +0100 Subject: [PATCH] Changed snapshot to JSONs --- .../SnapshotEntityConverter.php | 8 +++---- src/Upgrades/Upgrade31.php | 24 +++++++++++++++++++ src/di.php | 1 + 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 src/Upgrades/Upgrade31.php diff --git a/src/Dao/EntityConverters/SnapshotEntityConverter.php b/src/Dao/EntityConverters/SnapshotEntityConverter.php index 970e86d7..e5a8378d 100644 --- a/src/Dao/EntityConverters/SnapshotEntityConverter.php +++ b/src/Dao/EntityConverters/SnapshotEntityConverter.php @@ -14,8 +14,8 @@ class SnapshotEntityConverter extends AbstractEntityConverter implements IEntity 'primaryKey' => $entity->getPrimaryKey(), 'userId' => $entity->getUserId(), 'operation' => $entity->getOperation(), - 'data' => serialize($entity->getData()), - 'dataDifference' => serialize($entity->getDataDifference()), + 'data' => json_encode($entity->getData()), + 'dataDifference' => json_encode($entity->getDataDifference()), ]; } @@ -27,8 +27,8 @@ class SnapshotEntityConverter extends AbstractEntityConverter implements IEntity $entity->setPrimaryKey($array['primaryKey']); $entity->setUserId($array['userId']); $entity->setOperation($array['operation']); - $entity->setData(unserialize($array['data'])); - $entity->setDataDifference(unserialize($array['dataDifference'])); + $entity->setData(json_decode($array['data'], true)); + $entity->setDataDifference(json_decode($array['dataDifference'], true)); return $entity; } } diff --git a/src/Upgrades/Upgrade31.php b/src/Upgrades/Upgrade31.php new file mode 100644 index 00000000..a909db94 --- /dev/null +++ b/src/Upgrades/Upgrade31.php @@ -0,0 +1,24 @@ +getPDO(); + + foreach (array_chunk(iterator_to_array($pdo->from('snapshots')), 100) as $chunk) + { + $pdo->beginTransaction(); + foreach ($chunk as $array) + { + $pdo->update('snapshots')->set([ + 'data' => json_encode(unserialize($array['data'])), + 'dataDifference' => json_encode(unserialize($array['dataDifference'])) + ])->where('id', $array['id'])->execute(); + } + $pdo->commit(); + } + } +} diff --git a/src/di.php b/src/di.php index cff5a317..c9b90ac1 100644 --- a/src/di.php +++ b/src/di.php @@ -47,6 +47,7 @@ return [ $container->get(\Szurubooru\Upgrades\Upgrade28::class), $container->get(\Szurubooru\Upgrades\Upgrade29::class), $container->get(\Szurubooru\Upgrades\Upgrade30::class), + $container->get(\Szurubooru\Upgrades\Upgrade31::class), ]; }),