Blame view
sources/apps/contacts/appinfo/migrate.php
2.4 KB
|
d1bafeea1
|
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 31 32 33 34 |
<?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
|
|
6d9380f96
|
35 |
$query = $this->content->prepare('SELECT * FROM contacts_addressbooks WHERE userid = ?');
|
|
d1bafeea1
|
36 37 |
$results = $query->execute(array($this->olduid)); $idmap = array(); |
|
6d9380f96
|
38 |
$app = new \OCA\Contacts\App($this->uid); |
|
d1bafeea1
|
39 40 |
while($row = $results->fetchRow()) {
// Import each addressbook
|
|
6d9380f96
|
41 |
$addressbookquery = \OCP\DB::prepare('INSERT INTO `*PREFIX*contacts_addressbooks` '
|
|
d1bafeea1
|
42 43 44 45 46 47 48 49 50 51 52 |
. '(`userid`, `displayname`, `uri`, `description`, `ctag`) VALUES (?, ?, ?, ?, ?)'); $addressbookquery->execute( array( $this->uid, $row['displayname'], $row['uri'], $row['description'], $row['ctag'] ) ); // Map the id |
|
6d9380f96
|
53 |
$idmap[$row['id']] = \OCP\DB::insertid('*PREFIX*contacts_addressbooks');
|
|
d1bafeea1
|
54 |
// Make the addressbook active |
|
6d9380f96
|
55 56 |
$addressbook = $app->getAddressBook('local', $idmap[$row['id']]);
$addressbook->setActive(true);
|
|
d1bafeea1
|
57 58 59 |
}
// Now tags
foreach($idmap as $oldid => $newid) {
|
|
6d9380f96
|
60 |
$query = $this->content->prepare('SELECT * FROM contacts_cards WHERE addressbookid = ?');
|
|
d1bafeea1
|
61 62 63 |
$results = $query->execute(array($oldid));
while($row = $results->fetchRow()) {
// Import the contacts
|
|
6d9380f96
|
64 |
$contactquery = \OCP\DB::prepare('INSERT INTO `*PREFIX*contacts_cards` '
|
|
d1bafeea1
|
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
. '(`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');
|