public function refreshCache()
 {
     CacheLocal::delete('page', $this->getCollectionID() . ':' . $this->getVersionID());
     CacheLocal::delete('page', $this->getCollectionID() . ':' . 'RECENT');
     CacheLocal::delete('page', $this->getCollectionID() . ':' . 'ACTIVE');
     Events::fire('on_page_version_refresh_cache', $this);
 }
Example #2
0
	public static function getByName($stackName, $cvID = 'RECENT') {
		$cID = CacheLocal::getEntry('stack_by_name', $stackName);
		if (!$cID) {
			$db = Loader::db();
			$cID = $db->GetOne('select cID from Stacks where stName = ?', array($stackName));
			CacheLocal::set('stack_by_name', $stackName, $cID);
		}
		
		if ($cID) {
			return self::getByID($cID, $cvID);
		}
	}
Example #3
0
	public static function addValidate(PermissionKey $pk, $valid) {
		$cl = CacheLocal::get();
		if ($cl->enabled) {
			$object = $pk->getPermissionObject();
			if (is_object($object)) {
				$identifier = 'pk:' . $pk->getPermissionKeyHandle() . ':' . $object->getPermissionObjectIdentifier();
			} else {
				$identifier = 'pk:' . $pk->getPermissionKeyHandle();
			}
			$cl->cache[$identifier] = $valid;
		}
	}
Example #4
0
 /**
  * @param int $cID Collection ID of a page
  * @param string $versionOrig ACTIVE or RECENT
  * @param string $class
  * @return Page
  */
 public static function getByID($cID, $version = 'RECENT', $class = 'Page')
 {
     $c = CacheLocal::getEntry('page', $cID . ':' . $version);
     if ($c instanceof $class) {
         return $c;
     }
     $where = "where Pages.cID = ?";
     $c = new $class();
     $c->populatePage($cID, $where, $version);
     // must use cID instead of c->getCollectionID() because cID may be the pointer to another page
     CacheLocal::set('page', $cID . ':' . $version, $c);
     return $c;
 }
Example #5
0
 public static function set($type, $id, $object)
 {
     $loc = CacheLocal::get();
     if (!$loc->enabled) {
         return false;
     }
     $key = Cache::key($type, $id);
     if (is_object($object)) {
         $r = clone $object;
     } else {
         $r = $object;
     }
     $loc->cache[$key] = $r;
 }
Example #6
0
 public static function get($pkgIsInstalled = 1)
 {
     $pkgList = CacheLocal::getEntry('pkgList', $pkgIsInstalled);
     if ($pkgList != false) {
         return $pkgList;
     }
     $db = Loader::db();
     $r = $db->query("select pkgID, pkgName, pkgIsInstalled, pkgDescription, pkgVersion, pkgHandle, pkgDateInstalled from Packages where pkgIsInstalled = ? order by pkgID asc", array($pkgIsInstalled));
     $list = new PackageList();
     while ($row = $r->fetchRow()) {
         $pkg = new Package();
         $pkg->setPropertiesFromArray($row);
         $list->add($pkg);
     }
     CacheLocal::set('pkgList', $pkgIsInstalled, $list);
     return $list;
 }
Example #7
0
 public static function getList()
 {
     $gaItemTemplateTypeList = CacheLocal::getEntry('gaItemTemplateTypeList', false);
     if ($gaItemTemplateTypeList != false) {
         return $gaItemTemplateTypeList;
     }
     $db = Loader::db();
     $list = array();
     $r = $db->Execute('select gatTypeID from GatheringItemTemplateTypes order by gatTypeID asc');
     while ($row = $r->FetchRow()) {
         $type = static::getByID($row['gatTypeID']);
         if (is_object($type)) {
             $list[] = $type;
         }
     }
     $r->Close();
     CacheLocal::set('gaItemTemplateTypeList', false, $list);
     return $list;
 }
Example #8
0
 static final function getByID($peID)
 {
     $obj = CacheLocal::getEntry('permission_access_entity', $peID);
     if ($obj instanceof PermissionAccessEntity) {
         return $obj;
     }
     $db = Loader::db();
     $r = $db->GetRow('select petID, peID from PermissionAccessEntities where peID = ?', array($peID));
     if (is_array($r)) {
         $pt = PermissionAccessEntityType::getByID($r['petID']);
         if (!is_object($pt)) {
             return false;
         }
         $class = Loader::helper('text')->camelcase($pt->getAccessEntityTypeHandle());
         $class .= 'PermissionAccessEntity';
         $obj = new $class();
         $r['petHandle'] = $pt->getAccessEntityTypeHandle();
         $obj->setPropertiesFromArray($r);
         $obj->load();
     }
     CacheLocal::set('permission_access_entity', $peID, $obj);
     return $obj;
 }
