change AbConfig to use channel_id instead of channel_hash; which was a mistake in retrospect

This commit is contained in:
redmatrix 2016-06-23 18:12:26 -07:00
parent e5c66d94f2
commit b19bbf5473
7 changed files with 30 additions and 32 deletions

View File

@ -5,18 +5,18 @@ namespace Zotlabs\Lib;
class AbConfig { class AbConfig {
static public function Load($chash,$xhash) { static public function Load($chan,$xhash) {
$r = q("select * from abconfig where chan = '%s' and xchan = '%s'", $r = q("select * from abconfig where chan = %d and xchan = '%s'",
dbesc($chash), intval($chan),
dbesc($xhash) dbesc($xhash)
); );
return $r; return $r;
} }
static public function Get($chash,$xhash,$family,$key) { static public function Get($chan,$xhash,$family,$key) {
$r = q("select * from abconfig where chan = '%s' and xchan = '%s' and cat = '%s' and k = '%s' limit 1", $r = q("select * from abconfig where chan = %d and xchan = '%s' and cat = '%s' and k = '%s' limit 1",
dbesc($chash), intval($chan),
dbesc($xhash), dbesc($xhash),
dbesc($family), dbesc($family),
dbesc($key) dbesc($key)
@ -28,14 +28,14 @@ class AbConfig {
} }
static public function Set($chash,$xhash,$family,$key,$value) { static public function Set($chan,$xhash,$family,$key,$value) {
$dbvalue = ((is_array($value)) ? serialize($value) : $value); $dbvalue = ((is_array($value)) ? serialize($value) : $value);
$dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue); $dbvalue = ((is_bool($dbvalue)) ? intval($dbvalue) : $dbvalue);
if(self::Get($chash,$xhash,$family,$key) === false) { if(self::Get($chan,$xhash,$family,$key) === false) {
$r = q("insert into abconfig ( chan, xchan, cat, k, v ) values ( '%s', '%s', '%s', '%s', '%s' ) ", $r = q("insert into abconfig ( chan, xchan, cat, k, v ) values ( %d, '%s', '%s', '%s', '%s' ) ",
dbesc($chash), intval($chan),
dbesc($xhash), dbesc($xhash),
dbesc($family), dbesc($family),
dbesc($key), dbesc($key),
@ -43,9 +43,9 @@ class AbConfig {
); );
} }
else { else {
$r = q("update abconfig set v = '%s' where chan = '%s' and xchan = '%s' and cat = '%s' and k = '%s' ", $r = q("update abconfig set v = '%s' where chan = %d and xchan = '%s' and cat = '%s' and k = '%s' ",
dbesc($dbvalue), dbesc($dbvalue),
dbesc($chash), dbesc($chan),
dbesc($xhash), dbesc($xhash),
dbesc($family), dbesc($family),
dbesc($key) dbesc($key)
@ -58,10 +58,10 @@ class AbConfig {
} }
static public function Delete($chash,$xhash,$family,$key) { static public function Delete($chan,$xhash,$family,$key) {
$r = q("delete from abconfig where chan = '%s' and xchan = '%s' and cat = '%s' and k = '%s' ", $r = q("delete from abconfig where chan = %d and xchan = '%s' and cat = '%s' and k = '%s' ",
dbesc($chash), intval($chan),
dbesc($xhash), dbesc($xhash),
dbesc($family), dbesc($family),
dbesc($key) dbesc($key)
@ -70,4 +70,4 @@ class AbConfig {
return $r; return $r;
} }
} }

View File

@ -345,7 +345,7 @@ class Connedit extends \Zotlabs\Web\Controller {
unset($clone['abook_account']); unset($clone['abook_account']);
unset($clone['abook_channel']); unset($clone['abook_channel']);
$abconfig = load_abconfig($channel['channel_hash'],$clone['abook_xchan']); $abconfig = load_abconfig($channel['channel_id'],$clone['abook_xchan']);
if($abconfig) if($abconfig)
$clone['abconfig'] = $abconfig; $clone['abconfig'] = $abconfig;

View File

@ -43,7 +43,7 @@ class Follow extends \Zotlabs\Web\Controller {
unset($clone['abook_account']); unset($clone['abook_account']);
unset($clone['abook_channel']); unset($clone['abook_channel']);
$abconfig = load_abconfig($channel['channel_hash'],$clone['abook_xchan']); $abconfig = load_abconfig($channel['channel_id'],$clone['abook_xchan']);
if($abconfig) if($abconfig)
$clone['abconfig'] = $abconfig; $clone['abconfig'] = $abconfig;

View File

@ -389,8 +389,7 @@ class Import extends \Zotlabs\Web\Controller {
if($abconfig) { if($abconfig) {
// @fixme does not handle sync of del_abconfig // @fixme does not handle sync of del_abconfig
foreach($abconfig as $abc) { foreach($abconfig as $abc) {
if($abc['chan'] === $channel['channel_hash']) set_abconfig($channel['channel_id'],$abc['xchan'],$abc['cat'],$abc['k'],$abc['v']);
set_abconfig($abc['chan'],$abc['xchan'],$abc['cat'],$abc['k'],$abc['v']);
} }
} }

View File

@ -516,7 +516,7 @@ function identity_basic_export($channel_id, $items = false) {
for($x = 0; $x < count($ret['abook']); $x ++) { for($x = 0; $x < count($ret['abook']); $x ++) {
$xchans[] = $ret['abook'][$x]['abook_chan']; $xchans[] = $ret['abook'][$x]['abook_chan'];
$abconfig = load_abconfig($ret['channel']['channel_hash'],$ret['abook'][$x]['abook_xchan']); $abconfig = load_abconfig($channel_id,$ret['abook'][$x]['abook_xchan']);
if($abconfig) if($abconfig)
$ret['abook'][$x]['abconfig'] = $abconfig; $ret['abook'][$x]['abconfig'] = $abconfig;
} }

View File

@ -98,20 +98,20 @@ function del_aconfig($account_id, $family, $key) {
} }
function load_abconfig($chash,$xhash) { function load_abconfig($chan,$xhash) {
Zlib\AbConfig::Load($chash,$xhash); Zlib\AbConfig::Load($chan,$xhash);
} }
function get_abconfig($chash,$xhash,$family,$key) { function get_abconfig($chan,$xhash,$family,$key) {
return Zlib\AbConfig::Get($chash,$xhash,$family,$key); return Zlib\AbConfig::Get($chan,$xhash,$family,$key);
} }
function set_abconfig($chash,$xhash,$family,$key,$value) { function set_abconfig($chan,$xhash,$family,$key,$value) {
return Zlib\AbConfig::Set($chash,$xhash,$family,$key,$value); return Zlib\AbConfig::Set($chan,$xhash,$family,$key,$value);
} }
function del_abconfig($chash,$xhash,$family,$key) { function del_abconfig($chan,$xhash,$family,$key) {
return Zlib\AbConfig::Delete($chash,$xhash,$family,$key); return Zlib\AbConfig::Delete($chan,$xhash,$family,$key);
} }
function load_iconfig(&$item) { function load_iconfig(&$item) {

View File

@ -552,7 +552,7 @@ function zot_refresh($them, $channel = null, $force = false) {
unset($new_connection[0]['abook_account']); unset($new_connection[0]['abook_account']);
unset($new_connection[0]['abook_channel']); unset($new_connection[0]['abook_channel']);
$abconfig = load_abconfig($channel['channel_hash'],$new_connection['abook_xchan']); $abconfig = load_abconfig($channel['channel_id'],$new_connection['abook_xchan']);
if($abconfig) if($abconfig)
$new_connection['abconfig'] = $abconfig; $new_connection['abconfig'] = $abconfig;
@ -3335,8 +3335,7 @@ function process_channel_sync_delivery($sender, $arr, $deliveries) {
if($abconfig) { if($abconfig) {
// @fixme does not handle sync of del_abconfig // @fixme does not handle sync of del_abconfig
foreach($abconfig as $abc) { foreach($abconfig as $abc) {
if($abc['chan'] === $channel['channel_hash']) set_abconfig($channel['channel_id'],$abc['xchan'],$abc['cat'],$abc['k'],$abc['v']);
set_abconfig($abc['chan'],$abc['xchan'],$abc['cat'],$abc['k'],$abc['v']);
} }
} }
} }