Files
FreshRSS/cli/db-restore.php
Alexandre Alapetite b1d24fbdb7 PHPStan 2.0 (#7131)
* PHPStan 2.0
fix https://github.com/FreshRSS/FreshRSS/issues/6989
https://github.com/phpstan/phpstan/releases/tag/2.0.0
https://github.com/phpstan/phpstan/blob/2.0.x/UPGRADING.md

* More

* More

* Done

* fix i18n CLI

* Restore a PHPStan Next test
For work towards PHPStan Level 10

* 4 more on Level 10

* fix getTagsForEntry

* API at Level 10

* More Level 10

* Finish Minz at Level 10

* Finish CLI at Level 10

* Finish Controllers at Level 10

* More Level 10

* More

* Pass bleedingEdge

* Clean PHPStan options and add TODOs

* Level 10 for main config

* More

* Consitency array vs. list

* Sanitize themes get_infos

* Simplify TagDAO->getTagsForEntries()

* Finish reportAnyTypeWideningInVarTag

* Prepare checkBenevolentUnionTypes and checkImplicitMixed

* Fixes

* Refix

* Another fix

* Casing of __METHOD__ constant
2024-12-27 12:12:49 +01:00

66 lines
1.9 KiB
PHP
Executable File

#!/usr/bin/env php
<?php
declare(strict_types=1);
require(__DIR__ . '/_cli.php');
performRequirementCheck(FreshRSS_Context::systemConf()->db['type'] ?? '');
$cliOptions = new class extends CliOptionsParser {
public string $deleteBackup;
public string $forceOverwrite;
public function __construct() {
$this->addOption('deleteBackup', (new CliOption('delete-backup'))->withValueNone());
$this->addOption('forceOverwrite', (new CliOption('force-overwrite'))->withValueNone());
parent::__construct();
}
};
if (!empty($cliOptions->errors)) {
fail('FreshRSS error: ' . array_shift($cliOptions->errors) . "\n" . $cliOptions->usage);
}
FreshRSS_Context::initSystem(true);
Minz_User::change(Minz_User::INTERNAL_USER);
$ok = false;
try {
$error = initDb();
if ($error != '') {
$_SESSION['bd_error'] = $error;
} else {
$ok = true;
}
} catch (Exception $ex) {
$_SESSION['bd_error'] = $ex->getMessage();
}
if (!$ok) {
fail('FreshRSS database error: ' . (is_string($_SESSION['bd_error'] ?? null) ? $_SESSION['bd_error'] : 'Unknown error'));
}
foreach (listUsers() as $username) {
$username = cliInitUser($username);
$filename = DATA_PATH . "/users/{$username}/backup.sqlite";
if (!file_exists($filename)) {
fwrite(STDERR, "FreshRSS SQLite backup not found for user “{$username}”!\n");
$ok = false;
continue;
}
echo 'FreshRSS restore database from SQLite for user “', $username, "”…\n";
$databaseDAO = FreshRSS_Factory::createDatabaseDAO($username);
$clearFirst = isset($cliOptions->forceOverwrite);
$ok &= $databaseDAO->dbCopy($filename, FreshRSS_DatabaseDAO::SQLITE_IMPORT, $clearFirst);
if ($ok) {
if (isset($cliOptions->deleteBackup)) {
unlink($filename);
}
} else {
fwrite(STDERR, "FreshRSS database already exists for user “{$username}”!\n");
fwrite(STDERR, "If you would like to clear the user database first, use the option --force-overwrite\n");
}
invalidateHttpCache($username);
}
done((bool)$ok);