Webpage import tool works again after setting iconfig properly and following the Impel class function example. More testing is needed.

This commit is contained in:
Andrew Manning 2017-02-11 20:52:06 -05:00
parent bc3605a502
commit 8ff9ad7636
2 changed files with 20 additions and 14 deletions

View File

@ -288,6 +288,7 @@ class Webpages extends \Zotlabs\Web\Controller {
if ($zip->open($source) === true) { if ($zip->open($source) === true) {
$tmp_folder_name = random_string(5); $tmp_folder_name = random_string(5);
$website = dirname($source) . '/' . $tmp_folder_name; $website = dirname($source) . '/' . $tmp_folder_name;
logger($website ,LOGGER_DEBUG);
$zip->extractTo($website); // change this to the correct site path $zip->extractTo($website); // change this to the correct site path
$zip->close(); $zip->close();
@unlink($source); // delete the compressed file now that the content has been extracted @unlink($source); // delete the compressed file now that the content has been extracted

View File

@ -1295,6 +1295,7 @@ function import_webpage_element($element, $channel, $type) {
// LAYOUTS // LAYOUTS
// //
case 'layout': case 'layout':
logger('Importing layout...', LOGGER_DEBUG);
$arr['item_type'] = ITEM_TYPE_PDL; $arr['item_type'] = ITEM_TYPE_PDL;
$namespace = 'PDL'; $namespace = 'PDL';
$name = $element['name']; $name = $element['name'];
@ -1315,7 +1316,7 @@ function import_webpage_element($element, $channel, $type) {
return null; // return null if invalid element type return null; // return null if invalid element type
} }
$arr['uid'] = $channel['channel_id']; $arr['uid'] = local_channel();
$arr['aid'] = $channel['channel_account_id']; $arr['aid'] = $channel['channel_account_id'];
// Check if an item already exists based on the name // Check if an item already exists based on the name
@ -1376,36 +1377,40 @@ function import_webpage_element($element, $channel, $type) {
} }
} }
$z = q("select * from iconfig where v = '%s' and k = '%s' and cat = 'system' limit 1", // $z = q("select * from iconfig where v = '%s' and k = '%s' and cat = 'system' limit 1",
dbesc($name), // dbesc($name),
dbesc($namespace) // dbesc($namespace)
); // );
$i = q("select id, edited, item_deleted from item where mid = '%s' and uid = %d limit 1", $i = q("select id, edited, item_deleted from item where mid = '%s' and uid = %d limit 1",
dbesc($arr['mid']), dbesc($arr['mid']),
intval(local_channel()) intval(local_channel())
); );
$remote_id = 0;
if($z && $i) { \Zotlabs\Lib\IConfig::Set($arr,'system',$namespace,(($name) ? $name : substr($arr['mid'],0,16)),true);
$remote_id = $z[0]['id'];
if($i) {
$arr['id'] = $i[0]['id']; $arr['id'] = $i[0]['id'];
// don't update if it has the same timestamp as the original // don't update if it has the same timestamp as the original
if($arr['edited'] > $i[0]['edited']) if($arr['edited'] > $i[0]['edited'])
$x = item_store_update($arr, $execflag); $x = item_store_update($arr,$execflag);
} }
else { else {
if(($i) && (intval($i[0]['item_deleted']))) { if(($i) && (intval($i[0]['item_deleted']))) {
// was partially deleted already, finish it off // was partially deleted already, finish it off
q("delete from item where mid = '%s' and uid = %d", q("delete from item where mid = '%s' and uid = %d",
dbesc($arr['mid']), dbesc($arr['mid']),
intval(local_channel()) intval(local_channel())
); );
} }
$x = item_store($arr, $execflag); else
$x = item_store($arr,$execflag);
} }
if($x['success']) {
if($x && $x['success']) {
$item_id = $x['item_id']; $item_id = $x['item_id'];
update_remote_id($channel, $item_id, $arr['item_type'], $name, $namespace, $remote_id, $arr['mid']); //update_remote_id($channel, $item_id, $arr['item_type'], $name, $namespace, $remote_id, $arr['mid']);
$element['import_success'] = 1; $element['import_success'] = 1;
} }
else { else {