Import Module documentation and @-sign replacement.
If you copy the identity from your profile page the @-sign is invalid for the import and fails. Replace it for convenience.
This commit is contained in:
parent
2115eb26a7
commit
49e77e0f71
@ -2,23 +2,29 @@
|
|||||||
|
|
||||||
namespace Zotlabs\Module;
|
namespace Zotlabs\Module;
|
||||||
|
|
||||||
// Import a channel, either by direct file upload or via
|
|
||||||
// connection to original server.
|
|
||||||
|
|
||||||
|
|
||||||
require_once('include/zot.php');
|
require_once('include/zot.php');
|
||||||
require_once('include/channel.php');
|
require_once('include/channel.php');
|
||||||
require_once('include/import.php');
|
require_once('include/import.php');
|
||||||
require_once('include/perm_upgrade.php');
|
require_once('include/perm_upgrade.php');
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Module for channel import.
|
||||||
|
*
|
||||||
|
* Import a channel, either by direct file upload or via
|
||||||
|
* connection to another server.
|
||||||
|
*/
|
||||||
class Import extends \Zotlabs\Web\Controller {
|
class Import extends \Zotlabs\Web\Controller {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Import channel into account.
|
||||||
|
*
|
||||||
|
* @param int $account_id
|
||||||
|
*/
|
||||||
function import_account($account_id) {
|
function import_account($account_id) {
|
||||||
|
|
||||||
if(! $account_id){
|
if(! $account_id){
|
||||||
logger("import_account: No account ID supplied");
|
logger('No account ID supplied');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,11 +39,11 @@ class Import extends \Zotlabs\Web\Controller {
|
|||||||
$filesize = intval($_FILES['filename']['size']);
|
$filesize = intval($_FILES['filename']['size']);
|
||||||
$filetype = $_FILES['filename']['type'];
|
$filetype = $_FILES['filename']['type'];
|
||||||
|
|
||||||
|
// import channel from file
|
||||||
if($src) {
|
if($src) {
|
||||||
|
|
||||||
// This is OS specific and could also fail if your tmpdir isn't very large
|
// This is OS specific and could also fail if your tmpdir isn't very
|
||||||
// mostly used for Diaspora which exports gzipped files.
|
// large mostly used for Diaspora which exports gzipped files.
|
||||||
|
|
||||||
if(strpos($filename,'.gz')){
|
if(strpos($filename,'.gz')){
|
||||||
@rename($src,$src . '.gz');
|
@rename($src,$src . '.gz');
|
||||||
@ -50,12 +56,16 @@ class Import extends \Zotlabs\Web\Controller {
|
|||||||
unlink($src);
|
unlink($src);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// import channel from another server
|
||||||
if(! $src) {
|
if(! $src) {
|
||||||
$old_address = ((x($_REQUEST,'old_address')) ? $_REQUEST['old_address'] : '');
|
$old_address = ((x($_REQUEST,'old_address')) ? $_REQUEST['old_address'] : '');
|
||||||
if(! $old_address) {
|
if(! $old_address) {
|
||||||
logger('mod_import: nothing to import.');
|
logger('Nothing to import.');
|
||||||
notice( t('Nothing to import.') . EOL);
|
notice( t('Nothing to import.') . EOL);
|
||||||
return;
|
return;
|
||||||
|
} else if(strpos($old_address, '@')) {
|
||||||
|
// if you copy the identity address from your profile page, make it work for convenience
|
||||||
|
$old_address = str_replace('@', '@', $old_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
$email = ((x($_REQUEST,'email')) ? $_REQUEST['email'] : '');
|
$email = ((x($_REQUEST,'email')) ? $_REQUEST['email'] : '');
|
||||||
@ -87,7 +97,7 @@ class Import extends \Zotlabs\Web\Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(! $data) {
|
if(! $data) {
|
||||||
logger('mod_import: empty file.');
|
logger('Empty import file.');
|
||||||
notice( t('Imported file is empty.') . EOL);
|
notice( t('Imported file is empty.') . EOL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -97,7 +107,6 @@ class Import extends \Zotlabs\Web\Controller {
|
|||||||
// logger('import: data: ' . print_r($data,true));
|
// logger('import: data: ' . print_r($data,true));
|
||||||
// print_r($data);
|
// print_r($data);
|
||||||
|
|
||||||
|
|
||||||
if(! array_key_exists('compatibility',$data)) {
|
if(! array_key_exists('compatibility',$data)) {
|
||||||
call_hooks('import_foreign_channel_data',$data);
|
call_hooks('import_foreign_channel_data',$data);
|
||||||
if($data['handled'])
|
if($data['handled'])
|
||||||
@ -137,7 +146,6 @@ class Import extends \Zotlabs\Web\Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$channel = import_channel($data['channel'], $account_id, $seize);
|
$channel = import_channel($data['channel'], $account_id, $seize);
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$moving = false;
|
$moving = false;
|
||||||
@ -145,22 +153,17 @@ class Import extends \Zotlabs\Web\Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(! $channel) {
|
if(! $channel) {
|
||||||
logger('mod_import: channel not found. ', print_r($channel,true));
|
logger('Channel not found. ', print_r($channel,true));
|
||||||
notice( t('No channel. Import failed.') . EOL);
|
notice( t('No channel. Import failed.') . EOL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(is_array($data['config'])) {
|
if(is_array($data['config'])) {
|
||||||
import_config($channel,$data['config']);
|
import_config($channel,$data['config']);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger('import step 2');
|
logger('import step 2');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(array_key_exists('channel',$data)) {
|
if(array_key_exists('channel',$data)) {
|
||||||
if($data['photo']) {
|
if($data['photo']) {
|
||||||
require_once('include/photo/photo_driver.php');
|
require_once('include/photo/photo_driver.php');
|
||||||
@ -212,7 +215,6 @@ class Import extends \Zotlabs\Web\Controller {
|
|||||||
logger('import step 5');
|
logger('import step 5');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// import xchans and contact photos
|
// import xchans and contact photos
|
||||||
|
|
||||||
if(array_key_exists('channel',$data) && $seize) {
|
if(array_key_exists('channel',$data) && $seize) {
|
||||||
@ -223,7 +225,6 @@ class Import extends \Zotlabs\Web\Controller {
|
|||||||
dbesc($channel['channel_hash'])
|
dbesc($channel['channel_hash'])
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
$r = xchan_store_lowlevel(
|
$r = xchan_store_lowlevel(
|
||||||
[
|
[
|
||||||
'xchan_hash' => $channel['channel_hash'],
|
'xchan_hash' => $channel['channel_hash'],
|
||||||
@ -248,7 +249,6 @@ class Import extends \Zotlabs\Web\Controller {
|
|||||||
logger('import step 6');
|
logger('import step 6');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$xchans = $data['xchan'];
|
$xchans = $data['xchan'];
|
||||||
if($xchans) {
|
if($xchans) {
|
||||||
foreach($xchans as $xchan) {
|
foreach($xchans as $xchan) {
|
||||||
@ -357,7 +357,7 @@ class Import extends \Zotlabs\Web\Controller {
|
|||||||
translate_abook_perms_inbound($channel,$abook_copy);
|
translate_abook_perms_inbound($channel,$abook_copy);
|
||||||
|
|
||||||
if($abconfig) {
|
if($abconfig) {
|
||||||
// @fixme does not handle sync of del_abconfig
|
/// @FIXME does not handle sync of del_abconfig
|
||||||
foreach($abconfig as $abc) {
|
foreach($abconfig as $abc) {
|
||||||
set_abconfig($channel['channel_id'],$abc['xchan'],$abc['cat'],$abc['k'],$abc['v']);
|
set_abconfig($channel['channel_id'],$abc['xchan'],$abc['cat'],$abc['k'],$abc['v']);
|
||||||
}
|
}
|
||||||
@ -469,12 +469,12 @@ class Import extends \Zotlabs\Web\Controller {
|
|||||||
change_channel($channel['channel_id']);
|
change_channel($channel['channel_id']);
|
||||||
|
|
||||||
goaway(z_root() . '/network' );
|
goaway(z_root() . '/network' );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Handle POST action on channel import page.
|
||||||
|
*/
|
||||||
function post() {
|
function post() {
|
||||||
|
|
||||||
$account_id = get_account_id();
|
$account_id = get_account_id();
|
||||||
if(! $account_id)
|
if(! $account_id)
|
||||||
return;
|
return;
|
||||||
@ -482,6 +482,11 @@ class Import extends \Zotlabs\Web\Controller {
|
|||||||
$this->import_account($account_id);
|
$this->import_account($account_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Generate channel import page.
|
||||||
|
*
|
||||||
|
* @return string with parsed HTML.
|
||||||
|
*/
|
||||||
function get() {
|
function get() {
|
||||||
|
|
||||||
if(! get_account_id()) {
|
if(! get_account_id()) {
|
||||||
@ -508,7 +513,6 @@ class Import extends \Zotlabs\Web\Controller {
|
|||||||
));
|
));
|
||||||
|
|
||||||
return $o;
|
return $o;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user