]>
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";
17 if (!defined('PHP_EXECUTABLE'))
18 define('PHP_EXECUTABLE', '/usr/bin/php');
22 if (count($argv) == 1 ||
in_array("-help", $op) ) {
23 print "Tiny Tiny RSS data update script.\n\n";
25 print " -feeds - update feeds\n";
26 print " -feedbrowser - update feedbrowser\n";
27 print " -daemon - start single-process update daemon\n";
28 print " -cleanup-tags - perform tags table maintenance\n";
29 print " -get-feeds - receive popular feeds from linked instances\n";
30 print " -import USER FILE - import articles from XML\n";
31 print " -quiet - don't show messages\n";
32 print " -indexes - recreate missing schema indexes\n";
33 print " -help - show this help\n";
37 define('QUIET', in_array("-quiet", $op));
39 if (!in_array("-daemon", $op)) {
40 $lock_filename = "update.lock";
42 $lock_filename = "update_daemon.lock";
45 $lock_handle = make_lockfile($lock_filename);
48 // Try to lock a file in order to avoid concurrent update.
50 die("error: Can't create lockfile ($lock_filename). ".
51 "Maybe another update process is already running.\n");
54 // Create a database connection.
55 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
57 init_connection($link);
59 $plugins = new Plugins($link);
61 if (in_array("-feeds", $op)) {
62 // Update all feeds needing a update.
63 update_daemon_common($link);
66 $count = update_feedbrowser_cache($link);
67 _debug("Feedbrowser updated, $count feeds processed.");
69 // Purge orphans and cleanup tags
70 purge_orphans($link, true);
72 $rc = cleanup_tags($link, 14, 50000);
73 _debug("Cleaned $rc cached tags.");
75 get_linked_feeds($link);
78 if (in_array("-feedbrowser", $op)) {
79 $count = update_feedbrowser_cache($link);
80 print "Finished, $count feeds processed.\n";
83 if (in_array("-daemon", $op)) {
84 $op = array_diff($op, array("-daemon"));
86 passthru(PHP_EXECUTABLE
. " " . implode(' ', $op) . " -daemon-loop");
87 _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL
. " seconds...");
88 sleep(DAEMON_SLEEP_INTERVAL
);
92 if (in_array("-daemon-loop", $op)) {
93 if (!make_stampfile('update_daemon.stamp')) {
94 die("error: unable to create stampfile\n");
97 // Call to the feed batch update function
98 // or regenerate feedbrowser cache
100 if (rand(0,100) > 30) {
101 update_daemon_common($link);
103 $count = update_feedbrowser_cache($link);
104 _debug("Feedbrowser updated, $count feeds processed.");
106 purge_orphans($link, true);
108 $rc = cleanup_tags($link, 14, 50000);
110 _debug("Cleaned $rc cached tags.");
112 get_linked_feeds($link);
117 if (in_array("-cleanup-tags", $op)) {
118 $rc = cleanup_tags($link, 14, 50000);
119 _debug("$rc tags deleted.\n");
122 if (in_array("-get-feeds", $op)) {
123 get_linked_feeds($link);
126 if (in_array("-import",$op)) {
127 $username = $argv[count($argv) - 2];
128 $filename = $argv[count($argv) - 1];
131 print "error: please specify username.\n";
135 if (!is_file($filename)) {
136 print "error: input filename ($filename) doesn't exist.\n";
140 _debug("importing $filename for user $username...\n");
142 $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$username'");
144 if (db_num_rows($result) == 0) {
145 print "error: could not find user $username.\n";
149 $owner_uid = db_fetch_result($result, 0, "id");
151 perform_data_import($link, $filename, $owner_uid);
155 if (in_array("-indexes", $op)) {
156 _debug("PLEASE BACKUP YOUR DATABASE BEFORE PROCEEDING!");
157 _debug("Type 'yes' to continue.");
159 if (read_stdin() != 'yes')
162 _debug("clearing existing indexes...");
164 if (DB_TYPE
== "pgsql") {
165 $result = db_query($link, "SELECT relname FROM
166 pg_catalog.pg_class WHERE relname LIKE 'ttrss_%'
167 AND relname NOT LIKE '%_pkey'
170 $result = db_query($link, "SELECT index_name,table_name FROM
171 information_schema.statistics WHERE index_name LIKE 'ttrss_%'");
174 while ($line = db_fetch_assoc($result)) {
175 if (DB_TYPE
== "pgsql") {
176 $statement = "DROP INDEX " . $line["relname"];
179 $statement = "ALTER TABLE ".
180 $line['table_name']." DROP INDEX ".$line['index_name'];
183 db_query($link, $statement, false);
186 _debug("reading indexes from schema for: " . DB_TYPE
);
188 $fp = fopen("schema/ttrss_schema_" . DB_TYPE
. ".sql", "r");
190 while ($line = fgets($fp)) {
193 if (preg_match("/^create index ([^ ]+) on ([^ ]+)$/i", $line, $matches)) {
194 $index = $matches[1];
195 $table = $matches[2];
197 $statement = "CREATE INDEX $index ON $table";
200 db_query($link, $statement);
205 _debug("unable to open schema file.");
212 if ($lock_handle != false) {
213 fclose($lock_handle);
216 unlink(LOCK_DIRECTORY
. "/$lock_filename");