summaryrefslogtreecommitdiffstats
path: root/apps/user_migrate
diff options
context:
space:
mode:
authorTom Needham <needham.thomas@gmail.com>2012-03-13 23:09:43 +0000
committerTom Needham <needham.thomas@gmail.com>2012-03-13 23:09:43 +0000
commita310a81053c31205abd6d62491304705b1f565e2 (patch)
tree5704bb5a96430b8fed99dd9f5cebf2c14b7b80f9 /apps/user_migrate
parent5a50144a16fa9b5d8caf9ee261e3c4a39eaa04bc (diff)
downloadnextcloud-server-a310a81053c31205abd6d62491304705b1f565e2.tar.gz
nextcloud-server-a310a81053c31205abd6d62491304705b1f565e2.zip
move zip creation inside OC_Migrate
Diffstat (limited to 'apps/user_migrate')
-rw-r--r--apps/user_migrate/settings.php77
1 files changed, 16 insertions, 61 deletions
diff --git a/apps/user_migrate/settings.php b/apps/user_migrate/settings.php
index 5e8ac9c21df..9fbb4da9e56 100644
--- a/apps/user_migrate/settings.php
+++ b/apps/user_migrate/settings.php
@@ -24,72 +24,27 @@
*/
OC_Util::checkAppEnabled('user_migrate');
-define('DS', '/');
-
if (isset($_POST['user_export'])) {
-
- // Setup the export
- $zip = new ZipArchive();
- $tmp = get_temp_dir();
- $user = OC_User::getUser();
-
- $userdatadir = OC_Config::getValue( 'datadirectory' ) . '/' . $user;
- $filename = $userdatadir . '/owncloud_export_' . $user . '_' . date("y-m-d_H-i-s") . ".zip";
- OC_Log::write('user_migrate',"Creating export file at: " . $filename,OC_Log::INFO);
- if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
- exit("Cannot open <$filename>\n");
- }
-
- // Migrate the app info
- $info = json_encode( OC_Migrate::export( $user ) );
- $infofile = $userdatadir . '/exportinfo.json';
- file_put_contents( $infofile, $info );
-
- // Add the data dir (which includes migration.db and exportinfo.json)
- zipAddDir( $userdatadir, $zip, true, "/" );
-
- // Save the zip
- $zip->close();
-
- // Send the zip
- header("Content-Type: application/zip");
- header("Content-Disposition: attachment; filename=" . basename($filename));
- header("Content-Length: " . filesize($filename));
- @ob_end_clean();
- readfile($filename);
- // Cleanup
- unlink($filename);
- OC_Migrate::cleanUp();
-
+ // Create the export zip
+ $user = OC_User::getUser();
+ $path = OC_Config::getValue( 'datadirectory' ) . '/' . OC_User::getUser() . '/';
+ if( OC_Migrate::createExportFile( $user, $path ) ){
+ // Download it then
+ header("Content-Type: application/zip");
+ header("Content-Disposition: attachment; filename=" . basename($path));
+ header("Content-Length: " . filesize($path));
+ @ob_end_clean();
+ readfile($path);
+ OC_Migrate::cleanUp();
+ } else {
+ die('error');
+ }
} if( isset( $_POST['user_import'] ) ){
// TODO
}else {
-
// fill template
- $tmpl = new OC_Template('user_migrate', 'settings');
- return $tmpl->fetchPage();
-
+ $tmpl = new OC_Template('user_migrate', '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('user_migrate',"Was not able to open directory: " . $dir,OC_Log::ERROR);
- }
-}