vendor/elements/process-manager-bundle/src/ElementsProcessManagerBundle.php line 27

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 phpDocumentor\Reflection\DocBlock\Tags\Var_;
  18. use Pimcore\Extension\Bundle\AbstractPimcoreBundle;
  19. use Pimcore\Extension\Bundle\Traits\PackageVersionTrait;
  20. use Pimcore\Extension\Bundle\Traits\StateHelperTrait;
  21. use Symfony\Component\DependencyInjection\ContainerBuilder;
  22. use Elements\Bundle\ProcessManagerBundle\DependencyInjection\Compiler;
  23. class ElementsProcessManagerBundle extends AbstractPimcoreBundle
  24. {
  25.     use ExecutionTrait;
  26.     use PackageVersionTrait;
  27.     use StateHelperTrait;
  28.     public static function getMaintenanceOptions(){
  29.         $logDir str_replace(PIMCORE_PROJECT_ROOT,"",self::getLogDir());
  30.         return [
  31.             'autoCreate' => true,
  32.             'name' => 'ProcessManager maintenance',
  33.             'loggers' => [
  34.                 [
  35.                     'logLevel' => 'DEBUG',
  36.                     'class' => '\Elements\Bundle\ProcessManagerBundle\Executor\Logger\Console',
  37.                     'simpleLogFormat' => true
  38.                 ],
  39.                 [
  40.                     'logLevel' => 'DEBUG',
  41.                     'filepath' => $logDir 'process-manager-maintenance.log',
  42.                     'class' => '\Elements\Bundle\ProcessManagerBundle\Executor\Logger\File',
  43.                     'simpleLogFormat' => true,
  44.                     'maxFileSizeMB' => 50
  45.                 ]
  46.             ]
  47.         ];
  48.     }
  49.     protected static $_config null;
  50.     protected static $monitoringItem;
  51.     const BUNDLE_NAME 'ElementsProcessManagerBundle';
  52.     const TABLE_NAME_CONFIGURATION 'bundle_process_manager_configuration';
  53.     const TABLE_NAME_MONITORING_ITEM 'bundle_process_manager_monitoring_item';
  54.     const TABLE_NAME_CALLBACK_SETTING 'bundle_process_manager_callback_setting';
  55.     const MONITORING_ITEM_ENV_VAR 'monitoringItemId';
  56.     /**
  57.      * @return array
  58.      */
  59.     public function getCssPaths()
  60.     {
  61.         return [
  62.             '/bundles/elementsprocessmanager/css/admin.css'
  63.         ];
  64.     }
  65.     /**
  66.      * @return array
  67.      */
  68.     public function getJsPaths()
  69.     {
  70.         $files = [
  71.             '/bundles/elementsprocessmanager/js/startup.js',
  72.             '/bundles/elementsprocessmanager/js/window/detailwindow.js',
  73.             '/bundles/elementsprocessmanager/js/helper/form.js',
  74.             '/bundles/elementsprocessmanager/js/panel/config.js',
  75.             '/bundles/elementsprocessmanager/js/panel/general.js',
  76.             '/bundles/elementsprocessmanager/js/panel/monitoringItem.js',
  77.             '/bundles/elementsprocessmanager/js/panel/callbackSetting.js',
  78.             '/bundles/elementsprocessmanager/js/executor/class/abstractExecutor.js',
  79.             '/bundles/elementsprocessmanager/js/executor/class/command.js',
  80.             '/bundles/elementsprocessmanager/js/executor/class/classMethod.js',
  81.             '/bundles/elementsprocessmanager/js/executor/class/pimcoreCommand.js',
  82.             '/bundles/elementsprocessmanager/js/executor/action/abstractAction.js',
  83.             '/bundles/elementsprocessmanager/js/executor/action/download.js',
  84.             '/bundles/elementsprocessmanager/js/executor/action/openItem.js',
  85.             '/bundles/elementsprocessmanager/js/executor/action/jsEvent.js',
  86.             '/bundles/elementsprocessmanager/js/executor/logger/abstractLogger.js',
  87.             '/bundles/elementsprocessmanager/js/executor/logger/file.js',
  88.             '/bundles/elementsprocessmanager/js/executor/logger/console.js',
  89.             '/bundles/elementsprocessmanager/js/executor/logger/application.js',
  90.             '/bundles/elementsprocessmanager/js/executor/logger/emailSummary.js',
  91.             '/bundles/elementsprocessmanager/js/executor/callback/abstractCallback.js',
  92.             '/bundles/elementsprocessmanager/js/executor/callback/example.js',
  93.             '/bundles/elementsprocessmanager/js/executor/callback/default.js',
  94.             '/bundles/elementsprocessmanager/js/window/activeProcesses.js',
  95.         ];
  96.         $callbackClasses ElementsProcessManagerBundle::getConfiguration()->getClassTypes()["executorCallbackClasses"];
  97.         foreach($callbackClasses as $e){
  98.             if($file $e["jsFile"]){
  99.                 $files[] = $file;
  100.             }
  101.         }
  102.         return $files;
  103.     }
  104.     /**
  105.      * @inheritDoc
  106.      */
  107.     public function getInstaller()
  108.     {
  109.         return \Pimcore::getContainer()->get(Installer::class);
  110.     }
  111.     /**
  112.      * @param ContainerBuilder $container
  113.      */
  114.     public function build(ContainerBuilder $container)
  115.     {
  116.         $container
  117.             ->addCompilerPass(new Compiler\ExecutorDefinitionPass());
  118.     }
  119.     public static function shutdownHandler($arguments)
  120.     {
  121.         /**
  122.          * @var $monitoringItem MonitoringItem
  123.          */
  124.         if ($monitoringItem self::getMonitoringItem()) {
  125.             $error error_get_last();
  126.             Helper::executeMonitoringItemLoggerShutdown($monitoringItem);
  127.             if (in_array($error['type'], [E_WARNINGE_DEPRECATEDE_STRICTE_NOTICE])) {
  128.                 if ($config Configuration::getById($monitoringItem->getConfigurationId())) {
  129.                     $versions $config->getKeepVersions();
  130.                     if (is_numeric($versions)) {
  131.                         $list = new MonitoringItem\Listing();
  132.                         $list->setOrder('DESC')->setOrderKey('id')->setOffset((int)$versions)->setLimit(100000000000); //a limit has to defined otherwise the offset wont work
  133.                         $list->setCondition('status ="finished" AND configurationId=? AND IFNULL(pid,0) != ? AND parentId IS NULL ', [$config->getId(), $monitoringItem->getPid()]);
  134.                         $items $list->load();
  135.                         foreach ($items as $item) {
  136.                             $item->delete();
  137.                         }
  138.                     }
  139.                 }
  140.                 if (!$monitoringItem->getMessage()) {
  141.                     $monitoringItem->setMessage('finished');
  142.                 }
  143.                 $monitoringItem->setCompleted();
  144.                 $monitoringItem->setPid(null)->save();
  145.             } else {
  146.                 $monitoringItem->setMessage('ERROR:' print_r($errortrue) . $monitoringItem->getMessage());
  147.                 $monitoringItem->setPid(null)->setStatus($monitoringItem::STATUS_FAILED)->save();
  148.             }
  149.         }
  150.     }
  151.     public static function startup($arguments)
  152.     {
  153.         $monitoringItem $arguments['monitoringItem'];
  154.         if ($monitoringItem instanceof MonitoringItem) {
  155.             $monitoringItem->resetState()->save();
  156.             $monitoringItem->setPid(getmypid());
  157.             $monitoringItem->setStatus($monitoringItem::STATUS_RUNNING);
  158.             $monitoringItem->save();
  159.         }
  160.     }
  161.     /**
  162.      * @return BundleConfiguration
  163.      */
  164.     public static function getConfiguration()
  165.     {
  166.         if (is_null(self::$_config)) {
  167.             $configArray \Pimcore::getKernel()->getContainer()->getParameter('elements_process_manager');
  168.             self::$_config = new BundleConfiguration($configArray);
  169.         }
  170.         return self::$_config;
  171.     }
  172.     public static function getLogDir()
  173.     {
  174.         $dir PIMCORE_LOG_DIRECTORY '/process-manager/';
  175.         if (!is_dir($dir)) {
  176.             \Pimcore\File::mkdir($dir);
  177.         }
  178.         return $dir;
  179.     }
  180.     public function getDescription()
  181.     {
  182.         return 'Process Manager';
  183.     }
  184.     /**
  185.      * @param mixed $monitoringItem
  186.      */
  187.     public static function setMonitoringItem($monitoringItem)
  188.     {
  189.         self::$monitoringItem $monitoringItem;
  190.     }
  191.     /**
  192.      * @param bool $createDummyObjectIfRequired
  193.      *
  194.      * @return MonitoringItem
  195.      */
  196.     public static function getMonitoringItem($createDummyObjectIfRequired true)
  197.     {
  198.         if ($createDummyObjectIfRequired && !self::$monitoringItem) {
  199.             if(getenv(self::MONITORING_ITEM_ENV_VAR)){
  200.                 self::$monitoringItem MonitoringItem::getById(getenv(self::MONITORING_ITEM_ENV_VAR));
  201.                 self::$monitoringItem->setStatus(MonitoringItem::STATUS_RUNNING)->save();
  202.             }else{
  203.                 self::$monitoringItem = new MonitoringItem();
  204.                 self::$monitoringItem->setIsDummy(true);
  205.             }
  206.         }
  207.         return self::$monitoringItem;
  208.     }
  209.     protected function getComposerPackageName(): string
  210.     {
  211.         return 'elements/process-manager-bundle';
  212.     }
  213.     public function getNiceName()
  214.     {
  215.         return self::BUNDLE_NAME;
  216.     }
  217. }