Blame view

sources/apps/contacts/appinfo/update.php 1.3 KB
d1bafeea1   Kload   [fix] Upgrade to ...
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
  <?php
  
  $installedVersion=OCP\Config::getAppValue('contacts', 'installed_version');
  if (version_compare($installedVersion, '0.2.5', '>=')) {
  	// Set all address books active as (de)activating went awol at rewrite.
  	$stmt = OCP\DB::prepare( 'UPDATE `*PREFIX*contacts_addressbooks` SET `active`= 1' );
  	$result = $stmt->execute(array());
  }
  elseif (version_compare($installedVersion, '0.2.4', '==')) {
  	// First set all address books in-active.
  	$stmt = OCP\DB::prepare( 'UPDATE `*PREFIX*contacts_addressbooks` SET `active`=0' );
  	$result = $stmt->execute(array());
  
  	// Then get all the active address books.
  	$stmt = OCP\DB::prepare( 'SELECT `userid`,`configvalue` FROM `*PREFIX*preferences` WHERE `appid`=\'contacts\' AND `configkey`=\'openaddressbooks\'' );
  	$result = $stmt->execute(array());
  
  	// Prepare statement for updating the new 'active' field.
  	$stmt = OCP\DB::prepare( 'UPDATE `*PREFIX*contacts_addressbooks` SET `active`=? WHERE `id`=? AND `userid`=?' );
  	while( $row = $result->fetchRow()) {
  		$ids = explode(';', $row['configvalue']);
  		foreach($ids as $id) {
  			$r = $stmt->execute(array(1, $id, $row['userid']));
  		}
  	}
  
  	// Remove the old preferences.
  	$stmt = OCP\DB::prepare( 'DELETE FROM `*PREFIX*preferences` WHERE `appid`=\'contacts\' AND `configkey`=\'openaddressbooks\'' );
  	$result = $stmt->execute(array());
  }