Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
Added a cache for getPageDetails() and outsourced the cache functiona…
Browse files Browse the repository at this point in the history
…lity into a separate library (see #3577)
  • Loading branch information
leofeyer committed Oct 25, 2011
1 parent 249618b commit ff79294
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/Resources/contao/dca/tl_comments.php
Expand Up @@ -312,10 +312,13 @@ protected function isAllowedToEditComment($intParent, $strSource)
return true;
}

$this->import('Cache');
$strKey = __METHOD__ . '-' . $strSource . '-' . $intParent;

// Load cached result
if (isset($this->arrCache[$strSource][$intParent]))
if (isset($this->Cache->$strKey))
{
return $this->arrCache[$strSource][$intParent];
return $this->Cache->$strKey;
}

// Get the pagemounts
Expand All @@ -330,7 +333,7 @@ protected function isAllowedToEditComment($intParent, $strSource)
$pagemounts = array_unique($pagemounts);

// Order deny,allow
$this->arrCache[$strSource][$intParent] = false;
$this->Cache->$strKey = false;

switch ($strSource)
{
Expand All @@ -342,7 +345,7 @@ protected function isAllowedToEditComment($intParent, $strSource)
// Check whether the page is mounted and the user is allowed to edit its articles
if ($objPage->numRows > 0 && in_array($objPage->id, $pagemounts) && $this->User->isAllowed(4, $objPage->row()))
{
$this->arrCache[$strSource][$intParent] = true;
$this->Cache->$strKey = true;
}
break;

Expand All @@ -354,7 +357,7 @@ protected function isAllowedToEditComment($intParent, $strSource)
// Check whether the page is mounted and the user is allowed to edit it
if ($objPage->numRows > 0 && in_array($objPage->id, $pagemounts) && $this->User->isAllowed(1, $objPage->row()))
{
$this->arrCache[$strSource][$intParent] = true;
$this->Cache->$strKey = true;
}
break;

Expand All @@ -369,7 +372,7 @@ protected function isAllowedToEditComment($intParent, $strSource)
// Check the access to the news archive
if ($objArchive->numRows > 0 && $this->User->hasAccess($objArchive->pid, 'news'))
{
$this->arrCache[$strSource][$intParent] = true;
$this->Cache->$strKey = true;
}
}
break;
Expand All @@ -385,7 +388,7 @@ protected function isAllowedToEditComment($intParent, $strSource)
// Check the access to the calendar
if ($objCalendar->numRows > 0 && $this->User->hasAccess($objCalendar->pid, 'calendars'))
{
$this->arrCache[$strSource][$intParent] = true;
$this->Cache->$strKey = true;
}
}
break;
Expand All @@ -394,7 +397,7 @@ protected function isAllowedToEditComment($intParent, $strSource)
// Check the access to the FAQ module
if ($this->User->hasAccess('faq', 'modules'))
{
$this->arrCache[$strSource][$intParent] = true;
$this->Cache->$strKey = true;
}
break;

Expand All @@ -408,15 +411,15 @@ protected function isAllowedToEditComment($intParent, $strSource)

if ($this->$callback[0]->$callback[1]($intParent, $strSource) === true)
{
$this->arrCache[$strSource][$intParent] = true;
$this->Cache->$strKey = true;
break;
}
}
}
break;
}

return $this->arrCache[$strSource][$intParent];
return $this->Cache->$strKey;
}


Expand Down

0 comments on commit ff79294

Please sign in to comment.