3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
37 * Access Control Cache
39 class CRM_ACL_BAO_Cache
extends CRM_ACL_DAO_Cache
{
41 static $_cache = NULL;
43 static function &build($id) {
45 self
::$_cache = array();
48 if (array_key_exists($id, self
::$_cache)) {
49 return self
::$_cache[$id];
52 // check if this entry exists in db
53 // if so retrieve and return
54 self
::$_cache[$id] = self
::retrieve($id);
55 if (self
::$_cache[$id]) {
56 return self
::$_cache[$id];
59 self
::$_cache[$id] = CRM_ACL_BAO_ACL
::getAllByContact($id);
60 self
::store($id, self
::$_cache[$id]);
61 return self
::$_cache[$id];
64 static function retrieve($id) {
67 FROM civicrm_acl_cache
70 $params = array(1 => array($id, 'Integer'));
73 $query .= " OR contact_id IS NULL";
76 $dao = CRM_Core_DAO
::executeQuery($query, $params);
79 while ($dao->fetch()) {
80 $cache[$dao->acl_id
] = 1;
85 static function store($id, &$cache) {
86 foreach ($cache as $aclID => $data) {
87 $dao = new CRM_ACL_DAO_Cache();
89 $dao->contact_id
= $id;
91 $dao->acl_id
= $aclID;
99 static function deleteEntry($id) {
101 array_key_exists($id, self
::$_cache)
103 unset(self
::$_cache[$id]);
107 DELETE FROM civicrm_acl_cache
108 WHERE contact_id = %1
110 $params = array(1 => array($id, 'Integer'));
111 $dao = CRM_Core_DAO
::executeQuery($query, $params);
114 static function updateEntry($id) {
115 // rebuilds civicrm_acl_cache
116 self
::deleteEntry($id);
119 // rebuilds civicrm_acl_contact_cache
120 CRM_Contact_BAO_Contact_Permission
::cache($id, CRM_Core_Permission
::VIEW
, TRUE);
123 // deletes all the cache entries
124 static function resetCache() {
125 // reset any static caching
126 self
::$_cache = NULL;
128 // reset any db caching
129 $config = CRM_Core_Config
::singleton();
130 $smartGroupCacheTimeout = CRM_Contact_BAO_GroupContactCache
::smartGroupCacheTimeout();
132 //make sure to give original timezone settings again.
133 $now = CRM_Utils_Date
::getUTCTime();
137 FROM civicrm_acl_cache
138 WHERE modified_date IS NULL
139 OR (TIMESTAMPDIFF(MINUTE, modified_date, $now) >= $smartGroupCacheTimeout)
141 CRM_Core_DAO
::singleValueQuery($query);
143 // CRM_Core_DAO::singleValueQuery("TRUNCATE TABLE civicrm_acl_contact_cache"); // No, force-commits transaction
144 // CRM_Core_DAO::singleValueQuery("DELETE FROM civicrm_acl_contact_cache"); // Transaction-safe
145 if (CRM_Core_Transaction
::isActive()) {
146 CRM_Core_Transaction
::addCallback(CRM_Core_Transaction
::PHASE_POST_COMMIT
, function(){
147 CRM_Core_DAO
::singleValueQuery("TRUNCATE TABLE civicrm_acl_contact_cache");
150 CRM_Core_DAO
::singleValueQuery("TRUNCATE TABLE civicrm_acl_contact_cache");