mirror of
https://codeberg.org/streams/streams.git
synced 2024-09-19 21:55:15 +00:00
Add some documentation for import functions.
This commit is contained in:
parent
3b6a0d8e5c
commit
2e2f984c45
5 changed files with 464 additions and 322 deletions
|
@ -83,6 +83,7 @@ class Import extends \Zotlabs\Web\Controller {
|
|||
$api_path .= 'channel/export/basic?f=&channel=' . $channelname;
|
||||
if($import_posts)
|
||||
$api_path .= '&posts=1';
|
||||
|
||||
$binary = false;
|
||||
$redirects = 0;
|
||||
$opts = array('http_auth' => $email . ':' . $password);
|
||||
|
@ -104,8 +105,8 @@ class Import extends \Zotlabs\Web\Controller {
|
|||
|
||||
$data = json_decode($data,true);
|
||||
|
||||
// logger('import: data: ' . print_r($data,true));
|
||||
// print_r($data);
|
||||
//logger('import: data: ' . print_r($data,true));
|
||||
//print_r($data);
|
||||
|
||||
if(! array_key_exists('compatibility',$data)) {
|
||||
call_hooks('import_foreign_channel_data',$data);
|
||||
|
@ -248,7 +249,7 @@ class Import extends \Zotlabs\Web\Controller {
|
|||
|
||||
logger('import step 6');
|
||||
|
||||
|
||||
// import xchans
|
||||
$xchans = $data['xchan'];
|
||||
if($xchans) {
|
||||
foreach($xchans as $xchan) {
|
||||
|
@ -292,13 +293,11 @@ class Import extends \Zotlabs\Web\Controller {
|
|||
dbesc($photodate),
|
||||
dbesc($xchan['xchan_hash'])
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
logger('import step 7');
|
||||
}
|
||||
|
||||
|
||||
$friends = 0;
|
||||
$feeds = 0;
|
||||
|
||||
|
@ -367,19 +366,20 @@ class Import extends \Zotlabs\Web\Controller {
|
|||
logger('import step 8');
|
||||
}
|
||||
|
||||
// import groups
|
||||
$groups = $data['group'];
|
||||
if($groups) {
|
||||
$saved = array();
|
||||
foreach($groups as $group) {
|
||||
$saved[$group['hash']] = array('old' => $group['id']);
|
||||
if(array_key_exists('name',$group)) {
|
||||
if(array_key_exists('name', $group)) {
|
||||
$group['gname'] = $group['name'];
|
||||
unset($group['name']);
|
||||
}
|
||||
unset($group['id']);
|
||||
$group['uid'] = $channel['channel_id'];
|
||||
|
||||
create_table_from_array('groups',$group);
|
||||
create_table_from_array('groups', $group);
|
||||
}
|
||||
$r = q("select * from groups where uid = %d",
|
||||
intval($channel['channel_id'])
|
||||
|
@ -391,7 +391,7 @@ class Import extends \Zotlabs\Web\Controller {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
// import group members
|
||||
$group_members = $data['group_member'];
|
||||
if($group_members) {
|
||||
foreach($group_members as $group_member) {
|
||||
|
@ -401,7 +401,7 @@ class Import extends \Zotlabs\Web\Controller {
|
|||
if($x['old'] == $group_member['gid'])
|
||||
$group_member['gid'] = $x['new'];
|
||||
}
|
||||
create_table_from_array('group_member',$group_member);
|
||||
create_table_from_array('group_member', $group_member);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -450,7 +450,6 @@ class Import extends \Zotlabs\Web\Controller {
|
|||
|
||||
notifications_on($channel['channel_id'],$saved_notification_flags);
|
||||
|
||||
|
||||
if(array_key_exists('item_id',$data) && $data['item_id'])
|
||||
import_item_ids($channel,$data['item_id']);
|
||||
|
||||
|
@ -490,7 +489,7 @@ class Import extends \Zotlabs\Web\Controller {
|
|||
function get() {
|
||||
|
||||
if(! get_account_id()) {
|
||||
notice( t('You must be logged in to use this feature.'));
|
||||
notice( t('You must be logged in to use this feature.') . EOL);
|
||||
return '';
|
||||
}
|
||||
|
||||
|
|
|
@ -3,54 +3,58 @@ namespace Zotlabs\Module;
|
|||
|
||||
require_once('include/import.php');
|
||||
|
||||
|
||||
/**
|
||||
* @brief Module for importing items.
|
||||
*
|
||||
* Import existing posts and content from an export file.
|
||||
*/
|
||||
class Import_items extends \Zotlabs\Web\Controller {
|
||||
|
||||
function post() {
|
||||
|
||||
|
||||
if(! local_channel())
|
||||
return;
|
||||
|
||||
|
||||
$data = null;
|
||||
|
||||
|
||||
$src = $_FILES['filename']['tmp_name'];
|
||||
$filename = basename($_FILES['filename']['name']);
|
||||
$filesize = intval($_FILES['filename']['size']);
|
||||
$filetype = $_FILES['filename']['type'];
|
||||
|
||||
|
||||
if($src) {
|
||||
// This is OS specific and could also fail if your tmpdir isn't very large
|
||||
// mostly used for Diaspora which exports gzipped files.
|
||||
|
||||
|
||||
if(strpos($filename,'.gz')){
|
||||
@rename($src,$src . '.gz');
|
||||
@system('gunzip ' . escapeshellarg($src . '.gz'));
|
||||
}
|
||||
|
||||
|
||||
if($filesize) {
|
||||
$data = @file_get_contents($src);
|
||||
}
|
||||
unlink($src);
|
||||
}
|
||||
|
||||
|
||||
if(! $src) {
|
||||
|
||||
|
||||
$old_address = ((x($_REQUEST,'old_address')) ? $_REQUEST['old_address'] : '');
|
||||
|
||||
|
||||
if(! $old_address) {
|
||||
logger('mod_import: nothing to import.');
|
||||
logger('Nothing to import.');
|
||||
notice( t('Nothing to import.') . EOL);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$email = ((x($_REQUEST,'email')) ? $_REQUEST['email'] : '');
|
||||
$password = ((x($_REQUEST,'password')) ? $_REQUEST['password'] : '');
|
||||
|
||||
|
||||
$year = ((x($_REQUEST,'year')) ? $_REQUEST['year'] : '');
|
||||
|
||||
|
||||
$channelname = substr($old_address,0,strpos($old_address,'@'));
|
||||
$servername = substr($old_address,strpos($old_address,'@')+1);
|
||||
|
||||
|
||||
$scheme = 'https://';
|
||||
$api_path = '/api/red/channel/export/items?f=&channel=' . $channelname . '&year=' . intval($year);
|
||||
$binary = false;
|
||||
|
@ -64,68 +68,65 @@ class Import_items extends \Zotlabs\Web\Controller {
|
|||
$data = $ret['body'];
|
||||
else
|
||||
notice( t('Unable to download data from old server') . EOL);
|
||||
|
||||
}
|
||||
|
||||
|
||||
if(! $data) {
|
||||
logger('mod_import: empty file.');
|
||||
logger('Empty file.');
|
||||
notice( t('Imported file is empty.') . EOL);
|
||||
return;
|
||||
}
|
||||
|
||||
$data = json_decode($data,true);
|
||||
|
||||
// logger('import: data: ' . print_r($data,true));
|
||||
// print_r($data);
|
||||
|
||||
|
||||
$data = json_decode($data, true);
|
||||
|
||||
//logger('import: data: ' . print_r($data,true));
|
||||
//print_r($data);
|
||||
|
||||
if(! is_array($data))
|
||||
return;
|
||||
|
||||
|
||||
if(array_key_exists('compatibility',$data) && array_key_exists('database',$data['compatibility'])) {
|
||||
$v1 = substr($data['compatibility']['database'],-4);
|
||||
$v2 = substr(DB_UPDATE_VERSION,-4);
|
||||
if($v2 > $v1) {
|
||||
$t = sprintf( t('Warning: Database versions differ by %1$d updates.'), $v2 - $v1 );
|
||||
notice($t);
|
||||
$t = sprintf( t('Warning: Database versions differ by %1$d updates.'), $v2 - $v1 );
|
||||
notice($t . EOL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$channel = \App::get_channel();
|
||||
|
||||
|
||||
|
||||
if(array_key_exists('item',$data) && $data['item']) {
|
||||
import_items($channel,$data['item'],false,((array_key_exists('relocate',$data)) ? $data['relocate'] : null));
|
||||
}
|
||||
|
||||
|
||||
if(array_key_exists('item_id',$data) && $data['item_id']) {
|
||||
import_item_ids($channel,$data['item_id']);
|
||||
}
|
||||
|
||||
|
||||
info( t('Import completed') . EOL);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Generate item import page.
|
||||
*
|
||||
* @return string with parsed HTML.
|
||||
*/
|
||||
function get() {
|
||||
|
||||
|
||||
if(! local_channel()) {
|
||||
notice( t('Permission denied') . EOL);
|
||||
return login();
|
||||
}
|
||||
|
||||
$o = replace_macros(get_markup_template('item_import.tpl'),array(
|
||||
|
||||
$o = replace_macros(get_markup_template('item_import.tpl'), array(
|
||||
'$title' => t('Import Items'),
|
||||
'$desc' => t('Use this form to import existing posts and content from an export file.'),
|
||||
'$label_filename' => t('File to Upload'),
|
||||
'$submit' => t('Submit')
|
||||
));
|
||||
|
||||
|
||||
return $o;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,17 @@
|
|||
<?php /** @file */
|
||||
|
||||
<?php
|
||||
/**
|
||||
* @file include/hubloc.php
|
||||
* @brief Hubloc related functions.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Create an array for hubloc table and insert record.
|
||||
*
|
||||
* Creates an assoziative array which will be inserted into the hubloc table.
|
||||
*
|
||||
* @param array $arr An assoziative array with hubloc values
|
||||
* @return boolean|PDOStatement
|
||||
*/
|
||||
function hubloc_store_lowlevel($arr) {
|
||||
|
||||
$store = [
|
||||
|
@ -25,8 +36,7 @@ function hubloc_store_lowlevel($arr) {
|
|||
'hubloc_deleted' => ((array_key_exists('hubloc_deleted',$arr)) ? $arr['hubloc_deleted'] : 0)
|
||||
];
|
||||
|
||||
return create_table_from_array('hubloc',$store);
|
||||
|
||||
return create_table_from_array('hubloc', $store);
|
||||
}
|
||||
|
||||
|
||||
|
@ -45,9 +55,8 @@ function prune_hub_reinstalls() {
|
|||
// see if this url has more than one sitekey, indicating it has been re-installed.
|
||||
|
||||
if(count($x) > 1) {
|
||||
|
||||
$d1 = datetime_convert('UTC','UTC',$x[0]['c']);
|
||||
$d2 = datetime_convert('UTC','UTC','now - 3 days');
|
||||
$d1 = datetime_convert('UTC', 'UTC', $x[0]['c']);
|
||||
$d2 = datetime_convert('UTC', 'UTC', 'now - 3 days');
|
||||
|
||||
// allow some slop period, say 3 days - just in case this is a glitch or transient occurrence
|
||||
// Then remove any hublocs pointing to the oldest entry.
|
||||
|
@ -63,18 +72,22 @@ function prune_hub_reinstalls() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Remove obsolete hublocs.
|
||||
*
|
||||
* Get rid of any hublocs which are ours but aren't valid anymore -
|
||||
* e.g. they point to a different and perhaps transient URL that we aren't using.
|
||||
*
|
||||
* I need to stress that this shouldn't happen. fix_system_urls() fixes hublocs
|
||||
* when it discovers the URL has changed. So it's unclear how we could end up
|
||||
* with URLs pointing to the old site name. But it happens. This may be an artifact
|
||||
* of an old bug or maybe a regression in some newer code. In any event, they
|
||||
* mess up communications and we have to take action if we find any.
|
||||
*/
|
||||
function remove_obsolete_hublocs() {
|
||||
|
||||
logger('remove_obsolete_hublocs',LOGGER_DEBUG);
|
||||
|
||||
// Get rid of any hublocs which are ours but aren't valid anymore -
|
||||
// e.g. they point to a different and perhaps transient URL that we aren't using.
|
||||
|
||||
// I need to stress that this shouldn't happen. fix_system_urls() fixes hublocs
|
||||
// when it discovers the URL has changed. So it's unclear how we could end up
|
||||
// with URLs pointing to the old site name. But it happens. This may be an artifact
|
||||
// of an old bug or maybe a regression in some newer code. In any event, they
|
||||
// mess up communications and we have to take action if we find any.
|
||||
logger('remove_obsolete_hublocs', LOGGER_DEBUG);
|
||||
|
||||
// First make sure we have any hublocs (at all) with this URL and sitekey.
|
||||
// We don't want to perform this operation while somebody is in the process
|
||||
|
@ -82,27 +95,25 @@ function remove_obsolete_hublocs() {
|
|||
|
||||
$r = q("select hubloc_id from hubloc where hubloc_url = '%s' and hubloc_sitekey = '%s'",
|
||||
dbesc(z_root()),
|
||||
dbesc(get_config('system','pubkey'))
|
||||
dbesc(get_config('system', 'pubkey'))
|
||||
);
|
||||
if((! $r) || (! count($r)))
|
||||
return;
|
||||
|
||||
$channels = array();
|
||||
|
||||
// Good. We have at least one *valid* hubloc.
|
||||
|
||||
// Do we have any invalid ones?
|
||||
|
||||
$r = q("select hubloc_id from hubloc where hubloc_sitekey = '%s' and hubloc_url != '%s'",
|
||||
dbesc(get_config('system','pubkey')),
|
||||
dbesc(get_config('system', 'pubkey')),
|
||||
dbesc(z_root())
|
||||
);
|
||||
$p = q("select hubloc_id from hubloc where hubloc_sitekey != '%s' and hubloc_url = '%s'",
|
||||
dbesc(get_config('system','pubkey')),
|
||||
dbesc(get_config('system', 'pubkey')),
|
||||
dbesc(z_root())
|
||||
);
|
||||
if(is_array($r) && is_array($p))
|
||||
$r = array_merge($r,$p);
|
||||
$r = array_merge($r, $p);
|
||||
|
||||
if(! $r)
|
||||
return;
|
||||
|
@ -111,8 +122,8 @@ function remove_obsolete_hublocs() {
|
|||
|
||||
logger('remove_obsolete_hublocs: removing ' . count($r) . ' hublocs.');
|
||||
|
||||
$interval = ((get_config('system','delivery_interval') !== false)
|
||||
? intval(get_config('system','delivery_interval')) : 2 );
|
||||
$interval = ((get_config('system', 'delivery_interval') !== false)
|
||||
? intval(get_config('system', 'delivery_interval')) : 2 );
|
||||
|
||||
foreach($r as $rr) {
|
||||
q("update hubloc set hubloc_deleted = 1 where hubloc_id = %d",
|
||||
|
@ -120,10 +131,10 @@ function remove_obsolete_hublocs() {
|
|||
);
|
||||
|
||||
$x = q("select channel_id from channel where channel_hash = '%s' limit 1",
|
||||
dbesc($rr['hubloc_hash'])
|
||||
dbesc($rr['hubloc_hash'])
|
||||
);
|
||||
if($x) {
|
||||
Zotlabs\Daemon\Master::Summon(array('Notifier','location',$x[0]['channel_id']));
|
||||
Zotlabs\Daemon\Master::Summon(array('Notifier', 'location', $x[0]['channel_id']));
|
||||
if($interval)
|
||||
@time_sleep_until(microtime(true) + (float) $interval);
|
||||
}
|
||||
|
@ -131,8 +142,15 @@ function remove_obsolete_hublocs() {
|
|||
}
|
||||
|
||||
|
||||
// This actually changes other structures to match the given (presumably current) hubloc primary selection
|
||||
|
||||
/**
|
||||
* @brief Change primary hubloc.
|
||||
*
|
||||
* This actually changes other structures to match the given (presumably current)
|
||||
* hubloc primary selection.
|
||||
*
|
||||
* @param array $hubloc
|
||||
* @return boolean
|
||||
*/
|
||||
function hubloc_change_primary($hubloc) {
|
||||
|
||||
if(! is_array($hubloc)) {
|
||||
|
@ -170,7 +188,7 @@ function hubloc_change_primary($hubloc) {
|
|||
dbesc($hubloc['hubloc_hash'])
|
||||
);
|
||||
if(! $r) {
|
||||
logger('xchan not found');
|
||||
logger('xchan not found');
|
||||
return false;
|
||||
}
|
||||
if($r[0]['xchan_addr'] === $hubloc['hubloc_addr']) {
|
||||
|
@ -179,7 +197,7 @@ function hubloc_change_primary($hubloc) {
|
|||
}
|
||||
|
||||
$url = $hubloc['hubloc_url'];
|
||||
$lwebbie = substr($hubloc['hubloc_addr'],0,strpos($hubloc['hubloc_addr'],'@'));
|
||||
$lwebbie = substr($hubloc['hubloc_addr'], 0, strpos($hubloc['hubloc_addr'], '@'));
|
||||
|
||||
$r = q("update xchan set xchan_addr = '%s', xchan_url = '%s', xchan_follow = '%s', xchan_connurl = '%s' where xchan_hash = '%s'",
|
||||
dbesc($hubloc['hubloc_addr']),
|
||||
|
@ -191,14 +209,19 @@ function hubloc_change_primary($hubloc) {
|
|||
if(! $r)
|
||||
logger('xchan_update failed.');
|
||||
|
||||
logger('primary hubloc changed.' . print_r($hubloc,true),LOGGER_DEBUG);
|
||||
logger('primary hubloc changed.' . print_r($hubloc, true), LOGGER_DEBUG);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
// We use the post url to distinguish between http and https hublocs.
|
||||
// The https might be alive, and the http dead.
|
||||
|
||||
/**
|
||||
* @brief Mark a hubloc as down.
|
||||
*
|
||||
* We use the post url to distinguish between http and https hublocs.
|
||||
* The https might be alive, and the http dead.
|
||||
*
|
||||
* @param string $posturl Hubloc callback url which to disable
|
||||
*/
|
||||
function hubloc_mark_as_down($posturl) {
|
||||
$r = q("update hubloc set hubloc_status = ( hubloc_status | %d ) where hubloc_callback = '%s'",
|
||||
intval(HUBLOC_OFFLINE),
|
||||
|
@ -208,22 +231,21 @@ function hubloc_mark_as_down($posturl) {
|
|||
|
||||
|
||||
|
||||
|
||||
function ping_site($url) {
|
||||
|
||||
$ret = array('success' => false);
|
||||
|
||||
$sys = get_sys_channel();
|
||||
|
||||
$m = zot_build_packet($sys,'ping');
|
||||
$r = zot_zot($url . '/post',$m);
|
||||
$m = zot_build_packet($sys, 'ping');
|
||||
$r = zot_zot($url . '/post', $m);
|
||||
if(! $r['success']) {
|
||||
$ret['message'] = 'no answer from ' . $url;
|
||||
return $ret;
|
||||
}
|
||||
$packet_result = json_decode($r['body'],true);
|
||||
$packet_result = json_decode($r['body'], true);
|
||||
if(! $packet_result['success']) {
|
||||
$ret['message'] = 'packet failure from ' . $url;
|
||||
$ret['message'] = 'packet failure from ' . $url;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -3050,7 +3050,15 @@ function array2XML($obj, $array) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Inserts an array into $table.
|
||||
*
|
||||
* @TODO Why is this function in include/text.php?
|
||||
*
|
||||
* @param string $table
|
||||
* @param array $arr
|
||||
* @return boolean|PDOStatement
|
||||
*/
|
||||
function create_table_from_array($table, $arr) {
|
||||
|
||||
if(! ($arr && $table))
|
||||
|
|
Loading…
Reference in a new issue