summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Needham <needham.thomas@gmail.com>2012-03-20 20:32:01 +0000
committerTom Needham <needham.thomas@gmail.com>2012-03-20 20:32:01 +0000
commit0fa5e196ef8d0b220e4af17b008fb4908b080445 (patch)
tree956a534595f047dc603ca15afcc4914c0e4ac8c5
parent514c9ad8e7df1d7882adc33c42eb32a209537273 (diff)
downloadnextcloud-server-0fa5e196ef8d0b220e4af17b008fb4908b080445.tar.gz
nextcloud-server-0fa5e196ef8d0b220e4af17b008fb4908b080445.zip
Try to use old uid when importing
-rw-r--r--apps/user_migrate/admin.php65
-rw-r--r--apps/user_migrate/appinfo/app.php1
-rw-r--r--lib/migrate.php11
3 files changed, 11 insertions, 66 deletions
diff --git a/apps/user_migrate/admin.php b/apps/user_migrate/admin.php
index d54bd6965b5..c1afb0aed4f 100644
--- a/apps/user_migrate/admin.php
+++ b/apps/user_migrate/admin.php
@@ -40,69 +40,10 @@ if (isset($_POST['user_import'])) {
exit();
}
- OC_Migrate::import( $to, 'user', 'newuser' );
- die();
- // Find folder
- $files = scandir( $importdir );
- unset($files[0]);
- unset($files[1]);
-
- // Get the user
- if( count($files) != 1 ){
- OC_Log::write('migration', 'Invalid import file', OC_Log::ERROR);
- die('invalid import, no user included');
- }
-
- $olduser = reset($files);
-
- // Check for dbexport.xml and export info and data dir
- $files = scandir( $importdir . '/' . $olduser );
-
- $required = array( 'migration.db', 'export_info.json', 'files');
- foreach($required as $require){
- if( !in_array( $require, $files) ){
- OC_Log::write('migration', 'Invlaid import file', OC_Log::ERROR);
- die('invalid import');
- }
- }
-
- $migrateinfo = $importdir . '/' . $olduser . '/export_info.json';
- $migrateinfo = json_decode( file_get_contents( $migrateinfo ) );
-
- // Check if uid is available
- if( OC_User::UserExists( $olduser ) ){
- OC_Log::write('migration','Username exists', OC_Log::ERROR);
- die('user exists');
- }
-
- // Create the user
- if( !OC_Migrate::createUser( $olduser, $migrateinfo->hash ) ){
- OC_Log::write('migration', 'Failed to create the new user', OC_Log::ERROR);
- die('coundlt create new user');
- }
-
- $datadir = OC_Config::getValue( 'datadirectory' );
- // Make the new users data dir
- $path = $datadir . '/' . $olduser . '/files/';
- if( !mkdir( $path, 0755, true ) ){
- OC_Log::write('migration','Failed to create users data dir: '.$path, OC_Log::ERROR);
- die('failed to create users data dir');
- }
-
- // Copy data
- if( !copy_r( $importdir . '/' . $olduser . '/files', $datadir . '/' . $olduser . '/files' ) ){
- OC_Log::write('migration','Failed to copy user files to destination', OC_Log::ERROR);
- die('failed to copy user files');
+ if( !OC_Migrate::import( $to, 'user' ) ){
+ die( 'failed to to import' );
}
-
- // Import user data
- if( !OC_Migrate::importAppData( $importdir . '/' . $olduser . '/migration.db', $migrateinfo ) ){
- OC_Log::write('migration','Failed to import user data', OC_Log::ERROR);
- die('failed to import user data');
- }
-
- // All done!
- die('done');
+
} else {
// fill template
diff --git a/apps/user_migrate/appinfo/app.php b/apps/user_migrate/appinfo/app.php
index 18b97b93df1..4b9cbd1308a 100644
--- a/apps/user_migrate/appinfo/app.php
+++ b/apps/user_migrate/appinfo/app.php
@@ -22,7 +22,6 @@
*/
OC_APP::registerPersonal('user_migrate','settings');
-OC_APP::registerAdmin('user_migrate','admin');
// add settings page to navigation
$entry = array(
diff --git a/lib/migrate.php b/lib/migrate.php
index 0058de73919..8b0a2aa3f74 100644
--- a/lib/migrate.php
+++ b/lib/migrate.php
@@ -190,9 +190,10 @@ class OC_Migrate{
/**
* @breif imports a user, or owncloud instance
* @param $path string path to zip
+ * @param optional $type type of import (user or instance)
* @param optional $uid userid of new user
*/
- public static function import( $path, $uid=null ){
+ public static function import( $path, $type='user', $uid=null ){
OC_Util::checkAdminUser();
$datadir = OC_Config::getValue( 'datadirectory' );
// Extract the zip
@@ -207,8 +208,12 @@ class OC_Migrate{
return false;
}
$json = json_decode( file_get_contents( $extractpath . 'export_info.json' ) );
- self::$exporttype = $json->exporttype;
-
+ if( !$json->exporttype != $type ){
+ OC_Log::write( 'migration', 'Invalid import file', OC_Log::ERROR );
+ return false;
+ }
+ self::$exporttype = $type;
+
// Have we got a user if type is user
if( self::$exporttype == 'user' ){
if( !$uid ){