mirror of
https://github.com/owncloud/bookmarks.git
synced 2025-02-18 15:54:28 +01:00
Add OC_Migrate::copyRows() method
This commit is contained in:
parent
a3ac799e39
commit
3aa9c0e2d2
@ -2,73 +2,48 @@
|
|||||||
class OC_Migrate_Provider_Bookmarks extends OC_Migrate_Provider{
|
class OC_Migrate_Provider_Bookmarks extends OC_Migrate_Provider{
|
||||||
|
|
||||||
// Create the xml for the user supplied
|
// Create the xml for the user supplied
|
||||||
function export($uid){
|
function export( $uid ){
|
||||||
|
|
||||||
$bookmarks = array();
|
$options = array(
|
||||||
|
'table'=>'bookmarks',
|
||||||
$query = OC_DB::prepare("SELECT * FROM *PREFIX*bookmarks WHERE *PREFIX*bookmarks.user_id = ?");
|
'matchcol'=>'user_id',
|
||||||
$bookmarksdata =& $query->execute(array($uid));
|
'matchval'=>$uid,
|
||||||
// Foreach bookmark
|
'idcol'=>'id'
|
||||||
while ($row = $bookmarksdata->fetchRow()) {
|
);
|
||||||
|
$ids = OC_Migrate::copyRows( $options );
|
||||||
// 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();
|
$options = array(
|
||||||
// Foreach tag
|
'table'=>'bookmarks_tags',
|
||||||
while ($row = $tagsdata->fetchRow()) {
|
'matchcol'=>'id',
|
||||||
$tags[] = $row['tag'];
|
'matchval'=>$ids
|
||||||
}
|
);
|
||||||
|
|
||||||
$bookmarks[] = array(
|
|
||||||
'url' => $row['url'],
|
|
||||||
'title' => $row['title'],
|
|
||||||
'public' => $row['public'],
|
|
||||||
'added' => $row['added'],
|
|
||||||
'lastmodified' => $row['lastmodified'],
|
|
||||||
'clickcount' => $row['clickcount'],
|
|
||||||
'tags' => $tags
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return array('bookmarks' => $bookmarks);
|
// Export tags
|
||||||
|
OC_Migrate::copyRows( $options );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Import function for bookmarks
|
// Import function for bookmarks
|
||||||
function import($data,$uid){
|
function import( $data, $uid ){
|
||||||
|
|
||||||
// Different import code for different versions of the app
|
// new id mapping
|
||||||
switch($data['info']['version']){
|
$newids = array();
|
||||||
default:
|
|
||||||
// Foreach bookmark
|
// Import bookmarks
|
||||||
foreach($data['data']['bookmarks'] as $bookmark){
|
foreach($data['bookmarks'] as $bookmark){
|
||||||
|
$bookmark['user_id'] = $uid;
|
||||||
$query = OC_DB::prepare( "INSERT INTO `*PREFIX*bookmarks` ( `url`, `title`, `user_id`, `public`, `added`, `lastmodified`, `clickcount` ) VALUES( ?, ?, ?, ?, ?, ?, ? )" );
|
// import to the db now
|
||||||
$result = $query->execute( array(
|
$newids[$bookmark['id']] = OC_DB::insertid();
|
||||||
$bookmark['url'],
|
}
|
||||||
$bookmark['title'],
|
|
||||||
$uid,
|
// Import tags
|
||||||
$bookmark['public'],
|
foreach($data['bookmarks_tags'] as $tag){
|
||||||
$bookmark['added'],
|
// Map the new ids
|
||||||
$bookmark['lastmodified'],
|
$tag['id'] = $newids[$tag['id']];
|
||||||
$bookmark['clickcount']
|
// Import to the db now using OC_DB
|
||||||
) );
|
|
||||||
// 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');
|
new OC_Migrate_Provider_Bookmarks( 'bookmarks' );
|
Loading…
x
Reference in New Issue
Block a user