2021-10-05 10:30:52 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace OCA\GPodderSync\Migration;
|
|
|
|
|
|
|
|
use OCP\IDBConnection;
|
|
|
|
use OCP\Migration\IOutput;
|
2024-09-23 15:19:34 +00:00
|
|
|
use DateTime;
|
2021-10-05 10:30:52 +00:00
|
|
|
|
|
|
|
class TimestampMigration implements \OCP\Migration\IRepairStep
|
|
|
|
{
|
2024-09-23 15:19:34 +00:00
|
|
|
private IDBConnection $db;
|
2021-10-05 10:30:52 +00:00
|
|
|
|
2024-09-23 15:19:34 +00:00
|
|
|
public function __construct(IDBConnection $db)
|
|
|
|
{
|
|
|
|
$this->db = $db;
|
|
|
|
}
|
2021-10-05 10:30:52 +00:00
|
|
|
|
2024-09-23 15:19:34 +00:00
|
|
|
/**
|
2021-10-05 10:30:52 +00:00
|
|
|
* @inheritDoc
|
|
|
|
*/
|
2024-09-23 15:19:34 +00:00
|
|
|
public function getName(): string
|
2021-10-05 10:30:52 +00:00
|
|
|
{
|
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)
|
|
|
|
{
|
2024-09-23 15:19:34 +00:00
|
|
|
$queryTimestamps =
|
|
|
|
"SELECT id, timestamp FROM `*PREFIX*gpodder_episode_action` WHERE timestamp_epoch = 0";
|
|
|
|
$timestamps = $this->db->executeQuery($queryTimestamps)->fetchAll();
|
|
|
|
|
|
|
|
$result = 0;
|
|
|
|
|
|
|
|
foreach ($timestamps as $timestamp) {
|
|
|
|
$timestampEpoch = (new DateTime($timestamp["timestamp"]))->format(
|
|
|
|
"U"
|
|
|
|
);
|
|
|
|
$sql =
|
|
|
|
"UPDATE `*PREFIX*gpodder_episode_action` " .
|
|
|
|
"SET `timestamp_epoch` = " .
|
|
|
|
$timestampEpoch .
|
|
|
|
" " .
|
|
|
|
"WHERE `id` = " .
|
|
|
|
$timestamp["id"];
|
|
|
|
|
|
|
|
$result += $this->db->executeUpdate($sql);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
2021-10-05 10:30:52 +00:00
|
|
|
}
|
|
|
|
}
|