Safely changing a store to inactive or active

From Zarafa wiki

Revision as of 09:44, 30 December 2010 by Msartor (Talk | contribs)
Jump to: navigation, search

This page will describe how to change a store to active or inactive preserving the data that is in the store.

This page only applies to Zarafa versions < 6.40 (in Zarafa 6.40 or higher, you are able to change active <-> inactive on the fly, without Zarafa orphaning the store).

Explanation of fields

You need to do two changes per store:

  • Change the type of the store in the database
  • Change the LDAP attribute of the store

The MySQL changes you need to do are in the users table. The users table has the following fields:

1. id          | int(11)        ->  Internal ID of user
2. externid    | blob           ->  External ID of user
3. object_type | int(11)        ->  1=active, 5=inactive(shared store)
4. signature   | varchar(255)
5. company     | int(11) 

For field nr. 2 the following goes: The value depends on the back-end you are using. If you are using OpenLDAP the externid will probably be an integer (mostly used is uidNumber)... If you use ADS as back-end then the externid is a binary value which is really hard to relate to any user.

Below you will find a PHP script which you can place on the Zarafa server somewhere so that you can access it from a web browser.

You need to modify the credentials on top of the script (any Zarafa user will do). This script will get all the users from Zarafa and will show an HTML table. The last field is the internal id (field nr. 1) of the user. So this can make it easier for you finding the id's of the stores you want to make inactive or active.

The steps

So the steps to change a store would be:

  • Find all the id's of the stores you want to make inactive with the PHP script.
  • Write a script that will do the following SQL statement for each user you want to change (object_type=1 for active, object_type=5 for inactive):
update users set object_type=[new_object_type] where id=[internal ID]

Or if you want to use external ID (with OpenLDAP -> Of course internal id will also work):

update users set object_type=[new_object_type] where externid=[external ID]
  • Stop Zarafa-server
  • Run the MySQL script
  • Change the stores to inactive (shared store) in LDAP (DO NOT FORGET)
  • check check, double check
  • Start Zarafa-server

The script

Here you find the PHP script (change credentials to a valid Zarafa user). This script shows an HTML table which will show all the Zarafa stores, the last field in each row contains the internal id of the store (field nr.1 in users table).

* {
  font-family: verdana;
  font-size: 8pt;




$session = mapi_logon_zarafa("$zarafa_user","$zarafa_pass", "$zarafa_sock");
if(!$session) { print "Unable to open session\n"; exit(1); }

$msgstorestable = mapi_getmsgstorestable($session);
if(!$msgstorestable) { print "Unable to open message stores table\n"; exit(1); }

$msgstores = mapi_table_queryallrows($msgstorestable, array(PR_DEFAULT_STORE, PR_ENTRYID));

foreach ($msgstores as $row) {
    if($row[PR_DEFAULT_STORE]) {
        $storeentryid = $row[PR_ENTRYID];

if(!$storeentryid) { print "Can't find default store\n"; exit(1); }

$store = mapi_openmsgstore($session, $storeentryid);
if(!$store) { print "Unable to open default store\n"; exit(1); }

$ab = mapi_openaddressbook($session);
if(!$ab) { print "Unable to open addressbook\n"; exit(1); }

$gabid = mapi_ab_getdefaultdir($ab);
if(!$gabid) { print "Unable to get default dir\n"; exit(1); }

$gab = mapi_ab_openentry($ab, $gabid);
if(!$gab) { print "Unable to open GAB $gabid\n"; exit(1); }

$table = mapi_folder_getcontentstable($gab);
if(!$table) { print "Unable to get GAB table\n"; exit(1); }

$rows = mapi_table_queryallrows($table);

$columns = Array();
// Find all the used 'string' type columns first
foreach($rows as $row) {
  foreach($row as $proptag => $propval) {
   if(mapi_prop_type($proptag) == PT_STRING8)
     $columns[$proptag] = 1; 

// Dump all the data
print "Zarafa Global Addresslist:\n";
print "<p>\n";
print "<TABLE>\n";
foreach($rows as $row) {
  $color = $i %2 ? '#eeeeee' : '#dddddd';
  print "<TR style='background: $color'>";
  foreach($columns as $proptag => $dummy) {
    print "<TD>";
    if(isset($row[$proptag])) {
      print $row[$proptag];
    } else {
      print " ";
    print "</TD>";
  print "<TD>";
  $array = unpack("lunk/lunk/lunk/lunk/lunk/lunk/Ltype/Lid",$row[PR_ENTRYID]);
  print $array["id"];
  print "</TD>";
  print "</TR>\n";
print "</TABLE>\n";

Personal tools