Skip to content

Commit

Permalink
Merge branch '8.2' into 8.3
Browse files Browse the repository at this point in the history
  • Loading branch information
kitsunet committed Nov 1, 2023
2 parents 1a0d8d5 + a03de9e commit ddafc93
Show file tree
Hide file tree
Showing 14 changed files with 760 additions and 15 deletions.
8 changes: 5 additions & 3 deletions Neos.Fusion/Classes/FusionObjects/ComponentImplementation.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ protected function getPrivateProps(array $context): \ArrayAccess
protected function render(array $context)
{
$this->runtime->pushContextArray($context);
$result = $this->runtime->render($this->path . '/renderer');
$this->runtime->popContext();
return $result;
try {
return $this->runtime->render($this->path . '/renderer');
} finally {
$this->runtime->popContext();
}
}
}
33 changes: 33 additions & 0 deletions Neos.Media.Browser/Classes/Controller/AssetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
use Neos\Media\Domain\Repository\AssetRepository;
use Neos\Media\Domain\Repository\TagRepository;
use Neos\Media\Domain\Service\AssetService;
use Neos\Media\Domain\Service\AssetVariantGenerator;
use Neos\Media\Exception\AssetServiceException;
use Neos\Media\TypeConverter\AssetInterfaceConverter;
use Neos\Neos\Controller\BackendUserTranslationTrait;
Expand Down Expand Up @@ -140,6 +141,12 @@ class AssetController extends ActionController
*/
protected $assetSourceService;

/**
* @Flow\Inject
* @var AssetVariantGenerator
*/
protected $assetVariantGenerator;

/**
* @var AssetSourceInterface[]
*/
Expand Down Expand Up @@ -469,6 +476,32 @@ public function variantsAction(string $assetSourceIdentifier, string $assetProxy
}
}

/**
* Create missing variants for the given image
*
* @param string $assetSourceIdentifier
* @param string $assetProxyIdentifier
* @param string $overviewAction
* @throws StopActionException
* @throws UnsupportedRequestTypeException
*/
public function createVariantsAction(string $assetSourceIdentifier, string $assetProxyIdentifier, string $overviewAction): void
{
$assetSource = $this->assetSources[$assetSourceIdentifier];
$assetProxyRepository = $assetSource->getAssetProxyRepository();

$assetProxy = $assetProxyRepository->getAssetProxy($assetProxyIdentifier);
$asset = $this->persistenceManager->getObjectByIdentifier($assetProxy->getLocalAssetIdentifier(), Asset::class);

/** @var VariantSupportInterface $originalAsset */
$originalAsset = ($asset instanceof AssetVariantInterface ? $asset->getOriginalAsset() : $asset);

$this->assetVariantGenerator->createVariants($originalAsset);
$this->assetRepository->update($originalAsset);

$this->redirect('variants', null, null, ['assetSourceIdentifier' => $assetSourceIdentifier, 'assetProxyIdentifier' => $assetProxyIdentifier, 'overviewAction' => $overviewAction]);
}

/**
* @return void
* @throws NoSuchArgumentException
Expand Down
2 changes: 1 addition & 1 deletion Neos.Media.Browser/Configuration/Policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ privilegeTargets:

'Neos.Media.Browser:ManageAssets':
label: Allowed to manage assets
matcher: 'method(Neos\Media\Browser\Controller\(Asset|Image)Controller->(index|new|show|edit|update|initializeCreate|create|replaceAssetResource|updateAssetResource|initializeUpload|upload|tagAsset|delete|createTag|editTag|updateTag|deleteTag|addAssetToCollection|relatedNodes|variants)Action()) || method(Neos\Media\Browser\Controller\ImageVariantController->(update)Action())'
matcher: 'method(Neos\Media\Browser\Controller\(Asset|Image)Controller->(index|new|show|edit|update|initializeCreate|create|replaceAssetResource|updateAssetResource|initializeUpload|upload|tagAsset|delete|createTag|editTag|updateTag|deleteTag|addAssetToCollection|relatedNodes|variants|createVariants)Action()) || method(Neos\Media\Browser\Controller\ImageVariantController->(update)Action())'

'Neos.Media.Browser:AssetUsage':
label: Allowed to calculate asset usages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
<f:form action="update" controller="ImageVariant" package="Neos.Media.Browser" format="json" id="postHelper" method="post" useParentRequest="{isSubRequest}">
<f:render partial="ConstraintsHiddenFields" arguments="{constraints: constraints}" />
</f:form>

<div class="neos-footer">
<f:form action="createVariants" addQueryString="true">
<button type="submit" class="neos-button">{neos:backend.translate(id: 'createMissingVariants', package: 'Neos.Media.Browser')}</button>
</f:form>
</div>

</f:section>

<f:section name="Scripts">
Expand Down
3 changes: 3 additions & 0 deletions Neos.Media.Browser/Resources/Private/Translations/en/Main.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@
<trans-unit id="missingDocumentNode" xml:space="preserve">
<source>No document node found for this node</source>
</trans-unit>
<trans-unit id="createMissingVariants" xml:space="preserve">
<source>Create missing variants</source>
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions Neos.Media/Classes/Domain/Service/AssetVariantGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ public function createVariant(AssetInterface $asset, string $presetIdentifier, s
$createdVariant = null;
$preset = $this->getVariantPresets()[$presetIdentifier] ?? null;
if ($preset instanceof VariantPreset && $preset->matchesMediaType($asset->getMediaType())) {
$existingVariant = $asset->getVariant($presetIdentifier, $variantIdentifier);
if ($existingVariant !== null) {
return $existingVariant;
}

$variantConfiguration = $preset->variants()[$variantIdentifier] ?? null;

if ($variantConfiguration instanceof Configuration\Variant) {
Expand Down
9 changes: 8 additions & 1 deletion Neos.Media/Classes/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
* source code.
*/

