コード例 #1
0
ファイル: CronWorker.php プロジェクト: abhijitroy07/mibew
 /**
  * Performs all periodical actions.
  *
  * @return boolean True if all periodical actions are done and false
  * otherwise.
  */
 public function run()
 {
     try {
         set_time_limit(0);
         // Update time of last cron run
         Settings::set('_last_cron_run', time());
         // Remove stale cached items
         $this->cache->purge();
         // Run cron jobs of the core
         calculate_thread_statistics();
         calculate_operator_statistics();
         calculate_page_statistics();
         // Trigger cron event
         $dispatcher = EventDispatcher::getInstance();
         $dispatcher->triggerEvent(Events::CRON_RUN);
         if (Settings::get('autocheckupdates') == '1') {
             // Run the update checker
             $update_checker = $this->getUpdateChecker();
             if (!$update_checker->run()) {
                 $this->errors = array_merge($this->errors, $update_checker->getErrors());
                 return false;
             }
         }
     } catch (\Exception $e) {
         $this->log[] = $e->getMessage();
         return false;
     }
     return true;
 }
コード例 #2
0
ファイル: CacheSpec.php プロジェクト: toin0u/concise
 function it_expands_a_url(Provider $provider, PoolInterface $pool, ItemInterface $item)
 {
     $item->isMiss()->willReturn(true);
     $item->set('http://any.url')->shouldBeCalled();
     $pool->getItem(md5('http://short.ly/1234'))->willReturn($item);
     $provider->expand('http://short.ly/1234')->willReturn('http://any.url');
     $this->expand('http://short.ly/1234')->shouldReturn('http://any.url');
 }
コード例 #3
0
 /**
  * Prepend keys with prefix.
  *
  * {@see \Psr\Cache\CacheItemPoolInterface}
  *
  * @param array $keys
  * @return \Stash\Interfaces\ItemInterface[]
  */
 public function getItems(array $keys = array())
 {
     $prefix = self::SPI_CACHE_KEY_PREFIX;
     $keys = array_map(function ($key) use($prefix) {
         $key = $this->washKey($key);
         return $key === '' ? $prefix : $prefix . '/' . $key;
     }, $keys);
     return $this->cachePool->getItems($keys);
 }
コード例 #4
0
 /**
  * Returns the current cache pool.
  *
  * @return \Stash\Interfaces\PoolInterface
  */
 public function getCachePool()
 {
     if (!isset($this->cachePool)) {
         $this->cachePool = new Pool();
         if (isset($this->logger) && $this->logger instanceof LoggerInterface) {
             $this->cachePool->setLogger($this->logger);
         }
     }
     return $this->cachePool;
 }
コード例 #5
0
ファイル: Cache.php プロジェクト: toin0u/concise
 /**
  * Shorten or expand a URL checking it in the cache first
  *
  * @param string $url
  * @param string $transformation
  *
  * @return string
  */
 protected function transformUrl($url, $transformation)
 {
     $cachedUrl = $this->pool->getItem(md5($url));
     if ($cachedUrl->isMiss()) {
         $url = $this->provider->{$transformation}($url);
         $cachedUrl->set($url);
     } else {
         $url = $cachedUrl->get();
     }
     return $url;
 }
コード例 #6
0
 /**
  * Returns a Cache item for the specified key. The key can be either a series of string arguments,
  * or an array.
  *
  * @internal param array|string $key , $key, $key...
  *
  * @return \Stash\Interfaces\ItemInterface
  */
 public function getItem()
 {
     $args = func_get_args();
     // check to see if a single array was used instead of multiple arguments, & check empty in case of empty clear()
     if (empty($args)) {
         $args = array();
     } elseif (!isset($args[1]) && is_array($args[0])) {
         $args = $args[0];
     }
     array_unshift($args, self::SPI_CACHE_KEY_PREFIX);
     return $this->cachePool->getItem($args);
 }
コード例 #7
0
 /**
  * {@inheritdoc}
  */
 public function removeRolePermission(Role $role, Permission $permission)
 {
     $this->driver->removeRolePermission($role, $permission);
     // Invalidate cache
     $cacheId = sprintf('roles/%s', $role->getRoleName());
     $item = $this->pool->getItem($cacheId);
     $item->clear();
 }
コード例 #8
0
ファイル: CronWorker.php プロジェクト: am83087/MyTest
 /**
  * Performs all periodical actions.
  *
  * @return boolean True if all periodical actions are done and false
  * otherwise.
  */
 public function run()
 {
     try {
         set_time_limit(0);
         // Remove stale cached items
         $this->cache->purge();
         // Run cron jobs of the core
         calculate_thread_statistics();
         calculate_operator_statistics();
         calculate_page_statistics();
         // Trigger cron event
         $dispatcher = EventDispatcher::getInstance();
         $dispatcher->triggerEvent(Events::CRON_RUN);
         // Update time of last cron run
         Settings::set('_last_cron_run', time());
     } catch (\Exception $e) {
         $this->log[] = $e->getMessage();
         return false;
     }
     return true;
 }
