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

70 lines
2.3 KiB
PHP
Raw Normal View History

2012-04-01 01:55:41 +02:00
<?php
class OC_Migration_Provider_Contacts extends OC_Migration_Provider{
2012-09-07 14:32:45 +02:00
2012-04-01 01:55:41 +02:00
// Create the xml for the user supplied
2012-07-20 17:09:03 +02:00
function export( ) {
2012-04-01 01:55:41 +02:00
$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
);
2012-09-07 14:32:45 +02:00
2012-04-01 01:55:41 +02:00
// Export tags
$ids2 = $this->content->copyRows( $options );
2012-09-07 14:32:45 +02:00
2012-04-01 01:55:41 +02:00
// If both returned some ids then they worked
2012-07-20 17:09:03 +02:00
if(is_array($ids) && is_array($ids2)) {
return true;
2012-04-01 01:55:41 +02:00
} else {
return false;
}
2012-09-07 14:32:45 +02:00
2012-04-01 01:55:41 +02:00
}
2012-09-07 14:32:45 +02:00
2012-06-30 13:04:35 +02:00
// Import function for contacts
2012-07-20 17:09:03 +02:00
function import( ) {
switch( $this->appinfo->version ) {
2012-04-01 01:55:41 +02:00
default:
// All versions of the app have had the same db structure, so all can use the same import function
2013-03-19 00:36:45 +01:00
$query = $this->content->prepare( 'SELECT * FROM `contacts_addressbooks` WHERE `userid` = ?' );
2012-04-01 01:55:41 +02:00
$results = $query->execute( array( $this->olduid ) );
$idmap = array();
2012-07-20 17:09:03 +02:00
while( $row = $results->fetchRow() ) {
2012-09-07 14:32:45 +02:00
// Import each addressbook
$addressbookquery = OCP\DB::prepare( 'INSERT INTO `*PREFIX*contacts_addressbooks` (`userid`, `displayname`, `uri`, `description`, `ctag`) VALUES (?, ?, ?, ?, ?)' );
2012-06-27 23:18:15 +02:00
$addressbookquery->execute( array( $this->uid, $row['displayname'], $row['uri'], $row['description'], $row['ctag'] ) );
2012-04-01 01:55:41 +02:00
// Map the id
2012-06-30 13:04:35 +02:00
$idmap[$row['id']] = OCP\DB::insertid('*PREFIX*contacts_addressbooks');
// Make the addressbook active
2012-10-25 03:34:12 +02:00
OCA\Contacts\Addressbook::setActive($idmap[$row['id']], true);
2012-04-01 01:55:41 +02:00
}
// Now tags
2012-07-20 17:09:03 +02:00
foreach($idmap as $oldid => $newid) {
2012-09-07 14:32:45 +02:00
2013-03-19 00:36:45 +01:00
$query = $this->content->prepare( 'SELECT * FROM `contacts_cards` WHERE `addressbookid` = ?' );
2012-04-01 01:55:41 +02:00
$results = $query->execute( array( $oldid ) );
2012-09-07 15:21:03 +02:00
while( $row = $results->fetchRow() ) {
2012-06-30 13:04:35 +02:00
// Import the contacts
$contactquery = OCP\DB::prepare( 'INSERT INTO `*PREFIX*contacts_cards` (`addressbookid`, `fullname`, `carddata`, `uri`, `lastmodified`) VALUES (?, ?, ?, ?, ?)' );
2012-09-07 14:32:45 +02:00
$contactquery->execute( array( $newid, $row['fullname'], $row['carddata'], $row['uri'], $row['lastmodified'] ) );
}
2012-04-01 01:55:41 +02:00
}
// All done!
break;
}
2012-09-07 14:32:45 +02:00
2012-04-01 01:55:41 +02:00
return true;
}
2012-09-07 14:32:45 +02:00
2012-04-01 01:55:41 +02:00
}
// Load the provider
new OC_Migration_Provider_Contacts( 'contacts' );