Aleksander Machniak
2015-11-17 818b78a89381be2f4de55c4f6a189da9379a1a3a
commit | author | age
3e2637 1 #!/usr/bin/env php
T 2 <?php
3 /*
4  +-----------------------------------------------------------------------+
5  | bin/indexcontacts.sh                                                  |
6  |                                                                       |
7  | This file is part of the Roundcube Webmail client                     |
8  | Copyright (C) 2011, The Roundcube Dev Team                            |
7fe381 9  |                                                                       |
T 10  | Licensed under the GNU General Public License version 3 or            |
11  | any later version with exceptions for skins & plugins.                |
12  | See the README file for a full license statement.                     |
3e2637 13  |                                                                       |
T 14  | PURPOSE:                                                              |
15  |   Update the fulltext index for all contacts of the internal          |
16  |   address book.                                                       |
17  +-----------------------------------------------------------------------+
18  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
19  +-----------------------------------------------------------------------+
20 */
21
0ea079 22 define('INSTALL_PATH', realpath(__DIR__ . '/..') . '/' );
3e2637 23
T 24 require_once INSTALL_PATH.'program/include/clisetup.php';
4aafd9 25 ini_set('memory_limit', -1);
3e2637 26
T 27 // connect to DB
dcc446 28 $RCMAIL = rcube::get_instance();
3e2637 29
T 30 $db = $RCMAIL->get_dbh();
31 $db->db_connect('w');
32
f23ef1 33 if (!$db->is_connected() || $db->is_error()) {
AM 34     rcube::raise_error("No DB connection", false, true);
35 }
3e2637 36
T 37 // iterate over all users
34a090 38 $sql_result = $db->query("SELECT `user_id` FROM " . $db->table_name('users', true) . " ORDER BY `user_id`");
3e2637 39 while ($sql_result && ($sql_arr = $db->fetch_assoc($sql_result))) {
T 40     echo "Indexing contacts for user " . $sql_arr['user_id'] . "...";
f23ef1 41
3e2637 42     $contacts = new rcube_contacts($db, $sql_arr['user_id']);
T 43     $contacts->set_pagesize(9999);
f23ef1 44
3e2637 45     $result = $contacts->list_records();
T 46     while ($result->count && ($row = $result->next())) {
47         unset($row['words']);
48         $contacts->update($row['ID'], $row);
49     }
4aafd9 50
3e2637 51     echo "done.\n";
T 52 }
53
54 ?>