Skip to content

Commit

Permalink
Persist changes during webhook handling
Browse files Browse the repository at this point in the history
This makes the data updated through the webhook handling actually
visible afterwards…

Since the middleware aborts the chain if it was the target, Flow
never gets to the point where it would persist pending changes.
  • Loading branch information
kdambekalns committed Feb 17, 2022
1 parent 931f78f commit ed13210
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Classes/Service/AssetUpdateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Neos\Flow\Annotations as Flow;
use Neos\Flow\Log\ThrowableStorageInterface;
use Neos\Flow\Log\Utility\LogEnvironment;
use Neos\Flow\Persistence\PersistenceManagerInterface;
use Neos\Flow\ResourceManagement\ResourceManager;
use Neos\Media\Domain\Model\AssetInterface;
use Neos\Media\Domain\Model\AssetSource\AssetSourceInterface;
Expand Down Expand Up @@ -68,6 +69,12 @@ final class AssetUpdateService
*/
protected $resourceManager;

/**
* @Flow\Inject
* @var PersistenceManagerInterface
*/
protected $persistenceManager;

/**
* @Flow\Inject
* @var AssetSourceService
Expand Down Expand Up @@ -111,6 +118,8 @@ public function handleAssetMetadataUpdated(array $payload): bool
// $localAsset->setTitle($assetProxy->getIptcProperty('Title'));
// $localAsset->setCaption($assetProxy->getIptcProperty('CaptionAbstract'));

$this->persistenceManager->persistAll();

return true;
} catch (\Exception $e) {
return false;
Expand All @@ -130,13 +139,14 @@ public function handleNewAssetVersionAdded(array $payload): bool
try {
$this->replaceAsset($identifier);

$this->persistenceManager->persistAll();

return true;
} catch (\Exception $e) {
return false;
}
}

// TODO this "works" but used assets still have the same filename when used in frontend, so it seems incomplete
private function replaceAsset(string $identifier): void
{
$importedAsset = $this->importedAssetRepository->findOneByAssetSourceIdentifierAndRemoteAssetIdentifier(CantoAssetSource::ASSET_SOURCE_IDENTIFIER, $identifier);
Expand Down

0 comments on commit ed13210

Please sign in to comment.