vendor/elements/process-manager-bundle/src/SystemEventsListener.php line 42

Open in your IDE?
  1. <?php
  2. /**
  3.  * Elements.at
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Enterprise License (PEL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) elements.at New Media Solutions GmbH (https://www.elements.at)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PEL
  13.  */
  14. namespace Elements\Bundle\ProcessManagerBundle;
  15. use Elements\Bundle\ProcessManagerBundle\Model\Configuration;
  16. use Elements\Bundle\ProcessManagerBundle\Model\MonitoringItem;
  17. use Symfony\Component\Console\ConsoleEvents;
  18. use Symfony\Component\Console\Event\ConsoleErrorEvent;
  19. use Symfony\Component\Console\Event\ConsoleTerminateEvent;
  20. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  21. class SystemEventsListener implements EventSubscriberInterface
  22. {
  23.     /**
  24.      * @return array
  25.      */
  26.     public static function getSubscribedEvents()
  27.     {
  28.         return [
  29.             ConsoleEvents::ERROR => 'onConsoleError',
  30.             ConsoleEvents::TERMINATE => 'onConsoleTerminate',
  31.         ];
  32.     }
  33.     /**
  34.      * @param ConsoleErrorEvent $e
  35.      */
  36.     public function onConsoleError(ConsoleErrorEvent $e)
  37.     {
  38.         if (!\Pimcore::isInstalled() || !ElementsProcessManagerBundle::isInstalled()) {
  39.             return;
  40.         }
  41.         if ($monitoringItem ElementsProcessManagerBundle::getMonitoringItem()) {
  42.             $error $e->getError();
  43.             $monitoringItem->setMessage('ERROR: ' $error->getMessage());
  44.             $monitoringItem->getLogger()->error($error);
  45.             $monitoringItem->setPid(null)->setStatus($monitoringItem::STATUS_FAILED)->save();
  46.         }
  47.     }
  48.     /**
  49.      * @param ConsoleTerminateEvent $e
  50.      */
  51.     public function onConsoleTerminate(ConsoleTerminateEvent $e)
  52.     {
  53.         if (!\Pimcore::isInstalled() || !ElementsProcessManagerBundle::isInstalled()) {
  54.             return;
  55.         }
  56.         if ($monitoringItem ElementsProcessManagerBundle::getMonitoringItem()) {
  57.             Helper::executeMonitoringItemLoggerShutdown($monitoringItem);
  58.         }
  59.         if ($e->getExitCode() == 0) {
  60.             if ($monitoringItem ElementsProcessManagerBundle::getMonitoringItem()) {
  61.                 if ($config Configuration::getById($monitoringItem->getConfigurationId())) {
  62.                     $versions $config->getKeepVersions();
  63.                     if (is_numeric($versions)) {
  64.                         $list = new MonitoringItem\Listing();
  65.                         $list->setOrder('DESC')->setOrderKey('id')->setOffset((int)$versions)->setLimit(
  66.                             100000000000
  67.                         ); //a limit has to defined otherwise the offset wont work
  68.                         $list->setCondition(
  69.                             'status ="finished" AND configurationId=? AND IFNULL(pid,0) != ? AND parentId IS NULL ',
  70.                             [$config->getId(), $monitoringItem->getPid()]
  71.                         );
  72.                         $items $list->load();
  73.                         foreach ($items as $item) {
  74.                             $item->delete();
  75.                         }
  76.                     }
  77.                 }
  78.                 if (!$monitoringItem->getMessage()) {
  79.                     $monitoringItem->setMessage('finished');
  80.                 }
  81.                 $monitoringItem->setCompleted();
  82.                 $monitoringItem->setPid(null)->save();
  83.             }
  84.         }
  85.     }
  86. }