<?php
declare(strict_types=1);
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
namespace IndabaSyncroAssetsBundle\EventListener;
use Pimcore\Event\Model\ElementEventInterface;
use Pimcore\Event\Model\AssetEvent;
use Pimcore\Model\Asset;
use IndabaSyncroAssetsBundle\Model\SyncroAsset;
/**
* Description of AssetEventListener
*
* @author PcCom
*/
class AssetEventListener
{
public function onPostAssetUpdate(ElementEventInterface $e)
{
if ($e instanceof AssetEvent) {
$asset = $e->getAsset();
if ($asset) {
$assetId = $asset->getId();
$syncroAssetList = SyncroAsset::getByAssetId($assetId);
if (\is_array($syncroAssetList) && \count($syncroAssetList)) {
/** @var SyncroAsset $syncroAsset */
foreach ($syncroAssetList as $syncroAsset) {
if ($syncroAsset->isFileModified()) {
$syncroAsset->setAction(SyncroAsset::ACTION_UPDATE);
$syncroAsset->setMustUpdate(true);
$syncroAsset->save();
}
}
}
}
}
}
}