1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2024-12-01 13:24:10 +01:00
OwncloudContactsOfficial/appinfo/migrate.php
Thomas Tanghus c3fa18e4a7 Merge branch 'contacts_backends' into contacts_oc6
Conflicts:
	contacts/ajax/categories/add.php
	contacts/ajax/contact/add.php
	contacts/appinfo/app.php
	contacts/appinfo/migrate.php
	contacts/css/contacts.css
	contacts/index.php
	contacts/js/app.js
	contacts/js/contacts.js
	contacts/js/groups.js
	contacts/lib/app.php
	contacts/lib/carddav/addressbook.php
	contacts/lib/sabre/backend.php
	contacts/lib/vcard.php
	contacts/templates/contacts.php
	contacts/thumbnail.php
2013-04-17 15:07:59 +02:00

87 lines
2.3 KiB
PHP

<?php
namespace OCA\Contacts;
class MigrationProvider extends OC_Migration_Provider{
// Create the xml for the user supplied
function export( ) {
$options = array(
'table'=>'contacts_addressbooks',
'matchcol'=>'userid',
'matchval'=>$this->uid,
'idcol'=>'id'
);
$ids = $this->content->copyRows( $options );
$options = array(
'table'=>'contacts_cards',
'matchcol'=>'addressbookid',
'matchval'=>$ids
);
// Export tags
$ids2 = $this->content->copyRows( $options );
// If both returned some ids then they worked
return (is_array($ids) && is_array($ids2));
}
// Import function for contacts
function import() {
switch($this->appinfo->version) {
default:
// All versions of the app have had the same db structure, so all can use the same import function
$query = $this->content->prepare('SELECT * FROM `contacts_addressbooks` WHERE `userid` = ?');
$results = $query->execute(array($this->olduid));
$idmap = array();
while($row = $results->fetchRow()) {
// Import each addressbook
$addressbookquery = OCP\DB::prepare('INSERT INTO `*PREFIX*contacts_addressbooks` '
. '(`userid`, `displayname`, `uri`, `description`, `ctag`) VALUES (?, ?, ?, ?, ?)');
$addressbookquery->execute(
array(
$this->uid,
$row['displayname'],
$row['uri'],
$row['description'],
$row['ctag']
)
);
// Map the id
$idmap[$row['id']] = OCP\DB::insertid('*PREFIX*contacts_addressbooks');
// Make the addressbook active
OCA\Contacts\Addressbook::setActive($idmap[$row['id']], true);
}
// Now tags
foreach($idmap as $oldid => $newid) {
$query = $this->content->prepare('SELECT * FROM `contacts_cards` WHERE `addressbookid` = ?');
$results = $query->execute(array($oldid));
while($row = $results->fetchRow()) {
// Import the contacts
$contactquery = OCP\DB::prepare('INSERT INTO `*PREFIX*contacts_cards` '
. '(`addressbookid`, `fullname`, `carddata`, `uri`, `lastmodified`) VALUES (?, ?, ?, ?, ?)');
$contactquery->execute(
array(
$newid,
$row['fullname'],
$row['carddata'],
$row['uri'],
$row['lastmodified']
)
);
}
}
// All done!
break;
}
return true;
}
}
// Load the provider
new MigrationProvider('contacts');