Esempio n. 1
0
 /**
  * @param Entity $entity
  * @param array $uniqueKey One of the keys. It must contain only field names
  * @return string
  * @throws BaseException
  */
 public function getEntityCacheKeyByUniqueFields(Entity $entity, array $uniqueKey, $entityClass)
 {
     $uniqueVals = array();
     foreach ($uniqueKey as $uniqueKeyItem) {
         if (!is_array($uniqueKeyItem)) {
             $uniqueKeyItem = array($uniqueKeyItem);
         }
         foreach ($uniqueKeyItem as $item) {
             $val = $entity->getInfo($item);
             if (null !== $val) {
                 if (is_string($val)) {
                     $val = mb_strtolower($val);
                 }
                 $uniqueVals[] = $val;
             } else {
                 throw new BaseException('Unknown field - ' . $item);
             }
         }
     }
     return $this->getEntityCacheKeyByUniqueVals($uniqueVals, $entityClass);
 }
Esempio n. 2
0
 /**
  * Search in $newEntity new values of unique fields and update key if needed
  *
  * @param Entity $newEntity
  * @param entity $oldEntity
  * @return void
  */
 public function updateUniqueFields(Entity $newEntity, Entity $oldEntity)
 {
     $changedUniqueKeys = array();
     if ($this->hasUniqueFields()) {
         foreach ($this->uniqueFields as $uniqueKey) {
             foreach ($uniqueKey as $field) {
                 if ($oldEntity->getInfo($field) != $newEntity->getInfo($field)) {
                     $changedUniqueKeys[] = $uniqueKey;
                 }
             }
         }
         if (sizeof($changedUniqueKeys) != 0) {
             foreach ($changedUniqueKeys as $key) {
                 Manager::getInstance()->getCache()->delete($oldEntity->getCacheKeyByUniqueFields($key));
                 $this->createUniqueFieldsCache($newEntity, $key);
             }
         }
     }
 }