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