Add exportinfo to user exports.
This commit is contained in:
parent
27bf34f7be
commit
5234e66bab
|
@ -1,10 +1,8 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* ownCloud - admin export
|
||||
* ownCloud - user_migrate
|
||||
*
|
||||
* @author Thomas Schmidt
|
||||
* @copyright 2011 Thomas Schmidt tom@opensuse.org
|
||||
* @author Tom Needham
|
||||
* @copyright 2012 Tom Needham tom@owncloud.com
|
||||
*
|
||||
|
@ -26,7 +24,7 @@ OC_Util::checkAdminUser();
|
|||
OC_Util::checkAppEnabled('user_migrate');
|
||||
|
||||
// Import?
|
||||
if (isset($_POST['userimport'])) {
|
||||
if (isset($_POST['user_import'])) {
|
||||
|
||||
$root = OC::$SERVERROOT . "/";
|
||||
$importname = "owncloud_import_" . date("y-m-d_H-i-s");
|
||||
|
@ -38,14 +36,14 @@ if (isset($_POST['userimport'])) {
|
|||
$from = $_FILES['owncloud_import']['tmp_name'];
|
||||
$to = get_temp_dir().'/'.$importname.'.zip';
|
||||
if( !move_uploaded_file( $from, $to ) ){
|
||||
OC_Log::write('admin_export',"Failed to copy the uploaded file",OC_Log::INFO);
|
||||
OC_Log::write('migration',"Failed to copy the uploaded file",OC_Log::INFO);
|
||||
exit();
|
||||
}
|
||||
|
||||
// Extract zip
|
||||
$zip = new ZipArchive();
|
||||
if ($zip->open(get_temp_dir().'/'.$importname.'.zip') != TRUE) {
|
||||
OC_Log::write('admin_export',"Failed to open zip file",OC_Log::INFO);
|
||||
OC_Log::write('migration',"Failed to open zip file",OC_Log::INFO);
|
||||
exit();
|
||||
}
|
||||
$zip->extractTo(get_temp_dir().'/'.$importname.'/');
|
||||
|
|
|
@ -84,7 +84,7 @@ class OC_Migrate{
|
|||
if( is_array( $tables ) ){
|
||||
// Save the table names
|
||||
foreach($tables as $table){
|
||||
$return['app'][$provider->id]['tables'][] = $table;
|
||||
$return['apps'][$provider->id]['tables'][] = $table;
|
||||
}
|
||||
} else {
|
||||
// It failed to create the tables
|
||||
|
@ -94,22 +94,17 @@ class OC_Migrate{
|
|||
|
||||
// Run the import function?
|
||||
if( !$failed ){
|
||||
$return['app'][$provider->id]['success'] = $provider->export( self::$uid );
|
||||
$return['apps'][$provider->id]['success'] = $provider->export( self::$uid );
|
||||
} else {
|
||||
$return['app'][$provider->id]['success'] = false;
|
||||
$return['app'][$provider->id]['message'] = 'failed to create the app tables';
|
||||
$return['apps'][$provider->id]['success'] = false;
|
||||
$return['apps'][$provider->id]['message'] = 'failed to create the app tables';
|
||||
}
|
||||
|
||||
// Now add some app info the the return array
|
||||
$appinfo = OC_App::getAppInfo( $provider->id );
|
||||
$return['app'][$provider->id]['version'] = $appinfo['version'];
|
||||
$return['apps'][$provider->id]['version'] = $appinfo['version'];
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Add some general info to the return array
|
||||
$return['migrateinfo']['uid'] = self::$uid;
|
||||
$return['migrateinfo']['ocversion'] = OC_Util::getVersionString();
|
||||
|
||||
return $return;
|
||||
|
||||
|
@ -205,13 +200,27 @@ class OC_Migrate{
|
|||
* @breif adds a json file with infomation on the export to the zips root (used on import)
|
||||
* @return bool
|
||||
*/
|
||||
static private function addExportInfo(){
|
||||
static private function addExportInfo( $array=array() ){
|
||||
$info = array(
|
||||
'ocversion' => OC_Util::getVersion(),
|
||||
'exporttime' => time(),
|
||||
'exportedby' => OC_User::getUser(),
|
||||
'exporttype' => self::$exporttype
|
||||
);
|
||||
// Add hash if user export
|
||||
if( self::$exporttype = 'user' ){
|
||||
$query = OC_DB::prepare( "SELECT password FROM *PREFIX*users WHERE uid LIKE ?" );
|
||||
$result = $query->execute( array( self::$uid ) );
|
||||
$row = $result->fetchRow();
|
||||
$hash = $row ? $row['password'] : false;
|
||||
if( !$hash ){
|
||||
OC_Log::write( 'migration', 'Failed to get the users password hash', OC_log::ERROR);
|
||||
return false;
|
||||
}
|
||||
$info['hash'] = $hash;
|
||||
}
|
||||
// Merge in other data
|
||||
$info = array_merge( $info, $array );
|
||||
// Create json
|
||||
$json = json_encode( $info );
|
||||
$tmpfile = tempnam("/tmp", "oc_export_info_");
|
||||
|
@ -297,8 +306,8 @@ class OC_Migrate{
|
|||
return false;
|
||||
}
|
||||
// Export the app info
|
||||
$info = json_encode( self::exportAppData() );
|
||||
file_put_contents( $userdatadir . '/exportinfo.json', $info );
|
||||
$exportinfo = json_encode( self::addExportInfo( self::exportAppData() ) );
|
||||
file_put_contents( $userdatadir . '/exportinfo.json', $exportinfo );
|
||||
// Add the data dir to the zip
|
||||
self::addDirToZip( $userdatadir );
|
||||
// Close the zip
|
||||
|
@ -670,7 +679,7 @@ class OC_Migrate{
|
|||
// @param $uid string user_id of the user to be created
|
||||
// @param $hash string hash of the user to be created
|
||||
// @return bool result of user creation
|
||||
private static function createUser( $uid, $hash ){
|
||||
public static function createUser( $uid, $hash ){
|
||||
|
||||
// Check if userid exists
|
||||
if(OC_User::userExists( $uid )){
|
||||
|
|
Loading…
Reference in New Issue