3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
37 * Access Control Cache
39 class CRM_ACL_BAO_Cache
extends CRM_ACL_DAO_Cache
{
41 static $_cache = NULL;
48 public static function &build($id) {
50 self
::$_cache = array();
53 if (array_key_exists($id, self
::$_cache)) {
54 return self
::$_cache[$id];
57 // check if this entry exists in db
58 // if so retrieve and return
59 self
::$_cache[$id] = self
::retrieve($id);
60 if (self
::$_cache[$id]) {
61 return self
::$_cache[$id];
64 self
::$_cache[$id] = CRM_ACL_BAO_ACL
::getAllByContact($id);
65 self
::store($id, self
::$_cache[$id]);
66 return self
::$_cache[$id];
74 public static function retrieve($id) {
77 FROM civicrm_acl_cache
80 $params = array(1 => array($id, 'Integer'));
83 $query .= " OR contact_id IS NULL";
86 $dao = CRM_Core_DAO
::executeQuery($query, $params);
89 while ($dao->fetch()) {
90 $cache[$dao->acl_id
] = 1;
99 public static function store($id, &$cache) {
100 foreach ($cache as $aclID => $data) {
101 $dao = new CRM_ACL_DAO_Cache();
103 $dao->contact_id
= $id;
105 $dao->acl_id
= $aclID;
116 public static function deleteEntry($id) {
118 array_key_exists($id, self
::$_cache)
120 unset(self
::$_cache[$id]);
124 DELETE FROM civicrm_acl_cache
125 WHERE contact_id = %1
127 $params = array(1 => array($id, 'Integer'));
128 CRM_Core_DAO
::executeQuery($query, $params);
134 public static function updateEntry($id) {
135 // rebuilds civicrm_acl_cache
136 self
::deleteEntry($id);
139 // rebuilds civicrm_acl_contact_cache
140 CRM_Contact_BAO_Contact_Permission
::cache($id, CRM_Core_Permission
::VIEW
, TRUE);
144 * Deletes all the cache entries.
146 public static function resetCache() {
147 // reset any static caching
148 self
::$_cache = NULL;
150 // reset any db caching
151 $config = CRM_Core_Config
::singleton();
152 $smartGroupCacheTimeout = CRM_Contact_BAO_GroupContactCache
::smartGroupCacheTimeout();
154 //make sure to give original timezone settings again.
155 $now = CRM_Utils_Date
::getUTCTime();
159 FROM civicrm_acl_cache
160 WHERE modified_date IS NULL
161 OR (TIMESTAMPDIFF(MINUTE, modified_date, $now) >= $smartGroupCacheTimeout)
163 CRM_Core_DAO
::singleValueQuery($query);
165 // CRM_Core_DAO::singleValueQuery("TRUNCATE TABLE civicrm_acl_contact_cache"); // No, force-commits transaction
166 // CRM_Core_DAO::singleValueQuery("DELETE FROM civicrm_acl_contact_cache"); // Transaction-safe
167 if (CRM_Core_Transaction
::isActive()) {
168 CRM_Core_Transaction
::addCallback(CRM_Core_Transaction
::PHASE_POST_COMMIT
, function () {
169 CRM_Core_DAO
::singleValueQuery("TRUNCATE TABLE civicrm_acl_contact_cache");
173 CRM_Core_DAO
::singleValueQuery("TRUNCATE TABLE civicrm_acl_contact_cache");