Remove usage of safe-library for compability

This commit is contained in:
JonOfUs 2024-09-23 17:19:34 +02:00 committed by Jonathan Flueren
parent df17366e0f
commit e8611c6e99

View File

@ -5,21 +5,21 @@ namespace OCA\GPodderSync\Migration;
use OCP\IDBConnection;
use OCP\Migration\IOutput;
use Safe\DateTime;
use DateTime;
class TimestampMigration implements \OCP\Migration\IRepairStep
{
private IDBConnection $db;
private IDBConnection $db;
public function __construct(IDBConnection $db)
{
$this->db = $db;
}
public function __construct(IDBConnection $db)
{
$this->db = $db;
}
/**
/**
* @inheritDoc
*/
public function getName() : string
public function getName(): string
{
return "Migrate timestamp values to integer to store unix epoch";
}
@ -29,22 +29,27 @@ class TimestampMigration implements \OCP\Migration\IRepairStep
*/
public function run(IOutput $output)
{
$queryTimestamps = 'SELECT id, timestamp FROM `*PREFIX*gpodder_episode_action` WHERE timestamp_epoch = 0';
$timestamps = $this->db->executeQuery($queryTimestamps)->fetchAll();
$queryTimestamps =
"SELECT id, timestamp FROM `*PREFIX*gpodder_episode_action` WHERE timestamp_epoch = 0";
$timestamps = $this->db->executeQuery($queryTimestamps)->fetchAll();
$result = 0;
$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"];
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);
$result += $this->db->executeUpdate($sql);
}
}
return $result;
return $result;
}
}