diff --git a/lib/Alchemy/Phrasea/WorkerManager/Controller/AdminConfigurationController.php b/lib/Alchemy/Phrasea/WorkerManager/Controller/AdminConfigurationController.php index 790d5eb111..db0337df47 100644 --- a/lib/Alchemy/Phrasea/WorkerManager/Controller/AdminConfigurationController.php +++ b/lib/Alchemy/Phrasea/WorkerManager/Controller/AdminConfigurationController.php @@ -6,6 +6,7 @@ use Alchemy\Phrasea\Controller\Controller; use Alchemy\Phrasea\Model\Entities\WorkerRunningJob; use Alchemy\Phrasea\Model\Repositories\WorkerRunningJobRepository; +use Alchemy\Phrasea\Plugin\Exception\JsonValidationException; use Alchemy\Phrasea\SearchEngine\Elastic\ElasticsearchOptions; use Alchemy\Phrasea\Twig\PhraseanetExtension; use Alchemy\Phrasea\WorkerManager\Event\PopulateIndexEvent; @@ -19,6 +20,7 @@ use Alchemy\Phrasea\WorkerManager\Queue\MessagePublisher; use Alchemy\Phrasea\WorkerManager\Worker\RecordsActionsWorker\RecordsActionsWorker; use Doctrine\ORM\OptimisticLockException; +use Exception; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Form\Form; use Symfony\Component\Form\FormInterface; @@ -117,7 +119,7 @@ public function infoAction(PhraseaApplication $app, Request $request) if ($timeFilter != null) { try { $dateTimeFilter = (new \DateTime())->sub(new \DateInterval($timeFilter)); - } catch (\Exception $e) { + } catch (Exception $e) { } } @@ -502,28 +504,32 @@ public function recordsActionsAction(PhraseaApplication $app, Request $request) public function recordsActionsFacilityAction(PhraseaApplication $app, Request $request) { - $ret = ['tasks' => []]; - $job = new RecordsActionsWorker($app); - switch ($request->get('ACT')) { - case 'PLAYTEST': - $sxml = simplexml_load_string($request->get('xml')); - if (isset($sxml->tasks->task)) { - foreach ($sxml->tasks->task as $sxtask) { - $ret['tasks'][] = $job->calcSQL($sxtask, true); + $ret = [ + 'error' => null, + 'tasks' => [] + ]; + try { + $job = new RecordsActionsWorker($app); + switch ($request->get('ACT')) { + case 'PLAYTEST': + case 'CALCTEST': + case 'CALCSQL': + $sxml = simplexml_load_string($request->get('xml')); + if ((string)$sxml['version'] !== '2') { + throw new JsonValidationException(sprintf("bad settings version (%s), should be \"2\"", (string)$sxml['version'])); } - } - break; - case 'CALCTEST': - case 'CALCSQL': - $sxml = simplexml_load_string($request->get('xml')); - if (isset($sxml->tasks->task)) { - foreach ($sxml->tasks->task as $sxtask) { - $ret['tasks'][] = $job->calcSQL($sxtask, false); + if (isset($sxml->tasks->task)) { + foreach ($sxml->tasks->task as $sxtask) { + $ret['tasks'][] = $job->calcSQL($sxtask, $request->get('ACT') === 'PLAYTEST'); + } } - } - break; - default: - throw new NotFoundHttpException('Route not found.'); + break; + default: + throw new NotFoundHttpException('Route not found.'); + } + } + catch (Exception $e) { + $ret['error'] = $e->getMessage(); } return $app->json($ret); diff --git a/lib/Alchemy/Phrasea/WorkerManager/Worker/RecordsActionsWorker/RecordsActionsWorker.php b/lib/Alchemy/Phrasea/WorkerManager/Worker/RecordsActionsWorker/RecordsActionsWorker.php index 9102506c1c..5bdbfbba10 100644 --- a/lib/Alchemy/Phrasea/WorkerManager/Worker/RecordsActionsWorker/RecordsActionsWorker.php +++ b/lib/Alchemy/Phrasea/WorkerManager/Worker/RecordsActionsWorker/RecordsActionsWorker.php @@ -6,6 +6,7 @@ use Alchemy\Phrasea\Core\Configuration\PropertyAccess; use Alchemy\Phrasea\Model\Entities\WorkerRunningJob; use Alchemy\Phrasea\Model\Repositories\WorkerRunningJobRepository; +use Alchemy\Phrasea\Plugin\Exception\JsonValidationException; use Alchemy\Phrasea\WorkerManager\Queue\MessagePublisher; use Alchemy\Phrasea\WorkerManager\Worker\WorkerInterface; use collection; @@ -53,6 +54,10 @@ public function process(array $payload) return 0; } else { + $sxSettings = simplexml_load_string($xmlSettings); + if((string)$sxSettings['version'] !== "2") { + throw new JsonValidationException(sprintf("bad settings version (%s), should be \"2\"", (string)$sxml['version'])); + } $em = $this->repoWorker->getEntityManager(); $em->beginTransaction(); @@ -73,15 +78,14 @@ public function process(array $payload) $em->rollback(); } - $settings = simplexml_load_string($xmlSettings); - $tasks = array(); - foreach($settings->tasks->task as $task) { - $tasks[] = $task; + $sxTasks = array(); + foreach($sxSettings->tasks->task as $sxTask) { + $sxTasks[] = $sxTask; } try { // process will act on db, so we first fetch all... - $data = $this->getData($tasks); + $data = $this->getData($sxTasks); // ... then process foreach ($data as $record) { $this->processData($record); @@ -119,12 +123,12 @@ public function process(array $payload) } } - private function getData(array $tasks) + private function getData(array $sxTasks) { $ret = []; /** @var SimpleXMLElement $sxtask */ - foreach ($tasks as $sxtask) { + foreach ($sxTasks as $sxtask) { $task = $this->calcSQL($sxtask); if (!$task['active'] || !$task['sql']) { diff --git a/templates/web/admin/worker-manager/worker_records_actions.html.twig b/templates/web/admin/worker-manager/worker_records_actions.html.twig index 695f5c88a7..708bb923df 100644 --- a/templates/web/admin/worker-manager/worker_records_actions.html.twig +++ b/templates/web/admin/worker-manager/worker_records_actions.html.twig @@ -172,9 +172,20 @@ , dataType:'json' , type:"POST" , async:true + , error: function(data) { + $("#sqla").html(data.statusText); + } , success:function(data) { + if(data.error) { + $("#sqla").text(data.error); + return; + } t = ""; for (i in data.tasks) { + // o = $("
") + // .append($(" X ")) + // ; + //$("#sqla").append() t += "
 "; if (data.tasks[i].active) { t += " X  ";