Skip to content

Commit 559a152

Browse files
committed
Add a selfossctl CLI tool
This replaces the `cliupdate.php` script with a `symfony/console` based entry point: php bin/selfossctl update In the future we are going to introduce more commands. We are creating `LazyCommand`s manually because `Symfony\Component\Console\CommandLoader\ContainerCommandLoader` does not support lazy loading of commands. That appears to only be supported through Symfony’s DI container: https://symfony.com/blog/new-in-symfony-5-3-lazy-command-description Specifically, regular commands are getting turned to lazy ones in `Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass`. The individual commands cannot be more lazy so `selfossctl help update` will still connect to database.
1 parent ad588fd commit 559a152

File tree

11 files changed

+773
-703
lines changed

11 files changed

+773
-703
lines changed

.php-cs-fixer.php

+2-1
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('selfossctl');
89

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

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
- Source filters are stricter, they need to start and end with a `/`. ([#1423](https://github.com/fossar/selfoss/pull/1423))
4242
- OPML importer has been merged into the React client. ([#1442](https://github.com/fossar/selfoss/pull/1442))
4343
- Web requests will send `Accept-Encoding` header. ([#1482](https://github.com/fossar/selfoss/pull/1482))
44+
- **`cliupdate.php` program has been replaced with `bin/selfossctl update`**. Do not forget to update cron scripts. ([#1440](https://github.com/fossar/selfoss/pull/1440))
4445

4546
## 2.19 – 2022-10-12
4647
**This version requires PHP ~~5.6~~ 7.2 (see known regressions section) or newer. It is also the last version to support PHP 7.**

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ For more information visit our [web site](https://selfoss.aditu.de).
1717
2. Make the directories `data/cache`, `data/favicons`, `data/logs`, `data/thumbnails` and `data/sqlite` writeable.
1818
3. Insert database access data in `config.ini` (see below). You do not need to change anything if you want to use SQLite.
1919
4. You do not need to create the database tables, they will be created automatically (ensure that your database user is allowed to create triggers).
20-
5. Create cronjob or systemd timer for updating feeds and point it to https://yourselfossurl.com/update via wget or curl. You can also execute the `cliupdate.php` from command line.
20+
5. Create cronjob or systemd timer for updating feeds and point it to https://yourselfossurl.com/update via wget or curl. You can also execute `bin/selfossctl update` from command line.
2121

2222
If you obtained selfoss using Git, some more steps will be required. See the [development](#development) section.
2323

bin/selfossctl

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
declare(strict_types=1);
5+
6+
// SPDX-FileCopyrightText: 2023 Jan Tojnar <[email protected]>
7+
// SPDX-License-Identifier: GPL-3.0-or-later
8+
9+
use Commands\UpdateCommand;
10+
use Psr\Container\ContainerInterface;
11+
use Symfony\Component\Console\Application;
12+
use Symfony\Component\Console\Command\LazyCommand;
13+
14+
require __DIR__ . '/../src/common.php';
15+
16+
/** @var ContainerInterface $container */
17+
$commands = [
18+
UpdateCommand::class,
19+
];
20+
21+
$application = new Application();
22+
23+
// We cannot use ContainerCommandLoader because it does not support lazy loading.
24+
foreach ($commands as $command) {
25+
$name = $command::$defaultName;
26+
$description = $command::$defaultDescription;
27+
28+
$lazyCommand = new LazyCommand(
29+
/* name: */ $name,
30+
/* aliases: */ [],
31+
/* description: */ $description,
32+
/* isHidden: */ false,
33+
fn() => $container->get($command)
34+
);
35+
$application->add($lazyCommand);
36+
}
37+
38+
$application->run();

cliupdate.php

-23
This file was deleted.

composer.json

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"slince/di": "^3.2",
2525
"smottt/wideimage": "^1.1",
2626
"symfony/cache": "^5.4",
27+
"symfony/console": "^5.4",
2728
"symfony/polyfill-php80": "^1.26",
2829
"violet/streaming-json-encoder": "^1.1",
2930
"vstelmakh/url-highlight": "^3.0",
@@ -44,13 +45,17 @@
4445
],
4546
"autoload": {
4647
"psr-4": {
48+
"Commands\\": "src/Commands/",
4749
"controllers\\": "src/controllers/",
4850
"daos\\": "src/daos/",
4951
"helpers\\": "src/helpers/",
5052
"spouts\\": "src/spouts/",
5153
"Tests\\": "tests/"
5254
}
5355
},
56+
"bin": [
57+
"bin/selfossctl"
58+
],
5459
"config": {
5560
"platform": {
5661
"php": "7.4.0"

0 commit comments

Comments
 (0)