<?php
declare(strict_types=1);
require __DIR__ . '/../lib/bootstrap.php';

if (PHP_SAPI !== 'cli') {
    http_response_code(404);
    exit;
}

$rows = db()->query("SELECT id, password FROM playlists WHERE password IS NOT NULL AND password <> '' AND password NOT LIKE 'enc:v1:%'")->fetchAll();
$stmt = db()->prepare('UPDATE playlists SET password = ? WHERE id = ?');
foreach ($rows as $row) {
    $stmt->execute([encrypt_secret($row['password']), (int) $row['id']]);
}
echo 'Encrypted ' . count($rows) . " playlist secrets.\n";