use Neos\Flow\Configuration\ConfigurationManager;
use Neos\Flow\Core\Bootstrap;
use Neos\Flow\Package\Package as BasePackage;
use Neos\Media\Domain\Model\AssetInterface;
use Neos\Media\Domain\Model\ImportedAssetManager;
use Neos\Media\Domain\Service\AssetService;
use Neos\Media\Domain\Service\AssetVariantGenerator;
Expand All @@ -30,7 +32,12 @@ class Package extends BasePackage
public function boot(Bootstrap $bootstrap)
{
$dispatcher = $bootstrap->getSignalSlotDispatcher();
$dispatcher->connect(AssetService::class, 'assetCreated', AssetVariantGenerator::class, 'createVariants');
$dispatcher->connect(AssetService::class, 'assetCreated', function (AssetInterface $asset) use ($bootstrap) {
$configurationManager = $bootstrap->getObjectManager()->get(ConfigurationManager::class);
if ($configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.Media.autoCreateImageVariantPresets')) {
$bootstrap->getObjectManager()->get(AssetVariantGenerator::class)->createVariants($asset);
}
});
$dispatcher->connect(AssetService::class, 'assetCreated', ThumbnailGenerator::class, 'createThumbnails');
$dispatcher->connect(AssetService::class, 'assetCreated', ImportedAssetManager::class, 'registerCreatedAsset');
$dispatcher->connect(AssetService::class, 'assetRemoved', ImportedAssetManager::class, 'registerRemovedAsset');
Expand Down
2 changes: 1 addition & 1 deletion Neos.Media/Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Neos:
# Variant presets
variantPresets: []
# Automatically create asset variants for configured presets when assets are added
autoCreateImageVariantPresets: false
autoCreateImageVariantPresets: true

thumbnailGenerators:

Expand Down
6 changes: 3 additions & 3 deletions Neos.Media/Documentation/VariantPresets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ The following example shows the required structure and possible fields of the pr
options:
aspectRatio: '1:1'
The automatic variant generation for new assets has to be enabled via setting as
by default this feature is disabled.
The automatic variant generation for new assets is active by default.
It can be disabled via setting:

.. code-block:: yaml
Neos:
Media:
autoCreateImageVariantPresets: true
autoCreateImageVariantPresets: false
To show and edit the variants in the media module the variants tab has to be enabled.

Expand Down
175 changes: 175 additions & 0 deletions Neos.Neos/Documentation/Appendixes/ChangeLogs/7316.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
`7.3.16 (2023-10-21) <https://github.com/neos/neos-development-collection/releases/tag/7.3.16>`_
================================================================================================

Overview of merged pull requests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

`BUGFIX: Only discard nodes in same workspace <https://github.com/neos/neos-development-collection/pull/4578>`_
---------------------------------------------------------------------------------------------------------------

* Resolves: `#4577 <https://github.com/neos/neos-development-collection/issues/4577>`_

* Packages: ``ContentRepository``

`BUGFIX: Load all thumbnails for an asset to skip further requests <https://github.com/neos/neos-development-collection/pull/4624>`_
------------------------------------------------------------------------------------------------------------------------------------

For the usecase of images with responsive variants this change prevents additional database requests for each additional variant of an image.

This can greatly reduce the number of queries on pages with many source tags or sources attributes for pictures and images.

**Review instructions**

As soon as an image is rendered in several sizes on a page the patch should skip additional db requests in the thumbnails repository.
Persistent resources and image entities are still queried as via the node property getter and to resolve the thumbnail.


* Packages: ``Neos`` ``Media``

`BUGFIX: Allow unsetting thumbnail presets <https://github.com/neos/neos-development-collection/pull/4516>`_
------------------------------------------------------------------------------------------------------------

* Resolves: `#3544 <https://github.com/neos/neos-development-collection/issues/3544>`_

* Packages: ``Neos`` ``Media``

`BUGFIX: Don’t query for abstract nodetypes in nodedata repository <https://github.com/neos/neos-development-collection/pull/4501>`_
--------------------------------------------------------------------------------------------------------------------------------------

As abstract nodetypes don't (shouldn't) appear in the database it makes no sense to query them.

This is a regression that was introduced a long time ago, when the default parameter to include abstract nodetypes was added to the ``getSubNodeTypes`` method in the ``NodeTypeManager`` without adjusting the call in the ``NodeDataRepository->getNodeTypeFilterConstraintsForDql`` which relied on the previous behaviour.

