fusion task, tasks, scheduler dans taskmanager

todo : tests
This commit is contained in:
jygaulier
2012-09-06 15:26:40 +02:00
parent 6e302e85a4
commit 90841c5ba1
10 changed files with 536 additions and 568 deletions

View File

@@ -27,6 +27,7 @@ use Alchemy\Phrasea\Controller\Admin\Subdefs;
use Alchemy\Phrasea\Controller\Admin\Users; use Alchemy\Phrasea\Controller\Admin\Users;
use Alchemy\Phrasea\Controller\Admin\Tasks; use Alchemy\Phrasea\Controller\Admin\Tasks;
use Alchemy\Phrasea\Controller\Admin\Task; use Alchemy\Phrasea\Controller\Admin\Task;
use Alchemy\Phrasea\Controller\Admin\TaskManager;
use Alchemy\Phrasea\Controller\Admin\Scheduler; use Alchemy\Phrasea\Controller\Admin\Scheduler;
use Alchemy\Phrasea\Controller\Utils\ConnectionTest; use Alchemy\Phrasea\Controller\Utils\ConnectionTest;
use Alchemy\Phrasea\Controller\Utils\PathFileTest; use Alchemy\Phrasea\Controller\Utils\PathFileTest;
@@ -44,9 +45,11 @@ return call_user_func(
$app->mount('/sphinx', new Sphinx()); $app->mount('/sphinx', new Sphinx());
$app->mount('/connected-users', new ConnectedUsers()); $app->mount('/connected-users', new ConnectedUsers());
$app->mount('/tasks', new Tasks()); $app->mount('/task-manager', new TaskManager());
$app->mount('/task', new Task());
$app->mount('/scheduler', new Scheduler()); // $app->mount('/tasks', new Tasks());
// $app->mount('/task', new Task());
// $app->mount('/scheduler', new Scheduler());
$app->mount('/publications', new Publications()); $app->mount('/publications', new Publications());
$app->mount('/users', new Users()); $app->mount('/users', new Users());

View File

@@ -1,131 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2012 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Controller\Admin;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Scheduler implements ControllerProviderInterface
{
public function connect(Application $app)
{
$appbox = \appbox::get_instance($app['phraseanet.core']);
$controllers = $app['controllers_factory'];
/*
* route /admin/scheduler/start
*/
$controllers->get('/start', $this->call('startScheduler'));
/*
* route /admin/scheduler/stop
*/
$controllers->get('/stop', function(Application $app, Request $request) use ($app, $appbox) {
try {
$task_manager = new \task_manager($appbox);
$task_manager->setSchedulerState(\task_manager::STATE_TOSTOP);
return $app->json(true);
} catch (Exception $e) {
}
return $app->json(false);
});
/*
$controllers->before(function(Application $app) {
// todo : check sceduler key
$scheduler_key = \phrasea::scheduler_key();
$user = $app['phraseanet.core']->getAuthenticatedUser();
if ( ! $user || ! $user->ACL()->has_right('task_manager')) {
throw new AccessDeniedHttpException('User can not access task manager');
}
});
*/
return $controllers;
}
public function startScheduler(Application $app, Request $request)
{
set_time_limit(0);
session_write_close();
ignore_user_abort(true);
$app['task-manager']->getSchedulerProcess()->run();
// $nullfile = '/dev/null';
//
// if (defined('PHP_WINDOWS_VERSION_BUILD')) {
// $nullfile = 'NUL';
// }
//
// $phpcli = $registry->get('GV_cli');
//
// $cmd = $phpcli . ' -f ' . $registry->get('GV_RootPath') . "bin/console scheduler:start";
//
// $descriptors[1] = array("file", $nullfile, "a+");
// $descriptors[2] = array("file", $nullfile, "a+");
//
// $pipes = null;
// $cwd = $registry->get('GV_RootPath') . "bin/";
// $proc = proc_open($cmd, $descriptors, $pipes, $cwd, null, array('bypass_shell' => true));
//
// $pid = NULL;
// if (is_resource($proc)) {
// $proc_status = proc_get_status($proc);
// if ($proc_status['running'])
// $pid = $proc_status['pid'];
// }
// if ($pid !== NULL) {
// $msg = sprintf("scheduler '%s' started (pid=%s)", $cmd, $pid);
// // my_syslog(LOG_INFO, $msg);
// } else {
// @fclose($pipes[1]);
// @fclose($pipes[2]);
// @proc_close($process);
//
// $msg = sprintf("scheduler '%s' failed to start", $cmd);
// // my_syslog(LOG_INFO, $msg);
// }
return $app->json(true);
}
/**
* Prefix the method to call with the controller class name
*
* @param string $method The method to call
* @return string
*/
private function call($method)
{
return sprintf('%s::%s', __CLASS__, $method);
}
}

View File

@@ -1,334 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2012 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Controller\Admin;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
use Symfony\Component\Finder\Finder;
class XMLParseErrorException extends \Exception
{
private $_XMLErrMessage = '';
public function getXMLErrMessage()
{
return $this->_XMLErrMessage;
}
public function __construct($xml)
{
set_error_handler(array($this, "errorHandler"));
$dom = new \DomDocument('1.0', 'UTF-8');
@$dom->loadXML($xml);
restore_error_handler();
$this->message = "XML Parse Error";
parent::__construct();
}
public function errorHandler($errno, $errstr, $errfile, $errline)
{
// var_dump($errno, $errstr, $errfile, $errline);
// $pos = strpos($errstr,"]:") ;
// if ($pos) {
// $errstr = substr($errstr,$pos+ 2);
// }
$this->_XMLErrMessage = $errstr;
}
}
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Task implements ControllerProviderInterface
{
public function connect(Application $app)
{
$controllers = $app['controllers_factory'];
/*
* route /admin/task/{id}/log
* show logs of a task
*/
$controllers->get('/{id}/log', function(Application $app, Request $request, $id) {
$appbox = \appbox::get_instance($app['phraseanet.core']);
$registry = $appbox->get_registry();
$logdir = \p4string::addEndSlash($registry->get('GV_RootPath') . 'logs');
$rname = '/task_' . $id . '((\.log)|(-.*\.log))$/';
$finder = new Finder();
$finder
->files()->name($rname)
->in($logdir)
// ->date('> now - 1 days')
->sortByModifiedTime();
$found = false;
foreach ($finder->getIterator() as $file) {
// printf("%s <br/>\n", ($file->getRealPath()));
if ($request->get('clr') == $file->getFilename()) {
file_put_contents($file->getRealPath(), '');
$found = true;
}
}
if ($found) {
return $app->redirect(sprintf("/admin/task/%s/log", urlencode($id)));
}
return $app->stream(
function() use ($finder, $id) {
foreach ($finder->getIterator() as $file) {
printf("<h4>%s\n", $file->getRealPath());
printf("&nbsp;<a href=\"/admin/task/%s/log?clr=%s\">%s</a>"
, $id
, urlencode($file->getFilename())
, _('Clear')
);
print("</h4>\n<pre>\n");
print(htmlentities(file_get_contents($file->getRealPath())));
print("</pre>\n");
ob_flush();
flush();
}
});
});
/*
* route /admin/task/{id}/delete
* delete a task
*/
$controllers->get('/{id}/delete', function(Application $app, Request $request, $id) {
// $appbox = \appbox::get_instance($app['phraseanet.core']);
// $task_manager = new \task_manager($appbox);
try {
$task = $app['task-manager']->getTask($id);
$task->delete();
return $app->redirect('/admin/tasks/');
} catch (\Exception $e) {
/*
* todo : add a message back
*/
return $app->redirect('/admin/tasks/');
}
});
/*
* route /admin/task/{id}/start
* set a task to 'tostart'
*/
$controllers->get('/{id}/tostart', function(Application $app, Request $request, $id) {
$appbox = \appbox::get_instance($app['phraseanet.core']);
$task_manager = new \task_manager($appbox);
$ret = false;
try {
$task = $task_manager->getTask($id);
$pid = (int) ($task->getPID());
if ( ! $pid) {
$task->setState(\task_abstract::STATE_TOSTART);
$ret = true;
}
} catch (Exception $e) {
}
return $app->json($ret);
});
/*
* route /admin/task/{id}/stop
* set a task to 'tostop'
*/
$controllers->get('/{id}/tostop', function(Application $app, Request $request, $id) {
$appbox = \appbox::get_instance($app['phraseanet.core']);
$task_manager = new \task_manager($appbox);
$ret = false;
try {
$task = $task_manager->getTask($id);
$pid = $task->getPID();
$signal = $request->get('signal');
$task->setState(\task_abstract::STATE_TOSTOP);
if ((int) $pid > 0 && (int) $signal > 0 && function_exists('posix_kill')) {
posix_kill((int) $pid, (int) $signal);
}
$ret = true;
} catch (Exception $e) {
}
return $app->json($ret);
});
/*
* route /admin/task/{id}/resetcrashcounter
* return json
*/
$controllers->get('/{id}/resetcrashcounter/', function(Application $app, Request $request, $id) {
$appbox = \appbox::get_instance($app['phraseanet.core']);
$task_manager = new \task_manager($appbox);
try {
$task = $task_manager->getTask($id);
$task->resetCrashCounter();
return $app->json(true);
} catch (\Exception $e) {
return $app->json(false);
}
});
/*
* route /admin/task/{id}/save
* return json
*/
$controllers->post('/{id}/save/', function(Application $app, Request $request, $id) {
$appbox = \appbox::get_instance($app['phraseanet.core']);
$task_manager = new \task_manager($appbox);
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->strictErrorChecking = true;
try {
if ( ! @$dom->loadXML($request->get('xml'))) {
throw new XMLParseErrorException($request->get('xml'));
}
} catch (XMLParseErrorException $e) {
return new Response(
$e->getXMLErrMessage(),
412 // Precondition Failed
);
}
try {
$task = $task_manager->getTask($id);
$task->setTitle($request->get('title'));
$task->setActive(\p4field::isyes($request->get('active')));
$task->setSettings($request->get('xml'));
return $app->json(true);
} catch (\Exception $e) {
return new Response(
'Bad task ID',
404 // Not Found
);
}
});
/*
* route /admin/task/{id}/facility/
* call callback(s) of a task, for ex. to transform gui(form) to xml settings
*/
$controllers->post('/{id}/facility/', function(Application $app, Request $request, $id) {
$appbox = \appbox::get_instance($app['phraseanet.core']);
$task_manager = new \task_manager($appbox);
$ret = '';
try {
$task = $task_manager->getTask($id);
} catch (\Exception $e) {
return new Response(
'Bad task ID',
404 // Not Found
);
}
switch ($request->get('__action')) {
case 'FORM2XML':
if (@simplexml_load_string($request->get('__xml'))) {
$ret = $task->graphic2xml($request->get('__xml'));
} else {
$ret = new Response(
'Bad XML',
412 // Precondition Failed
);
}
break;
case null:
// no __action, so delegates to the task (call method "facility")
if(method_exists($task, 'facility'))
{
$ret = $task->facility();
}
break;
default:
$ret = new Response(
'Bad action',
404 // Not Found
);
break;
}
return $ret;
});
/*
* route /admin/task/{id}
* render a task editing interface
*/
$controllers->get('/{id}', function(Application $app, Request $request, $id) {
$appbox = \appbox::get_instance($app['phraseanet.core']);
$task_manager = new \task_manager($appbox);
$task = $task_manager->getTask($id);
/* @var $twig \Twig_Environment */
$twig = $app['phraseanet.core']->getTwig();
$template = 'admin/task.html.twig';
return $twig->render($template, array(
'task' => $task,
'view' => 'XML'
));
});
/*
* route /admin/task/checkxml/
* check if the xml is valid
*/
$controllers->post('/checkxml/', function(Application $app, Request $request) {
$ret = array('ok' => true, 'err' => null);
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->strictErrorChecking = true;
try {
if ( ! @$dom->loadXML($request->get('xml'))) {
throw new XMLParseErrorException($request->get('xml'));
}
$ret = $app->json($ret);
} catch (XMLParseErrorException $e) {
$ret = new Response(
$e->getXMLErrMessage(),
412 // Precondition Failed
);
}
return $ret;
});
return $controllers;
}
}

View File

@@ -0,0 +1,512 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2010 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Controller\Admin;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Finder\Finder;
class TaskManager implements ControllerProviderInterface
{
public function connect(Application $app)
{
$controllers = $app['controllers_factory'];
$controllers->get('/', function(Application $app, Request $request) {
return $app->redirect('/admin/task-manager/tasks/');
});
/*
* route /admin/task-manager/tasks/
* tasks status in json
* or
* task manager page in html
*/
$controllers->get('/tasks/', function(Application $app, Request $request) {
$task_manager = new \task_manager($app['phraseanet.appbox']);
if ($request->getContentType() == 'json') {
return $app->json($task_manager->toArray());
} else {
$template = 'admin/tasks/list.html.twig';
/* @var $twig \Twig_Environment */
$twig = $app['phraseanet.core']->getTwig();
return $twig->render($template, array(
'task_manager' => $task_manager,
'scheduler_key' => \phrasea::scheduler_key()
));
}
});
/**
* route /admin/task-manager/tasks/create
*/
$controllers->post('/tasks/create/', function(Application $app, Request $request) {
$appbox = $app['phraseanet.appbox'];
$user = \User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
$tcl = $request->get('tcl');
if( $tcl )
{
$task = \task_abstract::create($appbox, $tcl);
$tid = $task->getId();
return $app->redirect('/admin/task-manager/task/'.$tid);
// return $tid;
}
return $app->redirect('/admin/task-manager/');
});
/*
* route /admin/taskmanager/scheduler/start
*/
$controllers->get('/scheduler/start', $this->call('startScheduler'));
/*
* route /admin/scheduler/stop
*/
$controllers->get('/scheduler/stop', function(Application $app, Request $request) use ($app) {
try {
$task_manager = new \task_manager($app['phraseanet.appbox']);
$task_manager->setSchedulerState(\task_manager::STATE_TOSTOP);
return $app->json(true);
} catch (Exception $e) {
}
return $app->json(false);
});
$controllers->get('/scheduler/log', function(Application $app, Request $request) {
$appbox = $app['phraseanet.appbox'];
$registry = $appbox->get_registry();
$logdir = \p4string::addEndSlash($registry->get('GV_RootPath') . 'logs');
$rname = '/scheduler((\.log)|(-.*\.log))$/';
$finder = new Finder();
$finder
->files()->name($rname)
->in($logdir)
// ->date('> now - 1 days')
->sortByModifiedTime();
$found = false;
foreach ($finder->getIterator() as $file) {
// printf("%s <br/>\n", ($file->getRealPath()));
if ($request->get('clr') == $file->getFilename()) {
file_put_contents($file->getRealPath(), '');
$found = true;
}
}
if ($found) {
return $app->redirect("/admin/task-manager/scheduler/log");
}
return $app->stream(
function() use ($finder) {
foreach ($finder->getIterator() as $file) {
printf("<h4>%s\n", $file->getRealPath());
printf("&nbsp;<a href=\"/admin/task-manager/scheduler/log?clr=%s\">%s</a>"
, urlencode($file->getFilename())
, _('Clear')
);
print("</h4>\n<pre>\n");
print(htmlentities(file_get_contents($file->getRealPath())));
print("</pre>\n");
ob_flush();
flush();
}
});
});
/*
$controllers->before(function(Application $app) {
// todo : check sceduler key
$scheduler_key = \phrasea::scheduler_key();
$user = $app['phraseanet.core']->getAuthenticatedUser();
if ( ! $user || ! $user->ACL()->has_right('task_manager')) {
throw new AccessDeniedHttpException('User can not access task manager');
}
});
*/
$controllers->get('/task/{id}/log', function(Application $app, Request $request, $id) {
$appbox = $app['phraseanet.appbox'];
$registry = $appbox->get_registry();
$logdir = \p4string::addEndSlash($registry->get('GV_RootPath') . 'logs');
$rname = '/task_' . $id . '((\.log)|(-.*\.log))$/';
$finder = new Finder();
$finder
->files()->name($rname)
->in($logdir)
// ->date('> now - 1 days')
->sortByModifiedTime();
$found = false;
foreach ($finder->getIterator() as $file) {
// printf("%s <br/>\n", ($file->getRealPath()));
if ($request->get('clr') == $file->getFilename()) {
file_put_contents($file->getRealPath(), '');
$found = true;
}
}
if ($found) {
return $app->redirect(sprintf("/admin/task-manager/task/%s/log", urlencode($id)));
}
return $app->stream(
function() use ($finder, $id) {
foreach ($finder->getIterator() as $file) {
printf("<h4>%s\n", $file->getRealPath());
printf("&nbsp;<a href=\"/admin/task-manager/task/%s/log?clr=%s\">%s</a>"
, $id
, urlencode($file->getFilename())
, _('Clear')
);
print("</h4>\n<pre>\n");
print(htmlentities(file_get_contents($file->getRealPath())));
print("</pre>\n");
ob_flush();
flush();
}
});
});
/*
* route /admin/task-manager/task/{id}/delete
* delete a task
*/
$controllers->get('/task/{id}/delete', function(Application $app, Request $request, $id) {
try {
$task = $app['task-manager']->getTask($id);
$task->delete();
return $app->redirect('/admin/task-manager/tasks/');
} catch (\Exception $e) {
/*
* todo : add a message back
*/
return $app->redirect('/admin/task-manager/tasks/');
}
});
/*
* route /admin/task-manager/task/{id}/start
* set a task to 'tostart'
*/
$controllers->get('/task/{id}/tostart', function(Application $app, Request $request, $id) {
$task_manager = new \task_manager($app['phraseanet.appbox']);
$ret = false;
try {
$task = $task_manager->getTask($id);
$pid = (int) ($task->getPID());
if ( ! $pid) {
$task->setState(\task_abstract::STATE_TOSTART);
$ret = true;
}
} catch (Exception $e) {
}
return $app->json($ret);
});
/*
* route /admin/task-manager/task/{id}/stop
* set a task to 'tostop'
*/
$controllers->get('/task/{id}/tostop', function(Application $app, Request $request, $id) {
$task_manager = new \task_manager($app['phraseanet.appbox']);
$ret = false;
try {
$task = $task_manager->getTask($id);
$pid = $task->getPID();
$signal = $request->get('signal');
$task->setState(\task_abstract::STATE_TOSTOP);
if ((int) $pid > 0 && (int) $signal > 0 && function_exists('posix_kill')) {
posix_kill((int) $pid, (int) $signal);
}
$ret = true;
} catch (Exception $e) {
}
return $app->json($ret);
});
/*
* route /admin/task-manager/task/{id}/resetcrashcounter
* return json
*/
$controllers->get('/task/{id}/resetcrashcounter/', function(Application $app, Request $request, $id) {
$task_manager = new \task_manager($app['phraseanet.appbox']);
try {
$task = $task_manager->getTask($id);
$task->resetCrashCounter();
return $app->json(true);
} catch (\Exception $e) {
return $app->json(false);
}
});
/*
* route /admin/task-manager/task/{id}/save
* return json
*/
$controllers->post('/task/{id}/save/', function(Application $app, Request $request, $id) {
$task_manager = new \task_manager($app['phraseanet.appbox']);
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->strictErrorChecking = true;
try {
if ( ! @$dom->loadXML($request->get('xml'))) {
throw new XMLParseErrorException($request->get('xml'));
}
} catch (XMLParseErrorException $e) {
return new Response(
$e->getXMLErrMessage(),
412 // Precondition Failed
);
}
try {
$task = $task_manager->getTask($id);
$task->setTitle($request->get('title'));
$task->setActive(\p4field::isyes($request->get('active')));
$task->setSettings($request->get('xml'));
return $app->json(true);
} catch (\Exception $e) {
return new Response(
'Bad task ID',
404 // Not Found
);
}
});
/*
* route /admin/task-manager/task/{id}/facility/
* call callback(s) of a task, for ex. to transform gui(form) to xml settings
*/
$controllers->post('/task/{id}/facility/', function(Application $app, Request $request, $id) {
$task_manager = new \task_manager($app['phraseanet.appbox']);
$ret = '';
try {
$task = $task_manager->getTask($id);
} catch (\Exception $e) {
return new Response(
'Bad task ID',
404 // Not Found
);
}
switch ($request->get('__action')) {
case 'FORM2XML':
if (@simplexml_load_string($request->get('__xml'))) {
$ret = $task->graphic2xml($request->get('__xml'));
} else {
$ret = new Response(
'Bad XML',
412 // Precondition Failed
);
}
break;
case null:
// no __action, so delegates to the task (call method "facility")
if (method_exists($task, 'facility')) {
$ret = $task->facility();
}
break;
default:
$ret = new Response(
'Bad action',
404 // Not Found
);
break;
}
return $ret;
});
/*
* route /admin/task-manager/task/{id}
* render a task editing interface
*/
$controllers->get('/task/{id}', function(Application $app, Request $request, $id) {
$task_manager = new \task_manager($app['phraseanet.appbox']);
$task = $task_manager->getTask($id);
/* @var $twig \Twig_Environment */
$twig = $app['phraseanet.core']->getTwig();
$template = 'admin/task.html.twig';
return $twig->render($template, array(
'task' => $task,
'view' => 'XML'
));
});
/*
* route /admin/task/checkxml/
* check if the xml is valid
*/
$controllers->post('/task/checkxml/', function(Application $app, Request $request) {
$ret = array('ok' => true, 'err' => null);
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->strictErrorChecking = true;
try {
if ( ! @$dom->loadXML($request->get('xml'))) {
throw new XMLParseErrorException($request->get('xml'));
}
$ret = $app->json($ret);
} catch (XMLParseErrorException $e) {
$ret = new Response(
$e->getXMLErrMessage(),
412 // Precondition Failed
);
}
return $ret;
});
return $controllers;
}
public function startScheduler(Application $app, Request $request)
{
set_time_limit(0);
session_write_close();
ignore_user_abort(true);
$app['task-manager']->getSchedulerProcess()->run();
// $nullfile = '/dev/null';
//
// if (defined('PHP_WINDOWS_VERSION_BUILD')) {
// $nullfile = 'NUL';
// }
//
// $phpcli = $registry->get('GV_cli');
//
// $cmd = $phpcli . ' -f ' . $registry->get('GV_RootPath') . "bin/console scheduler:start";
//
// $descriptors[1] = array("file", $nullfile, "a+");
// $descriptors[2] = array("file", $nullfile, "a+");
//
// $pipes = null;
// $cwd = $registry->get('GV_RootPath') . "bin/";
// $proc = proc_open($cmd, $descriptors, $pipes, $cwd, null, array('bypass_shell' => true));
//
// $pid = NULL;
// if (is_resource($proc)) {
// $proc_status = proc_get_status($proc);
// if ($proc_status['running'])
// $pid = $proc_status['pid'];
// }
// if ($pid !== NULL) {
// $msg = sprintf("scheduler '%s' started (pid=%s)", $cmd, $pid);
// // my_syslog(LOG_INFO, $msg);
// } else {
// @fclose($pipes[1]);
// @fclose($pipes[2]);
// @proc_close($process);
//
// $msg = sprintf("scheduler '%s' failed to start", $cmd);
// // my_syslog(LOG_INFO, $msg);
// }
return $app->json(true);
}
/**
* Prefix the method to call with the controller class name
*
* @param string $method The method to call
* @return string
*/
private function call($method)
{
return sprintf('%s::%s', __CLASS__, $method);
}
}

View File

@@ -1,80 +0,0 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2012 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Controller\Admin;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Silex\Application;
use Silex\ControllerProviderInterface;
use Silex\ControllerCollection;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class Tasks implements ControllerProviderInterface
{
public function connect(Application $app)
{
$controllers = $app['controllers_factory'];
/*
* route /admin/tasks/
* tasks status in json
* or
* task manager page in html
*/
$controllers->get('/', function(Application $app, Request $request) {
$appbox = \appbox::get_instance($app['phraseanet.core']);
$task_manager = new \task_manager($appbox);
if ($request->getContentType() == 'json') {
return $app->json($task_manager->toArray());
} else {
$template = 'admin/tasks/list.html.twig';
/* @var $twig \Twig_Environment */
$twig = $app['phraseanet.core']->getTwig();
return $twig->render($template, array(
'task_manager' => $task_manager,
'scheduler_key' => \phrasea::scheduler_key()
));
}
});
/**
* route /admin/tasks/create
*/
$controllers->post('/create/', function(Application $app, Request $request) {
$appbox = \appbox::get_instance($app['phraseanet.core']);
$user = \User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox);
$tcl = $request->get('tcl');
if( $tcl )
{
$task = \task_abstract::create($appbox, $tcl);
$tid = $task->getId();
return $app->redirect('/admin/task/'.$tid);
// return $tid;
}
return $app->redirect('/admin/publications/list/');
});
return $controllers;
}
}

