Skip to content

Commit 2d89214

Browse files
committed
Add a selfoss 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`.
1 parent 31ef53d commit 2d89214

File tree

11 files changed

+770
-702
lines changed

11 files changed

+770
-702
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
@@ -37,6 +37,7 @@
3737
- Back-end source code is now checked using [PHPStan](https://phpstan.org/). ([#1409](https://github.com/fossar/selfoss/pull/1409))
3838
- Content Extraction spout will no longer try to extract content we have already extracted. ([#1413](https://github.com/fossar/selfoss/pull/1413))
3939
- Source filters are stricter, they need to start and end with a `/`. ([#1423](https://github.com/fossar/selfoss/pull/1423))
40+
- **`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))
4041

4142
## 2.19 – 2022-10-12
4243
**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

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
use Commands\UpdateCommand;
8+
use Psr\Container\ContainerInterface;
9+
use Symfony\Component\Console\Application;
10+
use Symfony\Component\Console\Command\LazyCommand;
11+
12+
require __DIR__ . '/../src/common.php';
13+
14+
/** @var ContainerInterface $container */
15+
$commands = [
16+
UpdateCommand::class,
17+
];
18+
19+
$application = new Application();
20+
21+
// We cannot use ContainerCommandLoader because it does not support lazy loading.
22+
foreach ($commands as $command) {
23+
$name = $command::$defaultName;
24+
$description = $command::$defaultDescription;
25+
26+
$lazyCommand = new LazyCommand(
27+
/* name: */ $name,
28+
/* aliases: */ [],
29+
/* description: */ $description,
30+
/* isHidden: */ false,
31+
fn() => $container->get($command)
32+
);
33+
$application->add($lazyCommand);
34+
}
35+
36+
$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)