summaryrefslogtreecommitdiffstats
path: root/apps/bookmarks
diff options
context:
space:
mode:
authorTom Needham <needham.thomas@gmail.com>2012-03-03 17:30:21 +0000
committerTom Needham <needham.thomas@gmail.com>2012-03-03 17:30:21 +0000
commit691103acd5aad2673b6375726ba24fb56e88451b (patch)
tree8f33e40e158e22ee9f140f5f859f539786af49d6 /apps/bookmarks
parent34f05ba180792afb40d953b6cf8595a4513eb972 (diff)
downloadnextcloud-server-691103acd5aad2673b6375726ba24fb56e88451b.tar.gz
nextcloud-server-691103acd5aad2673b6375726ba24fb56e88451b.zip
Use json for migration data
Diffstat (limited to 'apps/bookmarks')
-rw-r--r--apps/bookmarks/lib/migrate.php98
1 files changed, 50 insertions, 48 deletions
diff --git a/apps/bookmarks/lib/migrate.php b/apps/bookmarks/lib/migrate.php
index c655154d41b..f50a8c46334 100644
--- a/apps/bookmarks/lib/migrate.php
+++ b/apps/bookmarks/lib/migrate.php
@@ -4,69 +4,71 @@ class OC_Migrate_Provider_Bookmarks extends OC_Migrate_Provider{
// Create the xml for the user supplied
function export($uid){
- $doc = new DOMDocument();
- $doc->formatOutput = true;
- $bookmarks = $doc->createElement('bookmarks');
- $bookmarks = $doc->appendChild($bookmarks);
-
+ $bookmarks = array();
+
$query = OC_DB::prepare("SELECT * FROM *PREFIX*bookmarks WHERE *PREFIX*bookmarks.user_id = ?");
$bookmarksdata =& $query->execute(array($uid));
-
-
// Foreach bookmark
while ($row = $bookmarksdata->fetchRow()) {
- $bookmark = $doc->createElement('bookmark');
- $bookmark = $bookmarks->appendChild($bookmark);
-
- $attr = $doc->createElement('title');
- $attr = $bookmark->appendChild($attr);
- $value = $doc->createTextNode($row['title']);
- $attr->appendChild($value);
-
- $attr = $doc->createElement('url');
- $attr = $bookmark->appendChild($attr);
- $value = $doc->createTextNode($row['url']);
- $attr->appendChild($value);
-
- $attr = $doc->createElement('added');
- $attr = $bookmark->appendChild($attr);
- $value = $doc->createTextNode($row['added']);
- $attr->appendChild($value);
-
- $attr = $doc->createElement('lastmodified');
- $attr = $bookmark->appendChild($attr);
- $value = $doc->createTextNode($row['lastmodified']);
- $attr->appendChild($value);
-
- $attr = $doc->createElement('public');
- $attr = $bookmark->appendChild($attr);
- $value = $doc->createTextNode($row['public']);
- $attr->appendChild($value);
-
- $attr = $doc->createElement('clickcount');
- $attr = $bookmark->appendChild($attr);
- $value = $doc->createTextNode($row['clickcount']);
- $attr->appendChild($value);
-
- $attr = $doc->createElement('tags');
- $tags = $bookmark->appendChild($attr);
+ // Get the tags
$query = OC_DB::prepare("SELECT * FROM *PREFIX*bookmarks_tags WHERE *PREFIX*bookmarks_tags.bookmark_id = ?");
$tagsdata =& $query->execute(array($row['id']));
+ $tags = array();
// Foreach tag
while ($row = $tagsdata->fetchRow()) {
- $attr = $doc->createElement('tag');
- $attr = $tags->appendChild($attr);
- $value = $doc->createTextNode($row['tag']);
- $attr->appendChild($value);
- }
+ $tags[] = $row['tag'];
+ }
+
+ $bookmarks[] = array(
+ 'url' => $row['url'],
+ 'title' => $row['title'],
+ 'public' => $row['public'],
+ 'added' => $row['added'],
+ 'lastmodified' => $row['lastmodified'],
+ 'clickcount' => $row['clickcount'],
+ 'tags' => $tags
+ );
+
}
- return $doc;
+ return array('bookmarks' => $bookmarks);
}
+ // Import function for bookmarks
+ function import($data,$uid){
+
+ // Different import code for different versions of the app
+ switch($data['info']['version']){
+ default:
+ // Foreach bookmark
+ foreach($data['data']['bookmarks'] as $bookmark){
+
+ $query = OC_DB::prepare( "INSERT INTO `*PREFIX*bookmarks` ( `url`, `title`, `user_id`, `public`, `added`, `lastmodified`, `clickcount` ) VALUES( ?, ?, ?, ?, ?, ?, ? )" );
+ $result = $query->execute( array(
+ $bookmark['url'],
+ $bookmark['title'],
+ $uid,
+ $bookmark['public'],
+ $bookmark['added'],
+ $bookmark['lastmodified'],
+ $bookmark['clickcount']
+ ) );
+ // Now add the tags
+ $id = OC_DB::insertid();
+ foreach($bookmark['tags'] as $tag){
+ $query = OC_DB::prepare( "INSERT INTO `*PREFIX*bookmarks_tags` ( `id`, `tag` ) VALUES( ?, ? )" );
+ $result = $query->execute( array( $id, $tag));
+ }
+
+ }
+ break;
+ }
+ // Finished import
+ }
+
}
new OC_Migrate_Provider_Bookmarks('bookmarks'); \ No newline at end of file