begin code to sync channel changes across all channel clones.

This commit is contained in:
friendica 2013-06-25 18:15:17 -07:00
parent a0a91fc971
commit 57c7f725f6
4 changed files with 102 additions and 9 deletions

View File

@ -195,7 +195,18 @@ function set_pconfig($uid,$family,$key,$value) {
if(! array_key_exists($family,$a->config[$uid])) if(! array_key_exists($family,$a->config[$uid]))
$a->config[$uid][$family] = array(); $a->config[$uid][$family] = array();
// keep a separate copy for all variables which were
// set in the life of this page. We need this to
// synchronise channel clones.
if(! array_key_exists('transient',$a->config[$uid]))
$a->config[$uid]['transient'] = array();
if(! array_key_exists($family,$a->config[$uid]['transient']))
$a->config[$uid]['transient'][$family] = array();
$a->config[$uid][$family][$key] = $value; $a->config[$uid][$family][$key] = $value;
$a->config[$uid]['transient'][$family][$key] = $value;
$ret = q("INSERT INTO pconfig ( uid, cat, k, v ) VALUES ( %d, '%s', '%s', '%s' ) ", $ret = q("INSERT INTO pconfig ( uid, cat, k, v ) VALUES ( %d, '%s', '%s', '%s' ) ",
intval($uid), intval($uid),
dbesc($family), dbesc($family),
@ -214,7 +225,17 @@ function set_pconfig($uid,$family,$key,$value) {
dbesc($key) dbesc($key)
); );
// keep a separate copy for all variables which were
// set in the life of this page. We need this to
// synchronise channel clones.
if(! array_key_exists('transient',$a->config[$uid]))
$a->config[$uid]['transient'] = array();
if(! array_key_exists($family,$a->config[$uid]['transient']))
$a->config[$uid]['transient'][$family] = array();
$a->config[$uid][$family][$key] = $value; $a->config[$uid][$family][$key] = $value;
$a->config[$uid]['transient'][$family][$key] = $value;
if($ret) if($ret)
return $value; return $value;

77
include/settings.php Normal file
View File

@ -0,0 +1,77 @@
<?php /** @file */
function build_sync_packet($packet = null) {
$a = get_app();
$uid = local_user();
if(! $uid)
return;
$channel = $a->get_channel();
$h = q("select * from hubloc where hubloc_hash = '%s'",
dbesc($channel['channel_hash'])
);
if(! $h)
return;
$synchubs = array();
foreach($h as $x) {
if($x['host'] == $a->get_hostname())
continue;
$synchubs[] = $x;
}
if(! $synchubs)
return;
$info = (($packet) ? $packet : array());
if(array_key_exists($uid,$a->config) && array_key_exists('transient',$a->config[$uid])) {
$settings = $a->config[$uid]['transient'];
if($settings) {
$info['config'] = $settings;
}
}
if($channel) {
$info['channel'] = array();
foreach($channel as $k => $v) {
if(strpos('channel_',$k) !== 0)
continue;
if($k === 'channel_id')
continue;
if($k === 'channel_account_id')
continue;
$info['channel'][$k] = $v;
}
}
$interval = ((get_config('system','delivery_interval') !== false)
? intval(get_config('system','delivery_interval')) : 2 );
foreach($synchubs as $hub) {
$hash = random_string();
$n = zot_build_packet($channel,'channel_sync');
q("insert into outq ( outq_hash, outq_account, outq_channel, outq_posturl, outq_async, outq_created, outq_updated, outq_notify, outq_msg ) values ( '%s', %d, %d, '%s', %d, '%s', '%s', '%s', '%s' )",
dbesc($hash),
intval($channel['channel_account']),
intval($channel['channel_id']),
dbesc($hub['hubloc_callback']),
intval(1),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
dbesc($n),
dbesc($info)
);
proc_run('php','include/deliver.php',$hash);
if($interval)
@time_sleep_until(microtime(true) + (float) $interval);
}
}

View File

@ -1,5 +1,7 @@
<?php <?php
require_once('include/settings.php');
function get_theme_config_file($theme){ function get_theme_config_file($theme){
@ -115,13 +117,6 @@ function settings_post(&$a) {
return; return;
// if(count($a->user) && x($a->user,'uid') && $a->user['uid'] != local_user()) {
// notice( t('Permission denied.') . EOL);
// return;
// }
$old_page_flags = $a->user['page-flags'];
if((argc() > 1) && (argv(1) === 'oauth') && x($_POST,'remove')){ if((argc() > 1) && (argv(1) === 'oauth') && x($_POST,'remove')){
check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth'); check_form_security_token_redirectOnErr('/settings/oauth', 'settings_oauth');
@ -292,7 +287,7 @@ function settings_post(&$a) {
$errs[] = t('Not valid email.'); $errs[] = t('Not valid email.');
$adm = trim(get_config('system','admin_email')); $adm = trim(get_config('system','admin_email'));
if(($adm) && (strcasecmp($email,$adm) == 0)) { if(($adm) && (strcasecmp($email,$adm) == 0)) {
$errs[] = t('Protected email. Cannot change to that email.'); $errs[] = t('Protected email address. Cannot change to that email.');
$email = $a->user['email']; $email = $a->user['email'];
} }
if(! $errs) { if(! $errs) {

View File

@ -1 +1 @@
2013-06-23.353 2013-06-25.355