src/PromemoriaBundle/Services/HookConfigurationTagEvent.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\PromemoriaBundle\Services;
  3. use Pimcore\Event\Model\TagEvent;
  4. use Pimcore\Db;
  5. class HookConfigurationTagEvent
  6. {
  7.     public function onPreAdd(TagEvent $e): void
  8.     {
  9.     }
  10.     public function onPostAdd(TagEvent $e): void
  11.     {
  12.         }
  13.     public function onPreUpdate(TagEvent $e): void {}
  14.     public function onPostUpdate(TagEvent $e): void
  15.     {
  16.         $tag $e->getTag();
  17.         if (!$tag || !$tag->getId()) {
  18.             return;
  19.         }
  20.         $tagId $tag->getId();
  21.         $db Db::get();
  22.         $tags $db->fetchFirstColumn(
  23.             'SELECT id FROM tags WHERE idPath LIKE ? OR id = ?',
  24.             ['%/' $tagId '/%'$tagId]
  25.         );
  26.         if (!empty($tags)) {
  27.             $inClause implode(','array_map('intval'$tags));
  28.             $assignments $db->fetchAllAssociative("SELECT cid, ctype FROM tags_assignment WHERE tagid IN ($inClause)");
  29.             foreach ($assignments as $rel) {
  30.                 shell_exec("php /var/www/html/slim-sync/index.php /sync/{$rel['ctype']}/{$rel['cid']} >/dev/null 2>/dev/null &");
  31.             }
  32.         }
  33.     }
  34.     public function onPreDelete(TagEvent $e): void
  35.     {
  36.         $tag $e->getTag();
  37.         if (!$tag || !$tag->getId()) {
  38.             return;
  39.         }
  40.         $tagId $tag->getId();
  41.         $db Db::get();
  42.         $tags $db->fetchFirstColumn(
  43.             'SELECT id FROM tags WHERE idPath LIKE ? OR id = ?',
  44.             ['%/' $tagId '/%'$tagId]
  45.         );
  46.         if (!empty($tags)) {
  47.             $inClause implode(','array_map('intval'$tags));
  48.             $assignments $db->fetchAllAssociative("SELECT cid, ctype FROM tags_assignment WHERE tagid IN ($inClause)");
  49.             foreach ($assignments as $rel) {
  50.                 shell_exec("php /var/www/html/slim-sync/index.php /sync/{$rel['ctype']}/{$rel['cid']} >/dev/null 2>/dev/null &");
  51.             }
  52.         }
  53.     }
  54.     public function onPostDelete(TagEvent $e): void {}
  55. }