Exemplo n.º 1
0
 /**
  * @param \Generated\Shared\Transfer\CmsBlockTransfer $cmsBlockTransfer
  *
  * @return array
  */
 public function getBlockByName(CmsBlockTransfer $cmsBlockTransfer)
 {
     $blockName = $cmsBlockTransfer->getName() . '-' . $cmsBlockTransfer->getType() . '-' . $cmsBlockTransfer->getValue();
     $key = $this->keyBuilder->generateKey($blockName, $cmsBlockTransfer->getLocale()->getLocaleName());
     $block = $this->storage->get($key);
     return $block;
 }
Exemplo n.º 2
0
 /**
  * @param string $locale
  *
  * @return array
  */
 public function getCategories($locale)
 {
     $urlKey = $this->urlBuilder->generateKey([], $locale);
     $categories = $this->keyValueReader->get($urlKey);
     if ($categories) {
         return $categories;
     }
     return [];
 }
 /**
  * @param array $blockIds
  * @param string $locale
  *
  * @return array
  */
 public function fetchBlocksByIds(array $blockIds, $locale)
 {
     $blockKeys = [];
     foreach ($blockIds as $blockId) {
         $blockKeys[] = $this->keyBuilder->generateKey($blockId, $locale);
     }
     $blocks = $this->storageReader->getMulti($blockKeys);
     $decodedBlocks = [];
     foreach ($blocks as $key => $block) {
         $decodedBlocks[$key] = $this->decodeBlock($block);
     }
     return $decodedBlocks;
 }
Exemplo n.º 4
0
 /**
  * @param string $url
  * @param string $localeName
  *
  * @return array|bool
  */
 public function matchUrl($url, $localeName)
 {
     $url = rawurldecode($url);
     $urlKey = $this->urlKeyBuilder->generateKey($url, $localeName);
     $urlDetails = $this->keyValueReader->get($urlKey);
     if ($urlDetails) {
         $data = $this->keyValueReader->get($urlDetails['reference_key']);
         if ($data) {
             return ['type' => $urlDetails['type'], 'data' => $data];
         }
     }
     return false;
 }
Exemplo n.º 5
0
 /**
  * @param array $ids
  * @param string|null $indexByKey
  *
  * @return array
  */
 public function getProductDataByIds(array $ids, $indexByKey = null)
 {
     $idKeys = [];
     foreach ($ids as $id) {
         $idKeys[] = $this->productKeyBuilder->generateKey($id, $this->locale);
     }
     $productsFromStorage = $this->storageReader->getMulti($idKeys);
     if ($productsFromStorage === null) {
         return [];
     }
     foreach ($productsFromStorage as $key => $product) {
         $productsFromStorage[$key] = $this->mergeAttributes(json_decode($product, true));
     }
     if ($indexByKey) {
         return $this->mapKeysToValue($indexByKey, $productsFromStorage);
     }
     return $productsFromStorage;
 }
 /**
  * @param array $categoryNode
  * @param string $locale
  *
  * @return array
  */
 public function createTreeFromCategoryNode(array $categoryNode, $locale)
 {
     $parents = array_slice(array_reverse($categoryNode[CategoryNodeKeyInterface::PARENTS]), 0, self::SUBTREE_DEPTH);
     $subtree = [];
     foreach ($parents as $parent) {
         $storageKey = $this->keyBuilder->generateKey($parent[CategoryNodeKeyInterface::NODE_ID], $locale);
         $parentCategory = $this->kvReader->get($storageKey);
         if (empty($subtree)) {
             $subtree = $parentCategory;
         }
         if ($parentCategory) {
             $parentCategory = $this->addCurrentSubtree($parentCategory, $subtree);
             $subtree = $parentCategory;
         }
     }
     if (empty($categoryNode[CategoryNodeKeyInterface::PARENTS]) || empty($subtree)) {
         $subtree = $categoryNode;
     }
     $subtree[self::SUBTREE_DEPTH_KEY] = self::SUBTREE_DEPTH;
     return $subtree;
 }
Exemplo n.º 7
0
 /**
  * @param \Spryker\Zed\Gui\Communication\Table\TableConfiguration $config
  *
  * @return array
  */
 protected function prepareData(TableConfiguration $config)
 {
     $keys = $this->storageClient->getAllKeys();
     sort($keys);
     $result = [];
     foreach ($keys as $i => $key) {
         $keys[$i] = str_replace('kv:', '', $key);
     }
     $values = $this->storageClient->getMulti($keys);
     $fixedValues = [];
     foreach ($values as $i => $value) {
         $i = str_replace('kv:', '', $i);
         $fixedValues[$i] = $value;
     }
     $values = $fixedValues;
     foreach ($values as $key => $value) {
         $url = Url::generate('/storage/maintenance/key', ['key' => $key]);
         $result[] = ['key' => '<a href="' . $url . '">' . Html::escape($key) . '</a>', 'value' => substr($value, 0, 200)];
     }
     $this->setTotal(count($result));
     return $result;
 }
Exemplo n.º 8
0
 /**
  * @api
  *
  * @deprecated Use persistRequestCache() instead.
  *
  * @param \Symfony\Component\HttpFoundation\Request|null $request
  *
  * @return void
  */
 public static function persistCache(Request $request = null)
 {
     $cacheKey = static::generateCacheKey($request);
     if (!empty($cacheKey) && is_array(self::$cachedKeys)) {
         $updateCache = false;
         foreach (self::$cachedKeys as $key => $status) {
             if ($status === self::KEY_INIT) {
                 unset(self::$cachedKeys[$key]);
             }
             if ($status !== self::KEY_USED) {
                 $updateCache = true;
                 break;
             }
         }
         if ($updateCache) {
             $ttl = 86400;
             // TTL = 1 day to avoid artifacts in Storage
             self::$service->set($cacheKey, json_encode(array_keys(self::$cachedKeys)), $ttl);
         }
     }
 }
Exemplo n.º 9
0
 /**
  * @param string $keyName
  *
  * @return void
  */
 protected function loadTranslation($keyName)
 {
     $key = $this->keyBuilder->generateKey($keyName, $this->localeName);
     $this->addTranslation($keyName, $this->storage->get($key));
 }
Exemplo n.º 10
0
 /**
  * @param int $idProductAbstract
  *
  * @return mixed
  */
 public function getProductAbstractFromStorageById($idProductAbstract)
 {
     $key = $this->keyBuilder->generateKey($idProductAbstract, $this->locale);
     $product = $this->storage->get($key);
     return $product;
 }
Exemplo n.º 11
0
 /**
  * @param \Generated\Shared\Transfer\SearchConfigCacheTransfer $searchConfigCacheTransfer
  *
  * @return void
  */
 public function save(SearchConfigCacheTransfer $searchConfigCacheTransfer)
 {
     $searchConfigCacheKey = $this->getSearchConfigCacheKey();
     $this->storageClient->set($searchConfigCacheKey, $searchConfigCacheTransfer->toArray());
 }