2012-02-03 20:32:06 +00:00
|
|
|
<?php
|
2012-03-19 20:44:20 +00:00
|
|
|
class OC_Migration_Provider_Bookmarks extends OC_Migration_Provider{
|
2012-03-03 13:22:45 +00:00
|
|
|
|
2012-02-03 20:32:06 +00:00
|
|
|
// Create the xml for the user supplied
|
2012-03-19 20:44:20 +00:00
|
|
|
function export( ){
|
2012-03-10 15:52:38 +00:00
|
|
|
$options = array(
|
|
|
|
'table'=>'bookmarks',
|
|
|
|
'matchcol'=>'user_id',
|
2012-03-19 20:44:20 +00:00
|
|
|
'matchval'=>$this->uid,
|
2012-03-10 15:52:38 +00:00
|
|
|
'idcol'=>'id'
|
|
|
|
);
|
2012-03-19 20:44:20 +00:00
|
|
|
$ids = $this->content->copyRows( $options );
|
2012-03-11 22:09:16 +00:00
|
|
|
|
2012-03-10 15:52:38 +00:00
|
|
|
$options = array(
|
|
|
|
'table'=>'bookmarks_tags',
|
2012-03-10 18:18:58 +00:00
|
|
|
'matchcol'=>'bookmark_id',
|
2012-03-10 15:52:38 +00:00
|
|
|
'matchval'=>$ids
|
|
|
|
);
|
2012-03-03 13:22:45 +00:00
|
|
|
|
2012-03-10 15:52:38 +00:00
|
|
|
// Export tags
|
2012-03-19 20:44:20 +00:00
|
|
|
$ids2 = $this->content->copyRows( $options );
|
2012-03-11 22:20:01 +00:00
|
|
|
|
|
|
|
// If both returned some ids then they worked
|
|
|
|
if( is_array( $ids ) && is_array( $ids2 ) )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
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
|
2012-03-19 20:44:20 +00:00
|
|
|
function import( ){
|
|
|
|
switch( $this->appinfo->version ){
|
2012-03-13 21:24:07 +00:00
|
|
|
default:
|
|
|
|
// All versions of the app have had the same db structure, so all can use the same import function
|
2012-03-20 20:19:21 +00:00
|
|
|
$query = $this->content->prepare( "SELECT * FROM bookmarks WHERE user_id LIKE ?" );
|
|
|
|
$results = $query->execute( array( $this->olduid ) );
|
2012-03-13 21:24:07 +00:00
|
|
|
$idmap = array();
|
2012-03-20 20:19:21 +00:00
|
|
|
while( $row = $results->fetchRow() ){
|
2012-03-13 21:24:07 +00:00
|
|
|
// 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 (?, ?, ?, ?, ?, ?)" );
|
2012-03-20 20:19:21 +00:00
|
|
|
$query->execute( array( $row['url'], $row['title'], $this->uid, $row['public'], $row['added'], $row['lastmodified'] ) );
|
2012-03-13 21:24:07 +00:00
|
|
|
// Map the id
|
|
|
|
$idmap[$row['id']] = OC_DB::insertid();
|
|
|
|
}
|
|
|
|
// Now tags
|
|
|
|
foreach($idmap as $oldid => $newid){
|
2012-03-27 21:35:29 +00:00
|
|
|
$query = $this->content->prepare( "SELECT * FROM bookmarks_tags WHERE bookmark_id LIKE ?" );
|
2012-03-13 21:24:07 +00:00
|
|
|
$results = $query->execute( array( $oldid ) );
|
2012-03-27 21:35:29 +00:00
|
|
|
while( $row = $results->fetchRow() ){
|
2012-03-13 21:24:07 +00:00
|
|
|
// 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 15:52:38 +00:00
|
|
|
}
|
2012-03-03 17:30:21 +00:00
|
|
|
|
2012-03-13 21:24:07 +00:00
|
|
|
return true;
|
2012-03-03 17:30:21 +00:00
|
|
|
}
|
|
|
|
|
2012-02-03 20:32:06 +00:00
|
|
|
}
|
2012-03-03 13:22:45 +00:00
|
|
|
|
2012-03-13 16:21:17 +00:00
|
|
|
// Load the provider
|
2012-03-19 20:44:20 +00:00
|
|
|
new OC_Migration_Provider_Bookmarks( 'bookmarks' );
|