import - get rid of 'step system', we should be able to process any import file at any time.

This commit is contained in:
zotlabs 2017-02-05 20:46:11 -08:00
parent 56a08f0d17
commit d8472cc9f5

View File

@ -27,15 +27,12 @@ class Import extends \Zotlabs\Web\Controller {
$data = null; $data = null;
$seize = ((x($_REQUEST,'make_primary')) ? intval($_REQUEST['make_primary']) : 0); $seize = ((x($_REQUEST,'make_primary')) ? intval($_REQUEST['make_primary']) : 0);
$import_posts = ((x($_REQUEST,'import_posts')) ? intval($_REQUEST['import_posts']) : 0); $import_posts = ((x($_REQUEST,'import_posts')) ? intval($_REQUEST['import_posts']) : 0);
$moving = intval($_REQUEST['moving']);
$src = $_FILES['filename']['tmp_name']; $src = $_FILES['filename']['tmp_name'];
$filename = basename($_FILES['filename']['name']); $filename = basename($_FILES['filename']['name']);
$filesize = intval($_FILES['filename']['size']); $filesize = intval($_FILES['filename']['size']);
$filetype = $_FILES['filename']['type']; $filetype = $_FILES['filename']['type'];
$moving = intval($_REQUEST['moving']);
$completed = ((array_key_exists('import_step',$_SESSION)) ? intval($_SESSION['import_step']) : 0);
if($completed)
logger('saved import step: ' . $_SESSION['import_step']);
if($src) { if($src) {
@ -139,28 +136,13 @@ class Import extends \Zotlabs\Web\Controller {
} }
} }
if($completed < 1) {
$channel = import_channel($data['channel'], $account_id, $seize); $channel = import_channel($data['channel'], $account_id, $seize);
} }
else { else {
$r = q("select * from channel where channel_account_id = %d and channel_guid = '%s' limit 1", $moving = false;
intval($account_id),
dbesc($channel['channel_guid'])
);
if($r)
$channel = $r[0];
}
if(! $channel) {
logger('mod_import: channel not found. ', print_r($channel,true));
notice( t('Cloned channel not found. Import failed.') . EOL);
return;
}
}
if(! $channel)
$channel = \App::get_channel(); $channel = \App::get_channel();
}
if(! $channel) { if(! $channel) {
logger('mod_import: channel not found. ', print_r($channel,true)); logger('mod_import: channel not found. ', print_r($channel,true));
@ -169,17 +151,15 @@ class Import extends \Zotlabs\Web\Controller {
} }
if($completed < 2) {
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');
$_SESSION['import_step'] = 2;
}
if($completed < 3) {
if(array_key_exists('channel',$data)) { if(array_key_exists('channel',$data)) {
if($data['photo']) { if($data['photo']) {
@ -190,22 +170,15 @@ class Import extends \Zotlabs\Web\Controller {
if(is_array($data['profile'])) if(is_array($data['profile']))
import_profiles($channel,$data['profile']); import_profiles($channel,$data['profile']);
} }
logger('import step 3'); logger('import step 3');
$_SESSION['import_step'] = 3;
}
if($completed < 4) {
if(is_array($data['hubloc'])) { if(is_array($data['hubloc'])) {
import_hublocs($channel,$data['hubloc'],$seize,$moving); import_hublocs($channel,$data['hubloc'],$seize,$moving);
} }
logger('import step 4'); logger('import step 4');
$_SESSION['import_step'] = 4;
}
if($completed < 5) {
// create new hubloc for the new channel at this site // create new hubloc for the new channel at this site
if(array_key_exists('channel',$data)) { if(array_key_exists('channel',$data)) {
@ -237,11 +210,8 @@ class Import extends \Zotlabs\Web\Controller {
} }
logger('import step 5'); logger('import step 5');
$_SESSION['import_step'] = 5;
}
if($completed < 6) {
// import xchans and contact photos // import xchans and contact photos
@ -274,11 +244,10 @@ class Import extends \Zotlabs\Web\Controller {
] ]
); );
} }
logger('import step 6');
$_SESSION['import_step'] = 6;
}
if($completed < 7) { logger('import step 6');
$xchans = $data['xchan']; $xchans = $data['xchan'];
if($xchans) { if($xchans) {
@ -315,8 +284,7 @@ class Import extends \Zotlabs\Web\Controller {
else else
$photodate = $xchan['xchan_photo_date']; $photodate = $xchan['xchan_photo_date'];
$r = q("update xchan set xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s', xchan_photo_date = '%s' $r = q("update xchan set xchan_photo_l = '%s', xchan_photo_m = '%s', xchan_photo_s = '%s', xchan_photo_mimetype = '%s', xchan_photo_date = '%s' where xchan_hash = '%s'",
where xchan_hash = '%s'",
dbesc($photos[0]), dbesc($photos[0]),
dbesc($photos[1]), dbesc($photos[1]),
dbesc($photos[2]), dbesc($photos[2]),
@ -326,15 +294,11 @@ class Import extends \Zotlabs\Web\Controller {
); );
} }
}
logger('import step 7'); logger('import step 7');
$_SESSION['import_step'] = 7;
} }
// FIXME - ensure we have an xchan if somebody is trying to pull a fast one
if($completed < 8) {
$friends = 0; $friends = 0;
$feeds = 0; $feeds = 0;
@ -398,18 +362,11 @@ class Import extends \Zotlabs\Web\Controller {
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']);
} }
} }
}
} }
logger('import step 8'); logger('import step 8');
$_SESSION['import_step'] = 8;
} }
if($completed < 9) {
$groups = $data['group']; $groups = $data['group'];
if($groups) { if($groups) {
$saved = array(); $saved = array();
@ -447,9 +404,8 @@ class Import extends \Zotlabs\Web\Controller {
create_table_from_array('group_member',$group_member); create_table_from_array('group_member',$group_member);
} }
} }
logger('import step 9'); logger('import step 9');
$_SESSION['import_step'] = 9;
}
if(is_array($data['obj'])) if(is_array($data['obj']))
import_objs($channel,$data['obj']); import_objs($channel,$data['obj']);
@ -498,9 +454,6 @@ class Import extends \Zotlabs\Web\Controller {
if(array_key_exists('item_id',$data) && $data['item_id']) if(array_key_exists('item_id',$data) && $data['item_id'])
import_item_ids($channel,$data['item_id']); import_item_ids($channel,$data['item_id']);
// FIXME - ensure we have a self entry if somebody is trying to pull a fast one
// send out refresh requests // send out refresh requests
// notify old server that it may no longer be primary. // notify old server that it may no longer be primary.
@ -515,7 +468,6 @@ class Import extends \Zotlabs\Web\Controller {
change_channel($channel['channel_id']); change_channel($channel['channel_id']);
unset($_SESSION['import_step']);
goaway(z_root() . '/network' ); goaway(z_root() . '/network' );
} }