Initial migration code, and basic export for bookmarks
This commit is contained in:
parent
6583d30e26
commit
5507db9b15
|
@ -5,6 +5,8 @@
|
||||||
*
|
*
|
||||||
* @author Thomas Schmidt
|
* @author Thomas Schmidt
|
||||||
* @copyright 2011 Thomas Schmidt tom@opensuse.org
|
* @copyright 2011 Thomas Schmidt tom@opensuse.org
|
||||||
|
* @author Tom Needham
|
||||||
|
* @copyright 2012 Tom Needham tom@owncloud.com
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
|
||||||
|
@ -22,6 +24,8 @@
|
||||||
*/
|
*/
|
||||||
OC_Util::checkAdminUser();
|
OC_Util::checkAdminUser();
|
||||||
OC_Util::checkAppEnabled('admin_export');
|
OC_Util::checkAppEnabled('admin_export');
|
||||||
|
|
||||||
|
|
||||||
if (isset($_POST['admin_export'])) {
|
if (isset($_POST['admin_export'])) {
|
||||||
$root = OC::$SERVERROOT . "/";
|
$root = OC::$SERVERROOT . "/";
|
||||||
$zip = new ZipArchive();
|
$zip = new ZipArchive();
|
||||||
|
@ -49,6 +53,7 @@ if (isset($_POST['admin_export'])) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($_POST['user_files'])) {
|
if (isset($_POST['user_files'])) {
|
||||||
|
// needs to handle data outside of the default data dir.
|
||||||
// adding user files
|
// adding user files
|
||||||
$zip->addFile($root . '/data/.htaccess', basename($root) . "/data/.htaccess");
|
$zip->addFile($root . '/data/.htaccess', basename($root) . "/data/.htaccess");
|
||||||
$zip->addFile($root . '/data/index.html', basename($root) . "/data/index.html");
|
$zip->addFile($root . '/data/index.html', basename($root) . "/data/index.html");
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class OC_Migrate_Provider_Bookmarks extends OC_Migrate_Provider{
|
||||||
|
$this->appid = 'bookmarks';
|
||||||
|
// Create the xml for the user supplied
|
||||||
|
function export($uid){
|
||||||
|
$xml = '';
|
||||||
|
$query = OC_DB::prepare("SELECT * FROM *PREFIX*bookmarks WHERE *PREFIX*bookmakrs.user_id = ?");
|
||||||
|
$bookmarks = $query->execute($uid);
|
||||||
|
OC_Log::write('user_migrate',print_r($bookmarks));
|
||||||
|
foreach($bookmarks as $bookmark){
|
||||||
|
$xml .= '<bookmark>';
|
||||||
|
$xml .='DATA WILL BE HERE';
|
||||||
|
$xml .= '</bookmark>';
|
||||||
|
}
|
||||||
|
return $xml;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ownCloud - user_migrate
|
||||||
|
*
|
||||||
|
* @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_APP::registerPersonal('user_migrate','settings');
|
||||||
|
|
||||||
|
?>
|
|
@ -0,0 +1,11 @@
|
||||||
|
<?xml version="1.0"?>
|
||||||
|
<info>
|
||||||
|
<id>user_migrate</id>
|
||||||
|
<name>User Account Migration</name>
|
||||||
|
<description>Migrate your user accounts</description>
|
||||||
|
<version>0.1</version>
|
||||||
|
<licence>AGPL</licence>
|
||||||
|
<author>Tom Needham</author>
|
||||||
|
<require>2</require>
|
||||||
|
<default_enable/>
|
||||||
|
</info>
|
|
@ -0,0 +1,95 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ownCloud - user_migrate
|
||||||
|
*
|
||||||
|
* @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');
|
||||||
|
|
||||||
|
|
||||||
|
if (isset($_POST['user_migrate'])) {
|
||||||
|
// Looks like they want to migrate
|
||||||
|
$errors = array();
|
||||||
|
$root = OC::$SERVERROOT . "/";
|
||||||
|
$user = OC_User::getUser();
|
||||||
|
$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");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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/");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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",OC_Log::INFO);
|
||||||
|
// Call to OC_Migrate for the xml file.
|
||||||
|
$appdatafile = $tempdir . "/appdata.xml";
|
||||||
|
$fh = fopen($appdatafile, 'w');
|
||||||
|
$appdata = OC_Migrate::export(OC_User::getUser());
|
||||||
|
fwrite($fh, $appdata);
|
||||||
|
$zip->addFile($appdatafile, "appdata.xml");
|
||||||
|
fclose($fh);
|
||||||
|
}
|
||||||
|
|
||||||
|
$zip->close();
|
||||||
|
|
||||||
|
header("Content-Type: application/zip");
|
||||||
|
header("Content-Disposition: attachment; filename=" . basename($filename));
|
||||||
|
header("Content-Length: " . filesize($filename));
|
||||||
|
@ob_end_clean();
|
||||||
|
readfile($filename);
|
||||||
|
unlink($filename);
|
||||||
|
} else {
|
||||||
|
// fill template
|
||||||
|
$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('admin_export',"Was not able to open directory: " . $dir,OC_Log::ERROR);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,12 @@
|
||||||
|
<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>
|
||||||
|
<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/>
|
||||||
|
</p>
|
||||||
|
<input type="submit" name="user_migrate" value="Export" />
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
|
@ -0,0 +1,66 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* ownCloud
|
||||||
|
*
|
||||||
|
* @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/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* provides an interface to all search providers
|
||||||
|
*/
|
||||||
|
class OC_Migrate{
|
||||||
|
static public $providers=array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* register a new migration provider
|
||||||
|
* @param OC_Migrate_Provider $provider
|
||||||
|
*/
|
||||||
|
public static function registerProvider($provider){
|
||||||
|
self::$providers[]=$provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* export app data for a user
|
||||||
|
* @param string userid
|
||||||
|
* @return string xml of app data
|
||||||
|
*/
|
||||||
|
public static function export($uid){
|
||||||
|
$xml = '';
|
||||||
|
foreach(self::$providers as $provider){
|
||||||
|
$xml .= '<app>';
|
||||||
|
$xml .= self::appInfoXML($provider->$appid);
|
||||||
|
$xml .= $provider->export($uid));
|
||||||
|
$xml .= '</app>';
|
||||||
|
}
|
||||||
|
return $xml;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* generates the app info xml
|
||||||
|
* @param string appid
|
||||||
|
* @return string xml app info
|
||||||
|
*/
|
||||||
|
public static function appInfoXML($appid){
|
||||||
|
$info = OC_App::getAppInfo($appid);
|
||||||
|
$xml = '<appinfo>';
|
||||||
|
$zml .= 'INFO HERE';
|
||||||
|
$xml .= '</appinfo>';
|
||||||
|
return $xml;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* provides search functionalty
|
||||||
|
*/
|
||||||
|
abstract class OC_Migrate_Provider{
|
||||||
|
public function __construct(){
|
||||||
|
OC_Migrate::registerProvider($this);
|
||||||
|
}
|
||||||
|
public static $appid;
|
||||||
|
/**
|
||||||
|
* exports data for apps
|
||||||
|
* @param string $uid
|
||||||
|
* @return string xml data for that app
|
||||||
|
*/
|
||||||
|
abstract function export($uid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* imports data for the app
|
||||||
|
* @param string $query
|
||||||
|
* @return array An array of OC_Search_Result's
|
||||||
|
*/
|
||||||
|
abstract function import($data);
|
||||||
|
}
|
Loading…
Reference in New Issue