1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2024-12-02 14:24:10 +01:00
OwncloudContactsOfficial/appinfo/update.php

45 lines
1.8 KiB
PHP
Raw Normal View History

2012-07-04 22:58:31 +02:00
<?php
2014-01-26 00:40:22 +01:00
/**
* @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.
*/
2012-07-04 22:58:31 +02:00
2014-03-08 16:22:51 +01:00
$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());
2014-03-08 16:22:51 +01:00
} elseif (version_compare($installedVersion, '0.2.4', '==')) {
2012-07-04 22:58:31 +02:00
// First set all address books in-active.
$stmt = OCP\DB::prepare('UPDATE `*PREFIX*contacts_addressbooks` SET `active`=0');
2012-07-04 22:58:31 +02:00
$result = $stmt->execute(array());
2012-09-07 14:32:45 +02:00
2012-07-04 22:58:31 +02:00
// Then get all the active address books.
$stmt = OCP\DB::prepare('SELECT `userid`,`configvalue` FROM `*PREFIX*preferences` WHERE `appid`=\'contacts\' AND `configkey`=\'openaddressbooks\'');
2012-07-04 22:58:31 +02:00
$result = $stmt->execute(array());
2012-09-07 14:32:45 +02:00
2012-07-04 22:58:31 +02:00
// Prepare statement for updating the new 'active' field.
$stmt = OCP\DB::prepare('UPDATE `*PREFIX*contacts_addressbooks` SET `active`=? WHERE `id`=? AND `userid`=?');
2014-03-08 16:22:51 +01:00
while ($row = $result->fetchRow()) {
2012-07-04 22:58:31 +02:00
$ids = explode(';', $row['configvalue']);
2014-03-08 16:22:51 +01:00
foreach ($ids as $id) {
2012-07-04 22:58:31 +02:00
$r = $stmt->execute(array(1, $id, $row['userid']));
}
}
2012-09-07 14:32:45 +02:00
2012-07-04 22:58:31 +02:00
// Remove the old preferences.
$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`');
2012-07-04 22:58:31 +02:00
$result = $stmt->execute(array());
}