]>
git.wh0rd.org - tt-rss.git/blob - update.php
3 set_include_path(get_include_path() . PATH_SEPARATOR
.
4 dirname(__FILE__
) . "/include");
6 define('DISABLE_SESSIONS', true);
8 chdir(dirname(__FILE__
));
10 require_once "functions.php";
11 require_once "rssfuncs.php";
12 require_once "sanity_check.php";
13 require_once "config.php";
14 require_once "db.php";
15 require_once "db-prefs.php";
16 require_once "update_self.php";
18 if (!defined('STDIN')) {
21 <title
>Database Updater
</title
>
22 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8">
23 <link rel
="stylesheet" type
="text/css" href
="utility.css">
27 <div
class="floatingLogo"><img src
="images/logo_wide.png"></div
>
28 <h1
><?php
echo __("Update") ?
></h1
>
30 <?php
print_error("Please run this script from the command line."); ?
>
37 if (!defined('PHP_EXECUTABLE'))
38 define('PHP_EXECUTABLE', '/usr/bin/php');
42 if (count($argv) == 1 ||
in_array("-help", $op) ) {
43 print "Tiny Tiny RSS data update script.\n\n";
45 print " -feeds - update feeds\n";
46 print " -feedbrowser - update feedbrowser\n";
47 print " -daemon - start single-process update daemon\n";
48 print " -cleanup-tags - perform tags table maintenance\n";
49 print " -get-feeds - receive popular feeds from linked instances\n";
50 print " -import USER FILE - import articles from XML\n";
51 print " -update-self - update tt-rss installation to latest version\n";
52 print " -quiet - don't show messages\n";
53 print " -indexes - recreate missing schema indexes\n";
54 print " -convert-filters - convert type1 filters to type2\n";
55 print " -help - show this help\n";
59 define('QUIET', in_array("-quiet", $op));
61 if (!in_array("-daemon", $op)) {
62 $lock_filename = "update.lock";
64 $lock_filename = "update_daemon.lock";
67 $lock_handle = make_lockfile($lock_filename);
70 // Try to lock a file in order to avoid concurrent update.
72 die("error: Can't create lockfile ($lock_filename). ".
73 "Maybe another update process is already running.\n");
76 // Create a database connection.
77 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
79 init_connection($link);
81 if (in_array("-feeds", $op)) {
82 // Update all feeds needing a update.
83 update_daemon_common($link);
86 $count = update_feedbrowser_cache($link);
87 _debug("Feedbrowser updated, $count feeds processed.");
89 // Purge orphans and cleanup tags
90 purge_orphans($link, true);
92 $rc = cleanup_tags($link, 14, 50000);
93 _debug("Cleaned $rc cached tags.");
95 get_linked_feeds($link);
98 if (in_array("-feedbrowser", $op)) {
99 $count = update_feedbrowser_cache($link);
100 print "Finished, $count feeds processed.\n";
103 if (in_array("-daemon", $op)) {
104 $op = array_diff($op, array("-daemon"));
106 passthru(PHP_EXECUTABLE
. " " . implode(' ', $op) . " -daemon-loop");
107 _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL
. " seconds...");
108 sleep(DAEMON_SLEEP_INTERVAL
);
112 if (in_array("-daemon-loop", $op)) {
113 if (!make_stampfile('update_daemon.stamp')) {
114 die("error: unable to create stampfile\n");
117 // Call to the feed batch update function
118 // or regenerate feedbrowser cache
120 if (rand(0,100) > 30) {
121 update_daemon_common($link);
123 $count = update_feedbrowser_cache($link);
124 _debug("Feedbrowser updated, $count feeds processed.");
126 purge_orphans($link, true);
128 $rc = cleanup_tags($link, 14, 50000);
130 _debug("Cleaned $rc cached tags.");
132 get_linked_feeds($link);
137 if (in_array("-cleanup-tags", $op)) {
138 $rc = cleanup_tags($link, 14, 50000);
139 _debug("$rc tags deleted.\n");
142 if (in_array("-get-feeds", $op)) {
143 get_linked_feeds($link);
146 if (in_array("-import",$op)) {
147 $username = $argv[count($argv) - 2];
148 $filename = $argv[count($argv) - 1];
151 print "error: please specify username.\n";
155 if (!is_file($filename)) {
156 print "error: input filename ($filename) doesn't exist.\n";
160 _debug("importing $filename for user $username...\n");
162 $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$username'");
164 if (db_num_rows($result) == 0) {
165 print "error: could not find user $username.\n";
169 $owner_uid = db_fetch_result($result, 0, "id");
171 perform_data_import($link, $filename, $owner_uid);
175 if (in_array("-indexes", $op)) {
176 _debug("PLEASE BACKUP YOUR DATABASE BEFORE PROCEEDING!");
177 _debug("Type 'yes' to continue.");
179 if (read_stdin() != 'yes')
182 _debug("clearing existing indexes...");
184 if (DB_TYPE
== "pgsql") {
185 $result = db_query($link, "SELECT relname FROM
186 pg_catalog.pg_class WHERE relname LIKE 'ttrss_%'
187 AND relname NOT LIKE '%_pkey'
190 $result = db_query($link, "SELECT index_name,table_name FROM
191 information_schema.statistics WHERE index_name LIKE 'ttrss_%'");
194 while ($line = db_fetch_assoc($result)) {
195 if (DB_TYPE
== "pgsql") {
196 $statement = "DROP INDEX " . $line["relname"];
199 $statement = "ALTER TABLE ".
200 $line['table_name']." DROP INDEX ".$line['index_name'];
203 db_query($link, $statement, false);
206 _debug("reading indexes from schema for: " . DB_TYPE
);
208 $fp = fopen("schema/ttrss_schema_" . DB_TYPE
. ".sql", "r");
210 while ($line = fgets($fp)) {
213 if (preg_match("/^create index ([^ ]+) on ([^ ]+)$/i", $line, $matches)) {
214 $index = $matches[1];
215 $table = $matches[2];
217 $statement = "CREATE INDEX $index ON $table";
220 db_query($link, $statement);
225 _debug("unable to open schema file.");
230 if (in_array("-update-self", $op)) {
231 _debug("Warning: self-updating is experimental. Use at your own risk.");
232 _debug("Please backup your tt-rss directory before continuing. Your database will not be modified.");
233 _debug("Type 'yes' to continue.");
235 if (read_stdin() != 'yes')
238 update_self($link, in_array("-force", $op));
241 if (in_array("-convert-filters", $op)) {
242 _debug("WARNING: this will remove all existing type2 filters.");
243 _debug("Type 'yes' to continue.");
245 if (read_stdin() != 'yes')
248 _debug("converting filters...");
250 db_query($link, "DELETE FROM ttrss_filters2");
252 $result = db_query($link, "SELECT * FROM ttrss_filters ORDER BY id");
254 while ($line = db_fetch_assoc($result)) {
255 $owner_uid = $line["owner_uid"];
257 // date filters are removed
258 if ($line["filter_type"] != 5) {
261 if (sql_bool_to_bool($line["cat_filter"])) {
262 $feed_id = "CAT:" . (int)$line["cat_id"];
264 $feed_id = (int)$line["feed_id"];
267 $filter["enabled"] = $line["enabled"] ?
"on" : "off";
268 $filter["rule"] = array(
270 "reg_exp" => $line["reg_exp"],
271 "feed_id" => $feed_id,
272 "filter_type" => $line["filter_type"])));
274 $filter["action"] = array(
276 "action_id" => $line["action_id"],
277 "action_param_label" => $line["action_param"],
278 "action_param" => $line["action_param"])));
280 // Oh god it's full of hacks
283 $_SESSION["uid"] = $owner_uid;
285 $filters = new Pref_Filters($link, $_REQUEST);
294 if ($lock_handle != false) {
295 fclose($lock_handle);
298 if (file_exists(LOCK_DIRECTORY
. "/$lock_filename"))
299 unlink(LOCK_DIRECTORY
. "/$lock_filename");