2021-10-05 10:30:52 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace OCA\GPodderSync\Migration;
|
|
|
|
|
|
|
|
use OCP\IDBConnection;
|
|
|
|
use OCP\Migration\IOutput;
|
|
|
|
use Safe\DateTime;
|
|
|
|
|
|
|
|
class TimestampMigration implements \OCP\Migration\IRepairStep
|
|
|
|
{
|
|
|
|
private IDBConnection $db;
|
|
|
|
|
2021-10-06 12:53:13 +00:00
|
|
|
public function __construct(IDBConnection $db)
|
2021-10-05 10:30:52 +00:00
|
|
|
{
|
|
|
|
$this->db = $db;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getName() : string
|
|
|
|
{
|
2021-10-06 15:09:52 +00:00
|
|
|
return "Migrate timestamp values to integer to store unix epoch";
|
2021-10-05 10:30:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function run(IOutput $output)
|
|
|
|
{
|
|
|
|
$queryTimestamps = 'SELECT id, timestamp FROM `*PREFIX*gpodder_episode_action` WHERE timestamp_epoch = 0';
|
|
|
|
$timestamps = $this->db->executeQuery($queryTimestamps)->fetchAll();
|
|
|
|
|
2021-10-13 14:39:51 +00:00
|
|
|
$result = 0;
|
2021-10-13 14:16:23 +00:00
|
|
|
|
2021-10-05 10:30:52 +00:00
|
|
|
foreach ($timestamps as $timestamp) {
|
|
|
|
$timestampEpoch = (new DateTime($timestamp["timestamp"]))->format("U");
|
|
|
|
$sql = 'UPDATE `*PREFIX*gpodder_episode_action` '
|
2021-10-06 15:04:21 +00:00
|
|
|
. 'SET `timestamp_epoch` = ' . $timestampEpoch . ' '
|
2021-10-13 14:16:23 +00:00
|
|
|
. 'WHERE `id` = ' . $timestamp["id"];
|
2021-10-05 10:30:52 +00:00
|
|
|
|
2021-10-13 14:39:51 +00:00
|
|
|
$result += $this->db->executeUpdate($sql);
|
2021-10-05 10:30:52 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|