Example #9
0
 /**
  * Get a collection type by its ID.
  *
  * @param $ctID
  * @return bool|CollectionType
  * @todo refactor to return null on not found.
  */
 public static function getByID($ctID)
 {
     $ctID = intval($ctID);
     $ct = CacheLocal::getEntry('collection_type_by_id', $ctID);
     if (is_object($ct)) {
         return $ct;
     } else {
         if ($ct === -1) {
             return false;
         }
     }
     $db = Loader::db();
     $q = "SELECT PageTypes.ctID, ComposerTypes.ctID as ctIDc, ctHandle, ctIsInternal, ctName, ctIcon, pkgID, ctComposerPublishPageMethod, ctComposerPublishPageTypeID, ctComposerPublishPageParentID from PageTypes left join ComposerTypes on PageTypes.ctID = ComposerTypes.ctID where PageTypes.ctID = ?";
     $r = $db->query($q, array($ctID));
     if ($r) {
         $row = $r->fetchRow();
         $r->free();
         if (is_array($row)) {
             $ct = new CollectionType();
             $ct->setPropertiesFromArray($row);
             if ($row['ctIDc']) {
                 $ct->ctIncludeInComposer = true;
             }
         }
     }
     CacheLocal::set('collection_type_by_id', $ctID, $ct);
     return $ct;
 }
Example #10
0
	public function getAccessListItems($accessType = PermissionKey::ACCESS_TYPE_INCLUDE, $filterEntities = array()) {
		if (count($this->paIDList) > 0) {
			$q = 'select paID, peID, pdID, accessType from PermissionAccessList where paID in (' . implode(',', $this->paIDList) . ')';
			return $this->deliverAccessListItems($q, $accessType, $filterEntities);
		} else {
			$filter = $accessType . ':';
			foreach($filterEntities as $pae) {
				$filter .= $pae->getAccessEntityID() . ':';
			}
			$filter = trim($filter, ':');
			$items = CacheLocal::getEntry('permission_access_list_items', $this->getPermissionAccessID() . $filter . strtolower(get_class($this->pk)));
			if (is_array($items)) {
				return $items;
			}				
			$q = 'select paID, peID, pdID, accessType from PermissionAccessList where paID = ' . $this->getPermissionAccessID();
			$items = $this->deliverAccessListItems($q, $accessType, $filterEntities);
			CacheLocal::set('permission_access_list_items', $this->getPermissionAccessID() . $filter . strtolower(get_class($this->pk)), $items);
			return $items;
		}
	}
Example #11
0
 /** 
  * Completely flushes the cache
  */
 public function flush()
 {
     $db = Loader::db();
     $r = $db->MetaTables();
     // flush the CSS cache
     if (is_dir(DIR_FILES_CACHE . '/' . DIRNAME_CSS)) {
         $fh = Loader::helper("file");
         $fh->removeAll(DIR_FILES_CACHE . '/' . DIRNAME_CSS);
     }
     $pageCache = PageCache::getLibrary();
     if (is_object($pageCache)) {
         $pageCache->flush();
     }
     if (in_array('Config', $r)) {
         // clear the environment overrides cache
         $env = Environment::get();
         $env->clearOverrideCache();
         if (in_array('btCachedBlockRecord', $db->MetaColumnNames('Blocks'))) {
             $db->Execute('update Blocks set btCachedBlockRecord = null');
         }
         if (in_array('CollectionVersionBlocksOutputCache', $r)) {
             $db->Execute('truncate table CollectionVersionBlocksOutputCache');
         }
     }
     $loc = CacheLocal::get();
     $loc->cache = array();
     $cache = Cache::getLibrary();
     if ($cache) {
         $cache->setOption('caching', true);
         $cache->clean(Zend_Cache::CLEANING_MODE_ALL);
     }
     if (function_exists('apc_clear_cache')) {
         apc_clear_cache();
     }
     Events::fire('on_cache_flush', $cache);
     return true;
 }
