Fix task controller

This commit is contained in:
Romain Neutron
2013-07-18 19:32:29 +02:00
parent 44126841bc
commit cfe3d0848b
3 changed files with 33 additions and 15 deletions

View File

@@ -11,6 +11,7 @@
namespace Alchemy\Phrasea\Controller\Admin; namespace Alchemy\Phrasea\Controller\Admin;
use Alchemy\Phrasea\Exception\XMLParseErrorException;
use Silex\Application; use Silex\Application;
use Silex\ControllerProviderInterface; use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
@@ -67,12 +68,12 @@ class TaskManager implements ControllerProviderInterface
try { try {
$app['task-manager']->setSchedulerState(\task_manager::STATE_TOSTOP); $app['task-manager']->setSchedulerState(\task_manager::STATE_TOSTOP);
return $app->json(true); return $app->json(array('success' => true));
} catch (Exception $e) { } catch (Exception $e) {
} }
return $app->json(false); return $app->json(array('success' => false));
})->bind('admin_tasks_scheduler_stop'); })->bind('admin_tasks_scheduler_stop');
$controllers->get('/scheduler/log', function(Application $app, Request $request) { $controllers->get('/scheduler/log', function(Application $app, Request $request) {
@@ -215,9 +216,9 @@ class TaskManager implements ControllerProviderInterface
$task->resetCrashCounter(); $task->resetCrashCounter();
return $app->json(true); return $app->json(array('success' => true));
} catch (\Exception $e) { } catch (\Exception $e) {
return $app->json(false); return $app->json(array('success' => false));
} }
})->bind('admin_tasks_task_reset'); })->bind('admin_tasks_task_reset');
@@ -234,10 +235,7 @@ class TaskManager implements ControllerProviderInterface
throw new XMLParseErrorException($request->request->get('xml')); throw new XMLParseErrorException($request->request->get('xml'));
} }
} catch (XMLParseErrorException $e) { } catch (XMLParseErrorException $e) {
return new Response( return $app->json(array('success' => false, 'message' => $e->getMessage()));
$e->getXMLErrMessage(),
412 // Precondition Failed
);
} }
try { try {
@@ -247,12 +245,9 @@ class TaskManager implements ControllerProviderInterface
$task->setActive(\p4field::isyes($request->request->get('active'))); $task->setActive(\p4field::isyes($request->request->get('active')));
$task->setSettings($request->request->get('xml')); $task->setSettings($request->request->get('xml'));
return $app->json(true); return $app->json(array('success' => true));
} catch (\Exception $e) { } catch (\Exception $e) {
return new Response( return $app->json(array('success' => false, 'message' => 'Task not found'));
'Bad task ID',
404 // Not Found
);
} }
})->bind('admin_tasks_task_save'); })->bind('admin_tasks_task_save');
@@ -346,7 +341,7 @@ class TaskManager implements ControllerProviderInterface
$app['task-manager']->getSchedulerProcess()->run(); $app['task-manager']->getSchedulerProcess()->run();
return $app->json(true); return $app->json(array('success' => true));
} }
/** /**

View File

@@ -0,0 +1,16 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Exception;
class XMLParseErrorException extends RuntimeException implements Exception
{
}

View File

@@ -199,7 +199,14 @@
, type:"POST" , type:"POST"
, async:false , async:false
, success:function(data) { , success:function(data) {
$("#taskFormByeBye").submit(); if (data.success) {
$("#taskFormByeBye").submit();
} else {
if (window.console) {
console.log(data.message);
}
alert("{% trans %}An error occured{% endtrans %}");
}
} }
, error:function(jqXHR, textStatus, errorThrown) { , error:function(jqXHR, textStatus, errorThrown) {
alert("Erreur XML:\n\n" + jqXHR.responseText); alert("Erreur XML:\n\n" + jqXHR.responseText);