3 set_include_path(dirname(__FILE__
) ."/include" . PATH_SEPARATOR
.
6 define('DISABLE_SESSIONS', true);
8 chdir(dirname(__FILE__
));
10 require_once "functions.php";
11 require_once "rssfuncs.php";
12 require_once "config.php";
13 require_once "sanity_check.php";
14 require_once "db.php";
15 require_once "db-prefs.php";
17 if (!defined('PHP_EXECUTABLE'))
18 define('PHP_EXECUTABLE', '/usr/bin/php');
20 // Create a database connection.
21 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
23 init_connection($link);
25 $longopts = array("feeds",
38 foreach ($pluginhost->get_commands() as $command => $data) {
39 array_push($longopts, $command);
42 $options = getopt("", $longopts);
44 if (count($options) == 0 && !defined('STDIN')) {
47 <title
>Tiny Tiny RSS data update script
.</title
>
48 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8">
49 <link rel
="stylesheet" type
="text/css" href
="utility.css">
53 <div
class="floatingLogo"><img src
="images/logo_wide.png"></div
>
54 <h1
><?php
echo __("Tiny Tiny RSS data update script.") ?
></h1
>
56 <?php
print_error("Please run this script from the command line. Use option \"-help\" to display command help if this error is displayed erroneously."); ?
>
64 if (count($options) == 0 ||
isset($options["help"]) ) {
65 print "Tiny Tiny RSS data update script.\n\n";
67 print " --feeds - update feeds\n";
68 print " --feedbrowser - update feedbrowser\n";
69 print " --daemon - start single-process update daemon\n";
70 print " --task N - create lockfile using this task id\n";
71 print " --cleanup-tags - perform tags table maintenance\n";
72 print " --quiet - don't show messages\n";
73 print " --indexes - recreate missing schema indexes\n";
74 print " --convert-filters - convert type1 filters to type2\n";
75 print " --force-update - force update of all feeds\n";
76 print " --list-plugins - list all available plugins\n";
77 print " --help - show this help\n";
78 print "Plugin options:\n";
80 foreach ($pluginhost->get_commands() as $command => $data) {
81 printf(" --%-19s - %s\n", "$command", $data["description"]);
87 define('QUIET', isset($options['quiet']));
89 if (!isset($options["daemon"])) {
90 $lock_filename = "update.lock";
92 $lock_filename = "update_daemon.lock";
95 if (isset($options["task"])) {
96 _debug("Using task id " . $options["task"]);
97 $lock_filename = $lock_filename . "-task_" . $options["task"];
100 $lock_handle = make_lockfile($lock_filename);
103 // Try to lock a file in order to avoid concurrent update.
105 die("error: Can't create lockfile ($lock_filename). ".
106 "Maybe another update process is already running.\n");
109 if (isset($options["force-update"])) {
110 _debug("marking all feeds as needing update...");
112 db_query($link, "UPDATE ttrss_feeds SET last_update_started = '1970-01-01',
113 last_updated = '1970-01-01'");
116 if (isset($options["feeds"])) {
117 // Update all feeds needing a update.
118 update_daemon_common($link);
120 // Update feedbrowser
121 $count = update_feedbrowser_cache($link);
122 _debug("Feedbrowser updated, $count feeds processed.");
124 // Purge orphans and cleanup tags
125 purge_orphans($link, true);
127 $rc = cleanup_tags($link, 14, 50000);
128 _debug("Cleaned $rc cached tags.");
131 $pluginhost->run_hooks($pluginhost::HOOK_UPDATE_TASK
, "hook_update_task", $op);
134 if (isset($options["feedbrowser"])) {
135 $count = update_feedbrowser_cache($link);
136 print "Finished, $count feeds processed.\n";
139 if (isset($options["daemon"])) {
141 passthru(PHP_EXECUTABLE
. " " . $argv[0] ." --daemon-loop");
142 _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL
. " seconds...");
143 sleep(DAEMON_SLEEP_INTERVAL
);
147 if (isset($options["daemon-loop"])) {
148 if (!make_stampfile('update_daemon.stamp')) {
149 die("error: unable to create stampfile\n");
152 // Call to the feed batch update function
153 // or regenerate feedbrowser cache
155 if (rand(0,100) > 30) {
156 update_daemon_common($link);
158 $count = update_feedbrowser_cache($link);
159 _debug("Feedbrowser updated, $count feeds processed.");
161 purge_orphans($link, true);
163 $rc = cleanup_tags($link, 14, 50000);
165 _debug("Cleaned $rc cached tags.");
168 $pluginhost->run_hooks($pluginhost::HOOK_UPDATE_TASK
, "hook_update_task", $op);
173 if (isset($options["cleanup-tags"])) {
174 $rc = cleanup_tags($link, 14, 50000);
175 _debug("$rc tags deleted.\n");
178 if (isset($options["indexes"])) {
179 _debug("PLEASE BACKUP YOUR DATABASE BEFORE PROCEEDING!");
180 _debug("Type 'yes' to continue.");
182 if (read_stdin() != 'yes')
185 _debug("clearing existing indexes...");
187 if (DB_TYPE
== "pgsql") {
188 $result = db_query($link, "SELECT relname FROM
189 pg_catalog.pg_class WHERE relname LIKE 'ttrss_%'
190 AND relname NOT LIKE '%_pkey'
193 $result = db_query($link, "SELECT index_name,table_name FROM
194 information_schema.statistics WHERE index_name LIKE 'ttrss_%'");
197 while ($line = db_fetch_assoc($result)) {
198 if (DB_TYPE
== "pgsql") {
199 $statement = "DROP INDEX " . $line["relname"];
202 $statement = "ALTER TABLE ".
203 $line['table_name']." DROP INDEX ".$line['index_name'];
206 db_query($link, $statement, false);
209 _debug("reading indexes from schema for: " . DB_TYPE
);
211 $fp = fopen("schema/ttrss_schema_" . DB_TYPE
. ".sql", "r");
213 while ($line = fgets($fp)) {
216 if (preg_match("/^create index ([^ ]+) on ([^ ]+)$/i", $line, $matches)) {
217 $index = $matches[1];
218 $table = $matches[2];
220 $statement = "CREATE INDEX $index ON $table";
223 db_query($link, $statement);
228 _debug("unable to open schema file.");
233 if (isset($options["convert-filters"])) {
234 _debug("WARNING: this will remove all existing type2 filters.");
235 _debug("Type 'yes' to continue.");
237 if (read_stdin() != 'yes')
240 _debug("converting filters...");
242 db_query($link, "DELETE FROM ttrss_filters2");
244 $result = db_query($link, "SELECT * FROM ttrss_filters ORDER BY id");
246 while ($line = db_fetch_assoc($result)) {
247 $owner_uid = $line["owner_uid"];
249 // date filters are removed
250 if ($line["filter_type"] != 5) {
253 if (sql_bool_to_bool($line["cat_filter"])) {
254 $feed_id = "CAT:" . (int)$line["cat_id"];
256 $feed_id = (int)$line["feed_id"];
259 $filter["enabled"] = $line["enabled"] ?
"on" : "off";
260 $filter["rule"] = array(
262 "reg_exp" => $line["reg_exp"],
263 "feed_id" => $feed_id,
264 "filter_type" => $line["filter_type"])));
266 $filter["action"] = array(
268 "action_id" => $line["action_id"],
269 "action_param_label" => $line["action_param"],
270 "action_param" => $line["action_param"])));
272 // Oh god it's full of hacks
275 $_SESSION["uid"] = $owner_uid;
277 $filters = new Pref_Filters($link, $_REQUEST);
284 if (isset($options["list-plugins"])) {
285 $tmppluginhost = new PluginHost($link);
286 $tmppluginhost->load_all($tmppluginhost::KIND_ALL
);
287 $enabled = array_map("trim", explode(",", PLUGINS
));
289 echo "List of all available plugins:\n";
291 foreach ($tmppluginhost->get_plugins() as $name => $plugin) {
292 $about = $plugin->about();
294 $status = $about[3] ?
"system" : "user";
296 if (in_array($name, $enabled)) $name .= "*";
298 printf("%-50s %-10s v%.2f (by %s)\n%s\n\n",
299 $name, $status, $about[0], $about[2], $about[1]);
302 echo "Plugins marked by * are currently enabled for all users.\n";
306 $pluginhost->run_commands($options);
310 if ($lock_handle != false) {
311 fclose($lock_handle);
314 if (file_exists(LOCK_DIRECTORY
. "/$lock_filename"))
315 unlink(LOCK_DIRECTORY
. "/$lock_filename");