Update the resource on an asset.

@param AssetInterface $asset
@param PersistentResource $resource
@param array $options
@return void
@throws StopActionException
@throws ForwardException
978653
public function updateAssetResourceAction(AssetInterface $asset, PersistentResource $resource, array $options = []): void
    {
        $sourceMediaType = MediaTypes::parseMediaType($asset->getMediaType());
        $replacementMediaType = MediaTypes::parseMediaType($resource->getMediaType());

        // Prevent replacement of image, audio and video by a different mimetype because of possible rendering issues.
        if ($sourceMediaType['type'] !== $replacementMediaType['type'] && in_array($sourceMediaType['type'], ['image', 'audio', 'video'])) {
            $this->addFlashMessage(
                'resourceCanOnlyBeReplacedBySimilarResource',
                '',
                Message::SEVERITY_WARNING,
                [$sourceMediaType['type'], $resource->getMediaType()],
                1462308179
            );
            $this->redirect('index');
        }

        try {
            $this->assetService->replaceAssetResource($asset, $resource, $options);
        } catch (\Exception $exception) {
            $this->addFlashMessage('couldNotReplaceAsset', '', Message::SEVERITY_OK, [], 1463472606);
            $this->forwardToReferringRequest();
            return;
        }

        $assetLabel = (method_exists($asset, 'getLabel') ? $asset->getLabel() : $resource->getFilename());
        $this->addFlashMessage('assetHasBeenReplaced', '', Message::SEVERITY_OK, [htmlspecialchars($assetLabel)]);
        $this->redirect('index');
    }
683516
public function afterSave(Event $event, EntityInterface $entity, ArrayObject $options) : void
    {
        EventManager::instance()->dispatch(new Event(
            (string)EventName::MODEL_AFTER_SAVE(),
            $this,
            ['entity' => $entity, 'options' => ['current_user' => User::getCurrentUser()]]
        ));
    }
377550
protected function addResourceString(string $resource): void
    {
        $data = json_decode($resource, true);
        if (json_last_error() !== \JSON_ERROR_NONE) {
            if (function_exists('json_last_error_msg')) {
                throw new \InvalidArgumentException(json_last_error_msg(), json_last_error());
            }
            throw new \InvalidArgumentException("Error parsing JSON.", json_last_error());
        }

        $this->addResourceArray($data);
    }
597675
public function filterLoad(AssetInterface $asset)
    {
        $inputFile = tempnam(sys_get_temp_dir(), 'csso');

        file_put_contents($inputFile, $asset->getContent());

        // Before we create our process builder we'll create the arguments to be given to the builder.
        // If we have a node bin supplied then we'll shift that to the beginning of the array.
        $builderArguments = array($this->cssoBin);

        if ( ! is_null($this->nodeBin))
        {
            array_unshift($builderArguments, $this->nodeBin);
        }

        $builder = $this->createProcessBuilder($builderArguments);

        $builder->add($inputFile);

        // Get the process from the builder and run the process.
        $process = $builder->getProcess();

        $code = $process->run();

        unlink($inputFile);

        if ($code !== 0)
        {
            throw FilterException::fromProcess($process)->setInput($asset->getContent());
        }

        $asset->setContent($process->getOutput());
    }
1098071
public function updateExisting(array $attributes, array $options = []) : bool
    {
        if (!$this->exists) {
            return false;
        }

        return $this->forceFill($attributes)->save($options);
    }
1132605
public function registerAssetChange(AssetInterface $asset)
    {
        if (!$asset->isInUse()) {
            return;
        }

        $cachingHelper = $this->getCachingHelper();

        foreach ($this->assetService->getUsageReferences($asset) as $reference) {
            if (!$reference instanceof AssetUsageInNodeProperties) {
                continue;
            }

            $workspaceHash = $cachingHelper->renderWorkspaceTagForContextNode($reference->getWorkspaceName());

            $this->registerChangeOnNodeIdentifier($workspaceHash . '_' . $reference->getNodeIdentifier());
            $this->registerChangeOnNodeType($reference->getNodeTypeName(), $reference->getNodeIdentifier(), $workspaceHash);

            $assetIdentifier = $this->persistenceManager->getIdentifierByObject($asset);

            $tagName = 'AssetDynamicTag_' . $workspaceHash . '_' . $assetIdentifier;
            $this->tagsToFlush[$tagName] = sprintf('which were tagged with "%s" because asset "%s" has changed.', $tagName, $assetIdentifier);
        }
    }
