]> git.donarmstrong.com Git - roundcube.git/blob - bin/indexcontacts.sh
Imported Upstream version 0.7
[roundcube.git] / bin / indexcontacts.sh
1 #!/usr/bin/env php
2 <?php
3 /*
4
5  +-----------------------------------------------------------------------+
6  | bin/indexcontacts.sh                                                  |
7  |                                                                       |
8  | This file is part of the Roundcube Webmail client                     |
9  | Copyright (C) 2011, The Roundcube Dev Team                            |
10  | Licensed under the GNU GPL                                            |
11  |                                                                       |
12  | PURPOSE:                                                              |
13  |   Update the fulltext index for all contacts of the internal          |
14  |   address book.                                                       |
15  +-----------------------------------------------------------------------+
16  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
17  +-----------------------------------------------------------------------+
18
19  $Id: indexcontacts.sh 5307 2011-10-05 09:28:25Z alec $
20
21 */
22
23 define('INSTALL_PATH', realpath(dirname(__FILE__) . '/..') . '/' );
24
25 require_once INSTALL_PATH.'program/include/clisetup.php';
26 ini_set('memory_limit', -1);
27
28 // connect to DB
29 $RCMAIL = rcmail::get_instance();
30
31 $db = $RCMAIL->get_dbh();
32 $db->db_connect('w');
33
34 if (!$db->is_connected() || $db->is_error())
35     die("No DB connection\n");
36
37 // iterate over all users
38 $sql_result = $db->query("SELECT user_id FROM " . $RCMAIL->config->get('db_table_users', 'users')." WHERE 1=1");
39 while ($sql_result && ($sql_arr = $db->fetch_assoc($sql_result))) {
40     echo "Indexing contacts for user " . $sql_arr['user_id'] . "...";
41     
42     $contacts = new rcube_contacts($db, $sql_arr['user_id']);
43     $contacts->set_pagesize(9999);
44     
45     $result = $contacts->list_records();
46     while ($result->count && ($row = $result->next())) {
47         unset($row['words']);
48         $contacts->update($row['ID'], $row);
49     }
50
51     echo "done.\n";
52 }
53
54 ?>