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;
use Alchemy\Phrasea\Exception\XMLParseErrorException;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Symfony\Component\HttpFoundation\Request;
@@ -67,12 +68,12 @@ class TaskManager implements ControllerProviderInterface
try {
$app['task-manager']->setSchedulerState(\task_manager::STATE_TOSTOP);
return $app->json(true);
return $app->json(array('success' => true));
} catch (Exception $e) {
}
return $app->json(false);
return $app->json(array('success' => false));
})->bind('admin_tasks_scheduler_stop');
$controllers->get('/scheduler/log', function(Application $app, Request $request) {
@@ -215,9 +216,9 @@ class TaskManager implements ControllerProviderInterface
$task->resetCrashCounter();
return $app->json(true);
return $app->json(array('success' => true));
} catch (\Exception $e) {
return $app->json(false);
return $app->json(array('success' => false));
}
})->bind('admin_tasks_task_reset');
@@ -234,10 +235,7 @@ class TaskManager implements ControllerProviderInterface
throw new XMLParseErrorException($request->request->get('xml'));
}
} catch (XMLParseErrorException $e) {
return new Response(
$e->getXMLErrMessage(),
412 // Precondition Failed
);
return $app->json(array('success' => false, 'message' => $e->getMessage()));
}
try {
@@ -247,12 +245,9 @@ class TaskManager implements ControllerProviderInterface
$task->setActive(\p4field::isyes($request->request->get('active')));
$task->setSettings($request->request->get('xml'));
return $app->json(true);
return $app->json(array('success' => true));
} catch (\Exception $e) {
return new Response(
'Bad task ID',
404 // Not Found
);
return $app->json(array('success' => false, 'message' => 'Task not found'));
}
})->bind('admin_tasks_task_save');
@@ -346,7 +341,7 @@ class TaskManager implements ControllerProviderInterface
$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"
, async:false
, success:function(data) {
if (data.success) {
$("#taskFormByeBye").submit();
} else {
if (window.console) {
console.log(data.message);
}
alert("{% trans %}An error occured{% endtrans %}");
}
}
, error:function(jqXHR, textStatus, errorThrown) {
alert("Erreur XML:\n\n" + jqXHR.responseText);