summaryrefslogtreecommitdiffstats
path: root/apps/contacts/appinfo/migrate.php
diff options
context:
space:
mode:
authorTom Needham <needham.thomas@gmail.com>2012-03-31 23:55:41 +0000
committerTom Needham <needham.thomas@gmail.com>2012-03-31 23:55:41 +0000
commitdaf742c086fefab9d715be3308088e626de1216c (patch)
tree99bae6a0b4c1f05cd4e00aa49a69c327e2647305 /apps/contacts/appinfo/migrate.php
parentd01b78a4b486860ab7110677e9969a37ee2a832f (diff)
downloadnextcloud-server-daf742c086fefab9d715be3308088e626de1216c.tar.gz
nextcloud-server-daf742c086fefab9d715be3308088e626de1216c.zip
Fix owncloud log
Diffstat (limited to 'apps/contacts/appinfo/migrate.php')
-rw-r--r--apps/contacts/appinfo/migrate.php68
1 files changed, 68 insertions, 0 deletions
diff --git a/apps/contacts/appinfo/migrate.php b/apps/contacts/appinfo/migrate.php
new file mode 100644
index 00000000000..a6c6bc20fa4
--- /dev/null
+++ b/apps/contacts/appinfo/migrate.php
@@ -0,0 +1,68 @@
+<?php
+class OC_Migration_Provider_Contacts 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
+ if( is_array( $ids ) && is_array( $ids2 ) )
+ {
+ return true;
+ } else {
+ return false;
+ }
+
+ }
+
+ // Import function for bookmarks
+ 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 LIKE ?" );
+ $results = $query->execute( array( $this->olduid ) );
+ $idmap = array();
+ while( $row = $results->fetchRow() ){
+ // Import each bookmark, saving its id into the map
+ $query = OC_DB::prepare( "INSERT INTO *PREFIX*contacts_addressbooks (`userid`, `displayname`, `uri`, `description`, `ctag`) VALUES (?, ?, ?, ?, ?)" );
+ $query->execute( array( $this->uid, $row['displayname'], $row['uri'], $row['description'], $row['ctag'] ) );
+ // Map the id
+ $idmap[$row['id']] = OC_DB::insertid();
+ }
+ // Now tags
+ foreach($idmap as $oldid => $newid){
+ $query = $this->content->prepare( "SELECT * FROM contacts_cards WHERE addressbookid LIKE ?" );
+ $results = $query->execute( array( $oldid ) );
+ while( $row = $results->fetchRow() ){
+ // Import the tags for this bookmark, using the new bookmark id
+ $query = OC_DB::prepare( "INSERT INTO *PREFIX*contacts_cards (`addressbookid`, `fullname`, `carddata`, `uri`, `lastmodified`) VALUES (?, ?, ?, ?, ?)" );
+ $query->execute( array( $newid, $row['fullname'], $row['carddata'], $row['uri'], $row['lastmodified'] ) );
+ }
+ }
+ // All done!
+ break;
+ }
+
+ return true;
+ }
+
+}
+
+// Load the provider
+new OC_Migration_Provider_Contacts( 'contacts' ); \ No newline at end of file