]>
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 if (in_array("-feeds", $op)) {
60 // Update all feeds needing a update.
61 update_daemon_common($link);
64 $count = update_feedbrowser_cache($link);
65 _debug("Feedbrowser updated, $count feeds processed.");
67 // Purge orphans and cleanup tags
68 purge_orphans($link, true);
70 $rc = cleanup_tags($link, 14, 50000);
71 _debug("Cleaned $rc cached tags.");
73 get_linked_feeds($link);
76 if (in_array("-feedbrowser", $op)) {
77 $count = update_feedbrowser_cache($link);
78 print "Finished, $count feeds processed.\n";
81 if (in_array("-daemon", $op)) {
82 $op = array_diff($op, array("-daemon"));
84 passthru(PHP_EXECUTABLE
. " " . implode(' ', $op) . " -daemon-loop");
85 _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL
. " seconds...");
86 sleep(DAEMON_SLEEP_INTERVAL
);
90 if (in_array("-daemon-loop", $op)) {
91 if (!make_stampfile('update_daemon.stamp')) {
92 die("error: unable to create stampfile\n");
95 // Call to the feed batch update function
96 // or regenerate feedbrowser cache
98 if (rand(0,100) > 30) {
99 update_daemon_common($link);
101 $count = update_feedbrowser_cache($link);
102 _debug("Feedbrowser updated, $count feeds processed.");
104 purge_orphans($link, true);
106 $rc = cleanup_tags($link, 14, 50000);
108 _debug("Cleaned $rc cached tags.");
110 get_linked_feeds($link);
115 if (in_array("-cleanup-tags", $op)) {
116 $rc = cleanup_tags($link, 14, 50000);
117 _debug("$rc tags deleted.\n");
120 if (in_array("-get-feeds", $op)) {
121 get_linked_feeds($link);
124 if (in_array("-import",$op)) {
125 $username = $argv[count($argv) - 2];
126 $filename = $argv[count($argv) - 1];
129 print "error: please specify username.\n";
133 if (!is_file($filename)) {
134 print "error: input filename ($filename) doesn't exist.\n";
138 _debug("importing $filename for user $username...\n");
140 $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$username'");
142 if (db_num_rows($result) == 0) {
143 print "error: could not find user $username.\n";
147 $owner_uid = db_fetch_result($result, 0, "id");
149 perform_data_import($link, $filename, $owner_uid);
153 if (in_array("-indexes", $op)) {
154 _debug("PLEASE BACKUP YOUR DATABASE BEFORE PROCEEDING!");
155 _debug("Type 'yes' to continue.");
157 if (read_stdin() != 'yes')
160 _debug("clearing existing indexes...");
162 if (DB_TYPE
== "pgsql") {
163 $result = db_query($link, "SELECT relname FROM
164 pg_catalog.pg_class WHERE relname LIKE 'ttrss_%'
165 AND relname NOT LIKE '%_pkey'
168 $result = db_query($link, "SELECT index_name,table_name FROM
169 information_schema.statistics WHERE index_name LIKE 'ttrss_%'");
172 while ($line = db_fetch_assoc($result)) {
173 if (DB_TYPE
== "pgsql") {
174 $statement = "DROP INDEX " . $line["relname"];
177 $statement = "ALTER TABLE ".
178 $line['table_name']." DROP INDEX ".$line['index_name'];
181 db_query($link, $statement, false);
184 _debug("reading indexes from schema for: " . DB_TYPE
);
186 $fp = fopen("schema/ttrss_schema_" . DB_TYPE
. ".sql", "r");
188 while ($line = fgets($fp)) {
191 if (preg_match("/^create index ([^ ]+) on ([^ ]+)$/i", $line, $matches)) {
192 $index = $matches[1];
193 $table = $matches[2];
195 $statement = "CREATE INDEX $index ON $table";
198 db_query($link, $statement);
203 _debug("unable to open schema file.");
210 if ($lock_handle != false) {
211 fclose($lock_handle);
214 unlink(LOCK_DIRECTORY
. "/$lock_filename");