Blame view

sources/apps/contacts/appinfo/update.php 1.82 KB
d1bafeea1   Kload   [fix] Upgrade to ...
1
  <?php
6d9380f96   Cédric Dupont   Update sources OC...
2
3
4
5
6
7
8
9
10
  /**
   * @author Thomas Tanghus
   * @copyright 2012-2014 Thomas Tanghus (thomas@tanghus.net)
   * This file is licensed under the Affero General Public License version 3 or
   * later.
   * See the COPYING-README file.
   */
  
  $installedVersion = OCP\Config::getAppValue('contacts', 'installed_version');
d1bafeea1   Kload   [fix] Upgrade to ...
11

d1bafeea1   Kload   [fix] Upgrade to ...
12
13
  if (version_compare($installedVersion, '0.2.5', '>=')) {
  	// Set all address books active as (de)activating went awol at rewrite.
6d9380f96   Cédric Dupont   Update sources OC...
14
  	$stmt = OCP\DB::prepare('UPDATE `*PREFIX*contacts_addressbooks` SET `active`= 1');
d1bafeea1   Kload   [fix] Upgrade to ...
15
  	$result = $stmt->execute(array());
6d9380f96   Cédric Dupont   Update sources OC...
16
  } elseif (version_compare($installedVersion, '0.2.4', '==')) {
d1bafeea1   Kload   [fix] Upgrade to ...
17
  	// First set all address books in-active.
6d9380f96   Cédric Dupont   Update sources OC...
18
  	$stmt = OCP\DB::prepare('UPDATE `*PREFIX*contacts_addressbooks` SET `active`=0');
d1bafeea1   Kload   [fix] Upgrade to ...
19
20
21
  	$result = $stmt->execute(array());
  
  	// Then get all the active address books.
6d9380f96   Cédric Dupont   Update sources OC...
22
  	$stmt = OCP\DB::prepare('SELECT `userid`,`configvalue` FROM `*PREFIX*preferences` WHERE `appid`=\'contacts\' AND `configkey`=\'openaddressbooks\'');
d1bafeea1   Kload   [fix] Upgrade to ...
23
24
25
  	$result = $stmt->execute(array());
  
  	// Prepare statement for updating the new 'active' field.
6d9380f96   Cédric Dupont   Update sources OC...
26
27
  	$stmt = OCP\DB::prepare('UPDATE `*PREFIX*contacts_addressbooks` SET `active`=? WHERE `id`=? AND `userid`=?');
  	while ($row = $result->fetchRow()) {
d1bafeea1   Kload   [fix] Upgrade to ...
28
  		$ids = explode(';', $row['configvalue']);
6d9380f96   Cédric Dupont   Update sources OC...
29
  		foreach ($ids as $id) {
d1bafeea1   Kload   [fix] Upgrade to ...
30
31
32
33
34
  			$r = $stmt->execute(array(1, $id, $row['userid']));
  		}
  	}
  
  	// Remove the old preferences.
6d9380f96   Cédric Dupont   Update sources OC...
35
36
37
38
39
40
41
42
  	$stmt = OCP\DB::prepare( 'DELETE FROM `*PREFIX*preferences` WHERE `appid`=\'contacts\' AND `configkey`=\'openaddressbooks\'');
  	$result = $stmt->execute(array());
  }
  if (version_compare($installedVersion, '0.3.0.14', '==')) {
  	// Rebuild this while we can
  	$stmt = OCP\DB::prepare('DELETE FROM `*PREFIX*contacts_ocu_cards`');
  	$result = $stmt->execute(array());
  	$stmt = OCP\DB::prepare('DELETE FROM `*PREFIX*contacts_ocu_cards_properties`');
d1bafeea1   Kload   [fix] Upgrade to ...
43
44
  	$result = $stmt->execute(array());
  }