]> git.wh0rd.org - tt-rss.git/blob - update_feeds.php
update_daemon2: fix locking
[tt-rss.git] / update_feeds.php
1 #!/usr/bin/php
2 <?php
3 // this script is probably run not from your httpd-user, so cache
4 // directory defined in config.php won't be accessible
5 define('MAGPIE_CACHE_DIR', '/var/tmp/magpie-ttrss-cache-cli');
6 define('SIMPLEPIE_CACHE_DIR', '/var/tmp/simplepie-ttrss-cache-cli');
7 define('DEFAULT_ERROR_LEVEL', E_ERROR | E_WARNING | E_PARSE);
8 define('DISABLE_SESSIONS', true);
9
10 error_reporting(DEFAULT_ERROR_LEVEL);
11
12 require_once "sanity_check.php";
13 require_once "config.php";
14 require_once "db.php";
15 require_once "db-prefs.php";
16 require_once "functions.php";
17
18 $lock_filename = "update_feeds.lock";
19
20 $lock_handle = make_lockfile($lock_filename);
21
22 if (!$lock_handle) {
23 die("error: Can't create lockfile ($lock_filename). ".
24 "Maybe another process is already running.\n");
25 }
26
27 $link = db_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
28
29 if (!$link) {
30 if (DB_TYPE == "mysql") {
31 print mysql_error();
32 }
33 // PG seems to display its own errors just fine by default.
34 return;
35 }
36
37 if (DB_TYPE == "pgsql") {
38 pg_query("set client_encoding = 'utf-8'");
39 pg_set_client_encoding("UNICODE");
40 } else {
41 if (defined('MYSQL_CHARSET') && MYSQL_CHARSET) {
42 db_query($link, "SET NAMES " . MYSQL_CHARSET);
43 // db_query($link, "SET CHARACTER SET " . MYSQL_CHARSET);
44 }
45 }
46
47 $result = db_query($link, "SELECT id FROM ttrss_users");
48
49 while ($line = db_fetch_assoc($result)) {
50 $user_id = $line["id"];
51 initialize_user_prefs($link, $user_id);
52 update_all_feeds($link, false, $user_id, true);
53 }
54
55 if (DAEMON_SENDS_DIGESTS) send_headlines_digests($link);
56
57 db_close($link);
58
59 unlink(LOCK_DIRECTORY . "/$lock_filename");
60 ?>