<?php
namespace App\PromemoriaBundle\Services;
use Pimcore\Event\Model\TagEvent;
use Pimcore\Db;
class HookConfigurationTagEvent
{
public function onPreAdd(TagEvent $e): void
{
}
public function onPostAdd(TagEvent $e): void
{
}
public function onPreUpdate(TagEvent $e): void {}
public function onPostUpdate(TagEvent $e): void
{
$tag = $e->getTag();
if (!$tag || !$tag->getId()) {
return;
}
$tagId = $tag->getId();
$db = Db::get();
$tags = $db->fetchFirstColumn(
'SELECT id FROM tags WHERE idPath LIKE ? OR id = ?',
['%/' . $tagId . '/%', $tagId]
);
if (!empty($tags)) {
$inClause = implode(',', array_map('intval', $tags));
$assignments = $db->fetchAllAssociative("SELECT cid, ctype FROM tags_assignment WHERE tagid IN ($inClause)");
foreach ($assignments as $rel) {
shell_exec("php /var/www/html/slim-sync/index.php /sync/{$rel['ctype']}/{$rel['cid']} >/dev/null 2>/dev/null &");
}
}
}
public function onPreDelete(TagEvent $e): void
{
$tag = $e->getTag();
if (!$tag || !$tag->getId()) {
return;
}
$tagId = $tag->getId();
$db = Db::get();
$tags = $db->fetchFirstColumn(
'SELECT id FROM tags WHERE idPath LIKE ? OR id = ?',
['%/' . $tagId . '/%', $tagId]
);
if (!empty($tags)) {
$inClause = implode(',', array_map('intval', $tags));
$assignments = $db->fetchAllAssociative("SELECT cid, ctype FROM tags_assignment WHERE tagid IN ($inClause)");
foreach ($assignments as $rel) {
shell_exec("php /var/www/html/slim-sync/index.php /sync/{$rel['ctype']}/{$rel['cid']} >/dev/null 2>/dev/null &");
}
}
}
public function onPostDelete(TagEvent $e): void {}
}