Operation postMediaCacheStoreConfig

Adds the specified MediaCache Store configuration.

@param string $serverName Reserved for future use (required)
@param MediaCacheStoreConfig $body  (required)

@return void
@throws ApiException on non-2xx response
436189
public function postMediaCacheStoreConfig($serverName, $body)
    {
        list($response) = $this->postMediaCacheStoreConfigWithHttpInfo($serverName, $body);
        return $response;
    }
753589
protected function addCacheDirectory(ContainerInterface $container, SerializerBuilder $builder): void
    {
        $config = $container->get('config');
        $libraryConfig = $config[ConfigKey::PROJECT][ConfigKey::API_CLIENT] ?? [];
        $cacheDir = (string) ($libraryConfig[ConfigKey::CACHE_DIR] ?? '');

        if ($cacheDir !== '') {
            $builder->setCacheDir($cacheDir);
        }
    }
11513
protected function setDefaultMetadataCache($cache, ServiceLocatorInterface $serviceLocator)
    {
        $metadataCache = null;

        if (is_string($cache)) {
            if ($serviceLocator->has($cache)) {
                $metadataCache = $serviceLocator->get($cache);
            }
        } else if ($cache instanceof Zend_Cache_Core) {
            $metadataCache = $cache;
        }

        if ($metadataCache instanceof Zend_Cache_Core) {
            Zend_Db_Table::setDefaultMetadataCache($metadataCache);
        }

    }
1314182
protected function addMediaToEntity($entityName, $id, $mediaId)
    {
        try {
            $em = $this->getDoctrine()->getManager();
            $entity = $em->getRepository($entityName)->find($id);
            $media = $this->container->get('sulu.repository.media')->find($mediaId);

            if (!$entity) {
                throw new EntityNotFoundException($entityName, $id);
            }

            if (!$media) {
                throw new EntityNotFoundException($this->getParameter('sulu.model.media.class'), $mediaId);
            }

            if ($entity->getMedias()->contains($media)) {
                throw new RestException('Relation already exists');
            }

            $entity->addMedia($media);
            $em->flush();

            $view = $this->view(
                new Media(
                    $media,
                    $this->getUser()->getLocale(),
                    null
                ),
                200
            );
        } catch (EntityNotFoundException $enfe) {
            $view = $this->view($enfe->toArray(), 404);
        } catch (RestException $exc) {
            $view = $this->view($exc->toArray(), 400);
        } catch (\Exception $e) {
            $view = $this->view($e->getMessage(), 400);
        }

        return $this->handleView($view);
    }
1229965
public function save(string $fileName = null)
    {
        if (is_null($fileName)) {
            $fileName = self::FILENAME_CONFIG_DEFAULT;
        }

        $saved = file_put_contents($fileName, $this->toJson());

        if ($saved === false) {
            throw new BunqException(self::ERROR_COULD_NOT_SAVE_THE_API_CONTEXT, [$fileName]);
        }
    }
598868
public function setAccessToken(?string $accessToken, string $tokenName = null)
    {
        $name = $this->config->getKey($tokenName);
        $cacheKey = $this->creteCacheKey($name);

        if (null === $accessToken) {
            $this->pool->deleteItem($cacheKey);

            return;
        }

        $item = $this->pool->getItem($cacheKey)->set(new AccessToken($name, $accessToken));
        $this->pool->save($item);
    }
228220
public function postPublishersConfig($serverName, $body)
    {
        list($response) = $this->postPublishersConfigWithHttpInfo($serverName, $body);
        return $response;
    }
1234003
private function createFileCache($subClassName, array $cacheConfig, ContainerBuilder $container)
    {
        $cacheDir = $this->getFileCacheDir($cacheConfig, $container);
        Utility::appendParameter('dirs', 'metadata_cache_dir', $cacheDir, $container);

        return new Definition(
            Utility::getLibraryClass($subClassName),
            [$cacheDir]
        );
    }
560148
public function delegateAction($templateKey, $mediaTypeName)
    {
        $mediaTypeManager = $this->get('phlexible_media_type.media_type_manager');
        $templateManager = $this->get('phlexible_media_template.template_manager');
        $delegateService = $this->get('phlexible_media_cache.image_delegate.service');

        $template = $templateManager->find($templateKey);

        $mediaType = $mediaTypeManager->find(strtolower($mediaTypeName));
        $filePath = $delegateService->getClean($template, $mediaType);
        $fileSize = filesize($filePath);
        $mimeType = 'image/gif';

        $response = new BinaryFileResponse($filePath, 200, array('Content-Type' => $mimeType));

        return $response;
    }
1043992
public function updateMedia(array $newMediaArray, string $collectionName = 'default'): Collection
    {
        $this->removeMediaItemsNotPresentInArray($newMediaArray, $collectionName);

        return collect($newMediaArray)
            ->map(function (array $newMediaItem) use ($collectionName) {
                static $orderColumn = 1;

                $mediaClass = config('medialibrary.media_model');
                $currentMedia = $mediaClass::findOrFail($newMediaItem['id']);

                if ($currentMedia->collection_name !== $collectionName) {
                    throw MediaCannotBeUpdated::doesNotBelongToCollection($collectionName, $currentMedia);
                }

                if (array_key_exists('name', $newMediaItem)) {
                    $currentMedia->name = $newMediaItem['name'];
                }

                if (array_key_exists('custom_properties', $newMediaItem)) {
                    $currentMedia->custom_properties = $newMediaItem['custom_properties'];
                }

                $currentMedia->order_column = $orderColumn++;

                $currentMedia->save();

                return $currentMedia;
            });
    }
