/** * Returns file last commit infos * * @param string $fileName * @param bool $useCache * @return mixed * @throws gitHubException */ public function getFileLastCommit($fileName, $useCache = TRUE) { if (!$useCache) { $this->cache->remove($fileName); } return $this->cache->load($fileName, function () use($fileName) { $path = $this->subdir ? $this->subdir . '/' : ''; $url = self::GITHUB_URL . '/' . $this->user . '/' . $this->repo . '/commits?path=' . $path . $fileName; $tree = $this->run($url); return count($tree) === 0 ? NULL : $tree[0]; }); }
/** * @param User $user * @throws ForeignKeyConstraintViolationException */ public function remove(User $user) { try { $this->cache->remove($user); // will be recreated if an error occur $userID = $user->getId(); $this->em->remove($user); $this->em->flush(); $this->onSuccessUserRemoval($user, $userID); } catch (ForeignKeyConstraintViolationException $e) { // todo log throw $e; } }
/** * @param array $values * @param User|null $user * @return ValidationObject */ public function update(array $values, User $user) { $this->em->beginTransaction(); $user->setFirstName($values['first_name']); $user->setLastName($values['last_name']); $validationObject = new ValidationObject(); // todo could be optimized $user->clearRoles(); $role = $this->getRole($values['role'], $validationObject); if (!$validationObject->isValid()) { $this->em->rollback(); return $validationObject; } $user->addRole($role); $this->em->persist($user); $this->em->flush(); if ($validationObject->isValid()) { $this->em->commit(); $this->onSuccessUserEditing($user); $this->cache->remove($user->getCacheKey()); } else { $this->em->rollback(); } return $validationObject; }
/** * Process all messages. */ private function processMessage() { if ($this->processed) { return; } $this->processed = TRUE; $files = glob($this->fileMailer->getTempDirectory() . DIRECTORY_SEPARATOR . '*.' . FileMailer::FILE_EXTENSION); foreach ($files as $path) { $cacheKey = basename($path); if ($this->removeExpired($path)) { $this->cache->remove($cacheKey); continue; } $message = $this->cache->load($cacheKey); if ($message === NULL) { $message = FileMailer::mailParser(file_get_contents($path), $cacheKey); $this->cache->save($cacheKey, $message); } $time = new DateTime(); if ($message->date > $time->modify($this->newMessageTime)) { $this->countNew++; } else { $message->isOld = TRUE; } $this->countAll++; $this->messages[] = $message; } usort($this->messages, function ($a1, $a2) { return $a2->date->getTimestamp() - $a1->date->getTimestamp(); }); }
/** * @return void */ public function cleanParametersCache() { $this->parameters = NULL; if ($this->cache) { $this->cache->remove(self::PARAMETER_KEY); } }
public function save(array $values) { $options = $this->prepareOptions($this->findOptions()); foreach ((array) $values as $key => $value) { $options[$key]->setValue($value == '' ? null : $value); $this->em->persist($options[$key]); } try { $this->em->flush(); $this->cache->remove(Option::getCacheKey()); $this->onSuccessOptionsSaving(); } catch (\Exception $e) { $this->em->rollback(); $this->em->close(); $this->logger->addError(sprintf('Save Options error: %s | error message: %s', date('Y-m-d H:i:s'), $e->getMessage())); throw $e; } }
private function getDomains() : array { $this->repository->onAfterInsert[] = function () { $this->cache->remove(NULL); }; return $this->cache->load(NULL, function (&$dependencies) { $dependencies[Nette\Caching\Cache::TAGS] = []; return array_map(function (Ytnuk\Web\Domain\Entity $entity) use($dependencies) { $dependencies[Nette\Caching\Cache::TAGS] = array_merge($dependencies[Nette\Caching\Cache::TAGS], $entity->getCacheTags()); return $entity->id; }, iterator_to_array($this->repository->findAll())); }); }
/** * Invalidates according graph Uri entries, the result and all triple pattern. * * @param Query $queryObject All data according to this query will be invalidated. */ public function invalidateByQuery(Query $queryObject) { // log it $this->addToLog(array('method' => 'invalidateByQuery', 'parameter' => array('queryObject' => $queryObject))); $query = $queryObject->getQuery(); // load query cache container by given query $queryCacheContainer = $this->cache->load($query); /** * remove according query from the query list which belongs to one of the graph URI's in the query * cache container. */ if (true === is_array($queryCacheContainer['graph_uris'])) { foreach ($queryCacheContainer['graph_uris'] as $graphUri) { $queryList = $this->cache->load($graphUri); unset($queryList[$query]); // if graphUri entry is empty after the operation, remove it from the cache if (0 == count($queryList)) { $this->cache->remove($graphUri); // otherwise save updated entry } else { $this->cache->save($graphUri, $queryList); } } } // check for according triple pattern if (true === is_array($queryCacheContainer['triple_pattern'])) { foreach ($queryCacheContainer['triple_pattern'] as $patternKey) { $queryList = $this->cache->load($patternKey); unset($queryList[$query]); // if patternKey entry is empty after the operation, remove it from the cache if (0 == count($queryList)) { $this->cache->remove($patternKey); // otherwise save updated entry } else { $this->cache->save($patternKey, $queryList); } } } /** * Remove query cache container */ $this->cache->remove($query); }
/** * @param string $message * @param string $event * @param int|null $userID * @throws \Exception */ public function saveLog($message, $event, $userID = null) { $eventLog = $this->getEventLog($event); if ($eventLog === null) { return; // todo monolog log } if (!$this->isEventLoggable($eventLog)) { return; } try { $user = null; if (isset($userID)) { $user = $this->em->getReference(User::class, $userID); } $newLog = new Log($message, $this->em->getReference(EventLog::class, $eventLog->getId()), $this->request->getRemoteAddress(), $user); $this->em->persist($newLog)->flush(); } catch (ForeignKeyConstraintViolationException $e) { // todo if user doesn't exist $this->cache->remove(self::getEventLogCacheKey($event)); } }
/** * @param Role $role * @param array $permissionDefinitions * @throws DBALException * @throws \Exception */ public function save(Role $role, array $permissionDefinitions) { $resources = $this->em->createQuery('SELECT r FROM ' . Resource::class . ' r INDEX BY r.id')->execute(); $privileges = $this->em->createQuery('SELECT p FROM ' . Privilege::class . ' p INDEX BY p.id')->execute(); try { $this->em->beginTransaction(); $this->em->createQuery('DELETE ' . Permission::class . ' p WHERE p.role = :role')->execute(['role' => $role->getId()]); $parentRole = null; if ($role->hasParent()) { /** @var Role $parentRole */ $parentRole = $this->em->find(Role::class, $role->getParentId()); } foreach ($permissionDefinitions as $definition => $isAllowed) { $isAllowed = (bool) $isAllowed; $x = explode('-', $definition); // eg. 1-3 /** @var \Users\Authorization\Resource $resource */ $resource = $resources[$x[0]]; /** @var Privilege $privilege */ $privilege = $privileges[$x[1]]; // check Users\Authorization\Authorizator ACL assembling // Role without parent // privilege: allowed -> must be in database // privilege: denied -> does NOT have to be in database // Role with parent (all depths) /* ------------------------------------------------------------ parent | descendant | should be persisted? ------------------------------------------------------------ allowed allowed NO allowed denied YES denied denied NO denied allowed YES ------------------------------------------------------------ We save records where permission and denial differ */ if ($parentRole !== null) { // has parent if ($this->authorizator->isAllowed($parentRole, $resource->getName(), $privilege->getName()) === $isAllowed) { continue; } } else { // doesn't have parent if ($isAllowed === false) { continue; } } $permission = new Permission($role, $resource, $privilege, $isAllowed); $this->em->persist($permission); } $this->em->flush(); $this->em->commit(); $this->cache->remove('acl'); $this->onSuccessRolePermissionsEditing($role); } catch (\Exception $e) { $this->em->rollback(); $this->em->close(); // todo log error throw new $e(); } }
/** * @param string $namespace * @param string $name */ public function clearImageVersion($namespace, $name) { $this->cache->remove('version/' . $namespace . '/' . $name); }
/** * Clears strings cache * @return HQ\DbTranslator */ public function clearStringsCache() { $cacheName = $this->getStringsCacheName(); $this->cache->remove($cacheName); return $this; }
/** * @param int $section */ public function deleteSection($section) { $this->cache->remove($section); }
private function cleanTargetCache(Brabijan\SeoComponents\Router\Target $target) { $this->cache->remove(serialize($target)); }
/** * Vrátí nacachované hodnoty z controlleru. * @return mixed|NULL */ public function getValue() { $files = $this->cache->load($this->getTokenizedCacheName($this->token)); $this->cache->remove($this->getTokenizedCacheName($this->token)); return $files; }
/** * Smaže událost * * @param Event $event */ function deleteEvent($event) { $this->cache->remove('Event.' . $event->id); $this->eventDao->delete($event); }
public function rebuild() { $this->cache->remove('hash'); $this->cache->remove('files'); $this->build(); }