]> git.wh0rd.org - tt-rss.git/blame - update.php
backend/fbexport: read key from _POST
[tt-rss.git] / update.php
CommitLineData
661135c7 1#!/usr/bin/php
fecd57c8 2<?php
661135c7
AD
3 define('DISABLE_SESSIONS', true);
4
9b27cec8
AD
5 chdir(dirname(__FILE__));
6
fb074239 7 require_once "functions.php";
81596c66 8 require_once "sanity_check.php";
81596c66
AD
9 require_once "config.php";
10 require_once "db.php";
661135c7 11 require_once "db-prefs.php";
661135c7 12
86268d8b
AD
13 if (!defined('PHP_EXECUTABLE'))
14 define('PHP_EXECUTABLE', '/usr/bin/php');
15
661135c7 16 $op = $argv[1];
70dcff6b 17
661135c7
AD
18 if (!$op || $op == "-help") {
19 print "Tiny Tiny RSS data update script.\n\n";
20 print "Options:\n";
21 print " -feeds - update feeds\n";
22 print " -feedbrowser - update feedbrowser\n";
23 print " -daemon - start single-process update daemon\n";
868650e4 24 print " -cleanup-tags - perform tags table maintenance\n";
ae5f7bb1 25 print " -get-feeds - receive popular feeds from linked instances\n";
661135c7
AD
26 print " -help - show this help\n";
27 return;
81596c66 28 }
87b9fb65 29
661135c7
AD
30 if ($op != "-daemon") {
31 $lock_filename = "update.lock";
32 } else {
33 $lock_filename = "update_daemon.lock";
34 }
fecd57c8 35
661135c7
AD
36 $lock_handle = make_lockfile($lock_filename);
37 $must_exit = false;
fecd57c8 38
661135c7
AD
39 // Try to lock a file in order to avoid concurrent update.
40 if (!$lock_handle) {
41 die("error: Can't create lockfile ($lock_filename). ".
42 "Maybe another update process is already running.\n");
43 }
fecd57c8 44
661135c7 45 // Create a database connection.
dbaa4e4a 46 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
fecd57c8 47
661135c7
AD
48 if (!$link) {
49 if (DB_TYPE == "mysql") {
50 print mysql_error();
51 }
dbaa4e4a 52 // PG seems to display its own errors just fine by default.
661135c7
AD
53 return;
54 }
b4c27af7 55
661135c7 56 init_connection($link);
ef59e6e8 57
661135c7
AD
58 if ($op == "-feeds") {
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.");
661135c7 71 }
fecd57c8 72
661135c7
AD
73 if ($op == "-feedbrowser") {
74 $count = update_feedbrowser_cache($link);
75 print "Finished, $count feeds processed.\n";
fecd57c8 76 }
661135c7
AD
77
78 if ($op == "-daemon") {
661135c7
AD
79 while (true) {
80 passthru(PHP_EXECUTABLE . " " . $argv[0] . " -daemon-loop");
81 _debug("Sleeping for " . DAEMON_SLEEP_INTERVAL . " seconds...");
82 sleep(DAEMON_SLEEP_INTERVAL);
fecd57c8 83 }
81596c66 84 }
9e21a571 85
661135c7
AD
86 if ($op == "-daemon-loop") {
87 if (!make_stampfile('update_daemon.stamp')) {
88 die("error: unable to create stampfile\n");
89 }
9e21a571 90
dbaa4e4a 91 // Call to the feed batch update function
661135c7 92 // or regenerate feedbrowser cache
9e21a571 93
661135c7
AD
94 if (rand(0,100) > 30) {
95 update_daemon_common($link);
9e21a571 96 } else {
661135c7 97 $count = update_feedbrowser_cache($link);
e3b42c5a
AD
98 _debug("Feedbrowser updated, $count feeds processed.");
99
100 purge_orphans($link, true);
dbaa4e4a 101
e3b42c5a
AD
102 $rc = cleanup_tags($link, 14, 50000);
103
104 _debug("Cleaned $rc cached tags.");
9e21a571 105 }
ef59e6e8 106
fecd57c8 107 }
fecd57c8 108
868650e4
AD
109 if ($op == "-cleanup-tags") {
110 $rc = cleanup_tags($link, 14, 50000);
111 print "$rc tags deleted.\n";
112 }
113
ae5f7bb1
AD
114 if ($op == "-get-feeds") {
115 get_linked_feeds($link);
116 }
117
661135c7 118 db_close($link);
fecd57c8 119
661135c7
AD
120 unlink(LOCK_DIRECTORY . "/$lock_filename");
121?>