diff --git a/lib/Alchemy/Phrasea/Application/Admin.php b/lib/Alchemy/Phrasea/Application/Admin.php index 8bb1b4dbbf..ae6a7bdf27 100644 --- a/lib/Alchemy/Phrasea/Application/Admin.php +++ b/lib/Alchemy/Phrasea/Application/Admin.php @@ -25,6 +25,9 @@ use Alchemy\Phrasea\Controller\Admin\Setup; use Alchemy\Phrasea\Controller\Admin\Sphinx; use Alchemy\Phrasea\Controller\Admin\Subdefs; use Alchemy\Phrasea\Controller\Admin\Users; +use Alchemy\Phrasea\Controller\Admin\Tasks; +use Alchemy\Phrasea\Controller\Admin\Task; +use Alchemy\Phrasea\Controller\Admin\Scheduler; use Alchemy\Phrasea\Controller\Utils\ConnectionTest; use Alchemy\Phrasea\Controller\Utils\PathFileTest; @@ -40,6 +43,10 @@ return call_user_func( $app->mount('/setup', new Setup()); $app->mount('/sphinx', new Sphinx()); $app->mount('/connected-users', new ConnectedUsers()); + $app->mount('/tasks', new Tasks()); + $app->mount('/task', new Task()); + $app->mount('/scheduler', new Scheduler()); + $app->mount('/publications', new Publications()); $app->mount('/users', new Users()); $app->mount('/fields', new Fields()); diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Scheduler.php b/lib/Alchemy/Phrasea/Controller/Admin/Scheduler.php new file mode 100644 index 0000000000..8c53ce4d15 --- /dev/null +++ b/lib/Alchemy/Phrasea/Controller/Admin/Scheduler.php @@ -0,0 +1,50 @@ +get_session(); + + $controllers = $app['controllers_factory']; + + /* + * route /admin/tasks/ + * tasks status in json + * or + * task manager page in html + */ + $controllers->get('/', function(Application $app, Request $request) use ($app) { + $request = $app['request']; + $task_manager = new \task_manager($appbox); + + return ""; + }); + + return $controllers; + } +} diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Task.php b/lib/Alchemy/Phrasea/Controller/Admin/Task.php new file mode 100644 index 0000000000..04bc2a8114 --- /dev/null +++ b/lib/Alchemy/Phrasea/Controller/Admin/Task.php @@ -0,0 +1,85 @@ +get('/{id}/log', function(Application $app, Request $request, $id) use ($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
\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("

%s\n", $file->getRealPath()); + printf(" %s" + , $id + , urlencode($file->getFilename()) + , _('Clear') + ); + print("

\n
\n");
+                                print(htmlentities(file_get_contents($file->getRealPath())));
+                                print("
\n"); + + ob_flush(); + flush(); + } + }); + }); + + return $controllers; + } +} diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Tasks.php b/lib/Alchemy/Phrasea/Controller/Admin/Tasks.php new file mode 100644 index 0000000000..ea5a99b732 --- /dev/null +++ b/lib/Alchemy/Phrasea/Controller/Admin/Tasks.php @@ -0,0 +1,79 @@ +get_session(); + + $controllers = $app['controllers_factory']; + + /* + * route /admin/tasks/ + * tasks status in json + * or + * task manager page in html + */ + $controllers->get('/', function(Application $app, Request $request) use ($appbox) { + $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['Core']->getTwig(); + + return $twig->render($template, array( + 'task_manager' => $task_manager, + 'scheduler_key' => \phrasea::scheduler_key() + )); + } + }); + + /* + $controllers->post('/create/', function() use ($app, $appbox) { + + $user = \User_Adapter::getInstance($appbox->get_session()->get_usr_id(), $appbox); + $request = $app['request']; + + $feed = \Feed_Adapter::create($appbox, $user, $request->get('title'), $request->get('subtitle')); + + if ($request->get('public') == '1') + $feed->set_public(true); + elseif ($request->get('base_id')) + $feed->set_collection(\collection::get_from_base_id($request->get('base_id'))); + + return $app->redirect('/admin/publications/list/'); + }); + */ + + return $controllers; + } +} diff --git a/lib/classes/task/manager.class.php b/lib/classes/task/manager.class.php index 6f4d7e4505..014f1f1135 100755 --- a/lib/classes/task/manager.class.php +++ b/lib/classes/task/manager.class.php @@ -33,6 +33,38 @@ class task_manager return $this; } + /** + * status of scheduler and tasks + * used do refresh the taskmanager page + * + * @return array + */ + public function toArray() + { + $ret = array( + 'time' => date("H:i:s"), + 'scheduler' => $this->getSchedulerState(), + 'tasks' => array() + ); + + foreach ($this->getTasks(true) as $task) { + if ($task->getState() == self::STATE_TOSTOP && $task->getPID() === NULL) { + // fix + $task->setState(self::STATE_STOPPED); + } + $id = $task->getID(); + $ret['tasks'][$id] = array( + 'id' => $id, + 'pid' => $task->getPID(), + 'crashed' => $task->getCrashCounter(), + 'completed' => $task->getCompletedPercentage(), + 'status' => $task->getState() + ); + } + + return $ret; + } + public function getTasks($refresh = false, Logger $logger = null) { if ($this->tasks && ! $refresh) { diff --git a/templates/web/admin/index.html.twig b/templates/web/admin/index.html.twig index d68a4cf047..3b2b9042ba 100644 --- a/templates/web/admin/index.html.twig +++ b/templates/web/admin/index.html.twig @@ -18,6 +18,7 @@ +