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