rework update.php to use getopt; allow --task parameter
This commit is contained in:
parent
84b48db4a7
commit
764555ff8a
|
@ -171,7 +171,7 @@ class PluginHost {
|
||||||
}
|
}
|
||||||
|
|
||||||
function add_command($command, $description, $sender) {
|
function add_command($command, $description, $sender) {
|
||||||
$command = "-" . str_replace("-", "_", strtolower($command));
|
$command = str_replace("-", "_", strtolower($command));
|
||||||
|
|
||||||
$this->commands[$command] = array("description" => $description,
|
$this->commands[$command] = array("description" => $description,
|
||||||
"class" => $sender);
|
"class" => $sender);
|
||||||
|
@ -201,7 +201,7 @@ class PluginHost {
|
||||||
|
|
||||||
function run_commands($args) {
|
function run_commands($args) {
|
||||||
foreach ($this->get_commands() as $command => $data) {
|
foreach ($this->get_commands() as $command => $data) {
|
||||||
if (in_array($command, $args)) {
|
if (isset($args[$command])) {
|
||||||
$command = str_replace("-", "", $command);
|
$command = str_replace("-", "", $command);
|
||||||
$data["class"]->$command($args);
|
$data["class"]->$command($args);
|
||||||
}
|
}
|
||||||
|
|
91
update.php
91
update.php
|
@ -22,9 +22,26 @@
|
||||||
|
|
||||||
init_connection($link);
|
init_connection($link);
|
||||||
|
|
||||||
$op = $argv;
|
$longopts = array("feeds",
|
||||||
|
"feedbrowser",
|
||||||
|
"daemon",
|
||||||
|
"daemon-loop",
|
||||||
|
"task:",
|
||||||
|
"cleanup-tags",
|
||||||
|
"quiet",
|
||||||
|
"indexes",
|
||||||
|
"convert-filters",
|
||||||
|
"force-update",
|
||||||
|
"list-plugins",
|
||||||
|
"help");
|
||||||
|
|
||||||
if (count($argv) == 0 && !defined('STDIN')) {
|
foreach ($pluginhost->get_commands() as $command => $data) {
|
||||||
|
array_push($longopts, $command);
|
||||||
|
}
|
||||||
|
|
||||||
|
$options = getopt("", $longopts);
|
||||||
|
|
||||||
|
if (count($options) == 0 && !defined('STDIN')) {
|
||||||
?> <html>
|
?> <html>
|
||||||
<head>
|
<head>
|
||||||
<title>Tiny Tiny RSS data update script.</title>
|
<title>Tiny Tiny RSS data update script.</title>
|
||||||
|
@ -43,36 +60,43 @@
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($argv) == 1 || in_array("-help", $op) ) {
|
|
||||||
|
if (count($options) == 0 || isset($options["help"]) ) {
|
||||||
print "Tiny Tiny RSS data update script.\n\n";
|
print "Tiny Tiny RSS data update script.\n\n";
|
||||||
print "Options:\n";
|
print "Options:\n";
|
||||||
print " -feeds - update feeds\n";
|
print " --feeds - update feeds\n";
|
||||||
print " -feedbrowser - update feedbrowser\n";
|
print " --feedbrowser - update feedbrowser\n";
|
||||||
print " -daemon - start single-process update daemon\n";
|
print " --daemon - start single-process update daemon\n";
|
||||||
print " -cleanup-tags - perform tags table maintenance\n";
|
print " --task N - create lockfile using this task id\n";
|
||||||
print " -quiet - don't show messages\n";
|
print " --cleanup-tags - perform tags table maintenance\n";
|
||||||
print " -indexes - recreate missing schema indexes\n";
|
print " --quiet - don't show messages\n";
|
||||||
print " -convert-filters - convert type1 filters to type2\n";
|
print " --indexes - recreate missing schema indexes\n";
|
||||||
print " -force-update - force update of all feeds\n";
|
print " --convert-filters - convert type1 filters to type2\n";
|
||||||
print " -list-plugins - list all available plugins\n";
|
print " --force-update - force update of all feeds\n";
|
||||||
print " -help - show this help\n";
|
print " --list-plugins - list all available plugins\n";
|
||||||
|
print " --help - show this help\n";
|
||||||
print "Plugin options:\n";
|
print "Plugin options:\n";
|
||||||
|
|
||||||
foreach ($pluginhost->get_commands() as $command => $data) {
|
foreach ($pluginhost->get_commands() as $command => $data) {
|
||||||
printf(" %-19s - %s\n", "$command", $data["description"]);
|
printf(" --%-19s - %s\n", "$command", $data["description"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
define('QUIET', in_array("-quiet", $op));
|
define('QUIET', isset($options['quiet']));
|
||||||
|
|
||||||
if (!in_array("-daemon", $op)) {
|
if (!isset($options["daemon"])) {
|
||||||
$lock_filename = "update.lock";
|
$lock_filename = "update.lock";
|
||||||
} else {
|
} else {
|
||||||
$lock_filename = "update_daemon.lock";
|
$lock_filename = "update_daemon.lock";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($options["task"])) {
|
||||||
|
_debug("Using task id " . $options["task"]);
|
||||||
|
$lock_filename = $lock_filename . "-task_" . $options["task"];
|
||||||
|
}
|
||||||
|
|
||||||
$lock_handle = make_lockfile($lock_filename);
|
$lock_handle = make_lockfile($lock_filename);
|
||||||
$must_exit = false;
|
$must_exit = false;
|
||||||
|
|
||||||
|
@ -82,7 +106,14 @@
|
||||||
"Maybe another update process is already running.\n");
|
"Maybe another update process is already running.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array("-feeds", $op)) {
|
if (isset($options["force-update"])) {
|
||||||
|
_debug("marking all feeds as needing update...");
|
||||||
|
|
||||||
|
db_query($link, "UPDATE ttrss_feeds SET last_update_started = '1970-01-01',
|
||||||
|
last_updated = '1970-01-01'");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($options["feeds"])) {
|
||||||
// Update all feeds needing a update.
|
// Update all feeds needing a update.
|
||||||
update_daemon_common($link);
|
update_daemon_common($link);
|
||||||
|
|
||||||
|
@ -100,21 +131,20 @@
|
||||||
$pluginhost->run_hooks($pluginhost::HOOK_UPDATE_TASK, "hook_update_task", $op);
|
$pluginhost->run_hooks($pluginhost::HOOK_UPDATE_TASK, "hook_update_task", $op);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array("-feedbrowser", $op)) {
|
if (isset($options["feedbrowser"])) {
|
||||||
$count = update_feedbrowser_cache($link);
|
$count = update_feedbrowser_cache($link);
|
||||||
print "Finished, $count feeds processed.\n";
|
print "Finished, $count feeds processed.\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array("-daemon", $op)) {
|
if (isset($options["daemon"])) {
|
||||||
$op = array_diff($op, array("-daemon"));
|
|
||||||
while (true) {
|
while (true) {
|
||||||
passthru(PHP_EXECUTABLE . " " . implode(' ', $op) . " -daemon-loop");
|
passthru(PHP_EXECUTABLE . " " . $argv[0] ." --daemon-loop");
|
||||||
_debug("Sleeping for " . DAEMON_SLEEP_INTERVAL . " seconds...");
|
_debug("Sleeping for " . DAEMON_SLEEP_INTERVAL . " seconds...");
|
||||||
sleep(DAEMON_SLEEP_INTERVAL);
|
sleep(DAEMON_SLEEP_INTERVAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array("-daemon-loop", $op)) {
|
if (isset($options["daemon-loop"])) {
|
||||||
if (!make_stampfile('update_daemon.stamp')) {
|
if (!make_stampfile('update_daemon.stamp')) {
|
||||||
die("error: unable to create stampfile\n");
|
die("error: unable to create stampfile\n");
|
||||||
}
|
}
|
||||||
|
@ -140,12 +170,12 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array("-cleanup-tags", $op)) {
|
if (isset($options["cleanup-tags"])) {
|
||||||
$rc = cleanup_tags($link, 14, 50000);
|
$rc = cleanup_tags($link, 14, 50000);
|
||||||
_debug("$rc tags deleted.\n");
|
_debug("$rc tags deleted.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array("-indexes", $op)) {
|
if (isset($options["indexes"])) {
|
||||||
_debug("PLEASE BACKUP YOUR DATABASE BEFORE PROCEEDING!");
|
_debug("PLEASE BACKUP YOUR DATABASE BEFORE PROCEEDING!");
|
||||||
_debug("Type 'yes' to continue.");
|
_debug("Type 'yes' to continue.");
|
||||||
|
|
||||||
|
@ -200,7 +230,7 @@
|
||||||
_debug("all done.");
|
_debug("all done.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array("-convert-filters", $op)) {
|
if (isset($options["convert-filters"])) {
|
||||||
_debug("WARNING: this will remove all existing type2 filters.");
|
_debug("WARNING: this will remove all existing type2 filters.");
|
||||||
_debug("Type 'yes' to continue.");
|
_debug("Type 'yes' to continue.");
|
||||||
|
|
||||||
|
@ -251,14 +281,7 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_array("-force-update", $op)) {
|
if (isset($options["list-plugins"])) {
|
||||||
_debug("marking all feeds as needing update...");
|
|
||||||
|
|
||||||
db_query($link, "UPDATE ttrss_feeds SET last_update_started = '1970-01-01',
|
|
||||||
last_updated = '1970-01-01'");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (in_array("-list-plugins", $op)) {
|
|
||||||
$tmppluginhost = new PluginHost($link);
|
$tmppluginhost = new PluginHost($link);
|
||||||
$tmppluginhost->load_all($tmppluginhost::KIND_ALL);
|
$tmppluginhost->load_all($tmppluginhost::KIND_ALL);
|
||||||
$enabled = array_map("trim", explode(",", PLUGINS));
|
$enabled = array_map("trim", explode(",", PLUGINS));
|
||||||
|
@ -280,7 +303,7 @@
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$pluginhost->run_commands($op);
|
$pluginhost->run_commands($options);
|
||||||
|
|
||||||
db_close($link);
|
db_close($link);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue