]> git.wh0rd.org - tt-rss.git/blob - update.php
fix help not loading on ? press
[tt-rss.git] / update.php
1 #!/usr/bin/php
2 <?php
3 set_include_path(get_include_path() . PATH_SEPARATOR .
4 dirname(__FILE__) . "/include");
5
6 define('DISABLE_SESSIONS', true);
7
8 chdir(dirname(__FILE__));
9
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
17 if (!defined('PHP_EXECUTABLE'))
18 define('PHP_EXECUTABLE', '/usr/bin/php');
19
20 $op = $argv[1];
21
22 if (!$op || $op == "-help") {
23 print "Tiny Tiny RSS data update script.\n\n";
24 print "Options:\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 " -help - show this help\n";
31 return;
32 }
33
34 if ($op != "-daemon") {
35 $lock_filename = "update.lock";
36 } else {
37 $lock_filename = "update_daemon.lock";
38 }
39
40 $lock_handle = make_lockfile($lock_filename);
41 $must_exit = false;
42
43 // Try to lock a file in order to avoid concurrent update.
44 if (!$lock_handle) {
45 die("error: Can't create lockfile ($lock_filename). ".
46 "Maybe another update process is already running.\n");
47 }
48
49 // Create a database connection.
50 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
51
52 init_connection($link);
53
54 if ($op == "-feeds") {
55 // Update all feeds needing a update.
56 update_daemon_common($link);
57
58 // Update feedbrowser
59 $count = update_feedbrowser_cache($link);
60 _debug("Feedbrowser updated, $count feeds processed.");
61
62 // Purge orphans and cleanup tags
63 purge_orphans($link, true);
64
65 $rc = cleanup_tags($link, 14, 50000);
66 _debug("Cleaned $rc cached tags.");
67
68 get_linked_feeds($link);
69 }
70
71 if ($op == "-feedbrowser") {
72 $count = update_feedbrowser_cache($link);
73 print "Finished, $count feeds processed.\n";
74 }
75
76 if ($op == "-daemon") {
77 while (true) {
78 passthru(PHP_EXECUTABLE . " " . $argv[0] . " -daemon-loop");
79 _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL . " seconds...");
80 sleep(DAEMON_SLEEP_INTERVAL);
81 }
82 }
83
84 if ($op == "-daemon-loop") {
85 if (!make_stampfile('update_daemon.stamp')) {
86 die("error: unable to create stampfile\n");
87 }
88
89 // Call to the feed batch update function
90 // or regenerate feedbrowser cache
91
92 if (rand(0,100) > 30) {
93 update_daemon_common($link);
94 } else {
95 $count = update_feedbrowser_cache($link);
96 _debug("Feedbrowser updated, $count feeds processed.");
97
98 purge_orphans($link, true);
99
100 $rc = cleanup_tags($link, 14, 50000);
101
102 _debug("Cleaned $rc cached tags.");
103
104 get_linked_feeds($link);
105 }
106
107 }
108
109 if ($op == "-cleanup-tags") {
110 $rc = cleanup_tags($link, 14, 50000);
111 print "$rc tags deleted.\n";
112 }
113
114 if ($op == "-get-feeds") {
115 get_linked_feeds($link);
116 }
117
118 db_close($link);
119
120 if ($lock_handle != false) {
121 fclose($lock_handle);
122 }
123
124 unlink(LOCK_DIRECTORY . "/$lock_filename");
125 ?>