forked from chilek/google_addressbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync-cli.sh
executable file
·48 lines (38 loc) · 1.73 KB
/
sync-cli.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env php
<?php
/*
+-----------------------------------------------------------------------+
| sync-cli.sh |
| |
| Licensed under the GNU General Public License version 3 |
| |
| PURPOSE: |
| Sync your google addressbook via cli. |
+-----------------------------------------------------------------------+
| Author: Stefan Wagner <[email protected]> |
+-----------------------------------------------------------------------+
*/
define('INSTALL_PATH', realpath(dirname(__FILE__) . '/../..') . '/' );
require_once INSTALL_PATH.'program/include/clisetup.php';
require_once(dirname(__FILE__) . '/google_func.php');
ini_set('memory_limit', -1);
// connect to DB
$rcmail = rcmail::get_instance();
$db = $rcmail->get_dbh();
$db->db_connect('w');
if (!$db->is_connected() || $db->is_error())
die("No DB connection\n");
$rcmail->config->load_from_file(dirname(__FILE__) . '/config.inc.php.dist');
$rcmail->config->load_from_file(dirname(__FILE__) . '/config.inc.php');
$sql_result = $db->query("SELECT * FROM ".$db->table_name('users'));
while ($sql_result && ($sql_arr = $db->fetch_assoc($sql_result))) {
echo "Syncing contacts for user " . $sql_arr['username'] . "... ";
$user = new rcube_user($sql_arr['user_id'], $sql_arr);
if(google_func::is_enabled($user)) {
$res = google_func::google_sync_contacts($user);
echo $res['message']."\n";
} else {
echo "disabled.\n";
}
}
?>