View File

@@ -102,12 +102,13 @@ class module_console_taskrun extends Command
if ($input->getOption('verbose')) { if ($input->getOption('verbose')) {
$handler = new Handler\StreamHandler(fopen('php://stdout', 'a')); $handler = new Handler\StreamHandler(fopen('php://stdout', 'a'));
$this->container['monolog']->pushHandler($handler); $this->container['phraseanet.core']['monolog']->pushHandler($handler);
} }
$logfile = __DIR__ . '/../../../../logs/task_' . $task_id . '.log'; $logfile = __DIR__ . '/../../../../logs/task_' . $task_id . '.log';
$handler = new Handler\RotatingFileHandler($logfile, 10); $handler = new Handler\RotatingFileHandler($logfile, 10);
$this->container['monolog']->pushHandler($handler); $this->container['phraseanet.core']['monolog']->pushHandler($handler);
$logger = $this->container['phraseanet.core']['monolog'];
$this->task = $task_manager->getTask($task_id, $logger); $this->task = $task_manager->getTask($task_id, $logger);
register_tick_function(array($this, 'tick_handler'), true); register_tick_function(array($this, 'tick_handler'), true);

View File

@@ -196,7 +196,7 @@ class task_period_cindexer extends task_abstract
socket.value = xml.find("socket").text(); socket.value = xml.find("socket").text();
password.value = xml.find("password").text(); password.value = xml.find("password").text();
clng.value = xml.find("clng").text(); clng.value = xml.find("clng").text();
use_sbas.checked = isyes(xml.find("use_sbas").text()); use_sbas.checked = true | isyes(xml.find("use_sbas").text());
nolog.checked = isyes(xml.find("nolog").text()); nolog.checked = isyes(xml.find("nolog").text());
winsvc_run.checked = isyes(xml.find("winsvc_run").text()); winsvc_run.checked = isyes(xml.find("winsvc_run").text());
charset.value = xml.find("charset").text(); charset.value = xml.find("charset").text();
@@ -207,6 +207,8 @@ class task_period_cindexer extends task_abstract
var cmd = ''; var cmd = '';
with(document.forms['graphicForm']) with(document.forms['graphicForm'])
{ {
use_sbas.checked = true;
cmd += binpath.value + "/<?php echo $appname ?>"; cmd += binpath.value + "/<?php echo $appname ?>";
if(host.value) if(host.value)
cmd += " -h=" + host.value; cmd += " -h=" + host.value;
@@ -222,7 +224,7 @@ class task_period_cindexer extends task_abstract
cmd += " --socket=" + socket.value; cmd += " --socket=" + socket.value;
if(charset.value) if(charset.value)
cmd += " --default-character-set=" + charset.value; cmd += " --default-character-set=" + charset.value;
if(use_sbas.checked) if(1 || use_sbas.checked)
cmd += " -o"; cmd += " -o";
if(nolog.checked) if(nolog.checked)
cmd += " -n"; cmd += " -n";
@@ -286,7 +288,7 @@ class task_period_cindexer extends task_abstract
<?php echo _('task::cindexer:Debug mask') ?>&nbsp;:&nbsp;<input type="text" name="debugmask" style="width:50px;" value=""> <?php echo _('task::cindexer:Debug mask') ?>&nbsp;:&nbsp;<input type="text" name="debugmask" style="width:50px;" value="">
<br/> <br/>
<input type="checkbox" name="use_sbas">&nbsp;<?php echo _('task::cindexer:use table \'sbas\' (unchecked: use \'xbas\')') ?> <input type="checkbox" name="use_sbas" checked="checked" disabled="disabled">&nbsp;<?php echo _('task::cindexer:use table \'sbas\' (unchecked: use \'xbas\')') ?>
<br/> <br/>
<?php echo _('task::cindexer:default language for new candidates') ?>&nbsp;:&nbsp;<input type="text" name="clng" style="width:50px;" value=""> <?php echo _('task::cindexer:default language for new candidates') ?>&nbsp;:&nbsp;<input type="text" name="clng" style="width:50px;" value="">
@@ -381,7 +383,7 @@ class task_period_cindexer extends task_abstract
$args[] = '--socket=' . $this->socket; $args[] = '--socket=' . $this->socket;
$args_nopwd[] = '--socket=' . $this->socket; $args_nopwd[] = '--socket=' . $this->socket;
} }
if ($this->use_sbas) { if (1 || $this->use_sbas) {
$args[] = '-o'; $args[] = '-o';
$args_nopwd[] = '-o'; $args_nopwd[] = '-o';
} }

