summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Needham <needham.thomas@gmail.com>2012-04-07 21:55:16 +0000
committerTom Needham <needham.thomas@gmail.com>2012-04-07 21:55:16 +0000
commitc0869887cf91bf17421a9163069584d29ec5ed49 (patch)
tree920725089a1216a093b7c2892bbd6323777a1dc9
parent9edf45a324c2f1d4532d02e5c8fa37ebfa0c9dab (diff)
downloadnextcloud-server-c0869887cf91bf17421a9163069584d29ec5ed49.tar.gz
nextcloud-server-c0869887cf91bf17421a9163069584d29ec5ed49.zip
Return JSON for import and export methods of OC_Migrate
-rw-r--r--apps/bookmarks/appinfo/migrate.php1
-rw-r--r--apps/user_migrate/admin.php6
-rw-r--r--apps/user_migrate/ajax/export.php35
-rw-r--r--lib/migrate.php42
4 files changed, 42 insertions, 42 deletions
diff --git a/apps/bookmarks/appinfo/migrate.php b/apps/bookmarks/appinfo/migrate.php
index 603a8b72d3c..c1251e816ec 100644
--- a/apps/bookmarks/appinfo/migrate.php
+++ b/apps/bookmarks/appinfo/migrate.php
@@ -3,7 +3,6 @@ class OC_Migration_Provider_Bookmarks extends OC_Migration_Provider{
// Create the xml for the user supplied
function export( ){
- OC_Log::write('migration','starting export for bookmarks',OC_Log::INFO);
$options = array(
'table'=>'bookmarks',
'matchcol'=>'user_id',
diff --git a/apps/user_migrate/admin.php b/apps/user_migrate/admin.php
index 510c54abe3d..0160753af22 100644
--- a/apps/user_migrate/admin.php
+++ b/apps/user_migrate/admin.php
@@ -42,15 +42,15 @@ if (isset($_POST['user_import'])) {
$tmpl->assign('error',$error);
return $tmpl->fetchPage();
}
-
- if( !$appsstatus = OC_Migrate::import( $to, 'user' ) ){
+ $response = json_decode( OC_Migrate::import( $to, 'user' ) );
+ if( !$response->success ){
$error = array('error'=>'There was an error while importing the user!','hint'=>'Please check the logs for a more detailed explaination');
$tmpl = new OC_Template('user_migrate', 'admin');
$tmpl->assign('error',$error);
return $tmpl->fetchPage();
} else {
// Check import status
- foreach( $appsstatus as $app => $status ){
+ foreach( $response->data as $app => $status ){
if( $status != 'true' ){
// It failed for some reason
if( $status == 'notsupported' ){
diff --git a/apps/user_migrate/ajax/export.php b/apps/user_migrate/ajax/export.php
index fac96577fa2..86745d6b162 100644
--- a/apps/user_migrate/ajax/export.php
+++ b/apps/user_migrate/ajax/export.php
@@ -28,28 +28,29 @@ OC_JSON::checkLoggedIn();
OC_Util::checkAppEnabled('user_migrate');
// Which operation
if( $_GET['operation']=='create' ){
-$uid = !empty( $_POST['uid'] ) ? $_POST['uid'] : OC_User::getUser();
-if( $uid != OC_User::getUser() ){
- // Needs to be admin to export someone elses account
- OC_JSON::error();
- die();
-}
-// Create the export zip
-if( !$path = OC_Migrate::export( $uid ) ){
- // Error
- OC_JSON::error();
+ $uid = !empty( $_POST['uid'] ) ? $_POST['uid'] : OC_User::getUser();
+ if( $uid != OC_User::getUser() ){
+ // Needs to be admin to export someone elses account
+ OC_JSON::error();
+ die();
+ }
+ // Create the export zip
+ $response = json_decode( OC_Migrate::export( $uid ) );
+ if( !$response->success ){
+ // Error
+ OC_JSON::error();
+ die();
+ } else {
+ // Save path in session
+ $_SESSION['ocuserexportpath'] = $response->data;
+ }
+ OC_JSON::success();
die();
-} else {
- // Save path in session
- $_SESSION['ocuserexportpath'] = $path;
-}
-OC_JSON::success();
-die();
} else if( $_GET['operation']=='download' ){
// Download the export
$path = isset( $_SESSION['ocuserexportpath'] ) ? $_SESSION['ocuserexportpath'] : false;
if( !$path ){
- die();
+ OC_JSON::error();
}
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=" . basename($path));
diff --git a/lib/migrate.php b/lib/migrate.php
index 22c05606912..6734c805fcf 100644
--- a/lib/migrate.php
+++ b/lib/migrate.php
@@ -84,7 +84,7 @@ class OC_Migrate{
$types = array( 'user', 'instance', 'system', 'userfiles' );
if( !in_array( $type, $types ) ){
OC_Log::write( 'migration', 'Invalid export type', OC_Log::ERROR );
- return false;
+ return json_encode( array( array( 'success' => false ) ) );
}
self::$exporttype = $type;
// Userid?
@@ -93,7 +93,7 @@ class OC_Migrate{
if( !is_null($uid) ){
if( !OC_User_Database::userExists( $uid ) ){
OC_Log::write('migration', 'User: '.$uid.' is not in the database and so cannot be exported.', OC_Log::ERROR);
- return false;
+ return json_encode( array( 'success' => false ) );
}
self::$uid = $uid;
} else {
@@ -114,7 +114,7 @@ class OC_Migrate{
// Validate custom path
if( !file_exists( $path ) || !is_writeable( $path ) ){
OC_Log::write( 'migration', 'Path supplied is invalid.', OC_Log::ERROR );
- return false;
+ return json_encode( array( 'success' => false ) );
}
self::$zippath = $path . $zipname;
} else {
@@ -124,7 +124,7 @@ class OC_Migrate{
}
// Create the zip object
if( !self::createZip() ){
- return false;
+ return json_encode( array( 'success' => false ) );
}
// Do the export
self::findProviders();
@@ -134,7 +134,7 @@ class OC_Migrate{
// Connect to the db
self::$dbpath = $datadir . '/' . self::$uid . '/migration.db';
if( !self::connectDB() ){
- return false;
+ return json_encode( array( 'success' => false ) );
}
self::$content = new OC_Migration_Content( self::$zip, self::$MDB2 );
// Export the app info
@@ -178,14 +178,14 @@ class OC_Migrate{
break;
}
if( !$info = self::getExportInfo( $exportdata ) ){
- return false;
+ return json_encode( array( 'success' => false ) );
}
// Add the export info json to the export zip
self::$content->addFromString( $info, 'export_info.json' );
if( !self::$content->finish() ){
- return false;
+ return json_encode( array( 'success' => false ) );
}
- return self::$zippath;
+ return json_encode( array( 'success' => true, 'data' => self::$zippath ) );
}
/**
@@ -199,19 +199,19 @@ class OC_Migrate{
$datadir = OC_Config::getValue( 'datadirectory' );
// Extract the zip
if( !$extractpath = self::extractZip( $path ) ){
- return false;
+ return json_encode( array( 'success' => false ) );
}
// Get export_info.json
$scan = scandir( $extractpath );
// Check for export_info.json
if( !in_array( 'export_info.json', $scan ) ){
OC_Log::write( 'migration', 'Invalid import file, export_info.json note found', OC_Log::ERROR );
- return false;
+ return json_encode( array( 'success' => false ) );
}
$json = json_decode( file_get_contents( $extractpath . 'export_info.json' ) );
if( $json->exporttype != $type ){
OC_Log::write( 'migration', 'Invalid import file', OC_Log::ERROR );
- return false;
+ return json_encode( array( 'success' => false ) );
}
self::$exporttype = $type;
@@ -230,31 +230,31 @@ class OC_Migrate{
// Check user availability
if( OC_User::userExists( self::$uid ) ){
OC_Log::write( 'migration', 'User already exists', OC_Log::ERROR );
- return false;
+ return json_encode( array( 'success' => false ) );
}
// Create the user
if( !self::createUser( self::$uid, $json->hash ) ){
- return false;
+ return json_encode( array( 'success' => false ) );
}
// Make the new users data dir
$path = $datadir . '/' . self::$uid . '/files/';
if( !mkdir( $path, 0755, true ) ){
OC_Log::write( 'migration', 'Failed to create users data dir: '.$path, OC_Log::ERROR );
- return false;
+ return json_encode( array( 'success' => false ) );
}
// Copy data
if( !self::copy_r( $extractpath . $json->exporteduser . '/files', $datadir . '/' . self::$uid . '/files' ) ){
- return false;
+ return json_encode( array( 'success' => false ) );
}
// Import user app data
if( !$appsimported = self::importAppData( $extractpath . $json->exporteduser . '/migration.db', $json, self::$uid ) ){
- return false;
+ return json_encode( array( 'success' => false ) );
}
// All done!
if( !self::unlink_r( $extractpath ) ){
OC_Log::write( 'migration', 'Failed to delete the extracted zip', OC_Log::ERROR );
}
- return $appsimported;
+ return json_encode( array( 'success' => true, 'data' => $appsimported ) );
break;
case 'instance':
/*
@@ -266,21 +266,21 @@ class OC_Migrate{
OC_Log::write( 'migration', "Deleting current data dir", OC_Log::INFO );
if( !self::unlink_r( $datadir, false ) ){
OC_Log::write( 'migration', 'Failed to delete the current data dir', OC_Log::ERROR );
- return false;
+ return json_encode( array( 'success' => false ) );
}
// Copy over data
if( !self::copy_r( $extractpath . 'userdata', $datadir ) ){
OC_Log::write( 'migration', 'Failed to copy over data directory', OC_Log::ERROR );
- return false;
+ return json_encode( array( 'success' => false ) );
}
// Import the db
if( !OC_DB::replaceDB( $extractpath . 'dbexport.xml' ) ){
- return false;
+ return json_encode( array( 'success' => false ) );
}
// Done
- return true;
+ return json_encode( 'success' => true );
*/
break;
}