aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2017-07-25 20:52:29 -0700
committerzotlabs <mike@macgirvin.com>2017-07-25 20:52:29 -0700
commiteec2871680ae97810de4bdc20bb3decf2d919019 (patch)
treef5a60d4e35a17f337caf0ffa133d73586f5d4e21
parent029cf6395dc1da503ebda7718cae30a8c19de691 (diff)
downloadvolse-hubzilla-eec2871680ae97810de4bdc20bb3decf2d919019.tar.gz
volse-hubzilla-eec2871680ae97810de4bdc20bb3decf2d919019.tar.bz2
volse-hubzilla-eec2871680ae97810de4bdc20bb3decf2d919019.zip
consolidate duplicated code
-rw-r--r--include/xchan.php267
1 files changed, 59 insertions, 208 deletions
diff --git a/include/xchan.php b/include/xchan.php
index dba0b8b88..8c9c09c72 100644
--- a/include/xchan.php
+++ b/include/xchan.php
@@ -137,232 +137,83 @@ function xchan_fetch($arr) {
}
-function xchan_change_key($oldx,$newx,$data) {
-
- $r = q("update abook set abook_xchan = '%s' where abook_xchan = '%s'",
- dbsec($newx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
- );
-
- $r = q("update abconfig set xchan = '%s' where xchan = '%s'",
- dbsec($newx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
- );
-
- $r = q("update group_member set xchan = '%s' where xchan = '%s'",
- dbsec($newx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
- );
-
- $r = q("update chat set chat_xchan = '%s' where chat_xchan = '%s'",
- dbsec($newx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
- );
-
- $r = q("update chatpresence set cp_xchan = '%s' where cp_xchan = '%s'",
- dbsec($newx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
- );
-
- $r = q("update event set event_xchan = '%s' where event_xchan = '%s'",
- dbsec($newx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
- );
-
- $r = q("update item set owner_xchan = '%s' where owner_xchan = '%s'",
- dbsec($newx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
- );
-
- $r = q("update item set author_xchan = '%s' where author_xchan = '%s'",
- dbsec($newx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
- );
-
- $r = q("update item set source_xchan = '%s' where source_xchan = '%s'",
- dbsec($newx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
- );
-
- $r = q("update mail set from_xchan = '%s' where from_xchan = '%s'",
- dbsec($newx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
- );
-
- $r = q("update mail set to_xchan = '%s' where to_xchan = '%s'",
- dbsec($newx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
- );
-
- $r = q("update shares set share_xchan = '%s' where share_xchan = '%s'",
- dbsec($newx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
- );
-
- $r = q("update source set src_channel_xchan = '%s' where src_channel_xchan = '%s'",
- dbsec($newx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
- );
-
- $r = q("update source set src_xchan = '%s' where src_xchan = '%s'",
- dbsec($newx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
- );
-
- $r = q("update xchat set xchat_xchan = '%s' where xchat_xchan = '%s'",
- dbsec($newx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
- );
-
- $r = q("update xconfig set xchan = '%s' where xchan = '%s'",
- dbsec($newx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
- );
-
- $r = q("update xign set xchan = '%s' where xchan = '%s'",
- dbsec($newx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
- );
-
- $r = q("update xlink set xlink_xchan = '%s' where xlink_xchan = '%s'",
- dbsec($newx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
- );
-
- $r = q("update xprof set xprof_hash = '%s' where xprof_hash = '%s'",
- dbsec($newx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
- );
-
- $r = q("update xtag set xtag_hash = '%s' where xtag_hash = '%s'",
- dbsec($newx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
- );
-
- $r = q("select channel_id, channel_allow_cid, channel_deny_cid from channel where (channel_allow_cid like '%s' or channel_deny_cid like '%s') ",
- dbesc($oldx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
- );
-
- if($r) {
- foreach($r as $rv) {
- $z = q("update channel set channel_allow_cid = '%s', channel_deny_cid = '%s' where channel_id = %d",
- dbesc(str_replace('<' . $oldx['xchan_hash'] . '>', '<' . $newx['xchan_hash'] . '>', $rv['channel_allow_cid'])),
- dbesc(str_replace('<' . $oldx['xchan_hash'] . '>', '<' . $newx['xchan_hash'] . '>', $rv['channel_deny_cid'])),
- intval($rv['channel_id'])
- );
- }
- }
-
- $r = q("select id, allow_cid, deny_cid from attach where (allow_cid like '%s' or deny_cid like '%s') ",
- dbesc($oldx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
+function xchan_keychange_table($table,$column,$oldxchan,$newxchan) {
+ $r = q("update $table set $column = '%s' where $column = '%s'",
+ dbesc($newxchan['xchan_hash']),
+ dbesc($oldxchan['xchan_hash'])
);
+ return $r;
+}
- if($r) {
- foreach($r as $rv) {
- $z = q("update attach set allow_cid = '%s', deny_cid = '%s' where id = %d",
- dbesc(str_replace('<' . $oldx['xchan_hash'] . '>', '<' . $newx['xchan_hash'] . '>', $rv['allow_cid'])),
- dbesc(str_replace('<' . $oldx['xchan_hash'] . '>', '<' . $newx['xchan_hash'] . '>', $rv['deny_cid'])),
- intval($rv['id'])
- );
- }
- }
-
- $r = q("select cr_id, allow_cid, deny_cid from chatroom where (allow_cid like '%s' or deny_cid like '%s') ",
- dbesc($oldx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
- );
-
- if($r) {
- foreach($r as $rv) {
- $z = q("update chatroom set allow_cid = '%s', deny_cid = '%s' where cr_id = %d",
- dbesc(str_replace('<' . $oldx['xchan_hash'] . '>', '<' . $newx['xchan_hash'] . '>', $rv['allow_cid'])),
- dbesc(str_replace('<' . $oldx['xchan_hash'] . '>', '<' . $newx['xchan_hash'] . '>', $rv['deny_cid'])),
- intval($rv['cr_id'])
- );
- }
- }
-
-
- $r = q("select id, allow_cid, deny_cid from event where (allow_cid like '%s' or deny_cid like '%s') ",
- dbesc($oldx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
- );
+function xchan_keychange_acl($table,$column,$oldxchan,$newxchan) {
- if($r) {
- foreach($r as $rv) {
- $z = q("update event set allow_cid = '%s', deny_cid = '%s' where id = %d",
- dbesc(str_replace('<' . $oldx['xchan_hash'] . '>', '<' . $newx['xchan_hash'] . '>', $rv['allow_cid'])),
- dbesc(str_replace('<' . $oldx['xchan_hash'] . '>', '<' . $newx['xchan_hash'] . '>', $rv['deny_cid'])),
- intval($rv['id'])
- );
- }
- }
+ $allow = (($table === 'channel') ? 'channel_allow_cid' : 'allow_cid');
+ $deny = (($table === 'channel') ? 'channel_deny_cid' : 'deny_cid');
- $r = q("select id, allow_cid, deny_cid from item where (allow_cid like '%s' or deny_cid like '%s') ",
- dbesc($oldx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
+ $r = q("select $column, $allow, $deny from $table where ($allow like '%s' or $deny like '%s') ",
+ dbesc('<' . $oldxchan['xchan_hash'] . '>'),
+ dbesc('<' . $oldxchan['xchan_hash'] . '>')
);
if($r) {
foreach($r as $rv) {
- $z = q("update item set allow_cid = '%s', deny_cid = '%s' where id = %d",
- dbesc(str_replace('<' . $oldx['xchan_hash'] . '>', '<' . $newx['xchan_hash'] . '>', $rv['allow_cid'])),
- dbesc(str_replace('<' . $oldx['xchan_hash'] . '>', '<' . $newx['xchan_hash'] . '>', $rv['deny_cid'])),
- intval($rv['id'])
+ $z = q("update $table set $allow = '%s', $deny = '%s' where $column = %d",
+ dbesc(str_replace('<' . $oldxchan['xchan_hash'] . '>', '<' . $newxchan['xchan_hash'] . '>',
+ $rv[$allow])),
+ dbesc(str_replace('<' . $oldxchan['xchan_hash'] . '>', '<' . $newxchan['xchan_hash'] . '>',
+ $rv[$deny])),
+ intval($rv[$column])
);
}
}
+ return $z;
+}
- $r = q("select mitem_id, allow_cid, deny_cid from menu_item where (allow_cid like '%s' or deny_cid like '%s') ",
- dbesc($oldx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
- );
-
- if($r) {
- foreach($r as $rv) {
- $z = q("update menu_item set allow_cid = '%s', deny_cid = '%s' where mitem_id = %d",
- dbesc(str_replace('<' . $oldx['xchan_hash'] . '>', '<' . $newx['xchan_hash'] . '>', $rv['allow_cid'])),
- dbesc(str_replace('<' . $oldx['xchan_hash'] . '>', '<' . $newx['xchan_hash'] . '>', $rv['deny_cid'])),
- intval($rv['mitem_id'])
- );
- }
- }
-
+function xchan_change_key($oldx,$newx,$data) {
+ $tables = [
+ 'abook' => 'abook_xchan',
+ 'abconfig' => 'xchan',
+ 'group_member' => 'xchan',
+ 'chat' => 'chat_xchan',
+ 'chatpresence' => 'cp_xchan',
+ 'event' => 'event_xchan',
+ 'item' => 'owner_xchan',
+ 'item' => 'author_xchan',
+ 'item' => 'source_xchan',
+ 'mail' => 'from_xchan',
+ 'mail' => 'to_xchan',
+ 'shares' => 'share_xchan',
+ 'source' => 'src_channel_xchan',
+ 'source' => 'src_xchan',
+ 'xchat' => 'xchat_xchan',
+ 'xconfig' => 'xchan',
+ 'xign' => 'xchan',
+ 'xlink' => 'xlink_xchan',
+ 'xprof' => 'xprof_hash',
+ 'xtag' => 'xtag_hash'
+ ];
+
+
+ $acls = [
+ 'channel' => 'channel_id',
+ 'attach' => 'id',
+ 'chatroom' => 'cr_id',
+ 'event' => 'id',
+ 'item' => 'id',
+ 'menu_item' => 'mitem_id',
+ 'obj' => 'obj_id',
+ 'photo' => 'id'
+ ];
- $r = q("select obj_id, allow_cid, deny_cid from obj where (allow_cid like '%s' or deny_cid like '%s') ",
- dbesc($oldx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
- );
- if($r) {
- foreach($r as $rv) {
- $z = q("update obj set allow_cid = '%s', deny_cid = '%s' where obj_id = %d",
- dbesc(str_replace('<' . $oldx['xchan_hash'] . '>', '<' . $newx['xchan_hash'] . '>', $rv['allow_cid'])),
- dbesc(str_replace('<' . $oldx['xchan_hash'] . '>', '<' . $newx['xchan_hash'] . '>', $rv['deny_cid'])),
- intval($rv['obj_id'])
- );
- }
+ foreach($tables as $k => $v) {
+ xchan_keychange_table($k,$v,$oldx,$newx);
}
- $r = q("select id, allow_cid, deny_cid from photo where (allow_cid like '%s' or deny_cid like '%s') ",
- dbesc($oldx['xchan_hash']),
- dbesc($oldx['xchan_hash'])
- );
-
- if($r) {
- foreach($r as $rv) {
- $z = q("update photo set allow_cid = '%s', deny_cid = '%s' where id = %d",
- dbesc(str_replace('<' . $oldx['xchan_hash'] . '>', '<' . $newx['xchan_hash'] . '>', $rv['allow_cid'])),
- dbesc(str_replace('<' . $oldx['xchan_hash'] . '>', '<' . $newx['xchan_hash'] . '>', $rv['deny_cid'])),
- intval($rv['id'])
- );
- }
+ foreach($acls as $k => $v) {
+ xchan_keychange_acl($k,$v,$oldx,$newx);
}
-
-
} \ No newline at end of file