Changed snapshot to JSONs

This commit is contained in:
Marcin Kurczewski 2014-11-09 16:01:02 +01:00
parent ad8b235bb8
commit 178b17897c
3 changed files with 29 additions and 4 deletions

View file

@ -14,8 +14,8 @@ class SnapshotEntityConverter extends AbstractEntityConverter implements IEntity
'primaryKey' => $entity->getPrimaryKey(), 'primaryKey' => $entity->getPrimaryKey(),
'userId' => $entity->getUserId(), 'userId' => $entity->getUserId(),
'operation' => $entity->getOperation(), 'operation' => $entity->getOperation(),
'data' => serialize($entity->getData()), 'data' => json_encode($entity->getData()),
'dataDifference' => serialize($entity->getDataDifference()), 'dataDifference' => json_encode($entity->getDataDifference()),
]; ];
} }
@ -27,8 +27,8 @@ class SnapshotEntityConverter extends AbstractEntityConverter implements IEntity
$entity->setPrimaryKey($array['primaryKey']); $entity->setPrimaryKey($array['primaryKey']);
$entity->setUserId($array['userId']); $entity->setUserId($array['userId']);
$entity->setOperation($array['operation']); $entity->setOperation($array['operation']);
$entity->setData(unserialize($array['data'])); $entity->setData(json_decode($array['data'], true));
$entity->setDataDifference(unserialize($array['dataDifference'])); $entity->setDataDifference(json_decode($array['dataDifference'], true));
return $entity; return $entity;
} }
} }

View file

@ -0,0 +1,24 @@
<?php
namespace Szurubooru\Upgrades;
use Szurubooru\DatabaseConnection;
class Upgrade31 implements IUpgrade
{
public function run(DatabaseConnection $databaseConnection)
{
$pdo = $databaseConnection->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();
}
}
}

View file

@ -47,6 +47,7 @@ return [
$container->get(\Szurubooru\Upgrades\Upgrade28::class), $container->get(\Szurubooru\Upgrades\Upgrade28::class),
$container->get(\Szurubooru\Upgrades\Upgrade29::class), $container->get(\Szurubooru\Upgrades\Upgrade29::class),
$container->get(\Szurubooru\Upgrades\Upgrade30::class), $container->get(\Szurubooru\Upgrades\Upgrade30::class),
$container->get(\Szurubooru\Upgrades\Upgrade31::class),
]; ];
}), }),