]>
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 " -help - show this help\n";
58 define('QUIET', in_array("-quiet", $op));
60 if (!in_array("-daemon", $op)) {
61 $lock_filename = "update.lock";
63 $lock_filename = "update_daemon.lock";
66 $lock_handle = make_lockfile($lock_filename);
69 // Try to lock a file in order to avoid concurrent update.
71 die("error: Can't create lockfile ($lock_filename). ".
72 "Maybe another update process is already running.\n");
75 // Create a database connection.
76 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
78 init_connection($link);
80 if (in_array("-feeds", $op)) {
81 // Update all feeds needing a update.
82 update_daemon_common($link);
85 $count = update_feedbrowser_cache($link);
86 _debug("Feedbrowser updated, $count feeds processed.");
88 // Purge orphans and cleanup tags
89 purge_orphans($link, true);
91 $rc = cleanup_tags($link, 14, 50000);
92 _debug("Cleaned $rc cached tags.");
94 get_linked_feeds($link);
97 if (in_array("-feedbrowser", $op)) {
98 $count = update_feedbrowser_cache($link);
99 print "Finished, $count feeds processed.\n";
102 if (in_array("-daemon", $op)) {
103 $op = array_diff($op, array("-daemon"));
105 passthru(PHP_EXECUTABLE
. " " . implode(' ', $op) . " -daemon-loop");
106 _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL
. " seconds...");
107 sleep(DAEMON_SLEEP_INTERVAL
);
111 if (in_array("-daemon-loop", $op)) {
112 if (!make_stampfile('update_daemon.stamp')) {
113 die("error: unable to create stampfile\n");
116 // Call to the feed batch update function
117 // or regenerate feedbrowser cache
119 if (rand(0,100) > 30) {
120 update_daemon_common($link);
122 $count = update_feedbrowser_cache($link);
123 _debug("Feedbrowser updated, $count feeds processed.");
125 purge_orphans($link, true);
127 $rc = cleanup_tags($link, 14, 50000);
129 _debug("Cleaned $rc cached tags.");
131 get_linked_feeds($link);
136 if (in_array("-cleanup-tags", $op)) {
137 $rc = cleanup_tags($link, 14, 50000);
138 _debug("$rc tags deleted.\n");
141 if (in_array("-get-feeds", $op)) {
142 get_linked_feeds($link);
145 if (in_array("-import",$op)) {
146 $username = $argv[count($argv) - 2];
147 $filename = $argv[count($argv) - 1];
150 print "error: please specify username.\n";
154 if (!is_file($filename)) {
155 print "error: input filename ($filename) doesn't exist.\n";
159 _debug("importing $filename for user $username...\n");
161 $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$username'");
163 if (db_num_rows($result) == 0) {
164 print "error: could not find user $username.\n";
168 $owner_uid = db_fetch_result($result, 0, "id");
170 perform_data_import($link, $filename, $owner_uid);
174 if (in_array("-indexes", $op)) {
175 _debug("PLEASE BACKUP YOUR DATABASE BEFORE PROCEEDING!");
176 _debug("Type 'yes' to continue.");
178 if (read_stdin() != 'yes')
181 _debug("clearing existing indexes...");
183 if (DB_TYPE
== "pgsql") {
184 $result = db_query($link, "SELECT relname FROM
185 pg_catalog.pg_class WHERE relname LIKE 'ttrss_%'
186 AND relname NOT LIKE '%_pkey'
189 $result = db_query($link, "SELECT index_name,table_name FROM
190 information_schema.statistics WHERE index_name LIKE 'ttrss_%'");
193 while ($line = db_fetch_assoc($result)) {
194 if (DB_TYPE
== "pgsql") {
195 $statement = "DROP INDEX " . $line["relname"];
198 $statement = "ALTER TABLE ".
199 $line['table_name']." DROP INDEX ".$line['index_name'];
202 db_query($link, $statement, false);
205 _debug("reading indexes from schema for: " . DB_TYPE
);
207 $fp = fopen("schema/ttrss_schema_" . DB_TYPE
. ".sql", "r");
209 while ($line = fgets($fp)) {
212 if (preg_match("/^create index ([^ ]+) on ([^ ]+)$/i", $line, $matches)) {
213 $index = $matches[1];
214 $table = $matches[2];
216 $statement = "CREATE INDEX $index ON $table";
219 db_query($link, $statement);
224 _debug("unable to open schema file.");
229 if (in_array("-update-self", $op)) {
230 _debug("Warning: self-updating is experimental. Use at your own risk.");
231 _debug("Please backup your tt-rss directory before continuing. Your database will not be modified.");
232 _debug("Type 'yes' to continue.");
234 if (read_stdin() != 'yes')
237 update_self($link, in_array("-force", $op));
242 if ($lock_handle != false) {
243 fclose($lock_handle);
246 if (file_exists(LOCK_DIRECTORY
. "/$lock_filename"))
247 unlink(LOCK_DIRECTORY
. "/$lock_filename");