Example #12
0
	/**
	 * returns the FileVersion object for the provided fvID
	 * if none provided returns the approved version
	 * @param int $fvID
	 * @return FileVersion
	 */
	public function getVersion($fvID = null) {

		if ($fvID == null) {
			$fvID = $this->fvID; // approved version
		}
		$fv = CacheLocal::getEntry('file', $this->getFileID() . ':' . $fvID);
		if ($fv === -1) {
			return false;
		}
		if ($fv) {
			return $fv;
		}

		$db = Loader::db();
		$row = $db->GetRow("select * from FileVersions where fvID = ? and fID = ?", array($fvID, $this->fID));
		$row['fvAuthorName'] = $db->GetOne("select uName from Users where uID = ?", array($row['fvAuthorUID']));
		
		$fv = new FileVersion();
		$row['fslID'] = $this->fslID;
		$fv->setPropertiesFromArray($row);
		
		CacheLocal::set('file', $this->getFileID() . ':' . $fvID, $fv);
		return $fv;
	}
Example #13
0
 public function add($type, $args, $pkg = false)
 {
     CacheLocal::delete('user_attribute_key_by_handle', $args['akHandle']);
     $ak = parent::add('user', $type, $args, $pkg);
     extract($args);
     if ($uakProfileDisplay != 1) {
         $uakProfileDisplay = 0;
     }
     if ($uakMemberListDisplay != 1) {
         $uakMemberListDisplay = 0;
     }
     if ($uakProfileEdit != 1) {
         $uakProfileEdit = 0;
     }
     if ($uakProfileEditRequired != 1) {
         $uakProfileEditRequired = 0;
     }
     if ($uakRegisterEdit != 1) {
         $uakRegisterEdit = 0;
     }
     if ($uakRegisterEditRequired != 1) {
         $uakRegisterEditRequired = 0;
     }
     if (isset($uakIsActive) && !$uakIsActive) {
         $uakIsActive = 0;
     } else {
         $uakIsActive = 1;
     }
     $db = Loader::db();
     $displayOrder = $db->GetOne('select max(displayOrder) from UserAttributeKeys');
     if (!$displayOrder) {
         $displayOrder = 0;
     }
     $displayOrder++;
     $v = array($ak->getAttributeKeyID(), $uakProfileDisplay, $uakMemberListDisplay, $uakProfileEdit, $uakProfileEditRequired, $uakRegisterEdit, $uakRegisterEditRequired, $displayOrder, $uakIsActive);
     $db->Execute('insert into UserAttributeKeys (akID, uakProfileDisplay, uakMemberListDisplay, uakProfileEdit, uakProfileEditRequired, uakRegisterEdit, uakRegisterEditRequired, displayOrder, uakIsActive) values (?, ?, ?, ?, ?, ?, ?, ?, ?)', $v);
     $nak = new UserAttributeKey();
     $nak->load($ak->getAttributeKeyID());
     return $nak;
 }
 public function tearDown()
 {
     if (count($this->tables)) {
         if (in_array('BlockTypes', $this->tables)) {
             $this->tables[] = 'btCoreScrapbookDisplay';
         }
         foreach ($this->tables as $table) {
             // drop table
             $conn = $this->getConnection();
             $pdo = $conn->getConnection();
             $pdo->exec("DROP TABLE IF EXISTS `{$table}`;");
         }
     }
     $allTables = $this->getDataSet($this->fixtures)->getTableNames();
     foreach ($allTables as $table) {
         // drop table
         $conn = $this->getConnection();
         $pdo = $conn->getConnection();
         $pdo->exec("DROP TABLE IF EXISTS `{$table}`;");
     }
     $db = Loader::db();
     $db->getEntityManager()->clear();
     \CacheLocal::flush();
     parent::tearDown();
 }
Example #15
0
	/** 
	 * Gets the array of items that have been set using set()
	 * @return array
	 */
	public function getSets() { 
		$loc = CacheLocal::get();
		if (isset($loc->cache['controllerSets'])) {
			return $loc->cache['controllerSets'];
		}
		return array();
	}
