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