コード例 #9
0
ファイル: Updater.php プロジェクト: abhijitroy07/mibew
 /**
  * Performs all actions that are needed to update database structure.
  *
  * @return boolean True if the system updated successfully and false
  *   otherwise.
  */
 public function run()
 {
     $current_version = $this->getDatabaseVersion();
     if (!preg_match("/^([0-9]{1,2}\\.){2}[0-9]{1,2}(-(alpha|beta|rc)\\.[0-9]+)?\$/", $current_version)) {
         $this->errors[] = getlocal('The current version ({0}) is unknown or wrong formated', array($current_version));
         return false;
     }
     if (version_compare($current_version, MIBEW_VERSION) == 0) {
         $this->log[] = getlocal('The database is already up to date');
         return true;
     }
     if (version_compare($current_version, self::MIN_VERSION) < 0) {
         $this->errors[] = getlocal('You can update the system only from {0} and later versions. The current version is {1}', array(self::MIN_VERSION, $current_version));
         return false;
     }
     try {
         // Perform incremental updates
         foreach (Utils::getUpdates($this) as $version => $method) {
             if (version_compare($version, $current_version) <= 0) {
                 // Skip updates to lower versions.
                 continue;
             }
             // Run the update
             if (!$method()) {
                 $this->errors[] = getlocal('Cannot update to {0}', array($version));
                 return false;
             }
             // Store new version number in the database. With this info
             // we can rerun the updating process if one of pending
             // updates fails.
             if (!$this->setDatabaseVersion($version)) {
                 return false;
             } else {
                 $this->log[] = getlocal('Updated to {0}', array($version));
             }
             $current_version = $version;
         }
     } catch (\Exception $e) {
         // Something went wrong
         $this->errors[] = getlocal('Update failed: {0}', array($e->getMessage()));
         return false;
     }
     // Use the version from the PHP's constant as the current database
     // version.
     if ($this->setDatabaseVersion(MIBEW_VERSION)) {
         return false;
     }
     // Clean up the cache
     $this->cache->flush();
     return true;
 }
コード例 #10
0
ファイル: PackageDownloader.php プロジェクト: brad-jones/ppm
 /**
  * Downloads the composer packages data from packagist.org
  *
  * @param  string $packageName The name of composer package.
  * @return array               The parsed json response.
  *
  * @see https://packagist.org/apidoc
  */
 private function downloadPackagistPackageData($packageName)
 {
     $url = $this->packagistBaseUrl . $packageName . '.json';
     $this->cache->setNamespace(sha1(__CLASS__));
     $item = $this->cache->getItem(sha1($url));
     $data = $item->get();
     if ($item->isMiss()) {
         $item->lock();
         $response = $this->http->request('GET', $url);
         $data = json_decode($response->getBody(), true)['package'];
         $this->cache->save($item->set($data));
     }
     return $data;
 }
コード例 #11
0
ファイル: ComposerFileReader.php プロジェクト: brad-jones/ppm
 /**
  * Given the path to a composer file we return it's json as an array.
  *
  * @param  string $file
  * @return array
  */
 private function readFile($file)
 {
     $this->cache->setNamespace(sha1(__CLASS__));
     $item = $this->cache->getItem(sha1($file));
     $data = $item->get();
     if ($item->isMiss()) {
         $item->lock();
         if ($this->filesystem->has($file)) {
             $data = json_decode($this->filesystem->read($file), true);
         } else {
             throw new ComposerFileNotFound($this->filesystem->getAdapter()->applyPathPrefix($file));
         }
         $this->cache->save($item->set($data));
     }
     return $data;
 }
コード例 #12
0
ファイル: AbstractClient.php プロジェクト: RobinRadic/bnet
 /**
  * @param string $url
  * @param array  $options
  *
  * @return array
  */
 protected function makeRequest($url, array $options = [])
 {
     if ($this->client === null) {
         $this->client = new GuzzleClient();
     }
     $item = $this->cache->getItem($this->getRequestKey($url, $options));
     $data = $item->get();
     if ($item->isMiss() === false) {
         $options = array_replace_recursive($options, ['headers' => ['If-Modified-Since' => $data['modified']]]);
     }
     $options = array_replace_recursive($options, ['headers' => ['Accept' => 'application/json', 'User-Agent' => $this->getUserAgent()], 'query' => ['apikey' => $this->apiKey, 'locale' => $this->region->getLocale()]]);
     try {
         $response = $this->client->get($url, $options);
     } catch (ClientException $exception) {
         if ($exception->getCode() === 404) {
             return null;
         }
         throw new BattleNetException($exception->getResponse()->json()['detail'], $exception->getCode());
     }
     return $this->handleSuccessfulResponse($response, $item, $data);
 }
コード例 #13
0
 /**
  * @param tubepress_api_url_UrlInterface $url
  *
  * @return \Stash\Interfaces\ItemInterface
  */
 private function _getItem(tubepress_api_url_UrlInterface $url)
 {
     $key = str_replace('/', '~', "{$url}");
     return $this->_apiCache->getItem($key);
 }
コード例 #14
0
 /**
  * @return ItemInterface
  */
 private function getCachedRates()
 {
     return $this->pool->getItem('ongr_currency');
 }
コード例 #15
0
ファイル: Access.php プロジェクト: ming-hai/XoopsCore
 /**
  * clear all keys and data from the cache.
  *
  * @return boolean True if the cache was successfully cleared, false otherwise
  */
 public function clear()
 {
     return $this->pool->flush();
 }
コード例 #16
0
ファイル: Item.php プロジェクト: yakamoz-fang/concrete
 /**
  * {@inheritdoc}
  */
 public function setPool(PoolInterface $pool)
 {
     $this->pool = $pool;
     $this->setDriver($pool->getDriver());
 }
コード例 #17
0
 /**
  * Returns settings cache item.
  *
  * @return ItemInterface
  */
 protected function getCache()
 {
     return $this->pool->getItem('ongr_settings.settings_cache', join($this->profiles, ','));
 }