Skip to content

Commit

Permalink
exception if not settings/version=2
Browse files Browse the repository at this point in the history
  • Loading branch information
jygaulier committed Jul 18, 2023
1 parent e51e512 commit ffdba0b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
}
}

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand All @@ -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);
Expand Down Expand Up @@ -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']) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $("<div></div>")
// .append($("<span>&nbsp;X&nbsp;</span>"))
// ;
//$("#sqla").append()
t += "<div class=\"title\">&nbsp;";
if (data.tasks[i].active) {
t += "<span class=\"active\">&nbsp;X&nbsp;</span>&nbsp;";
Expand Down

0 comments on commit ffdba0b

Please sign in to comment.