]>
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 " -help - show this help\n";
36 define('QUIET', in_array("-quiet", $op));
38 if (!in_array("-daemon", $op)) {
39 $lock_filename = "update.lock";
41 $lock_filename = "update_daemon.lock";
44 $lock_handle = make_lockfile($lock_filename);
47 // Try to lock a file in order to avoid concurrent update.
49 die("error: Can't create lockfile ($lock_filename). ".
50 "Maybe another update process is already running.\n");
53 // Create a database connection.
54 $link = db_connect(DB_HOST
, DB_USER
, DB_PASS
, DB_NAME
);
56 init_connection($link);
58 if (in_array("-feeds", $op)) {
59 // Update all feeds needing a update.
60 update_daemon_common($link);
63 $count = update_feedbrowser_cache($link);
64 _debug("Feedbrowser updated, $count feeds processed.");
66 // Purge orphans and cleanup tags
67 purge_orphans($link, true);
69 $rc = cleanup_tags($link, 14, 50000);
70 _debug("Cleaned $rc cached tags.");
72 get_linked_feeds($link);
75 if (in_array("-feedbrowser", $op)) {
76 $count = update_feedbrowser_cache($link);
77 print "Finished, $count feeds processed.\n";
80 if (in_array("-daemon", $op)) {
81 $op = array_diff($op, array("-daemon"));
83 passthru(PHP_EXECUTABLE
. " " . implode(' ', $op) . " -daemon-loop");
84 _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL
. " seconds...");
85 sleep(DAEMON_SLEEP_INTERVAL
);
89 if (in_array("-daemon-loop", $op)) {
90 if (!make_stampfile('update_daemon.stamp')) {
91 die("error: unable to create stampfile\n");
94 // Call to the feed batch update function
95 // or regenerate feedbrowser cache
97 if (rand(0,100) > 30) {
98 update_daemon_common($link);
100 $count = update_feedbrowser_cache($link);
101 _debug("Feedbrowser updated, $count feeds processed.");
103 purge_orphans($link, true);
105 $rc = cleanup_tags($link, 14, 50000);
107 _debug("Cleaned $rc cached tags.");
109 get_linked_feeds($link);
114 if (in_array("-cleanup-tags", $op)) {
115 $rc = cleanup_tags($link, 14, 50000);
116 _debug("$rc tags deleted.\n");
119 if (in_array("-get-feeds", $op)) {
120 get_linked_feeds($link);
123 if (in_array("-import",$op)) {
124 $username = $argv[count($argv) - 2];
125 $filename = $argv[count($argv) - 1];
128 print "error: please specify username.\n";
132 if (!is_file($filename)) {
133 print "error: input filename ($filename) doesn't exist.\n";
137 _debug("importing $filename for user $username...\n");
139 $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$username'");
141 if (db_num_rows($result) == 0) {
142 print "error: could not find user $username.\n";
146 $owner_uid = db_fetch_result($result, 0, "id");
148 perform_data_import($link, $filename, $owner_uid);
154 if ($lock_handle != false) {
155 fclose($lock_handle);
158 unlink(LOCK_DIRECTORY
. "/$lock_filename");