Skip to content

Commit

Permalink
Add a selfossctl CLI tool
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jtojnar committed Jul 9, 2024
1 parent ad588fd commit 559a152
Show file tree
Hide file tree
Showing 11 changed files with 773 additions and 703 deletions.
3 changes: 2 additions & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
->exclude('client')
->exclude('utils')
->in(__DIR__)
->name('*.phtml');
->name('*.phtml')
->name('selfossctl');

$rules = [
'@Symfony' => true,
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
- Source filters are stricter, they need to start and end with a `/`. ([#1423](https://github.com/fossar/selfoss/pull/1423))
- OPML importer has been merged into the React client. ([#1442](https://github.com/fossar/selfoss/pull/1442))
- Web requests will send `Accept-Encoding` header. ([#1482](https://github.com/fossar/selfoss/pull/1482))
- **`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))

## 2.19 – 2022-10-12
**This version requires PHP ~~5.6~~ 7.2 (see known regressions section) or newer. It is also the last version to support PHP 7.**
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ For more information visit our [web site](https://selfoss.aditu.de).
2. Make the directories `data/cache`, `data/favicons`, `data/logs`, `data/thumbnails` and `data/sqlite` writeable.
3. Insert database access data in `config.ini` (see below). You do not need to change anything if you want to use SQLite.
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).
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.
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.

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

Expand Down
38 changes: 38 additions & 0 deletions bin/selfossctl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env php
<?php

declare(strict_types=1);

// SPDX-FileCopyrightText: 2023 Jan Tojnar <[email protected]>
// SPDX-License-Identifier: GPL-3.0-or-later

use Commands\UpdateCommand;
use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\LazyCommand;

require __DIR__ . '/../src/common.php';

/** @var ContainerInterface $container */
$commands = [
UpdateCommand::class,
];

$application = new Application();

// We cannot use ContainerCommandLoader because it does not support lazy loading.
foreach ($commands as $command) {
$name = $command::$defaultName;
$description = $command::$defaultDescription;

$lazyCommand = new LazyCommand(
/* name: */ $name,
/* aliases: */ [],
/* description: */ $description,
/* isHidden: */ false,
fn() => $container->get($command)
);
$application->add($lazyCommand);
}

$application->run();
23 changes: 0 additions & 23 deletions cliupdate.php

This file was deleted.

5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"slince/di": "^3.2",
"smottt/wideimage": "^1.1",
"symfony/cache": "^5.4",
"symfony/console": "^5.4",
"symfony/polyfill-php80": "^1.26",
"violet/streaming-json-encoder": "^1.1",
"vstelmakh/url-highlight": "^3.0",
Expand All @@ -44,13 +45,17 @@
],
"autoload": {
"psr-4": {
"Commands\\": "src/Commands/",
"controllers\\": "src/controllers/",
"daos\\": "src/daos/",
"helpers\\": "src/helpers/",
"spouts\\": "src/spouts/",
"Tests\\": "tests/"
}
},
"bin": [
"bin/selfossctl"
],
"config": {
"platform": {
"php": "7.4.0"
Expand Down
Loading

0 comments on commit 559a152

Please sign in to comment.