419266
public function getPublisherConfig3($serverName, $publisher)
    {
        list($response) = $this->getPublisherConfig3WithHttpInfo($serverName, $publisher);
        return $response;
    }
293800
private static void register(ObjectName objectName, Object mbean) {
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();
    try {
      if (!server.isRegistered(objectName)) {
        server.registerMBean(mbean, objectName);
      }
    } catch (InstanceAlreadyExistsException
        | MBeanRegistrationException | NotCompliantMBeanException e) {
      throw new CacheException("Error registering " + objectName, e);
    }
  }
37875
private void addBodyToContext(final String body) {
        if(!body.isEmpty()) {
            final JSONParser parser = new JSONParser();
            try {
                final JSONObject json = (JSONObject) parser.parse(body);
                context.put("requestBody", json);
            } catch (final ParseException e) {
                e.printStackTrace();
            }
        }
    }
1252556
public function mediaAction(Request $request)
    {
        $fileId = $request->get('file_id');
        $fileVersion = $request->get('file_version');
        $templateKey = $request->get('template_key');

        $cacheManager = $this->get('phlexible_media_cache.cache_manager');
        $storageManager = $this->get('phlexible_media_cache.storage_manager');
        $templateManager = $this->get('phlexible_media_template.template_manager');
        $mediaTypeManager = $this->get('phlexible_media_type.media_type_manager');
        $delegateService = $this->get('phlexible_media_cache.image_delegate.service');
        $volumeManager = $this->get('phlexible_media_manager.volume_manager');

        try {
            $cacheItem = $cacheManager->findByTemplateAndFile($templateKey, $fileId, $fileVersion);
        } catch (\Exception $e) {
            $cacheItem = null;
        }

        $template = $templateManager->find($templateKey);

        if ($cacheItem) {
            if ($cacheItem->getCacheStatus() === CacheItem::STATUS_WAITING) {
                $cacheItem = $this->doCache($fileId, $fileVersion, $template, $cacheItem);
            } elseif ($cacheItem->getCacheStatus() === CacheItem::STATUS_MISSING) {
                $cacheItem = $this->doCache($fileId, $fileVersion, $template, $cacheItem);
            }

            if ($cacheItem && $cacheItem->getCacheStatus() === CacheItem::STATUS_OK) {
                $storageKey = $template->getStorage();
                $storage = $storageManager->get($storageKey);
                $filePath = $storage->getLocalPath($cacheItem);

                if (!file_exists($filePath)) {
                    $filePath = null;
                    $cacheItem = $this->doCache($fileId, $fileVersion, $template, $cacheItem);

                    if ($cacheItem && $cacheItem->getCacheStatus() === CacheItem::STATUS_OK) {
                        $storageKey = $template->getStorage();
                        $storage = $storageManager->get($storageKey);
                        $filePath = $storage->getLocalPath($cacheItem);
                    }
                }
            }

            if ($cacheItem) {
                $mimeType = $cacheItem->getMimeType();
            }
        } else {
            $cacheItem = $this->doCache($fileId, $fileVersion, $template);

            if ($cacheItem) {
                if ($cacheItem->getCacheStatus() === CacheItem::STATUS_OK) {
                    $storageKey = $template->getStorage();
                    $storage = $storageManager->get($storageKey);
                    $filePath = $storage->getLocalPath($cacheItem);
                }
                $mimeType = $cacheItem->getMimeType();
            }
        }

        if (empty($filePath)) {
            if (!$template instanceof ImageTemplate) {
                return new Response('Not found', 404);
            }

            $file = $volumeManager->getByFileId($fileId)->findFile($fileId);
            $mediaType = $mediaTypeManager->find(strtolower($file->getMediaType()));
            $filePath = $delegateService->getClean($template, $mediaType, true);
            $mimeType = 'image/gif';
        }

        $response = new BinaryFileResponse($filePath, 200, array('Content-Type' => $mimeType));

        return $response;
    }
1261033
protected function pushCache(&$entity, $className) {
    if (!isset($entity->guid)) {
      return;
    }
    // Increment the entity access count.
    if (!isset($this->entityCount[$entity->guid])) {
      $this->entityCount[$entity->guid] = 0;
    }
    $this->entityCount[$entity->guid]++;
    // Check the threshold.
    if ($this->entityCount[$entity->guid] < $this->config['cache_threshold']) {
      return;
    }
    // Cache the entity.
    if ((array) $this->entityCache[$entity->guid] ===
        $this->entityCache[$entity->guid]) {
      $this->entityCache[$entity->guid][$className] = clone $entity;
    } else {
      while ($this->config['cache_limit']
          && count($this->entityCache) >= $this->config['cache_limit']) {
        // Find which entity has been accessed the least.
        asort($this->entityCount);
        foreach ($this->entityCount as $key => $val) {
          if (isset($this->entityCache[$key])) {
            break;
          }
        }
        // Remove it.
        if (isset($this->entityCache[$key])) {
          unset($this->entityCache[$key]);
        }
      }
      $this->entityCache[$entity->guid] = [$className => (clone $entity)];
    }
    $this->entityCache[$entity->guid][$className]->clearCache();
  }
781342
public function put($filename, $content)
    {
        // Merge existing content to new content
        if (file_exists($this->cacheDir . $filename) && file_get_contents($this->cacheDir . $filename) != '') {
            $cachedContent = $this->get($filename);
            $content       = array_merge($content, $cachedContent);
        }
        $this->files->put($this->cacheDir . $filename, json_encode($content));
    }
687308
public function saveConfiguration($filename, Config $config) {
        $this->workingPath = $this->parseFilepath($filename);

        $cacheManager = new CacheManager();
        $cacheManager->saveToCache('/' . $filename, $config->toDetailsArray());
    }