2021-10-05 12:30:52 +02: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 14:53:13 +02:00
|
|
|
public function __construct(IDBConnection $db)
|
2021-10-05 12:30:52 +02:00
|
|
|
{
|
|
|
|
$this->db = $db;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritDoc
|
|
|
|
*/
|
|
|
|
public function getName() : string
|
|
|
|
{
|
2021-10-06 17:09:52 +02:00
|
|
|
return "Migrate timestamp values to integer to store unix epoch";
|
2021-10-05 12:30:52 +02: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 16:39:51 +02:00
|
|
|
$result = 0;
|
2021-10-13 16:16:23 +02:00
|
|
|
|
2021-10-05 12:30:52 +02:00
|
|
|
foreach ($timestamps as $timestamp) {
|
|
|
|
$timestampEpoch = (new DateTime($timestamp["timestamp"]))->format("U");
|
|
|
|
$sql = 'UPDATE `*PREFIX*gpodder_episode_action` '
|
2021-10-06 17:04:21 +02:00
|
|
|
. 'SET `timestamp_epoch` = ' . $timestampEpoch . ' '
|
2021-10-13 16:16:23 +02:00
|
|
|
. 'WHERE `id` = ' . $timestamp["id"];
|
2021-10-05 12:30:52 +02:00
|
|
|
|
2021-10-13 16:39:51 +02:00
|
|
|
$result += $this->db->executeUpdate($sql);
|
2021-10-05 12:30:52 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|