mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 13:12:41 +00:00
More changes in anticipation of a release
- Added a 'user add' function to the CLI - Removed the last trace of paths from configuration; paths must default to null and Arsse must determine sensible defaults at runtime
This commit is contained in:
parent
5f66f3c8de
commit
f5efa39839
3 changed files with 37 additions and 10 deletions
39
lib/CLI.php
39
lib/CLI.php
|
@ -12,12 +12,13 @@ Usage:
|
|||
$prog daemon
|
||||
$prog feed refresh <n>
|
||||
$prog conf save-defaults <file>
|
||||
$prog user add <username> [<password>]
|
||||
$prog --version
|
||||
$prog --help | -h
|
||||
|
||||
The Arsse command-line interface currently allows you to start the refresh
|
||||
daemon, refresh a specific feed by numeric ID, or save default configuration
|
||||
to a sample file.
|
||||
daemon, refresh a specific feed by numeric ID, add a user, or save default
|
||||
configuration to a sample file.
|
||||
USAGE_TEXT;
|
||||
}
|
||||
|
||||
|
@ -38,6 +39,8 @@ USAGE_TEXT;
|
|||
if(file_exists(BASE."config.php")) {
|
||||
Arsse::$conf->importFile(BASE."config.php");
|
||||
}
|
||||
// command-line operations will never respect authorization
|
||||
Arsse::$user->authorizationEnabled(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -46,27 +49,47 @@ USAGE_TEXT;
|
|||
if(is_null($args)) {
|
||||
$args = $this->args;
|
||||
}
|
||||
if($args['daemon']) {
|
||||
if($this->command("daemon", $args)) {
|
||||
$this->loadConf();
|
||||
return $this->daemon();
|
||||
} else if($args['feed'] && $args['refresh']) {
|
||||
} else if($this->command("feed refresh", $args)) {
|
||||
$this->loadConf();
|
||||
return $this->feedRefresh((int) $args['<n>']);
|
||||
} else if($args['conf'] && $args['save-defaults']) {
|
||||
} else if($this->command("conf save-defaults", $args)) {
|
||||
return $this->confSaveDefaults($args['<file>']);
|
||||
} else if($this->command("user add", $args)) {
|
||||
$this->loadConf();
|
||||
return $this->userAdd($args['<username>'], $args['<password>']);
|
||||
}
|
||||
}
|
||||
|
||||
protected function daemon(bool $loop = true): int {
|
||||
protected function command($cmd, $args): bool {
|
||||
foreach(explode(" ", $cmd) as $part) {
|
||||
if(!$args[$part]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function daemon(bool $loop = true): int {
|
||||
(new Service)->watch($loop);
|
||||
return 0; // FIXME: should return the exception code of thrown exceptions
|
||||
}
|
||||
|
||||
protected function feedRefresh(int $id): int {
|
||||
function feedRefresh(int $id): int {
|
||||
return (int) !Arsse::$db->feedUpdate($id); // FIXME: exception error codes should be returned here
|
||||
}
|
||||
|
||||
protected function confSaveDefaults($file): int {
|
||||
function confSaveDefaults(string $file): int {
|
||||
return (int) !(new Conf)->exportFile($file, true);
|
||||
}
|
||||
|
||||
function userAdd(string $user, string $password = null): int {
|
||||
$passwd = Arsse::$user->add($user, $password);
|
||||
if(is_null($password)) {
|
||||
echo $passwd;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -15,8 +15,8 @@ class Conf {
|
|||
public $dbDriver = Db\SQLite3\Driver::class;
|
||||
/** @var boolean Whether to attempt to automatically update the database when updated to a new version with schema changes */
|
||||
public $dbAutoUpdate = true;
|
||||
/** @var string Full path and file name of SQLite database (if using SQLite) */
|
||||
public $dbSQLite3File = BASE."arsse.db";
|
||||
/** @var string|null Full path and file name of SQLite database (if using SQLite) */
|
||||
public $dbSQLite3File = null;
|
||||
/** @var string Encryption key to use for SQLite database (if using a version of SQLite with SEE) */
|
||||
public $dbSQLite3Key = "";
|
||||
/** @var integer Number of seconds for SQLite to wait before returning a timeout error when writing to the database */
|
||||
|
|
|
@ -22,6 +22,10 @@ class Driver extends \JKingWeb\Arsse\Db\AbstractDriver {
|
|||
throw new Exception("extMissing", self::driverName()); // @codeCoverageIgnore
|
||||
}
|
||||
$dbFile = Arsse::$conf->dbSQLite3File;
|
||||
if(is_null($dbFile)) {
|
||||
// if no database file is specified in the configuration, use a suitable default
|
||||
$dbFile = \JKingWeb\Arsse\BASE."arsse.db";
|
||||
}
|
||||
$mode = \SQLITE3_OPEN_READWRITE | \SQLITE3_OPEN_CREATE;
|
||||
$timeout = Arsse::$conf->dbSQLite3Timeout * 1000;
|
||||
try {
|
||||
|
|
Loading…
Reference in a new issue