Example #16
0
		/**
		 * List the block IDs in a collection or area within a collection
		 * @param string $arHandle. If specified, returns just the blocks in an area
		 * @return array
		 */
		public function getBlockIDs($arHandle = false) {
			$blockIDs = CacheLocal::getEntry('collection_block_ids', $this->getCollectionID() . ':' . $this->getVersionID());
			$blocks = array();
		
			if (!is_array($blockIDs)) {
				$v = array($this->getCollectionID(), $this->getVersionID());
				$db = Loader::db();
				$q = "select Blocks.bID, CollectionVersionBlocks.arHandle from CollectionVersionBlocks inner join Blocks on (CollectionVersionBlocks.bID = Blocks.bID) inner join BlockTypes on (Blocks.btID = BlockTypes.btID) where CollectionVersionBlocks.cID = ? and (CollectionVersionBlocks.cvID = ? or CollectionVersionBlocks.cbIncludeAll=1) order by CollectionVersionBlocks.cbDisplayOrder asc";
				$r = $db->GetAll($q, $v);
				$blockIDs = array();
				if (is_array($r)) {
					foreach($r as $bl) {
						$blockIDs[strtolower($bl['arHandle'])][] = $bl;
					}
				}
				CacheLocal::set('collection_block_ids', $this->getCollectionID() . ':'. $this->getVersionID(), $blockIDs);
			}
			

			if ($arHandle != false) {
				$blockIDsTmp = $blockIDs[strtolower($arHandle)];
				$blockIDs = $blockIDsTmp;
			} else {
				$blockIDsTmp = $blockIDs;
				$blockIDs = array();
				foreach($blockIDsTmp as $arHandle => $row) {
					foreach($row as $brow) {
						if (!in_array($brow, $blockIDs)) {
							$blockIDs[] = $brow;
						}
					}
				}
			}
			return $blockIDs;
		}
Example #17
0
 public function add($at, $args, $pkg = false)
 {
     CacheLocal::delete('file_attribute_key_by_handle', $args['akHandle']);
     $ak = parent::add('file', $at, $args, $pkg);
     return $ak;
 }
Example #18
0
	/**
	 * Gets the Area object for the given page and area handle
	 * @param Page|Collection $c
	 * @param string $arHandle
	 * @param int|null $arIsGlobal
	 * @return Area
	 */
	public static function get(&$c, $arHandle, $arIsGlobal = null) {
		if (!is_object($c)) {
			return false;
		}
		
		// Right now we are splitting the cache to deal with times when Areas
		// get converted to GlobalAreas and back the other way
		$globalCache = $arIsGlobal ? ':1' : '';
		$a = CacheLocal::getEntry('area', $c->getCollectionID() . ':' . $arHandle . $globalCache);
		if ($a instanceof Area) {
			return $a;
		}
		$db = Loader::db();
		// First, we verify that this is a legitimate area
		$v = array($c->getCollectionID(), $arHandle);
		$q = "select arID, arOverrideCollectionPermissions, arInheritPermissionsFromAreaOnCID, arIsGlobal from Areas where cID = ? and arHandle = ?";
		$arRow = $db->getRow($q, $v);
		if ($arRow['arID'] > 0) {
			$area = new Area($arHandle);

			$area->arID = $arRow['arID'];
			$area->arOverrideCollectionPermissions = $arRow['arOverrideCollectionPermissions'];
			$area->arIsGlobal = $arRow['arIsGlobal'];
			$area->arInheritPermissionsFromAreaOnCID = $arRow['arInheritPermissionsFromAreaOnCID'];
			$area->cID = $c->getCollectionID();
			$area->c = &$c;
			
			CacheLocal::set('area', $c->getCollectionID() . ':' . $arHandle . $globalCache, $area);
			
			return $area;
		}
	}
Example #19
0
 public static function getByHandle($pkHandle)
 {
     $keys = CacheLocal::getEntry('permission_keys', false);
     if (!is_array($keys)) {
         $keys = self::loadAll();
     }
     return $keys[$pkHandle];
 }
Example #20
0
 public static function getAccessObject($pk, $object)
 {
     if (!PermissionCache::$enabled) {
         return false;
     }
     $cl = CacheLocal::get();
     if ($cl->enabled) {
         $identifier = 'pka:' . $pk->getPermissionKeyHandle() . ':' . $object->getPermissionObjectIdentifier();
         if (array_key_exists($identifier, $cl->cache)) {
             return $cl->cache[$identifier];
         }
     }
     return false;
 }
Example #21
0
		/**
		 * Gets the BlockType for a given Block Type ID
		 * @param int $btID
		 * @return BlockType
		 */
		public static function getByID($btID) {
			$bt = CacheLocal::getEntry('blocktype', $btID);
			if ($bt === -1) {
				return false;
			} else if (!is_object($bt)) {
				$where = 'btID = ?';
				$bt = BlockType::get($where, array($btID));			
				if (is_object($bt)) {
					CacheLocal::set('blocktype', $btID, $bt);
				} else {
					CacheLocal::set('blocktype', $btID, -1);
				}
			}
			$bt->controller = Loader::controller($bt);
			return $bt;
		}
