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