aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2017-04-03 16:43:30 -0700
committerzotlabs <mike@macgirvin.com>2017-04-03 16:43:30 -0700
commitd6c23486d563e29862d3db891e67649d13e6def0 (patch)
treeaec0bc40905c4204eb13975e331978a4ce461007
parent26125bcf0b8ce98fa4522f89792d7e77f25ff1ca (diff)
downloadvolse-hubzilla-d6c23486d563e29862d3db891e67649d13e6def0.tar.gz
volse-hubzilla-d6c23486d563e29862d3db891e67649d13e6def0.tar.bz2
volse-hubzilla-d6c23486d563e29862d3db891e67649d13e6def0.zip
create site_store_lowlevel() to initialise data structures for the site table
-rw-r--r--include/dir_fns.php31
-rw-r--r--include/hubloc.php27
-rw-r--r--include/queue_fn.php12
-rw-r--r--include/zot.php32
4 files changed, 63 insertions, 39 deletions
diff --git a/include/dir_fns.php b/include/dir_fns.php
index 3922730fc..2bd1228ec 100644
--- a/include/dir_fns.php
+++ b/include/dir_fns.php
@@ -185,26 +185,17 @@ function sync_directories($dirmode) {
/** @FIXME What to do if we're in a different realm? */
if ((! $r) && (z_root() != DIRECTORY_FALLBACK_MASTER)) {
- $r = array();
- $r[] = array(
- 'site_url' => DIRECTORY_FALLBACK_MASTER,
- 'site_flags' => DIRECTORY_MODE_PRIMARY,
- 'site_update' => NULL_DATE,
- 'site_directory' => DIRECTORY_FALLBACK_MASTER . '/dirsearch',
- 'site_realm' => DIRECTORY_REALM,
- 'site_valid' => 1,
- 'site_crypto' => 'aes256cbc'
-
- );
- $x = q("insert into site ( site_url, site_flags, site_update, site_directory, site_realm, site_valid, site_crypto )
- values ( '%s', %d, '%s', '%s', '%s', %d, '%s' ) ",
- dbesc($r[0]['site_url']),
- intval($r[0]['site_flags']),
- dbesc($r[0]['site_update']),
- dbesc($r[0]['site_directory']),
- dbesc($r[0]['site_realm']),
- intval($r[0]['site_valid']),
- dbesc($r[0]['site_crypto'])
+
+ $x = site_store_lowlevel(
+ [
+ 'site_url' => DIRECTORY_FALLBACK_MASTER,
+ 'site_flags' => DIRECTORY_MODE_PRIMARY,
+ 'site_update' => NULL_DATE,
+ 'site_directory' => DIRECTORY_FALLBACK_MASTER . '/dirsearch',
+ 'site_realm' => DIRECTORY_REALM,
+ 'site_valid' => 1,
+ 'site_crypto' => 'aes256cbc'
+ ]
);
$r = q("select * from site where site_flags in (%d, %d) and site_url != '%s' and site_type = %d ",
diff --git a/include/hubloc.php b/include/hubloc.php
index 599252522..0daa5908c 100644
--- a/include/hubloc.php
+++ b/include/hubloc.php
@@ -39,6 +39,33 @@ function hubloc_store_lowlevel($arr) {
return create_table_from_array('hubloc', $store);
}
+function site_store_lowlevel($arr) {
+
+ $store = [
+ 'site_url' => ((array_key_exists('site_url',$arr)) ? $arr['site_url'] : ''),
+ 'site_access' => ((array_key_exists('site_access',$arr)) ? $arr['site_access'] : 0),
+ 'site_flags' => ((array_key_exists('site_flags',$arr)) ? $arr['site_flags'] : 0),
+ 'site_update' => ((array_key_exists('site_update',$arr)) ? $arr['site_update'] : NULL_DATE),
+ 'site_pull' => ((array_key_exists('site_pull',$arr)) ? $arr['site_pull'] : NULL_DATE),
+ 'site_sync' => ((array_key_exists('site_sync',$arr)) ? $arr['site_sync'] : NULL_DATE),
+ 'site_directory' => ((array_key_exists('site_directory',$arr)) ? $arr['site_directory'] : ''),
+ 'site_register' => ((array_key_exists('site_register',$arr)) ? $arr['site_register'] : 0),
+ 'site_sellpage' => ((array_key_exists('site_sellpage',$arr)) ? $arr['site_sellpage'] : ''),
+ 'site_location' => ((array_key_exists('site_location',$arr)) ? $arr['site_location'] : ''),
+ 'site_realm' => ((array_key_exists('site_realm',$arr)) ? $arr['site_realm'] : ''),
+ 'site_valid' => ((array_key_exists('site_valid',$arr)) ? $arr['site_valid'] : 0),
+ 'site_dead' => ((array_key_exists('site_dead',$arr)) ? $arr['site_dead'] : 0),
+ 'site_type' => ((array_key_exists('site_type',$arr)) ? $arr['site_type'] : 0),
+ 'site_project' => ((array_key_exists('site_project',$arr)) ? $arr['site_project'] : ''),
+ 'site_version' => ((array_key_exists('site_version',$arr)) ? $arr['site_version'] : ''),
+ 'site_crypto' => ((array_key_exists('site_crypto',$arr)) ? $arr['site_crypto'] : '')
+ ];
+
+ return create_table_from_array('site', $store);
+}
+
+
+
function prune_hub_reinstalls() {
diff --git a/include/queue_fn.php b/include/queue_fn.php
index ede6c8f11..c9179b953 100644
--- a/include/queue_fn.php
+++ b/include/queue_fn.php
@@ -146,10 +146,14 @@ function queue_deliver($outq, $immediate = false) {
// your site has existed. Since we don't know for sure what these sites are,
// call them unknown
- q("insert into site (site_url, site_update, site_dead, site_type, site_crypto) values ('%s','%s',0,%d,'') ",
- dbesc($base),
- dbesc(datetime_convert()),
- intval(($outq['outq_driver'] === 'post') ? SITE_TYPE_NOTZOT : SITE_TYPE_UNKNOWN)
+ site_store_lowlevel(
+ [
+ 'site_url' => $base,
+ 'site_update' => datetime_convert(),
+ 'site_dead' => 0,
+ 'site_type' => intval(($outq['outq_driver'] === 'post') ? SITE_TYPE_NOTZOT : SITE_TYPE_UNKNOWN),
+ 'site_crypto' => ''
+ ]
);
}
}
diff --git a/include/zot.php b/include/zot.php
index 266060839..1a4f6534b 100644
--- a/include/zot.php
+++ b/include/zot.php
@@ -2897,22 +2897,24 @@ function import_site($arr, $pubkey) {
else {
$update = true;
- $r = q("insert into site ( site_location, site_url, site_access, site_flags, site_update, site_directory, site_register, site_sellpage, site_realm, site_type, site_project, site_version, site_crypto )
- values ( '%s', '%s', %d, %d, '%s', '%s', %d, '%s', '%s', %d, '%s', '%s', '%s' )",
- dbesc($site_location),
- dbesc($url),
- intval($access_policy),
- intval($site_directory),
- dbesc(datetime_convert()),
- dbesc($directory_url),
- intval($register_policy),
- dbesc($sellpage),
- dbesc($site_realm),
- intval(SITE_TYPE_ZOT),
- dbesc($site_project),
- dbesc($site_version),
- dbesc($site_crypto)
+ $r = site_store_lowlevel(
+ [
+ 'site_location' => $site_location,
+ 'site_url' => $url,
+ 'site_access' => intval($access_policy),
+ 'site_flags' => intval($site_directory),
+ 'site_update' => datetime_convert(),
+ 'site_directory' => $directory_url,
+ 'site_register' => intval($register_policy),
+ 'site_sellpage' => $sellpage,
+ 'site_realm' => $site_realm,
+ 'site_type' => intval(SITE_TYPE_ZOT),
+ 'site_project' => $site_project,
+ 'site_version' => $site_version,
+ 'site_crypto' => $site_crypto
+ ]
);
+
if(! $r) {
logger('import_site: record create failed. ' . print_r($arr,true));
}