Example #22
0
 /**
  * Gets or creates if necessary an Area for the given Page, Handle 
  * @param Page|Collection $c
  * @param string $arHandle
  * @param boolean $arIsGlobal
  * @return Area
  */
 public static function getOrCreate(&$c, $arHandle, $arIsGlobal = 0)
 {
     /*
     	different than get(), getOrCreate() is called by the templates. If no area record exists for the
     	permissions cID / handle combination, we create one. This is to make our lives easier
     */
     $area = self::get($c, $arHandle, $arIsGlobal);
     if (is_object($area)) {
         if ($area->isGlobalArea() == $arIsGlobal) {
             return $area;
         } else {
             if (!$area->isGlobalArea() && !$arIsGlobal) {
                 return $area;
             }
         }
     }
     $cID = $c->getCollectionID();
     $db = Loader::db();
     if (!$arIsGlobal) {
         $arIsGlobal = 0;
     }
     $db->Replace('Areas', array('cID' => $cID, 'arHandle' => $arHandle, 'arIsGlobal' => $arIsGlobal), array('arHandle', 'cID'), true);
     if ($arIsGlobal) {
         // we create a stack for it
         Stack::getOrCreateGlobalArea($arHandle);
     }
     $area = self::get($c, $arHandle);
     // we're assuming the insert succeeded
     $area->rescanAreaPermissionsChain();
     // we need to update the local cache
     $globalCache = $arIsGlobal ? ':1' : '';
     CacheLocal::set('area', $c->getCollectionID() . ':' . $arHandle . $globalCache, $area);
     return $area;
 }
Example #23
0
 public function getBlockCustomStyleRuleID()
 {
     $db = Loader::db();
     if (!isset($this->csrID)) {
         $co = $this->getBlockCollectionObject();
         $csrCheck = CacheLocal::getEntry('csrCheck', $co->getCollectionID() . ':' . $co->getVersionID());
         $csrObject = CacheLocal::getEntry('csrObject', $co->getCollectionID() . ':' . $co->getVersionID() . ':' . $this->getAreaHandle() . ':' . $this->getBlockID());
         if (is_object($csrObject)) {
             $this->csrID = $csrObject->getCustomStyleRuleID();
             return $csrObject->getCustomStyleRuleID();
         } else {
             if ($csrCheck) {
                 return false;
             }
         }
         $arHandle = $this->getAreaHandle();
         if ($arHandle) {
             $a = $this->getBlockAreaObject();
             if ($a->isGlobalArea()) {
                 // then we need to check against the global area name. We currently have the wrong area handle passed in
                 $arHandle = STACKS_AREA_NAME;
             }
             $v = array($co->getCollectionID(), $co->getVersionID(), $arHandle, $this->bID);
             $this->csrID = $db->GetOne('select csrID from CollectionVersionBlockStyles where cID = ? and cvID = ? and arHandle = ? and bID = ?', $v);
         } else {
             $this->csrID = 0;
         }
     }
     return $this->csrID;
 }
Example #24
0
	/** 
	 * Completely flushes the cache
	 */	
	public function flush() {
		$cache = Cache::getLibrary();
		
		$loc = CacheLocal::get();
		$loc->cache = array();
		if (!$cache) {
			return false;
		}
		$cache->setOption('caching', true);
		$cache->clean(Zend_Cache::CLEANING_MODE_ALL);
		if (!ENABLE_CACHE) {
			Cache::disableCache();
		}		
		return true;
	}
Example #25
0
	/** 
	 * Removes an item from the cache
	 */	
	public function delete($type, $id){
		$cache = Cache::getLibrary();
		if ($cache) {
			$cache->remove(Cache::key($type, $id));
		}

		$loc = CacheLocal::get();
		if ($loc->enabled && isset($loc->cache[Cache::key($type, $id)])) {
			unset($loc->cache[Cache::key($type, $id)]);
		}
	}
Example #26
0
	public function add($at, $args, $pkg = false) {

		// legacy check
		$fargs = func_get_args();
		if (count($fargs) >= 5) {
			$at = $fargs[4];
			$pkg = false;
			$args = array('akHandle' => $fargs[0], 'akName' => $fargs[1], 'akIsSearchable' => $fargs[2]);
		}

		CacheLocal::delete('collection_attribute_key_by_handle', $args['akHandle']);

		$ak = parent::add('collection', $at, $args, $pkg);
		return $ak;
	}
Example #27
0
 public static function getByID($gID)
 {
     $db = Loader::db();
     $g = CacheLocal::getEntry('group', $gID);
     if (is_object($g)) {
         return $g;
     }
     $row = $db->getRow("select * from Groups where gID = ?", array($gID));
     if (isset($row['gID'])) {
         $g = new Group();
         $g->setPropertiesFromArray($row);
         CacheLocal::set('group', $gID, $g);
         return $g;
     }
 }