Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F774129
in-portal
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Feb 3, 8:31 AM
Size
12 KB
Mime Type
text/x-diff
Expires
Wed, Feb 5, 8:31 AM (4 h, 48 m)
Engine
blob
Format
Raw Data
Handle
557252
Attached To
rINP In-Portal
in-portal
View Options
Index: trunk/admin/category/permcacheupdate.php
===================================================================
--- trunk/admin/category/permcacheupdate.php (revision 577)
+++ trunk/admin/category/permcacheupdate.php (revision 578)
@@ -1,289 +1,289 @@
<?php
class clsRecursionStack
{
var $Stack;
function clsRecursionStack()
{
$this->Stack = Array();
}
function Push($values)
{
array_push($this->Stack, $values);
}
function Pop()
{
if ($this->Count() > 0) {
return array_pop($this->Stack);
}
else {
return false;
}
}
function Get()
{
if ($this->Count() > 0) {
- return end($this->Stack);
-// return $this->Stack[count($this->Stack)-1];
+// return end($this->Stack);
+ return $this->Stack[count($this->Stack)-1];
}
else {
return false;
}
}
function Update($values)
{
$this->Stack[count($this->Stack)-1] = $values;
}
function Count()
{
return count($this->Stack);
}
}
class clsCachedPermissions
{
var $Allow;
var $Deny;
var $CatId;
function clsCachedPermissions($CatId)
{
$this->CatId = $CatId;
}
function SetCatId($CatId)
{
$this->CatId = $CatId;
}
function CheckPermArray($Perm)
{
if (!isset($this->Allow[$Perm])) {
$this->Allow[$Perm] = array();
$this->Deny[$Perm] = array();
}
}
function AddAllow($Perm, $GroupId)
{
$this->CheckPermArray($Perm);
if (!in_array($GroupId, $this->Allow[$Perm])) {
array_push($this->Allow[$Perm], $GroupId);
$this->RemoveDeny($Perm, $GroupId);
}
}
function AddDeny($Perm, $GroupId)
{
$this->CheckPermArray($Perm);
if (!in_array($GroupId, $this->Deny[$Perm])) {
array_push($this->Deny[$Perm], $GroupId);
$this->RemoveAllow($Perm, $GroupId);
}
}
function RemoveDeny($Perm, $GroupId)
{
if (in_array($GroupId, $this->Deny[$Perm])) {
array_splice($this->Deny[$Perm], array_search($GroupId, $this->Deny[$Perm]), 1);
}
}
function RemoveAllow($Perm, $GroupId)
{
if (in_array($GroupId, $this->Allow[$Perm])) {
array_splice($this->Allow[$Perm], array_search($GroupId, $this->Allow[$Perm]), 1);
}
}
function GetInsertSQL()
{
$values = array();
$has_deny = array();
foreach ($this->Deny as $perm => $groups) {
if (count($groups) > 0) {
$values[] = '('.$this->CatId.', '.$perm.', "", "'.join(',', $groups).'")';
$has_deny[] = $perm;
}
}
foreach ($this->Allow as $perm => $groups) {
if (in_array($perm, $has_deny)) continue;
if (count($groups) > 0) {
$values[] = '(' .$this->CatId. ', ' .$perm. ', "' .join(',', $groups). '", "")';
}
}
if (!$values) return '';
- $sql = 'INSERT INTO inp_PermCache (CategoryId, PermId, ACL, DACL) VALUES '.join(',', $values);
+ $sql = 'INSERT INTO '.GetTablePrefix().'PermCache (CategoryId, PermId, ACL, DACL) VALUES '.join(',', $values);
return $sql;
}
}
class clsCacheUpdater
{
var $Stack;
var $iteration;
var $totalCats;
var $doneCats;
var $table;
function clsCacheUpdater($continuing=false)
{
$this->conn =& GetADODBConnection();
$this->iteration = 0;
$this->table=$GLOBALS['objSession']->GetEditTable('permCacheUpdate');
if (!$continuing) {
$this->Stack =& new clsRecursionStack();
- $sql = 'DELETE FROM inp_PermCache';
+ $sql = 'DELETE FROM '.GetTablePrefix().'PermCache';
$this->conn->Execute($sql);
$this->initData();
}
else {
$this->getData();
// $this->SetStack($data);
}
}
function getDonePercent()
{
if(!$this->totalCats)return 0;
return intval( round( $this->doneCats / $this->totalCats * 100 ) );
}
function getData()
{
$sql='SELECT data FROM '.$this->table;
if( $rs = $this->conn->Execute($sql) )
$tmp = unserialize($rs->fields['data']);
$this->totalCats = isset($tmp['totalCats']) ? $tmp['totalCats'] : 0;
$this->doneCats = isset($tmp['doneCats']) ? $tmp['doneCats'] : 0;
if(isset($tmp['stack']))
$this->Stack = $tmp['stack'];
else
$this->Stack = & new clsRecursionStack();
}
function setData()
{
$tmp=Array
(
'totalCats' =>$this->totalCats,
'doneCats' =>$this->doneCats,
'stack' =>$this->Stack,
);
$sql='DELETE FROM '.$this->table;
$this->conn->Execute($sql);
$sql='INSERT '.$this->table.' SET data="'.addslashes(serialize($tmp)).'"';
$this->conn->Execute($sql);
}
function initData()
{
$sql='CREATE TABLE '.$this->table.'(data LONGTEXT)';
$this->conn->Execute($sql);
$sql='SELECT COUNT(*) as count FROM '.GetTablePrefix().'Category';
if( $rs = $this->conn->Execute($sql) )
$this->totalCats=$rs->fields['count'];
$this->doneCats=0;
}
function clearData()
{
$sql='DROP TABLE IF EXISTS '.$this->table;
$this->conn->Execute($sql);
}
function DoTheJob()
{
$data = $this->Stack->Get();
if ($data === false) { //If Stack is empty
$data['current_id'] = 0;
$this->Stack->Push($data);
}
if (!isset($data['queried'])) {
$this->QueryChildren($data);
$this->QueryPermissions($data);
$data['queried'] = 1;
if($sql = $data['perms']->GetInsertSQL())
{
$this->conn->Execute($sql);
$this->doneCats++;
}
$this->iteration++;
}
// start with first child if we haven't started yet
if (!isset($data['current_child'])) $data['current_child'] = 0;
// if we have more children
if (isset($data['children'][$data['current_child']]))
{
$next_data = array();
$next_data['current_id'] = $data['children'][$data['current_child']]; //next iteration should process child
$next_data['perms'] = $data['perms']; //we should copy our permissions to child - inheritance
$next_data['perms']->SetCatId($next_data['current_id']);
$data['current_child']++;
$this->Stack->Update($data); //we need to update ourself for the iteration after the next (or further) return to next child
$this->Stack->Push($next_data); //next iteration should process this child
return true;
}
else {
$this->Stack->Pop(); //remove ourself from stack if we have finished all the childs (or there are none)
// we are getting here if we finished with current level, so check if it's first level - then bail out.
return $this->Stack->Count() > 0;
}
}
function QueryChildren(&$data)
{
- $sql = sprintf('SELECT CategoryId From inp_Category WHERE ParentId = %s',
+ $sql = sprintf('SELECT CategoryId From '.GetTablePrefix().'Category WHERE ParentId = %s',
$data['current_id']);
$rs = $this->conn->Execute($sql);
$data['children'] = Array();
while ($rs && !$rs->EOF)
{
$data['children'][] = $rs->fields['CategoryId'];
$rs->MoveNext();
}
}
function QueryPermissions(&$data)
{
- $sql = sprintf('SELECT ipc.PermissionConfigId, ip.GroupId, ip.PermissionValue FROM inp_Permissions AS ip
- LEFT JOIN inp_PermissionConfig AS ipc
+ $sql = sprintf('SELECT ipc.PermissionConfigId, ip.GroupId, ip.PermissionValue FROM '.GetTablePrefix().'Permissions AS ip
+ LEFT JOIN '.GetTablePrefix().'PermissionConfig AS ipc
ON ipc.PermissionName = ip.Permission
WHERE CatId = %s AND Permission LIKE "%%.VIEW"',
$data['current_id']);
$rs = $this->conn->Execute($sql);
//create permissions array only if we don't have it yet (set by parent)
if (!isset($data['perms'])) {
$data['perms'] = new clsCachedPermissions($data['current_id']);
}
while ($rs && !$rs->EOF)
{
if ($rs->fields['PermissionValue'] == 1) {
$data['perms']->AddAllow($rs->fields['PermissionConfigId'], $rs->fields['GroupId']);
}
else {
$data['perms']->AddDeny($rs->fields['PermissionConfigId'], $rs->fields['GroupId']);
}
$rs->MoveNext();
}
}
}
?>
\ No newline at end of file
Property changes on: trunk/admin/category/permcacheupdate.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.2
\ No newline at end of property
+1.3
\ No newline at end of property
Index: trunk/admin/category/category_maint.php
===================================================================
--- trunk/admin/category/category_maint.php (revision 577)
+++ trunk/admin/category/category_maint.php (revision 578)
@@ -1,122 +1,125 @@
<?php
##############################################################
##In-portal ##
##############################################################
## In-portal ##
## Intechnic Corporation ##
## All Rights Reserved, 1998-2002 ##
## ##
## No portion of this code may be copied, reproduced or ##
## otherwise redistributed without proper written ##
## consent of Intechnic Corporation. Violation will ##
## result in revocation of the license and support ##
## privileges along maximum prosecution allowed by law. ##
##############################################################
if(!defined('CACHE_PERM_CHUNK_SIZE'))define('CACHE_PERM_CHUNK_SIZE',30);
if(!strlen($pathtoroot))
{
$path = dirname(realpath(__FILE__));
if( strlen($path) )
{
// determine the OS type for path parsing
$pos = strpos($path, ':');
$gOS_TYPE = ($pos === false) ? 'unix' : 'win';
$pathchar = ($gOS_TYPE == 'unix') ? '/' : "\\";
$p = $path.$pathchar;
// Start looking for the root flag file
while( !strlen($pathtoroot) && strlen($p) )
{
$sub = substr($p, strlen($pathchar) * -1);
$filename = $p.( ($sub == $pathchar) ? '' : $pathchar).'root.flg';
if( !file_exists($filename) )
{
$parent = realpath($p.$pathchar."..".$pathchar);
$p = ($parent != $p) ? $parent : '';
}
else
$pathtoroot = $p;
}
if( !strlen($pathtoroot) ) $pathtoroot = '.'.$pathchar;
}
else
$pathtoroot = '.'.$pathchar;
}
$sub = substr($pathtoroot,strlen($pathchar)*-1);
if( $sub != $pathchar) $pathtoroot = $pathtoroot.$pathchar;
//echo $pathtoroot;
//$FrontEnd=2;
require_once($pathtoroot."kernel/startup.php");
//admin only util
$rootURL="http://".ThisDomain().$objConfig->Get("Site_Path");
$admin = $objConfig->Get("AdminDirectory");
if(!strlen($admin))
$admin = "admin";
$localURL=$rootURL."kernel/";
$adminURL = $rootURL.$admin;
$imagesURL = $adminURL."/images";
$pathtolocal = $pathtoroot."in-news/";
require_once ($pathtoroot.$admin."/include/elements.php");
require_once ($pathtoroot."kernel/admin/include/navmenu.php");
require_once ($pathtolocal."admin/include/navmenu.php");
require_once($pathtoroot.$admin."/toolbar.php");
require_once($pathtoroot.$admin."/listview/listview.php");
$section = "in-portal:category_maint";
require_once($pathtoroot.$admin."/category/permcacheupdate.php");
if(!$objSession->GetVariable('PermCache_UpdateRequired'))
die(header('Location: '.$adminURL.'/'.$objSession->GetVariable('ReturnScript').'?env='.BuildEnv()));
if (isset($_GET['continue'])) {
$updater =& new clsCacheUpdater(1);
}
else {
$updater =& new clsCacheUpdater();
}
$title = prompt_language("la_prompt_updating")." ".prompt_language("la_Text_Categories");
$title .= " $CatIndex / $NumCats ".prompt_language("la_Text_complete");
int_header(NULL,NULL,$title);
flush();
$percent=$updater->getDonePercent();
echo '<TABLE cellspacing="0" cellpadding="2" width="100%" border="0" class="tableborder">';
if ($percent == 0)
echo '<TR><TD BGCOLOR="#FFFFFF" width="100%" >'.$percent.'%</td></TR>';
else if ($percent < 60)
echo '<TR><TD BGCOLOR="#4682B2" width="'.$percent.'%"></td><TD BGCOLOR="#FFFFFF" width="'.(100-$percent).'%">'.$percent.'%</td></TR>';
else if ($percent == 100)
echo '<TR><TD BGCOLOR="#4682B2" align="right" width="100%"><FONT COLOR="#FFFFFF">'.$percent.'%</FONT></td>';
else
echo '<TR><TD BGCOLOR="#4682B2" align="right" width="'.$percent.'%"><FONT COLOR="#FFFFFF">'.$percent.'%</FONT></td><TD BGCOLOR="#FFFFFF" width="'.(100-$percent).'%"></td></TR>';
echo '</TABLE>';
flush();
$needs_more = TRUE;
while ($needs_more && $updater->iteration < CACHE_PERM_CHUNK_SIZE) {
$needs_more = $updater->DoTheJob();
}
+/*print_pre($updater);
+echo '<a href="'.$adminURL.'/'.$objSession->GetVariable('ReturnScript').'?env='.BuildEnv().'">go</a>';
+exit;*/
if ($needs_more)
{
$updater->setData();
$url=$adminURL.'/category/category_maint.php?env='.BuildEnv().'&continue=1';
}
else
{
$updater->clearData();
$url = $adminURL.'/'.$objSession->GetVariable('ReturnScript').'?env='.BuildEnv();
$objSession->SetVariable('PermCache_UpdateRequired', 0);
}
print "<script language=\"javascript\">" ;
print "setTimeout(\"document.location='$url';\",40);";
print " </script>";
int_footer();
exit;
?>
Property changes on: trunk/admin/category/category_maint.php
___________________________________________________________________
Modified: cvs2svn:cvs-rev
## -1 +1 ##
-1.11
\ No newline at end of property
+1.12
\ No newline at end of property
Event Timeline
Log In to Comment