Skip to content

Commit 65563be

Browse files
committed
Add a selfoss CLI tool
This introduces two commands for dumping and loading the database contents: - `php bin/selfoss db:export path.json` - `php bin/selfoss db:import path.json` Those are useful for testing, as well as for moving data from one database backend to another. Different databases support different formats of a datetime so we use ISO 8601 (“ATOM”) format as a normal form in the JSON file no matter the backend. Similarly, we use arrays instead of comma-separated-values strings since different backends might choose to implement them differently (e.g. using JSON data types).
1 parent 3aa24a7 commit 65563be

17 files changed

+1549
-1184
lines changed

.php-cs-fixer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
->exclude('client')
55
->exclude('utils')
66
->in(__DIR__)
7-
->name('*.phtml');
7+
->name('*.phtml')
8+
->name('selfoss');
89

910
$rules = [
1011
'@Symfony' => true,

bin/selfoss

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
// SPDX-FileCopyrightText: 2023 Jan Tojnar <[email protected]>
5+
// SPDX-License-Identifier: GPL-3.0-or-later
6+
7+
require __DIR__ . '/../src/common.php';
8+
9+
use Commands\Database\ExportCommand as DatabaseExportCommand;
10+
use Commands\Database\ImportCommand as DatabaseImportCommand;
11+
use Monolog\Handler\StreamHandler;
12+
use Symfony\Component\Console\Application;
13+
14+
$application = new Application();
15+
16+
$log->popHandler();
17+
$handler = new StreamHandler('php://stderr');
18+
$log->pushHandler($handler);
19+
20+
$application->add($dice->create(DatabaseExportCommand::class));
21+
$application->add($dice->create(DatabaseImportCommand::class));
22+
23+
$application->run();

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"simplepie/simplepie": "^1.8",
2424
"smottt/wideimage": "^1.1",
2525
"symfony/cache": "^5.4",
26+
"symfony/console": "^5.4",
2627
"symfony/polyfill-php80": "^1.26",
2728
"violet/streaming-json-encoder": "^1.1",
2829
"vstelmakh/url-highlight": "^3.0",
@@ -43,6 +44,7 @@
4344
],
4445
"autoload": {
4546
"psr-4": {
47+
"Commands\\": "src/Commands/",
4648
"controllers\\": "src/controllers/",
4749
"daos\\": "src/daos/",
4850
"helpers\\": "src/helpers/",

0 commit comments

Comments
 (0)