szurubooru/src/Upgrades/Upgrade09.php
Marcin Kurczewski 632bac8661 Added "use ..." statements
This version ditches backwards compatibility with PHP earlier than 5.6.
2014-10-18 18:48:36 +02:00

44 lines
1 KiB
PHP

<?php
namespace Szurubooru\Upgrades;
use Szurubooru\Dao\PostDao;
use Szurubooru\DatabaseConnection;
use Szurubooru\Services\HistoryService;
class Upgrade09 implements IUpgrade
{
private $postDao;
private $historyService;
public function __construct(
PostDao $postDao,
HistoryService $historyService)
{
$this->postDao = $postDao;
$this->historyService = $historyService;
}
public function run(DatabaseConnection $databaseConnection)
{
$pdo = $databaseConnection->getPDO();
$driver = $databaseConnection->getDriver();
$pdo->exec('DROP TABLE IF EXISTS snapshots');
$pdo->exec('CREATE TABLE snapshots
(
id INTEGER PRIMARY KEY ' . ($driver === 'mysql' ? 'AUTO_INCREMENT' : 'AUTOINCREMENT') . ',
time DATETIME NOT NULL,
type INTEGER NOT NULL,
primaryKey TEXT NOT NULL,
operation INTEGER NOT NULL,
userId INTEGER,
data BLOB,
dataDifference BLOB
)');
foreach ($this->postDao->findAll() as $post)
{
$this->historyService->saveSnapshot($this->historyService->getPostChangeSnapshot($post));
}
}
}