1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +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:
J. King 2017-08-28 19:38:58 -04:00
parent 5f66f3c8de
commit f5efa39839
3 changed files with 37 additions and 10 deletions

View file

@ -12,12 +12,13 @@ Usage:
$prog daemon $prog daemon
$prog feed refresh <n> $prog feed refresh <n>
$prog conf save-defaults <file> $prog conf save-defaults <file>
$prog user add <username> [<password>]
$prog --version $prog --version
$prog --help | -h $prog --help | -h
The Arsse command-line interface currently allows you to start the refresh The Arsse command-line interface currently allows you to start the refresh
daemon, refresh a specific feed by numeric ID, or save default configuration daemon, refresh a specific feed by numeric ID, add a user, or save default
to a sample file. configuration to a sample file.
USAGE_TEXT; USAGE_TEXT;
} }
@ -38,6 +39,8 @@ USAGE_TEXT;
if(file_exists(BASE."config.php")) { if(file_exists(BASE."config.php")) {
Arsse::$conf->importFile(BASE."config.php"); Arsse::$conf->importFile(BASE."config.php");
} }
// command-line operations will never respect authorization
Arsse::$user->authorizationEnabled(false);
return true; return true;
} }
@ -46,27 +49,47 @@ USAGE_TEXT;
if(is_null($args)) { if(is_null($args)) {
$args = $this->args; $args = $this->args;
} }
if($args['daemon']) { if($this->command("daemon", $args)) {
$this->loadConf(); $this->loadConf();
return $this->daemon(); return $this->daemon();
} else if($args['feed'] && $args['refresh']) { } else if($this->command("feed refresh", $args)) {
$this->loadConf(); $this->loadConf();
return $this->feedRefresh((int) $args['<n>']); 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>']); 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); (new Service)->watch($loop);
return 0; // FIXME: should return the exception code of thrown exceptions 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 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); 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;
}
} }

View file

@ -15,8 +15,8 @@ class Conf {
public $dbDriver = Db\SQLite3\Driver::class; 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 */ /** @var boolean Whether to attempt to automatically update the database when updated to a new version with schema changes */
public $dbAutoUpdate = true; public $dbAutoUpdate = true;
/** @var string Full path and file name of SQLite database (if using SQLite) */ /** @var string|null Full path and file name of SQLite database (if using SQLite) */
public $dbSQLite3File = BASE."arsse.db"; public $dbSQLite3File = null;
/** @var string Encryption key to use for SQLite database (if using a version of SQLite with SEE) */ /** @var string Encryption key to use for SQLite database (if using a version of SQLite with SEE) */
public $dbSQLite3Key = ""; public $dbSQLite3Key = "";
/** @var integer Number of seconds for SQLite to wait before returning a timeout error when writing to the database */ /** @var integer Number of seconds for SQLite to wait before returning a timeout error when writing to the database */

View file

@ -22,6 +22,10 @@ class Driver extends \JKingWeb\Arsse\Db\AbstractDriver {
throw new Exception("extMissing", self::driverName()); // @codeCoverageIgnore throw new Exception("extMissing", self::driverName()); // @codeCoverageIgnore
} }
$dbFile = Arsse::$conf->dbSQLite3File; $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; $mode = \SQLITE3_OPEN_READWRITE | \SQLITE3_OPEN_CREATE;
$timeout = Arsse::$conf->dbSQLite3Timeout * 1000; $timeout = Arsse::$conf->dbSQLite3Timeout * 1000;
try { try {