diff options
author | Tom Needham <needham.thomas@gmail.com> | 2012-03-19 20:44:20 +0000 |
---|---|---|
committer | Tom Needham <needham.thomas@gmail.com> | 2012-03-19 20:44:20 +0000 |
commit | 145d6f35660669397eaee08988ffbad1b65daff0 (patch) | |
tree | 2aa52588ebc1e4cc1b211cc147febccf1b85e88b /apps/admin_export | |
parent | 77f6872ea4859e13637efbc6d051072a5085394f (diff) | |
download | nextcloud-server-145d6f35660669397eaee08988ffbad1b65daff0.tar.gz nextcloud-server-145d6f35660669397eaee08988ffbad1b65daff0.zip |
Add OC_Migration_Content class to help app devs. Restructure OC_Migrate.
Diffstat (limited to 'apps/admin_export')
-rw-r--r-- | apps/admin_export/settings.php | 134 |
1 files changed, 4 insertions, 130 deletions
diff --git a/apps/admin_export/settings.php b/apps/admin_export/settings.php index 1c98bb552f1..af8dd0dbf54 100644 --- a/apps/admin_export/settings.php +++ b/apps/admin_export/settings.php @@ -27,11 +27,10 @@ OC_Util::checkAppEnabled('admin_export'); define('DS', '/'); - // Export? if (isset($_POST['admin_export'])) { // Create the export zip - if( !$path = OC_Migrate::createSysExportFile( $_POST['export_type'] ) ){ + if( !$path = OC_Migrate::export( $_POST['export_type'] ) ){ // Error die('error'); } else { @@ -46,136 +45,11 @@ if (isset($_POST['admin_export'])) { // Import? } else if( isset($_POST['admin_import']) ){ - $root = OC::$SERVERROOT . "/"; - $importname = "owncloud_import_" . date("y-m-d_H-i-s"); - - // Save data dir for later - $datadir = OC_Config::getValue( 'datadirectory' ); - - // Copy the uploaded file - $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); - 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); - exit(); - } - $zip->extractTo(get_temp_dir().'/'.$importname.'/'); - $zip->close(); - - // Delete uploaded file - unlink( get_temp_dir() . '/' . $importname . '.zip' ); - - // Now we need to check if everything is present. Data and dbexport.xml - - - // Delete current data folder. - OC_Log::write('admin_export',"Deleting current data dir",OC_Log::INFO); - unlinkRecursive( $datadir, false ); - - // Copy over data - if( !copy_r( get_temp_dir() . '/' . $importname . '/data', $datadir ) ){ - OC_Log::write('admin_export',"Failed to copy over data directory",OC_Log::INFO); - exit(); - } - - OC_DB::replaceDB( get_temp_dir() . '/' . $importname . '/dbexport.xml' ); + // TODO + // OC_Migrate::import( $pathtozipfile ); } else { // fill template $tmpl = new OC_Template('admin_export', 'settings'); return $tmpl->fetchPage(); -} - -function zipAddDir($dir, $zip, $recursive=true, $internalDir='') { - $dirname = basename($dir); - $zip->addEmptyDir($internalDir . $dirname); - $internalDir.=$dirname.='/'; - - if ($dirhandle = opendir($dir)) { - while (false !== ( $file = readdir($dirhandle))) { - - if (( $file != '.' ) && ( $file != '..' )) { - - if (is_dir($dir . '/' . $file) && $recursive) { - zipAddDir($dir . '/' . $file, $zip, $recursive, $internalDir); - } elseif (is_file($dir . '/' . $file)) { - $zip->addFile($dir . '/' . $file, $internalDir . $file); - } - } - } - closedir($dirhandle); - } else { - OC_Log::write('admin_export',"Was not able to open directory: " . $dir,OC_Log::ERROR); - } -} - -function unlinkRecursive($dir, $deleteRootToo) -{ - if(!$dh = @opendir($dir)) - { - return; - } - while (false !== ($obj = readdir($dh))) - { - if($obj == '.' || $obj == '..') - { - continue; - } - - if (!@unlink($dir . '/' . $obj)) - { - unlinkRecursive($dir.'/'.$obj, true); - } - } - - closedir($dh); - - if ($deleteRootToo) - { - @rmdir($dir); - } - - return; -} - - function copy_r( $path, $dest ) - { - if( is_dir($path) ) - { - @mkdir( $dest ); - $objects = scandir($path); - if( sizeof($objects) > 0 ) - { - foreach( $objects as $file ) - { - if( $file == "." || $file == ".." ) - continue; - // go on - if( is_dir( $path.DS.$file ) ) - { - copy_r( $path.DS.$file, $dest.DS.$file ); - } - else - { - copy( $path.DS.$file, $dest.DS.$file ); - } - } - } - return true; - } - elseif( is_file($path) ) - { - return copy($path, $dest); - } - else - { - return false; - } - } +}
\ No newline at end of file |