3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
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
35 * Access Control Cache.
37 class CRM_ACL_BAO_Cache
extends CRM_ACL_DAO_Cache
{
39 static $_cache = NULL;
46 public static function &build($id) {
48 self
::$_cache = array();
51 if (array_key_exists($id, self
::$_cache)) {
52 return self
::$_cache[$id];
55 // check if this entry exists in db
56 // if so retrieve and return
57 self
::$_cache[$id] = self
::retrieve($id);
58 if (self
::$_cache[$id]) {
59 return self
::$_cache[$id];
62 self
::$_cache[$id] = CRM_ACL_BAO_ACL
::getAllByContact($id);
63 self
::store($id, self
::$_cache[$id]);
64 return self
::$_cache[$id];
72 public static function retrieve($id) {
75 FROM civicrm_acl_cache
78 $params = array(1 => array($id, 'Integer'));
81 $query .= " OR contact_id IS NULL";
84 $dao = CRM_Core_DAO
::executeQuery($query, $params);
87 while ($dao->fetch()) {
88 $cache[$dao->acl_id
] = 1;
97 public static function store($id, &$cache) {
98 foreach ($cache as $aclID => $data) {
99 $dao = new CRM_ACL_DAO_Cache();
101 $dao->contact_id
= $id;
103 $dao->acl_id
= $aclID;
114 public static function deleteEntry($id) {
116 array_key_exists($id, self
::$_cache)
118 unset(self
::$_cache[$id]);
122 DELETE FROM civicrm_acl_cache
123 WHERE contact_id = %1
125 $params = array(1 => array($id, 'Integer'));
126 CRM_Core_DAO
::executeQuery($query, $params);
132 public static function updateEntry($id) {
133 // rebuilds civicrm_acl_cache
134 self
::deleteEntry($id);
137 // rebuilds civicrm_acl_contact_cache
138 CRM_Contact_BAO_Contact_Permission
::cache($id, CRM_Core_Permission
::VIEW
, TRUE);
142 * Deletes all the cache entries.
144 public static function resetCache() {
145 // reset any static caching
146 self
::$_cache = NULL;
148 // reset any db caching
149 $config = CRM_Core_Config
::singleton();
150 $smartGroupCacheTimeout = CRM_Contact_BAO_GroupContactCache
::smartGroupCacheTimeout();
152 //make sure to give original timezone settings again.
153 $now = CRM_Utils_Date
::getUTCTime();
157 FROM civicrm_acl_cache
158 WHERE modified_date IS NULL
159 OR (TIMESTAMPDIFF(MINUTE, modified_date, $now) >= $smartGroupCacheTimeout)
161 CRM_Core_DAO
::singleValueQuery($query);
163 // CRM_Core_DAO::singleValueQuery("TRUNCATE TABLE civicrm_acl_contact_cache"); // No, force-commits transaction
164 // CRM_Core_DAO::singleValueQuery("DELETE FROM civicrm_acl_contact_cache"); // Transaction-safe
165 if (CRM_Core_Transaction
::isActive()) {
166 CRM_Core_Transaction
::addCallback(CRM_Core_Transaction
::PHASE_POST_COMMIT
, function () {
167 CRM_Core_DAO
::singleValueQuery("TRUNCATE TABLE civicrm_acl_contact_cache");
171 CRM_Core_DAO
::singleValueQuery("TRUNCATE TABLE civicrm_acl_contact_cache");