]> git.wh0rd.org - tt-rss.git/blame - update.php
show empty categories in italic in category editor
[tt-rss.git] / update.php
CommitLineData
661135c7 1#!/usr/bin/php
fecd57c8 2<?php
55f34b81 3 set_include_path(get_include_path() . PATH_SEPARATOR .
f03a795d 4 dirname(__FILE__) . "/include");
107d0cf3 5
661135c7
AD
6 define('DISABLE_SESSIONS', true);
7
9b27cec8
AD
8 chdir(dirname(__FILE__));
9
fb074239 10 require_once "functions.php";
2c08214a 11 require_once "rssfuncs.php";
81596c66 12 require_once "sanity_check.php";
81596c66
AD
13 require_once "config.php";
14 require_once "db.php";
661135c7 15 require_once "db-prefs.php";
661135c7 16
86268d8b
AD
17 if (!defined('PHP_EXECUTABLE'))
18 define('PHP_EXECUTABLE', '/usr/bin/php');
19
661135c7 20 $op = $argv[1];
70dcff6b 21
661135c7
AD
22 if (!$op || $op == "-help") {
23 print "Tiny Tiny RSS data update script.\n\n";
24 print "Options:\n";
55f34b81
AD
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 " -help - show this help\n";
661135c7 32 return;
81596c66 33 }
87b9fb65 34
661135c7
AD
35 if ($op != "-daemon") {
36 $lock_filename = "update.lock";
37 } else {
38 $lock_filename = "update_daemon.lock";
39 }
fecd57c8 40
661135c7
AD
41 $lock_handle = make_lockfile($lock_filename);
42 $must_exit = false;
fecd57c8 43
661135c7
AD
44 // Try to lock a file in order to avoid concurrent update.
45 if (!$lock_handle) {
46 die("error: Can't create lockfile ($lock_filename). ".
47 "Maybe another update process is already running.\n");
48 }
fecd57c8 49
661135c7 50 // Create a database connection.
dbaa4e4a 51 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
fecd57c8 52
661135c7 53 init_connection($link);
ef59e6e8 54
661135c7
AD
55 if ($op == "-feeds") {
56 // Update all feeds needing a update.
57 update_daemon_common($link);
84e9a8c7
AD
58
59 // Update feedbrowser
60 $count = update_feedbrowser_cache($link);
61 _debug("Feedbrowser updated, $count feeds processed.");
62
63 // Purge orphans and cleanup tags
64 purge_orphans($link, true);
65
66 $rc = cleanup_tags($link, 14, 50000);
67 _debug("Cleaned $rc cached tags.");
f32eb194
AD
68
69 get_linked_feeds($link);
661135c7 70 }
fecd57c8 71
661135c7
AD
72 if ($op == "-feedbrowser") {
73 $count = update_feedbrowser_cache($link);
74 print "Finished, $count feeds processed.\n";
fecd57c8 75 }
661135c7
AD
76
77 if ($op == "-daemon") {
661135c7
AD
78 while (true) {
79 passthru(PHP_EXECUTABLE . " " . $argv[0] . " -daemon-loop");
80 _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL . " seconds...");
81 sleep(DAEMON_SLEEP_INTERVAL);
fecd57c8 82 }
81596c66 83 }
9e21a571 84
661135c7
AD
85 if ($op == "-daemon-loop") {
86 if (!make_stampfile('update_daemon.stamp')) {
87 die("error: unable to create stampfile\n");
88 }
9e21a571 89
dbaa4e4a 90 // Call to the feed batch update function
661135c7 91 // or regenerate feedbrowser cache
9e21a571 92
661135c7
AD
93 if (rand(0,100) > 30) {
94 update_daemon_common($link);
9e21a571 95 } else {
661135c7 96 $count = update_feedbrowser_cache($link);
e3b42c5a
AD
97 _debug("Feedbrowser updated, $count feeds processed.");
98
99 purge_orphans($link, true);
dbaa4e4a 100
e3b42c5a
AD
101 $rc = cleanup_tags($link, 14, 50000);
102
103 _debug("Cleaned $rc cached tags.");
f32eb194
AD
104
105 get_linked_feeds($link);
9e21a571 106 }
ef59e6e8 107
fecd57c8 108 }
fecd57c8 109
868650e4
AD
110 if ($op == "-cleanup-tags") {
111 $rc = cleanup_tags($link, 14, 50000);
112 print "$rc tags deleted.\n";
113 }
114
ae5f7bb1
AD
115 if ($op == "-get-feeds") {
116 get_linked_feeds($link);
117 }
118
55f34b81
AD
119 if ($op == "-import") {
120 $username = $argv[2];
121 $filename = $argv[3];
122
123 if (!$username) {
124 print "error: please specify username.\n";
125 return;
126 }
127
128 if (!is_file($filename)) {
129 print "error: input filename ($filename) doesn't exist.\n";
130 return;
131 }
132
133 print "importing $filename for user $username...\n";
134
135 $result = db_query($link, "SELECT id FROM ttrss_users WHERE login = '$username'");
136
137 if (db_num_rows($result) == 0) {
138 print "error: could not find user $username.\n";
139 return;
140 }
141
142 $owner_uid = db_fetch_result($result, 0, "id");
143
144 perform_data_import($link, $filename, $owner_uid);
145
146 }
147
661135c7 148 db_close($link);
107d0cf3 149