Skip to content

Commit

Permalink
Pimcore Command with extension prevent command execution
Browse files Browse the repository at this point in the history
  • Loading branch information
ctippler committed Dec 19, 2018
1 parent 20c134a commit b0a1e28
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class ElementsProcessManagerBundle extends AbstractPimcoreBundle
const TABLE_NAME_CONFIGURATION = 'plugin_process_manager_configuration';
const TABLE_NAME_MONITORING_ITEM = 'plugin_process_manager_monitoring_item';
const TABLE_NAME_CALLBACK_SETTING = 'plugin_process_manager_callback_setting';
const MONITORING_ITEM_ENV_VAR = 'monitoring-item-id';

/**
* @return array
Expand Down Expand Up @@ -122,7 +123,6 @@ public static function shutdownHandler($arguments)
*/
if ($monitoringItem = self::getMonitoringItem()) {
$error = error_get_last();
var_dump($error);

if (in_array($error['type'], [E_WARNING, E_DEPRECATED, E_STRICT, E_NOTICE])) {
if ($config = Configuration::getById($monitoringItem->getConfigurationId())) {
Expand Down Expand Up @@ -202,8 +202,12 @@ public static function setMonitoringItem($monitoringItem)
public static function getMonitoringItem($createDummyObjectIfRequired = true)
{
if ($createDummyObjectIfRequired && !self::$monitoringItem) {
self::$monitoringItem = new MonitoringItem();
self::$monitoringItem->setIsDummy(true);
if(getenv(self::MONITORING_ITEM_ENV_VAR)){
self::$monitoringItem = MonitoringItem::getById(getenv(self::MONITORING_ITEM_ENV_VAR));
}else{
self::$monitoringItem = new MonitoringItem();
self::$monitoringItem->setIsDummy(true);
}
}

return self::$monitoringItem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class ClassMethod extends AbstractExecutor
*/
public function getCommand($callbackSettings = [], $monitoringItem = null)
{
return Console::getPhpCli() . ' ' . realpath(PIMCORE_PROJECT_ROOT . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'console') . ' process-manager:class-method-executor -v';
$command = Console::getPhpCli() . ' ' . realpath(PIMCORE_PROJECT_ROOT . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'console') . ' process-manager:class-method-executor -v';

if($monitoringItem){
$command .= ' --monitoring-item-id='.$monitoringItem->getId();
}
return $command;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ public function getCommand($callbackSettings = [], $monitoringItem = null)
$command .= ' ' . $options;
}

if($monitoringItem){
$application = new \Pimcore\Console\Application(\Pimcore::getContainer()->get('kernel'));
/**
* @var \Pimcore\Console\AbstractCommand $commandObject
*/
$commandObject = $application->find($this->getValues()['command']);
if($commandObject->getDefinition()->hasOption('monitoring-item-id')){
$command .= ' --monitoring-item-id='.$monitoringItem->getId();
}
}
return $command;
}
}
3 changes: 2 additions & 1 deletion src/Elements/Bundle/ProcessManagerBundle/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ public static function executeJob($configId, $callbackSettings = [], $userId = 0

$command = $executor->getCommand($callbackSettings, $monitoringItem);

putenv(ElementsProcessManagerBundle::MONITORING_ITEM_ENV_VAR . '=' . $item->getId());

if (!$executor->getIsShellCommand()) {
$command .= ' --monitoring-item-id=' . $item->getId();
$monitoringItem->getLogger()->info('Execution Command: ' . $command . ' in Background');
$monitoringItem->setCommand($command)->save();
} else {
Expand Down

0 comments on commit b0a1e28

Please sign in to comment.