]>
Commit | Line | Data |
---|---|---|
ece78711 | 1 | #!/usr/bin/env php |
fecd57c8 | 2 | <?php |
88e8fb3a AD |
3 | set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR . |
4 | get_include_path()); | |
107d0cf3 | 5 | |
661135c7 AD |
6 | define('DISABLE_SESSIONS', true); |
7 | ||
9b27cec8 AD |
8 | chdir(dirname(__FILE__)); |
9 | ||
fb074239 | 10 | require_once "functions.php"; |
2c08214a | 11 | require_once "rssfuncs.php"; |
81596c66 | 12 | require_once "config.php"; |
f02713bb | 13 | require_once "sanity_check.php"; |
81596c66 | 14 | require_once "db.php"; |
661135c7 | 15 | require_once "db-prefs.php"; |
661135c7 | 16 | |
3de78afd AD |
17 | if (!defined('PHP_EXECUTABLE')) |
18 | define('PHP_EXECUTABLE', '/usr/bin/php'); | |
19 | ||
73f28fe9 AD |
20 | // Create a database connection. |
21 | $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); | |
22 | ||
23 | init_connection($link); | |
24 | ||
3de78afd AD |
25 | $op = $argv; |
26 | ||
27 | if (count($argv) == 0 && !defined('STDIN')) { | |
366f06f7 AD |
28 | ?> <html> |
29 | <head> | |
3de78afd | 30 | <title>Tiny Tiny RSS data update script.</title> |
366f06f7 AD |
31 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
32 | <link rel="stylesheet" type="text/css" href="utility.css"> | |
33 | </head> | |
34 | ||
35 | <body> | |
36 | <div class="floatingLogo"><img src="images/logo_wide.png"></div> | |
3de78afd | 37 | <h1><?php echo __("Tiny Tiny RSS data update script.") ?></h1> |
366f06f7 | 38 | |
3de78afd | 39 | <?php print_error("Please run this script from the command line. Use option \"-help\" to display command help if this error is displayed erroneously."); ?> |
366f06f7 AD |
40 | |
41 | </body></html> | |
42 | <?php | |
43 | exit; | |
44 | } | |
45 | ||
5439d333 | 46 | if (count($argv) == 1 || in_array("-help", $op) ) { |
661135c7 AD |
47 | print "Tiny Tiny RSS data update script.\n\n"; |
48 | print "Options:\n"; | |
55f34b81 AD |
49 | print " -feeds - update feeds\n"; |
50 | print " -feedbrowser - update feedbrowser\n"; | |
51 | print " -daemon - start single-process update daemon\n"; | |
52 | print " -cleanup-tags - perform tags table maintenance\n"; | |
5439d333 | 53 | print " -quiet - don't show messages\n"; |
9a57512c | 54 | print " -indexes - recreate missing schema indexes\n"; |
6aff7845 | 55 | print " -convert-filters - convert type1 filters to type2\n"; |
120c2b01 | 56 | print " -force-update - force update of all feeds\n"; |
7a866114 | 57 | print " -list-plugins - list all available plugins\n"; |
55f34b81 | 58 | print " -help - show this help\n"; |
73f28fe9 AD |
59 | print "Plugin options:\n"; |
60 | ||
61 | foreach ($pluginhost->get_commands() as $command => $data) { | |
62 | printf(" %-19s - %s\n", "$command", $data["description"]); | |
63 | } | |
64 | ||
661135c7 | 65 | return; |
81596c66 | 66 | } |
87b9fb65 | 67 | |
5439d333 RW |
68 | define('QUIET', in_array("-quiet", $op)); |
69 | ||
70 | if (!in_array("-daemon", $op)) { | |
661135c7 AD |
71 | $lock_filename = "update.lock"; |
72 | } else { | |
73 | $lock_filename = "update_daemon.lock"; | |
74 | } | |
fecd57c8 | 75 | |
661135c7 AD |
76 | $lock_handle = make_lockfile($lock_filename); |
77 | $must_exit = false; | |
fecd57c8 | 78 | |
661135c7 AD |
79 | // Try to lock a file in order to avoid concurrent update. |
80 | if (!$lock_handle) { | |
81 | die("error: Can't create lockfile ($lock_filename). ". | |
82 | "Maybe another update process is already running.\n"); | |
83 | } | |
fecd57c8 | 84 | |
5439d333 | 85 | if (in_array("-feeds", $op)) { |
661135c7 AD |
86 | // Update all feeds needing a update. |
87 | update_daemon_common($link); | |
84e9a8c7 AD |
88 | |
89 | // Update feedbrowser | |
90 | $count = update_feedbrowser_cache($link); | |
91 | _debug("Feedbrowser updated, $count feeds processed."); | |
92 | ||
93 | // Purge orphans and cleanup tags | |
94 | purge_orphans($link, true); | |
95 | ||
96 | $rc = cleanup_tags($link, 14, 50000); | |
97 | _debug("Cleaned $rc cached tags."); | |
f32eb194 | 98 | |
41b82aa4 AD |
99 | global $pluginhost; |
100 | $pluginhost->run_hooks($pluginhost::HOOK_UPDATE_TASK, "hook_update_task", $op); | |
661135c7 | 101 | } |
fecd57c8 | 102 | |
5439d333 | 103 | if (in_array("-feedbrowser", $op)) { |
661135c7 AD |
104 | $count = update_feedbrowser_cache($link); |
105 | print "Finished, $count feeds processed.\n"; | |
fecd57c8 | 106 | } |
661135c7 | 107 | |
5439d333 RW |
108 | if (in_array("-daemon", $op)) { |
109 | $op = array_diff($op, array("-daemon")); | |
661135c7 | 110 | while (true) { |
5439d333 | 111 | passthru(PHP_EXECUTABLE . " " . implode(' ', $op) . " -daemon-loop"); |
661135c7 AD |
112 | _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL . " seconds..."); |
113 | sleep(DAEMON_SLEEP_INTERVAL); | |
fecd57c8 | 114 | } |
81596c66 | 115 | } |
9e21a571 | 116 | |
5439d333 | 117 | if (in_array("-daemon-loop", $op)) { |
661135c7 AD |
118 | if (!make_stampfile('update_daemon.stamp')) { |
119 | die("error: unable to create stampfile\n"); | |
120 | } | |
9e21a571 | 121 | |
dbaa4e4a | 122 | // Call to the feed batch update function |
661135c7 | 123 | // or regenerate feedbrowser cache |
9e21a571 | 124 | |
661135c7 AD |
125 | if (rand(0,100) > 30) { |
126 | update_daemon_common($link); | |
9e21a571 | 127 | } else { |
661135c7 | 128 | $count = update_feedbrowser_cache($link); |
e3b42c5a AD |
129 | _debug("Feedbrowser updated, $count feeds processed."); |
130 | ||
131 | purge_orphans($link, true); | |
dbaa4e4a | 132 | |
e3b42c5a AD |
133 | $rc = cleanup_tags($link, 14, 50000); |
134 | ||
135 | _debug("Cleaned $rc cached tags."); | |
f32eb194 | 136 | |
41b82aa4 AD |
137 | global $pluginhost; |
138 | $pluginhost->run_hooks($pluginhost::HOOK_UPDATE_TASK, "hook_update_task", $op); | |
9e21a571 | 139 | } |
ef59e6e8 | 140 | |
fecd57c8 | 141 | } |
fecd57c8 | 142 | |
5439d333 | 143 | if (in_array("-cleanup-tags", $op)) { |
868650e4 | 144 | $rc = cleanup_tags($link, 14, 50000); |
5439d333 | 145 | _debug("$rc tags deleted.\n"); |
868650e4 AD |
146 | } |
147 | ||
871f0a7a AD |
148 | if (in_array("-indexes", $op)) { |
149 | _debug("PLEASE BACKUP YOUR DATABASE BEFORE PROCEEDING!"); | |
150 | _debug("Type 'yes' to continue."); | |
151 | ||
152 | if (read_stdin() != 'yes') | |
153 | exit; | |
154 | ||
155 | _debug("clearing existing indexes..."); | |
156 | ||
157 | if (DB_TYPE == "pgsql") { | |
158 | $result = db_query($link, "SELECT relname FROM | |
159 | pg_catalog.pg_class WHERE relname LIKE 'ttrss_%' | |
160 | AND relname NOT LIKE '%_pkey' | |
161 | AND relkind = 'i'"); | |
162 | } else { | |
163 | $result = db_query($link, "SELECT index_name,table_name FROM | |
164 | information_schema.statistics WHERE index_name LIKE 'ttrss_%'"); | |
165 | } | |
166 | ||
167 | while ($line = db_fetch_assoc($result)) { | |
168 | if (DB_TYPE == "pgsql") { | |
169 | $statement = "DROP INDEX " . $line["relname"]; | |
170 | _debug($statement); | |
171 | } else { | |
172 | $statement = "ALTER TABLE ". | |
173 | $line['table_name']." DROP INDEX ".$line['index_name']; | |
174 | _debug($statement); | |
175 | } | |
176 | db_query($link, $statement, false); | |
177 | } | |
178 | ||
179 | _debug("reading indexes from schema for: " . DB_TYPE); | |
180 | ||
181 | $fp = fopen("schema/ttrss_schema_" . DB_TYPE . ".sql", "r"); | |
182 | if ($fp) { | |
183 | while ($line = fgets($fp)) { | |
184 | $matches = array(); | |
185 | ||
186 | if (preg_match("/^create index ([^ ]+) on ([^ ]+)$/i", $line, $matches)) { | |
187 | $index = $matches[1]; | |
188 | $table = $matches[2]; | |
189 | ||
190 | $statement = "CREATE INDEX $index ON $table"; | |
191 | ||
192 | _debug($statement); | |
193 | db_query($link, $statement); | |
194 | } | |
195 | } | |
196 | fclose($fp); | |
197 | } else { | |
198 | _debug("unable to open schema file."); | |
199 | } | |
200 | _debug("all done."); | |
201 | } | |
202 | ||
6aff7845 AD |
203 | if (in_array("-convert-filters", $op)) { |
204 | _debug("WARNING: this will remove all existing type2 filters."); | |
205 | _debug("Type 'yes' to continue."); | |
206 | ||
207 | if (read_stdin() != 'yes') | |
208 | exit; | |
209 | ||
210 | _debug("converting filters..."); | |
211 | ||
212 | db_query($link, "DELETE FROM ttrss_filters2"); | |
213 | ||
214 | $result = db_query($link, "SELECT * FROM ttrss_filters ORDER BY id"); | |
215 | ||
216 | while ($line = db_fetch_assoc($result)) { | |
217 | $owner_uid = $line["owner_uid"]; | |
218 | ||
37f78940 AD |
219 | // date filters are removed |
220 | if ($line["filter_type"] != 5) { | |
221 | $filter = array(); | |
222 | ||
223 | if (sql_bool_to_bool($line["cat_filter"])) { | |
224 | $feed_id = "CAT:" . (int)$line["cat_id"]; | |
225 | } else { | |
226 | $feed_id = (int)$line["feed_id"]; | |
227 | } | |
6aff7845 | 228 | |
37f78940 AD |
229 | $filter["enabled"] = $line["enabled"] ? "on" : "off"; |
230 | $filter["rule"] = array( | |
231 | json_encode(array( | |
232 | "reg_exp" => $line["reg_exp"], | |
233 | "feed_id" => $feed_id, | |
234 | "filter_type" => $line["filter_type"]))); | |
6aff7845 | 235 | |
37f78940 AD |
236 | $filter["action"] = array( |
237 | json_encode(array( | |
238 | "action_id" => $line["action_id"], | |
239 | "action_param_label" => $line["action_param"], | |
240 | "action_param" => $line["action_param"]))); | |
6aff7845 | 241 | |
37f78940 | 242 | // Oh god it's full of hacks |
5451903c | 243 | |
37f78940 AD |
244 | $_REQUEST = $filter; |
245 | $_SESSION["uid"] = $owner_uid; | |
6aff7845 | 246 | |
37f78940 AD |
247 | $filters = new Pref_Filters($link, $_REQUEST); |
248 | $filters->add(); | |
249 | } | |
6aff7845 AD |
250 | } |
251 | ||
252 | } | |
253 | ||
120c2b01 AD |
254 | if (in_array("-force-update", $op)) { |
255 | _debug("marking all feeds as needing update..."); | |
256 | ||
257 | db_query($link, "UPDATE ttrss_feeds SET last_update_started = '1970-01-01', | |
258 | last_updated = '1970-01-01'"); | |
259 | } | |
260 | ||
7a866114 AD |
261 | if (in_array("-list-plugins", $op)) { |
262 | $tmppluginhost = new PluginHost($link); | |
d2a421e3 | 263 | $tmppluginhost->load_all($tmppluginhost::KIND_ALL); |
20b86c79 AD |
264 | $enabled = array_map("trim", explode(",", PLUGINS)); |
265 | ||
266 | echo "List of all available plugins:\n"; | |
267 | ||
7a866114 | 268 | foreach ($tmppluginhost->get_plugins() as $name => $plugin) { |
d2a421e3 | 269 | $about = $plugin->about(); |
7a866114 | 270 | |
20b86c79 AD |
271 | $status = $about[3] ? "system" : "user"; |
272 | ||
273 | if (in_array($name, $enabled)) $name .= "*"; | |
274 | ||
275 | printf("%-50s %-10s v%.2f (by %s)\n%s\n\n", | |
276 | $name, $status, $about[0], $about[2], $about[1]); | |
7a866114 | 277 | } |
20b86c79 AD |
278 | |
279 | echo "Plugins marked by * are currently enabled for all users.\n"; | |
280 | ||
7a866114 AD |
281 | } |
282 | ||
73f28fe9 AD |
283 | $pluginhost->run_commands($op); |
284 | ||
661135c7 | 285 | db_close($link); |
107d0cf3 | 286 | |