View File

@@ -27,7 +27,7 @@
<label for="taskTaskActive">{% trans 'admin::tasks: lancer au demarrage du scheduler' %}</label> <label for="taskTaskActive">{% trans 'admin::tasks: lancer au demarrage du scheduler' %}</label>
<input type="checkbox" id="taskTaskActive" {% if task.isActive() %}checked="checked"{% endif %} onchange="setDirty();" /> <input type="checkbox" id="taskTaskActive" {% if task.isActive() %}checked="checked"{% endif %} onchange="setDirty();" />
</form> </form>
<div id="idCrashLine" style="visibility:{% if task.getCrashCounter() == 0 %}not-hidden{% endif %}"> <div id="idCrashLine" style="display:{% if task.getCrashCounter() == 0 %}none{% endif %}">
{% trans 'admin::tasks: Nombre de crashes : ' %} {{task.getCrashCounter()}} {% trans 'admin::tasks: Nombre de crashes : ' %} {{task.getCrashCounter()}}
<button id="taskResetCrashCounterButton"> <button id="taskResetCrashCounterButton">
@@ -60,7 +60,7 @@
<!-- ___________ form to go back on list ___________ --> <!-- ___________ form to go back on list ___________ -->
<form id="taskFormByeBye" action="./tasks/" method="get"> <form id="taskFormByeBye" action="./task-manager/tasks/" method="get">
</form> </form>
<!-- __________ end form to go back on list __________ --> <!-- __________ end form to go back on list __________ -->
@@ -100,7 +100,7 @@
case "taskGuiTab": case "taskGuiTab":
var context = { acceptTab: true }; var context = { acceptTab: true };
// click on gui tab : fill the gui from xml, then switch to the gui view // click on gui tab : fill the gui from xml, then switch to the gui view
$.ajax({ url: "/admin/task/checkxml/" $.ajax({ url: "/admin/task-manager/task/checkxml/"
, context:context , context:context
, data: {xml:$("#txtareaxml").val()} , data: {xml:$("#txtareaxml").val()}
, dataType:'text' , dataType:'text'
@@ -137,7 +137,7 @@
var data = $("form[name='graphicForm']").serializeJSON(); var data = $("form[name='graphicForm']").serializeJSON();
data["__action"] = "FORM2XML"; data["__action"] = "FORM2XML";
data["__xml"] = $("#txtareaxml").val(); data["__xml"] = $("#txtareaxml").val();
$.ajax({ url: "/admin/task/{{task.getID()}}/facility/" $.ajax({ url: "/admin/task-manager/task/{{task.getID()}}/facility/"
, data: data , data: data
, dataType:'text' , dataType:'text'
, type:"POST" , type:"POST"
@@ -163,7 +163,7 @@
$("#taskResetCrashCounterButton").click(function() $("#taskResetCrashCounterButton").click(function()
{ {
// click on resetCrashCounter button // click on resetCrashCounter button
$.ajax({ url: "/admin/task/{{task.getID()}}/resetcrashcounter/" $.ajax({ url: "/admin/task-manager/task/{{task.getID()}}/resetcrashcounter/"
, data: {} , data: {}
, dataType:'json' , dataType:'json'
, type:"GET" , type:"GET"
@@ -181,7 +181,7 @@
$("#taskSaveButton").click(function() $("#taskSaveButton").click(function()
{ {
// click on save button // click on save button
$.ajax({ url: "/admin/task/{{task.getID()}}/save/" $.ajax({ url: "/admin/task-manager/task/{{task.getID()}}/save/"
, data: { , data: {
title:$("#taskTaskname").val(), title:$("#taskTaskname").val(),
active:!!$("#taskTaskActive").attr("checked"), active:!!$("#taskTaskActive").attr("checked"),

View File

@@ -64,13 +64,7 @@
{% if user.ACL().has_right('taskmanager') %} {% if user.ACL().has_right('taskmanager') %}
<li class="{% if feature == 'taskmanager' %}selected{% endif %}"> <li class="{% if feature == 'taskmanager' %}selected{% endif %}">
<a target="right" href="taskmanager.php"> <a target="right" href="/admin/task-manager/tasks/" class="ajax">
<img src="/skins/admin/TaskManager.png" />
<span>{% trans 'admin::utilisateurs: gestionnaire de taches' %}</span>
</a>
</li>
<li class="{% if feature == 'taskmanager' %}selected{% endif %}">
<a target="right" href="/admin/tasks/" class="ajax">
<img src="/skins/admin/TaskManager.png" /> <img src="/skins/admin/TaskManager.png" />
{% trans 'admin::utilisateurs: gestionnaire de taches 2' %} {% trans 'admin::utilisateurs: gestionnaire de taches 2' %}
</a> </a>

View File

@@ -6,7 +6,7 @@
RewriteRule ^(mail-export)/([a-zA-Z0-9]*)\/?$ /include/download_anonymous.php?type=$1&token=$2 [L] RewriteRule ^(mail-export)/([a-zA-Z0-9]*)\/?$ /include/download_anonymous.php?type=$1&token=$2 [L]
RewriteRule ^(mail-export)/([a-zA-Z0-9]*)\/get$ /include/download_anonymous.php?type=$1&token=$2&get=1 [L] RewriteRule ^(mail-export)/([a-zA-Z0-9]*)\/get$ /include/download_anonymous.php?type=$1&token=$2&get=1 [L]
RewriteRule ^admin/.*$ /admin/router.php [L] RewriteRule ^admin/$ /admin/router.php [L]
RewriteRule ^admin/databox/.*$ /admin/router.php [L] RewriteRule ^admin/databox/.*$ /admin/router.php [L]
RewriteRule ^admin/sphinx/.*$ /admin/router.php [L] RewriteRule ^admin/sphinx/.*$ /admin/router.php [L]
RewriteRule ^admin/structure/.*$ /admin/router.php [L] RewriteRule ^admin/structure/.*$ /admin/router.php [L]
@@ -25,6 +25,7 @@
RewriteRule ^admin/subdefs/.*$ /admin/router.php [L] RewriteRule ^admin/subdefs/.*$ /admin/router.php [L]
RewriteRule ^admin/tasks/.*$ /admin/router.php [L] RewriteRule ^admin/tasks/.*$ /admin/router.php [L]
RewriteRule ^admin/task/.*$ /admin/router.php [L] RewriteRule ^admin/task/.*$ /admin/router.php [L]
RewriteRule ^admin/task-manager/.*$ /admin/router.php [L]
RewriteRule ^admin/scheduler/.*$ /admin/router.php [L] RewriteRule ^admin/scheduler/.*$ /admin/router.php [L]
RewriteRule ^prod/records/edit/.*$ /prod/router.php [L] RewriteRule ^prod/records/edit/.*$ /prod/router.php [L]