1121120
public function addResource(AbstractResourceFile $resource) {
        if (!parent::offsetExists($resource->getMemberId())) {
            parent::offsetSet($resource->getMemberId(), $resource);
        }
    }
1182543
protected function addingAssetUrl($assetUrl,$resources)
    {
        foreach ($resources as &$resource) {
            if (gettype($resource)=="string") {
                $resource = $assetUrl."/".$resource;
            } else if (gettype($resource)=="array") {
                $resource = $this->addingAssetUrl($assetUrl, $resource);
            }
        }
        return $resources;
    }
832793
private function setOptions($options, $resource)
    {
        if (!empty($options['version']) && is_string($options['version'])) {
            $this->version = $options['version'];
        } elseif (!empty($resource[2])) {
            $this->version = $resource[2];
        }

        if (!empty($options['url']) && is_string($options['url'])) {
            $this->url = $options['url'];
        }

        if (isset($options['secured']) && is_bool($options['secured'])) {
            $this->secure = $options['secured'];
        }

        if (isset($options['call']) && is_bool($options['call'])) {
            $this->call = $options['call'];
        }
        $this->changed = true;
    }
1241993
public function add (array $assets, ?callable $progress) : void
    {
        $fileTypeRegistry = $this->locator->get(FileTypeRegistry::class);
        $deferred = [];

        foreach ($assets as $asset)
        {
            if ($fileTypeRegistry->importDeferred($asset))
            {
                $deferred[] = $asset;
                continue;
            }

            $this->addAsset($asset);

            if (null !== $progress)
            {
                $progress();
            }
        }

        foreach ($deferred as $asset)
        {
            $this->addAsset($asset);

            if (null !== $progress)
            {
                $progress();
            }
        }
    }
925616
public function getUsageCount(AssetInterface $asset)
    {
        $usageCount = 0;
        /** @var AssetUsageStrategyInterface $strategy */
        foreach ($this->getUsageStrategies() as $strategy) {
            $usageCount += $strategy->getUsageCount($asset);
        }

        return $usageCount;
    }
1184029
protected function storeVersion(PuliResource $resource)
    {
        if (null !== $this->changeStream) {
            $this->changeStream->append($resource);
        }
    }
915832
public function createAction(Asset $asset): void
    {
        if ($this->persistenceManager->isNewObject($asset)) {
            $this->assetRepository->add($asset);
        }
        $this->addFlashMessage('assetHasBeenAdded', '', Message::SEVERITY_OK, [htmlspecialchars($asset->getLabel())]);
        $this->redirect('index');
    }
1255789
protected function ensureByService(AssetInterface $asset, $service)
    {
        if (is_string($service)) {
            $this->ensureByFilter($asset, $this->getServiceLocator()->get($service));
        } else {
            throw new Exception\RuntimeException(
                'Unexpected service provided. Expected string or callback.'
            );
        }
    }
1097188
private function addAsset(AssetInterface $asset)
    {
        if ($asset instanceof FileAssetInterface) {
            $this->normalizeAsset($asset);
        }
        $this->assets[] = $asset;
    }
514966
public function deleteResource(PersistentResource $resource)
    {
        try {
            $this->getCurrentBucket()->object($this->keyPrefix . $resource->getSha1())->delete();
        } catch (NotFoundException $e) {
            return true;
        }

        return true;
    }
96474
protected function registerResource(ResourceInterface $resource): void
    {
        \assert($this->hasNotBeenAdded($resource));

        $this->addedResources[$resource->getId()][$resource->getType()] = true;
    }