diff options
author | Tom Needham <needham.thomas@gmail.com> | 2012-03-17 16:25:14 +0000 |
---|---|---|
committer | Tom Needham <needham.thomas@gmail.com> | 2012-03-17 16:25:14 +0000 |
commit | bc085c3ff40bd7980bb28a20238bf18a754ffba2 (patch) | |
tree | 6819a1fe9c4eb04a49d632146bbe8c344aad1308 /lib/migrate.php | |
parent | 247b25e7a97fcbe8386c63b1318537e669d40480 (diff) | |
download | nextcloud-server-bc085c3ff40bd7980bb28a20238bf18a754ffba2.tar.gz nextcloud-server-bc085c3ff40bd7980bb28a20238bf18a754ffba2.zip |
Create new user, create new data dir, copy files, import app data
Diffstat (limited to 'lib/migrate.php')
-rw-r--r-- | lib/migrate.php | 65 |
1 files changed, 36 insertions, 29 deletions
diff --git a/lib/migrate.php b/lib/migrate.php index 44d28297d48..415c33e5bea 100644 --- a/lib/migrate.php +++ b/lib/migrate.php @@ -53,6 +53,21 @@ class OC_Migrate{ self::$providers[]=$provider; } + /** + * @breif finds and loads the providers + */ + static private function findProviders(){ + // Find the providers + $apps = OC_App::getAllApps(); + + foreach($apps as $app){ + $path = OC::$SERVERROOT . '/apps/' . $app . '/lib/migrate.php'; + if( file_exists( $path ) ){ + include( $path ); + } + } + } + /** * @breif creates a migration.db in the users data dir with their app data in * @return bool whether operation was successfull @@ -64,14 +79,7 @@ class OC_Migrate{ $return = array(); // Find the providers - $apps = OC_App::getAllApps(); - - foreach($apps as $app){ - $path = OC::$SERVERROOT . '/apps/' . $app . '/lib/migrate.php'; - if( file_exists( $path ) ){ - include( $path ); - } - } + self::findProviders(); // Foreach provider foreach( self::$providers as $provider ){ @@ -217,7 +225,8 @@ class OC_Migrate{ OC_Log::write( 'migration', 'Failed to get the users password hash', OC_log::ERROR); return false; } - $info['hash'] = $hash; + $info['hash'] = $hash; + $info['exporteduser'] = self::$uid; } // Merge in other data $info = array_merge( $info, $array ); @@ -393,17 +402,15 @@ class OC_Migrate{ * @param $uid optional uid to use * @return bool if the import succedded */ - public static function importAppData( $db, $info, $uid=false ){ + public static function importAppData( $db, $info, $uid=null ){ - if(!self::$uid){ - OC_Log::write('migration','Tried to import without passing a uid',OC_Log::FATAL); - return false; - } + self::$uid = !is_null( $uid ) ? $uid : $info->exporteduser; // Check if the db exists if( file_exists( $db ) ){ // Connect to the db if(!self::connectDB( $db )){ + OC_Log::write('migration','Failed to connect to migration.db',OC_Log::ERROR); return false; } } else { @@ -411,25 +418,25 @@ class OC_Migrate{ return false; } - if( !is_array( $info ) ){ - OC_Log::write('migration','$migrateinfo is not an array', OC_Log::FATAL); - return false; - } - - // Set the user id - self::$uid = $info->migrateinfo->uid; - - $apps = $info->app; - + // Find providers + self::findProviders(); + + // Generate importinfo array + $importinfo = array( + 'olduid' => $info->exporteduser, + 'newuid' => self::$uid + ); + foreach( self::$providers as $provider){ // Is the app in the export? - if( array_key_exists( $provider->id, $apps ) ){ + $id = $provider->id; + if( isset( $info->apps->$id ) ){ // Did it succeed? - if( $app[$provider->id] ){ + if( $info->apps->$id->success ){ // Then do the import - $provider->import( $info ); + $provider->import( $info->apps->$id, $importinfo ); } - } + } } return true; @@ -691,7 +698,7 @@ class OC_Migrate{ // Create the user $query = OC_DB::prepare( "INSERT INTO `*PREFIX*users` ( `uid`, `password` ) VALUES( ?, ? )" ); - $result = $query->execute( array( $uid, $data['hash'])); + $result = $query->execute( array( $uid, $hash)); if( !$result ){ OC_Log::write('migration', 'Failed to create the new user "'.$uid.""); } |