2012-02-04 00:32:06 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ownCloud - user_migrate
|
|
|
|
*
|
2012-03-13 20:21:17 +04:00
|
|
|
* @author Thomas Schmidt
|
|
|
|
* @copyright 2011 Thomas Schmidt tom@opensuse.org
|
2012-02-04 00:32:06 +04:00
|
|
|
* @author Tom Needham
|
|
|
|
* @copyright 2012 Tom Needham tom@owncloud.com
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
OC_Util::checkAppEnabled('user_migrate');
|
|
|
|
|
2012-03-13 20:21:17 +04:00
|
|
|
define('DS', '/');
|
2012-02-04 00:32:06 +04:00
|
|
|
|
2012-03-13 20:21:17 +04:00
|
|
|
if (isset($_POST['user_export'])) {
|
|
|
|
|
|
|
|
// Setup the export
|
2012-02-04 00:32:06 +04:00
|
|
|
$zip = new ZipArchive();
|
2012-03-13 20:21:17 +04:00
|
|
|
$tmp = get_temp_dir();
|
|
|
|
$user = OC_User::getUser();
|
2012-03-13 21:27:47 +04:00
|
|
|
|
|
|
|
$userdatadir = OC_Config::getValue( 'datadirectory' ) . '/' . $user;
|
|
|
|
$filename = $userdatadir . '/owncloud_export_' . $user . '_' . date("y-m-d_H-i-s") . ".zip";
|
2012-03-13 20:21:17 +04:00
|
|
|
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");
|
2012-02-04 00:32:06 +04:00
|
|
|
}
|
2012-03-13 20:21:17 +04:00
|
|
|
|
|
|
|
// Migrate the app info
|
2012-03-13 21:04:49 +04:00
|
|
|
$info = json_encode( OC_Migrate::export( $user ) );
|
2012-03-13 21:27:47 +04:00
|
|
|
$infofile = $userdatadir . '/exportinfo.json';
|
2012-03-13 21:08:20 +04:00
|
|
|
file_put_contents( $infofile, $info );
|
2012-02-04 00:32:06 +04:00
|
|
|
|
2012-03-13 21:08:20 +04:00
|
|
|
// Add the data dir (which includes migration.db and exportinfo.json)
|
2012-03-13 21:27:47 +04:00
|
|
|
zipAddDir( $userdatadir, $zip, true, "/" );
|
2012-03-13 20:21:17 +04:00
|
|
|
|
|
|
|
// Save the zip
|
2012-02-04 00:32:06 +04:00
|
|
|
$zip->close();
|
2012-03-03 17:26:01 +04:00
|
|
|
|
2012-03-13 20:21:17 +04:00
|
|
|
// 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);
|
2012-03-13 21:18:42 +04:00
|
|
|
OC_Migrate::cleanUp();
|
2012-03-13 20:21:17 +04:00
|
|
|
|
|
|
|
} if( isset( $_POST['user_import'] ) ){
|
|
|
|
// TODO
|
|
|
|
}else {
|
|
|
|
|
|
|
|
// fill template
|
2012-02-04 00:32:06 +04:00
|
|
|
$tmpl = new OC_Template('user_migrate', 'settings');
|
|
|
|
return $tmpl->fetchPage();
|
2012-03-13 20:21:17 +04:00
|
|
|
|
2012-02-04 00:32:06 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2012-03-13 20:21:17 +04:00
|
|
|
OC_Log::write('user_migrate',"Was not able to open directory: " . $dir,OC_Log::ERROR);
|
2012-02-04 00:32:06 +04:00
|
|
|
}
|
|
|
|
}
|