diff --git a/apps/user_migrate/admin.php b/apps/user_migrate/admin.php index d54bd6965b..c1afb0aed4 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'); + if( !OC_Migrate::import( $to, 'user' ) ){ + die( 'failed to to import' ); } - - $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'); - } - - // 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 18b97b93df..4b9cbd1308 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 0058de7391..8b0a2aa3f7 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 ){