revise how we store perm_limits
This commit is contained in:
parent
08a4763bff
commit
e11330a5c8
@ -2,6 +2,8 @@
|
||||
|
||||
namespace Zotlabs\Access;
|
||||
|
||||
use \Zotlabs\Lib as ZLib;
|
||||
|
||||
class PermissionLimits {
|
||||
|
||||
static public function Std_Limits() {
|
||||
@ -17,43 +19,18 @@ class PermissionLimits {
|
||||
}
|
||||
|
||||
static public function Set($channel_id,$perm,$perm_limit) {
|
||||
$r = q("select * from perm_limits where channel_id = %d and perm = '%s' limit 1",
|
||||
intval($channel_id),
|
||||
dbesc($perm)
|
||||
);
|
||||
if($r) {
|
||||
if($r[0]['perm_limit'] != $perm_limit) {
|
||||
$x = q("update perm_limits set perm_limit = %d where id = %d",
|
||||
dbesc($perm_limit),
|
||||
intval($r[0]['id'])
|
||||
);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$r = q("insert into perm_limits ( perm, channel_id, perm_limit )
|
||||
values ( '%s', %d, %d ) ",
|
||||
dbesc($perm),
|
||||
intval($channel_id),
|
||||
intval($perm_limit)
|
||||
);
|
||||
}
|
||||
ZLib\PConfig::Set($channel_id,'perm_limits',$perm,$perm_limit);
|
||||
}
|
||||
|
||||
static public function Get($channel_id,$perm = '') {
|
||||
if($perm) {
|
||||
$r = q("select * from perm_limits where channel_id = %d and perm = '%s' limit 1",
|
||||
intval($channel_id),
|
||||
dbesc($perm)
|
||||
);
|
||||
if($r)
|
||||
return $r[0];
|
||||
return false;
|
||||
return Zlib\PConfig::Get($channel_id,'perm_limits',$perm);
|
||||
}
|
||||
else {
|
||||
return q("select * from perm_limits where channel_id = %d",
|
||||
intval($channel_id)
|
||||
);
|
||||
Zlib\PConfig::Load($channel_id);
|
||||
if(array_key_exists($channel_id,\App::$config) && array_key_exists('perm_limits',\App::$config[$channel_id]))
|
||||
return \App::$config[$channel_id]['perm_limits'];
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,22 +1,22 @@
|
||||
<?php
|
||||
|
||||
function perm_limits_upgrade($channel) {
|
||||
perm_limits_upgrade_create($channel['channel_id'],'view_stream',$channel['channel_r_stream']);
|
||||
perm_limits_upgrade_create($channel['channel_id'],'view_profile',$channel['channel_r_profile']);
|
||||
perm_limits_upgrade_create($channel['channel_id'],'view_contacts',$channel['channel_r_abook']);
|
||||
perm_limits_upgrade_create($channel['channel_id'],'view_storage',$channel['channel_r_storage']);
|
||||
perm_limits_upgrade_create($channel['channel_id'],'view_pages',$channel['channel_r_pages']);
|
||||
perm_limits_upgrade_create($channel['channel_id'],'send_stream',$channel['channel_w_stream']);
|
||||
perm_limits_upgrade_create($channel['channel_id'],'post_wall',$channel['channel_w_wall']);
|
||||
perm_limits_upgrade_create($channel['channel_id'],'post_comments',$channel['channel_w_comment']);
|
||||
perm_limits_upgrade_create($channel['channel_id'],'post_mail',$channel['channel_w_mail']);
|
||||
perm_limits_upgrade_create($channel['channel_id'],'post_like',$channel['channel_w_like']);
|
||||
perm_limits_upgrade_create($channel['channel_id'],'tag_deliver',$channel['channel_w_tagwall']);
|
||||
perm_limits_upgrade_create($channel['channel_id'],'chat',$channel['channel_w_chat']);
|
||||
perm_limits_upgrade_create($channel['channel_id'],'write_storage',$channel['channel_w_storage']);
|
||||
perm_limits_upgrade_create($channel['channel_id'],'write_pages',$channel['channel_w_pages']);
|
||||
perm_limits_upgrade_create($channel['channel_id'],'republish',$channel['channel_a_republish']);
|
||||
perm_limits_upgrade_create($channel['channel_id'],'delegate',$channel['channel_a_delegate']);
|
||||
set_pconfig($channel['channel_id'],'perm_limits','view_stream',$channel['channel_r_stream']);
|
||||
set_pconfig($channel['channel_id'],'perm_limits','view_profile',$channel['channel_r_profile']);
|
||||
set_pconfig($channel['channel_id'],'perm_limits','view_contacts',$channel['channel_r_abook']);
|
||||
set_pconfig($channel['channel_id'],'perm_limits','view_storage',$channel['channel_r_storage']);
|
||||
set_pconfig($channel['channel_id'],'perm_limits','view_pages',$channel['channel_r_pages']);
|
||||
set_pconfig($channel['channel_id'],'perm_limits','send_stream',$channel['channel_w_stream']);
|
||||
set_pconfig($channel['channel_id'],'perm_limits','post_wall',$channel['channel_w_wall']);
|
||||
set_pconfig($channel['channel_id'],'perm_limits','post_comments',$channel['channel_w_comment']);
|
||||
set_pconfig($channel['channel_id'],'perm_limits','post_mail',$channel['channel_w_mail']);
|
||||
set_pconfig($channel['channel_id'],'perm_limits','post_like',$channel['channel_w_like']);
|
||||
set_pconfig($channel['channel_id'],'perm_limits','tag_deliver',$channel['channel_w_tagwall']);
|
||||
set_pconfig($channel['channel_id'],'perm_limits','chat',$channel['channel_w_chat']);
|
||||
set_pconfig($channel['channel_id'],'perm_limits','write_storage',$channel['channel_w_storage']);
|
||||
set_pconfig($channel['channel_id'],'perm_limits','write_pages',$channel['channel_w_pages']);
|
||||
set_pconfig($channel['channel_id'],'perm_limits','republish',$channel['channel_a_republish']);
|
||||
set_pconfig($channel['channel_id'],'perm_limits','delegate',$channel['channel_a_delegate']);
|
||||
}
|
||||
|
||||
|
||||
|
@ -904,18 +904,6 @@ CREATE TABLE IF NOT EXISTS `pconfig` (
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
create table if not exists perm_limits {
|
||||
id int(10) not null AUTO_INCREMENT,
|
||||
perm varchar(64) not null default '',
|
||||
channel_id int(10) unsigned not null default 0,
|
||||
perm_limit int(10) unsigned not null default 0,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `perm` (`perm`),
|
||||
KEY `channel_id` (`channel_id`),
|
||||
KEY `perm_limit` (`perm_limit`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `photo` (
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`aid` int(10) unsigned NOT NULL DEFAULT '0',
|
||||
|
@ -888,16 +888,6 @@ CREATE TABLE "pconfig" (
|
||||
PRIMARY KEY ("id"),
|
||||
UNIQUE ("uid","cat","k")
|
||||
);
|
||||
create table perm_limits (
|
||||
id serial NOT NULL,
|
||||
perm varchar(64) not null default '',
|
||||
channel_id int(10) unsigned not null default 0,
|
||||
perm_limit int(10) unsigned not null default 0,
|
||||
primary key id
|
||||
);
|
||||
create index "idx_perm" on perm_limits ("perm");
|
||||
create index "idx_channel_id" on perm_limits ("channel_id");
|
||||
create index "idx_perm_limit" on perm_limits ("perm_limit");
|
||||
|
||||
CREATE TABLE "photo" (
|
||||
"id" serial NOT NULL,
|
||||
|
@ -2366,36 +2366,6 @@ function update_r1179() {
|
||||
|
||||
require_once('install/perm_upgrade.php');
|
||||
|
||||
if(ACTIVE_DBTYPE == DBTYPE_POSTGRES) {
|
||||
$r1 = q("create table perm_limits (
|
||||
id serial NOT NULL,
|
||||
perm varchar(64) not null default '',
|
||||
channel_id int(10) unsigned not null default 0,
|
||||
perm_limit int(10) unsigned not null default 0
|
||||
primary_key id )");
|
||||
$r2 = q("create index \"idx_perm\" on perm_limits (\"perm\") ");
|
||||
$r3 = q("create index \"idx_channel_id\" on perm_limits (\"channel_id\") ");
|
||||
$r4 = q("create index \"idx_perm_limit\" on perm_limits (\"perm_limit\") ");
|
||||
|
||||
|
||||
$r = $r1 && $r2 && $r3 && $r4;
|
||||
}
|
||||
|
||||
else {
|
||||
$r1 = q("create table if not exists perm_limits {
|
||||
id int(10) not null AUTO_INCREMENT,
|
||||
perm varchar(64) not null default '',
|
||||
channel_id int(10) unsigned not null default 0,
|
||||
perm_limit int(10) unsigned not null default 0,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `perm` (`perm`),
|
||||
KEY `channel_id` (`channel_id`),
|
||||
KEY `perm_limit` (`perm_limit`)
|
||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ");
|
||||
|
||||
$r = $r1;
|
||||
}
|
||||
|
||||
$r1 = q("select * from channel where true");
|
||||
if($r1) {
|
||||
foreach($r1 as $rr) {
|
||||
@ -2410,7 +2380,7 @@ function update_r1179() {
|
||||
}
|
||||
}
|
||||
|
||||
$r = $r && $r1 && $r2;
|
||||
$r = $r1 && $r2;
|
||||
if($r)
|
||||
return UPDATE_SUCCESS;
|
||||
return UPDATE_FAILED;
|
||||
|
Reference in New Issue
Block a user