nextcloud/apps/bookmarks/lib/migrate.php

69 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
2012-03-10 19:52:38 +04:00
function export( $uid ){
2012-03-12 02:09:16 +04:00
OC_Log::write('migration','starting export for bookmarks',OC_Log::INFO);
2012-03-10 19:52:38 +04:00
$options = array(
'table'=>'bookmarks',
'matchcol'=>'user_id',
'matchval'=>$uid,
'idcol'=>'id'
);
$ids = OC_Migrate::copyRows( $options );
2012-03-12 02:09:16 +04:00
2012-03-10 19:52:38 +04:00
$options = array(
'table'=>'bookmarks_tags',
'matchcol'=>'bookmark_id',
2012-03-10 19:52:38 +04:00
'matchval'=>$ids
);
2012-03-03 17:22:45 +04:00
2012-03-10 19:52:38 +04:00
// Export tags
2012-03-12 02:20:01 +04:00
$ids2 = OC_Migrate::copyRows( $options );
// If both returned some ids then they worked
if( is_array( $ids ) && is_array( $ids2 ) )
{
return true;
} else {
return false;
}
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( $app, $info ){
switch( $app->version ){
2012-03-14 01:24:07 +04:00
default:
// All versions of the app have had the same db structure, so all can use the same import function
$query = OC_Migrate::prepare( "SELECT * FROM bookmarks WHERE user_id LIKE ?" );
$results = $query->execute( array( $info['olduid'] ) );
2012-03-14 01:24:07 +04:00
$idmap = array();
while( $row = $data->fetchRow() ){
// Import each bookmark, saving its id into the map
$query = OC_DB::prepare( "INSERT INTO *PREFIX*bookmarks(url, title, user_id, public, added, lastmodified) VALUES (?, ?, ?, ?, ?, ?)" );
$query->execute( array( $row['url'], $row['title'], $info['newuid'], $row['public'], $row['added'], $row['lastmodified'] ) );
2012-03-14 01:24:07 +04:00
// Map the id
$idmap[$row['id']] = OC_DB::insertid();
}
// Now tags
foreach($idmap as $oldid => $newid){
$query = OC_Migrate::prepare( "SELECT * FROM bookmarks_tags WHERE user_id LIKE ?" );
$results = $query->execute( array( $oldid ) );
while( $row = $data->fetchRow() ){
// Import the tags for this bookmark, using the new bookmark id
$query = OC_DB::prepare( "INSERT INTO *PREFIX*bookmarks_tags(bookmark_id, tag) VALUES (?, ?)" );
$query->execute( array( $newid, $row['tag'] ) );
}
}
// All done!
break;
2012-03-10 19:52:38 +04:00
}
2012-03-03 21:30:21 +04:00
2012-03-14 01:24:07 +04:00
return true;
2012-03-03 21:30:21 +04:00
}
}
2012-03-03 17:22:45 +04:00
// Load the provider
2012-03-10 19:52:38 +04:00
new OC_Migrate_Provider_Bookmarks( 'bookmarks' );