summaryrefslogtreecommitdiffstats
path: root/apps/user_migrate
diff options
context:
space:
mode:
authorTom Needham <needham.thomas@gmail.com>2012-03-13 16:21:17 +0000
committerTom Needham <needham.thomas@gmail.com>2012-03-13 16:21:17 +0000
commit4d5646a59f813e09455c78d840d0f62397ec60ad (patch)
treef22c4bd65a4f6bca4b5669c2ca93ac599c1f90b3 /apps/user_migrate
parentd108bdc7c7940d23355c9a16f3f355387bbb66ef (diff)
downloadnextcloud-server-4d5646a59f813e09455c78d840d0f62397ec60ad.tar.gz
nextcloud-server-4d5646a59f813e09455c78d840d0f62397ec60ad.zip
Find migrate.php even for disabled apps. Improve ui for user and admin migrations
Diffstat (limited to 'apps/user_migrate')
-rw-r--r--apps/user_migrate/settings.php91
-rw-r--r--apps/user_migrate/templates/settings.php15
2 files changed, 64 insertions, 42 deletions
diff --git a/apps/user_migrate/settings.php b/apps/user_migrate/settings.php
index c1121f2ddf5..3b82e148b5c 100644
--- a/apps/user_migrate/settings.php
+++ b/apps/user_migrate/settings.php
@@ -3,6 +3,8 @@
/**
* ownCloud - user_migrate
*
+ * @author Thomas Schmidt
+ * @copyright 2011 Thomas Schmidt tom@opensuse.org
* @author Tom Needham
* @copyright 2012 Tom Needham tom@owncloud.com
*
@@ -22,52 +24,67 @@
*/
OC_Util::checkAppEnabled('user_migrate');
+define('DS', '/');
-if (isset($_POST['user_migrate'])) {
- // Looks like they want to migrate
- $root = OC::$SERVERROOT . "/";
- $user = OC_User::getUser();
+if (isset($_POST['user_export'])) {
+
+ // Setup the export
$zip = new ZipArchive();
- $tempdir = get_temp_dir();
- $filename = $tempdir . "/" . $user . "_export_" . date("y-m-d_H-i-s") . ".zip";
- OC_Log::write('user_migrate',"Creating user export file at: " . $filename,OC_Log::INFO);
- if ($zip->open($filename, ZIPARCHIVE::CREATE) !== TRUE) {
- exit("Cannot open <$filename>\n");
+ $tmp = get_temp_dir();
+ $user = OC_User::getUser();
+ // Create owncoud dir
+ if( !file_exists( $tmp . '/owncloud' ) ){
+ if( !mkdir( $tmp . '/owncloud' ) ){
+ die('Failed to create the owncloud tmp directory');
+ }
}
-
- // Does the user want to include their files?
- if (isset($_POST['user_files'])) {
- // needs to handle data outside of the default data dir.
- // adding user files
- OC_Log::write('user_migrate',"Adding owncloud user files of $user to export",OC_Log::INFO);
- zipAddDir($root . "data/" . $user, $zip, true, "files/");
+ // Create the export dir
+ $exportdir = $tmp . '/owncloud' . '/export_' . $user . '_' . date("y-m-d_H-i-s");
+ if( !file_exists( $exportdir ) ){
+ if( !mkdir( $exportdir ) ){
+ die('Failed to create the owncloud export directory');
+ }
}
-
- // Does the user want their app data?
- if (isset($_POST['user_appdata'])) {
- // adding owncloud system files
- OC_Log::write('user_migrate',"Adding app data to user export file",OC_Log::INFO);
- // Call to OC_Migrate for the xml file.
-
- // Create migration.db
- OC_Migrate::export(OC_User::getUser());
- // Add export db to zip
- $zip->addFile($root.'data/'.$user.'/migration.db', "migration.db");
-
+ $filename = $exportdir . '/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 = OC_Migrate::export( $user );
+ $infofile = $exportdir . '/exportinfo.json';
+ if( !file_put_contents( $infofile, $info ) ){
+ die('Failed to save the export info');
+ }
+ $zip->addFile( $infofile, "exportinfo.json");
+ $zip->addFile(OC::$SERVERROOT . '/data/' . $user . '/migration.db', "migration.db");
+ // Add the data dir
+ zipAddDir(OC::$SERVERROOT . "/data/" . $user, $zip, true, "files/");
+
+ // Save the zip
$zip->close();
-
- //header("Content-Type: application/zip");
- //header("Content-Disposition: attachment; filename=" . basename($filename));
- //header("Content-Length: " . filesize($filename));
- //readfile($filename);
- //unlink($filename);
-} else {
-// fill template
+ // 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);
+ unlink($infofile);
+ rmdir($exportdir);
+
+} if( isset( $_POST['user_import'] ) ){
+ // TODO
+}else {
+
+ // fill template
$tmpl = new OC_Template('user_migrate', 'settings');
return $tmpl->fetchPage();
+
}
function zipAddDir($dir, $zip, $recursive=true, $internalDir='') {
@@ -89,6 +106,6 @@ function zipAddDir($dir, $zip, $recursive=true, $internalDir='') {
}
closedir($dirhandle);
} else {
- OC_Log::write('admin_export',"Was not able to open directory: " . $dir,OC_Log::ERROR);
+ OC_Log::write('user_migrate',"Was not able to open directory: " . $dir,OC_Log::ERROR);
}
}
diff --git a/apps/user_migrate/templates/settings.php b/apps/user_migrate/templates/settings.php
index ece8f70e064..59a27a926d8 100644
--- a/apps/user_migrate/templates/settings.php
+++ b/apps/user_migrate/templates/settings.php
@@ -1,12 +1,17 @@
<form id="export" action="#" method="post">
<fieldset class="personalblock">
<legend><strong><?php echo $l->t('Export your user account');?></strong></legend>
- <p><?php echo $l->t('This will create a compressed file that contains the data of owncloud account.
- Please choose which components should be included:');?>
+ <p><?php echo $l->t('This will create a compressed file that contains your ownCloud account.');?>
</p>
- <p><input type="checkbox" id="user_files" name="user_files" value="true"><label for="user_files"><?php echo $l->t('Files');?></label><br/>
- <input type="checkbox" id="user_appdata" name="user_appdata" value="true"><label for="owncloud_system"><?php echo $l->t('User app data');?></label><br/>
+ <input type="submit" name="user_export" value="Export" />
+ </fieldset>
+</form>
+<form id="import" action="#" method="post" enctype="multipart/form-data">
+ <fieldset class="personalblock">
+ <legend><strong><?php echo $l->t('Import user account');?></strong></legend>
+ </p>
+ <p><input type="file" id="owncloud_import" name="owncloud_import"><label for="owncloud_import"><?php echo $l->t('ownCloud User Zip');?></label>
</p>
- <input type="submit" name="user_migrate" value="Export" />
+ <input type="submit" name="user_import" value="<?php echo $l->t('Import'); ?>" />
</fieldset>
</form>