nextcloud/apps/bookmarks/lib/migrate.php

74 lines
2.1 KiB
PHP
Raw Normal View History

<?php
class OC_Migrate_Provider_Bookmarks extends OC_Migrate_Provider{
2012-03-03 17:22:45 +04:00
// Create the xml for the user supplied
function export($uid){
2012-03-03 17:22:45 +04:00
2012-03-03 21:30:21 +04:00
$bookmarks = array();
$query = OC_DB::prepare("SELECT * FROM *PREFIX*bookmarks WHERE *PREFIX*bookmarks.user_id = ?");
2012-03-03 17:22:45 +04:00
$bookmarksdata =& $query->execute(array($uid));
// Foreach bookmark
while ($row = $bookmarksdata->fetchRow()) {
2012-03-03 21:30:21 +04:00
// Get the tags
2012-03-03 17:22:45 +04:00
$query = OC_DB::prepare("SELECT * FROM *PREFIX*bookmarks_tags WHERE *PREFIX*bookmarks_tags.bookmark_id = ?");
$tagsdata =& $query->execute(array($row['id']));
2012-03-03 21:30:21 +04:00
$tags = array();
2012-03-03 17:22:45 +04:00
// Foreach tag
while ($row = $tagsdata->fetchRow()) {
2012-03-03 21:30:21 +04:00
$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
);
}
2012-03-03 17:22:45 +04:00
2012-03-03 21:30:21 +04:00
return array('bookmarks' => $bookmarks);
2012-03-03 17:22:45 +04:00
}
2012-03-03 17:22:45 +04:00
2012-03-03 21:30:21 +04:00
// 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
}
}
2012-03-03 17:22:45 +04:00
2012-02-04 01:28:58 +04:00
new OC_Migrate_Provider_Bookmarks('bookmarks');