The call in the method ``getNodeTypeFilterConstraints`` was fixed some years ago, but that method seems unused.

* Packages: ``ContentRepository``

`BUGFIX: Consistently initialize asset sources via `createFromConfiguration` <https://github.com/neos/neos-development-collection/pull/4008>`_
----------------------------------------------------------------------------------------------------------------------------------------------

fixes: `#3965 <https://github.com/neos/neos-development-collection/issues/3965>`_

**The Problem**

The case at hand was an asset source that uses a value object to validate the incoming asset source options. I expected to be able to define a promoted constructor property with said value object as its declared type:

```php
final class MyAssetSource implements AssetSourceInterface
{
public function __construct(
private readonly string $assetSourceIdentifier,
private readonly Options $options
) {
}
/* ... */
}
```

...and initialize the value object in the ``createFromConfiguration`` static factory method defined by the ``AssetSourceInterface``:

```php
final class MyAssetSource implements AssetSourceInterface
{
/* ... */
public static function createFromConfiguration(string $assetSourceIdentifier, array $assetSourceOptions): AssetSourceInterface
{
return new static(
$assetSourceIdentifier,
Options::fromArray($assetSourceOptions)
);
}
}
```

This failed with a Type Error, because the ``AssetSourceService``, which is responsible for initializing asset sources, at one point does not utilize ``createFromConfiguration`` to perform initialization, but calls the asset source constructor directly:

https://github.com/neos/neos-development-collection/blob/`a4791b623161259b31d2d11b343310bd7ef76507 <https://github.com/neos/neos-development-collection/commit/a4791b623161259b31d2d11b343310bd7ef76507>`_/Neos.Media/Classes/Domain/Service/AssetSourceService.php#L178

**The Solution**

I adjusted the aforementioned routine of the ``AssetSourceService`` to use the ``AssetSourceInterface``-defined ``createFromConfiguration`` static factory method instead of the asset source's constructor.

Even though the pattern I described above only makes sense in a PHP >8.0 environment, I decided to target Neos 7.3 with this PR, because it should constitute a non-breaking bugfix.

* Packages: ``Neos`` ``Media``

`BUGFIX: Guard that Fusion path cannot be empty <https://github.com/neos/neos-development-collection/pull/4547>`_
-----------------------------------------------------------------------------------------------------------------

Previously in php 7.4 this ``Neos\\Fusion\\Exception\\MissingFusionObjectException`` was thrown

> No Fusion object found in path ""

but with php 8 this ``ValueError`` is thrown which is unexpected

> strrpos(): Argument `#3 <https://github.com/neos/neos-development-collection/issues/3>``_($offset) must be contained in argument ``#1 <https://github.com/neos/neos-development-collection/issues/1>`_($haystack)
This change takes care of throwing an explicit ``Neos\\Fusion\\Exception`` instead:

> Fusion path cannot be empty.


--------

This error was noticed in the out of band rendering, when there is no content element wrapping: https://discuss.neos.io/t/argument-3-offset-must-be-contained-in-argument-1-haystack/6416/4

<img width="593" alt="image" src="https://github.com/neos/neos-development-collection/assets/85400359/0ac8d025-3ab4-44e8-9034-eb883f0b1894">



**Upgrade instructions**

**Review instructions**


* Packages: ``Neos`` ``Fusion``

`BUGFIX: Fix `NodeType` `getTypeOfAutoCreatedChildNode` and `getPropertyType` <https://github.com/neos/neos-development-collection/pull/4482>`_
-----------------------------------------------------------------------------------------------------------------------------------------------

resolves partially `#4333 <https://github.com/neos/neos-development-collection/issues/4333>`_
resolves partially `#4344 <https://github.com/neos/neos-development-collection/issues/4344>`_

**Upgrade instructions**

**Review instructions**


* Packages: ``Neos`` ``ContentRepository``

`TASK: Fix documentation builds <https://github.com/neos/neos-development-collection/pull/4607>`_
-------------------------------------------------------------------------------------------------

… by pinning updated dependencies.

**Review instructions**

Best is to see if the builds succeed on RTD again with this merged…


* Packages: ``Neos`` ``Media``

`TASK: Fix paths for Neos.Media RTD rendering setup <https://github.com/neos/neos-development-collection/pull/4568>`_
---------------------------------------------------------------------------------------------------------------------

The paths need to be from the repo root, not relative to the ``.readthedocs.yaml`` file (it seems).


* Packages: ``Neos`` ``Media``

`TASK: Add configuration files for RTD <https://github.com/neos/neos-development-collection/pull/4565>`_
--------------------------------------------------------------------------------------------------------

This add ``.readthedocs.yaml`` files for the collection (handling ``Neos.Neos``) and for ``neos.Media``, to solve failing documentation rendering.

**Review instructions**

This can be compared to the configuration we have in place for ``Neos.Flow`` in the Flow development collection.


* Packages: ``Media``

`Detailed log <https://github.com/neos/neos-development-collection/compare/7.3.15...7.3.16>`_
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Loading

0 comments on commit ddafc93

Please sign in to comment.