Safely changing a store to inactive or active

From Zarafa wiki

(Difference between revisions)
Jump to: navigation, search
(New page: This page will describe howto change a store to active or inactive without losing the data that is in the store. This page only applies to zarafa versions < 6.40 (in zarafa 6.40 or highe...)
 
(9 intermediate revisions not shown)
Line 1: Line 1:
-
This page will describe howto change a store to active or inactive without losing the data that is in the store.
+
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).
+
'''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====
+
==Explanation of fields==
-
You need to do 2 changes per store:
+
You need to do two changes per store:
-
- Change the type of the store in the database
+
* Change the type of the store in the database
-
- Change the ldap attribute of the store
+
* Change the LDAP attribute of the store (e.g. in OpenLDAP with the zarafa-schema the attribute: zarafaSharedStoreOnly) - Check in you ldap config which attribute is used.
-
The mysql changes you need to do are in the users table. The users table has the  
+
 
-
following fields:
+
The MySQL changes you need to do are in the users table. The users table has the following fields:
<pre>
<pre>
1. id          | int(11)        ->  Internal ID of user
1. id          | int(11)        ->  Internal ID of user
2. externid    | blob          ->  External ID of user
2. externid    | blob          ->  External ID of user
-
3. object_type | int(11)        ->  1=active, 5=inactive(sharedstore)
+
3. object_type | int(11)        ->  1=active, 5=inactive(shared store)
4. signature  | varchar(255)
4. signature  | varchar(255)
5. company    | int(11)  
5. company    | int(11)  
</pre>
</pre>
For field nr. 2 the following goes:
For field nr. 2 the following goes:
-
The value depends on the backend you are using. If you are using openldap the  
+
The value depends on the back-end you are using. If you are using OpenLDAP the <tt>externid</tt> will probably be an integer (mostly used is <tt>uidNumber</tt>)... If you use ADS as back-end then the <tt>externid</tt> is a binary value which is really hard to relate to any user.
-
externid will probably be an integer (mostly used is uidNumber)... If you use ADS  
+
-
as backend 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 webbrowser.
+
-
You need to modify the credentials on top of the script (any zarafa user will do).
+
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.
-
This script will get all the users from zarafa and will show a 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.
+
 +
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====
+
==The steps==
So the steps to change a store would be:
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.
+
* 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  
+
* Write a script that will do the following SQL statement for each user you want to change (<tt>object_type=1</tt> for active, <tt>object_type=5</tt> for inactive):
-
to change (object_type=1 for active, object_type=5 for inactive):
+
<pre>
<pre>
update users set object_type=[new_object_type] where id=[internal ID]
update users set object_type=[new_object_type] where id=[internal ID]
</pre>
</pre>
-
Or if you want to use external ID (with openldap -> Of course internal id will also work):
+
Or if you want to use external ID (with OpenLDAP -> Of course internal id will also work):
<pre>
<pre>
update users set object_type=[new_object_type] where externid=[external ID]
update users set object_type=[new_object_type] where externid=[external ID]
</pre>
</pre>
* Stop Zarafa-server
* Stop Zarafa-server
-
* Run the mysql script
+
* Run the MySQL script
-
* Change the stores to inactive (sharedstore) in ldap  (DO NOT FORGET)
+
* Change the stores to inactive (shared store) in LDAP ('''DO NOT FORGET''')
* check check, double check
* check check, double check
-
* Start zarafa
+
* Start Zarafa-server
-
====The Script====
+
==The script==
-
Here you find the php script (change credentials to a valid zarafa user). This script shows a 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).
+
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).
<pre>
<pre>
<HTML>
<HTML>
Line 69: Line 60:
$zarafa_pass="";
$zarafa_pass="";
$zarafa_sock="file:///var/run/zarafa";
$zarafa_sock="file:///var/run/zarafa";
-
 
-
 
-
/*
 
-
* Updates all users' free/busy information
 
-
*/
 
include('/usr/share/php/mapi/mapi.util.php');
include('/usr/share/php/mapi/mapi.util.php');
Line 153: Line 139:
?>
?>
-
 
+
</BODY>
 +
</HTML>
</pre>
</pre>

Latest revision as of 10:37, 30 December 2010

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 (e.g. in OpenLDAP with the zarafa-schema the attribute: zarafaSharedStoreOnly) - Check in you ldap config which attribute is used.


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).

<HTML>
<HEAD>
<STYLE>
* {
  font-family: verdana;
  font-size: 8pt;
}
</STYLE>
</HEAD>
<BODY>
<?

$zarafa_user="";
$zarafa_pass="";
$zarafa_sock="file:///var/run/zarafa";

include('/usr/share/php/mapi/mapi.util.php');
include('/usr/share/php/mapi/mapidefs.php');
include('/usr/share/php/mapi/mapicode.php');
include('/usr/share/php/mapi/mapitags.php');
include('/usr/share/php/mapi/mapiguid.php');

include('/usr/share/php/mapi/class.recurrence.php');
include('/usr/share/php/mapi/class.freebusypublish.php');

$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
$i=0;
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";
  $i++;
}
print "</TABLE>\n";

?>
</BODY>
</HTML>
Personal tools