diff --git a/lib/classes/module/console/schedulerStart.class.php b/lib/classes/module/console/schedulerStart.class.php index dc4a3180ed..3455c30595 100644 --- a/lib/classes/module/console/schedulerStart.class.php +++ b/lib/classes/module/console/schedulerStart.class.php @@ -52,8 +52,8 @@ class module_console_schedulerStart extends Command $logger->pushHandler($handler); try { - $scheduler = new task_Scheduler(); - $scheduler->run($logger); + $scheduler = new task_Scheduler($logger); + $scheduler->run(); } catch (\Exception $e) { switch ($e->getCode()) { case task_Scheduler::ERR_ALREADY_RUNNING: // 114 : aka EALREADY (Operation already in progress) diff --git a/lib/classes/module/console/taskrun.class.php b/lib/classes/module/console/taskrun.class.php index c537b8a007..ab2169016c 100755 --- a/lib/classes/module/console/taskrun.class.php +++ b/lib/classes/module/console/taskrun.class.php @@ -81,7 +81,6 @@ class module_console_taskrun extends Command $appbox = \appbox::get_instance(\bootstrap::getCore()); $task_manager = new task_manager($appbox); - $this->task = $task_manager->getTask($task_id); if ($input->getOption('runner') === task_abstract::RUNNER_MANUAL) { $schedStatus = $task_manager->getSchedulerState(); @@ -109,6 +108,8 @@ class module_console_taskrun extends Command $handler = new Handler\RotatingFileHandler($logfile, 10, $level = Logger::WARNING); $logger->pushHandler($handler); + $this->task = $task_manager->getTask($task_id, $logger); + register_tick_function(array($this, 'tick_handler'), true); declare(ticks = 1); @@ -117,7 +118,7 @@ class module_console_taskrun extends Command } try { - $this->task->run($runner, $logger); + $this->task->run($runner); } catch (Exception $e) { $this->task->log(sprintf("taskrun : exception from 'run()', %s \n", $e->getMessage())); diff --git a/lib/classes/setup.class.php b/lib/classes/setup.class.php index d8dc60a0d6..b39215458e 100644 --- a/lib/classes/setup.class.php +++ b/lib/classes/setup.class.php @@ -237,42 +237,56 @@ class setup public static function discover_binaries() { - if (system_server::get_platform() == 'WINDOWS') { - $indexer = dirname(dirname(__DIR__)) . '/bin/phraseanet_indexer.exe'; - } else { - $indexer = null; - } + $finder = new \Symfony\Component\Process\ExecutableFinder(); return array( - 'php' => array('name' => 'PHP CLI', 'binary' => self::discover_binary('php')), - 'phraseanet_indexer' => array('name' => 'Indexeur Phrasea', 'binary' => self::discover_binary('phraseanet_indexer', array($indexer))), - 'convert' => array('name' => 'ImageMagick (convert)', 'binary' => self::discover_binary('convert')), - 'composite' => array('name' => 'ImageMagick (composite)', 'binary' => self::discover_binary('composite')), - 'pdf2swf' => array('name' => 'PDF 2 SWF', 'binary' => self::discover_binary('pdf2swf')), - 'unoconv' => array('name' => 'Unoconv', 'binary' => self::discover_binary('unoconv')), - 'swfextract' => array('name' => 'SWFextract', 'binary' => self::discover_binary('swfextract')), - 'swfrender' => array('name' => 'SWFrender', 'binary' => self::discover_binary('swfrender')), - 'MP4Box' => array('name' => 'MP4Box', 'binary' => self::discover_binary('MP4Box')), - 'xpdf' => array('name' => 'XPDF', 'binary' => self::discover_binary('xpdf')), - 'ffmpeg' => array('name' => 'FFmpeg', 'binary' => self::discover_binary('ffmpeg')), + 'php' => array( + 'name' => 'PHP CLI', + 'binary' => $finder->find('php') + ), + 'phraseanet_indexer' => array( + 'name' => 'Indexeur Phrasea', + 'binary' => $finder->find('phraseanet_indexer') + ), + 'convert' => array( + 'name' => 'ImageMagick (convert)', + 'binary' => $finder->find('convert') + ), + 'composite' => array( + 'name' => 'ImageMagick (composite)', + 'binary' => $finder->find('composite') + ), + 'pdf2swf' => array( + 'name' => 'PDF 2 SWF', + 'binary' => $finder->find('pdf2swf') + ), + 'unoconv' => array( + 'name' => 'Unoconv', + 'binary' => $finder->find('unoconv') + ), + 'swfextract' => array( + 'name' => 'SWFextract', + 'binary' => $finder->find('swfextract') + ), + 'swfrender' => array( + 'name' => 'SWFrender', + 'binary' => $finder->find('swfrender') + ), + 'MP4Box' => array( + 'name' => 'MP4Box', + 'binary' => $finder->find('MP4Box') + ), + 'xpdf' => array( + 'name' => 'XPDF', + 'binary' => $finder->find('xpdf') + ), + 'ffmpeg' => array( + 'name' => 'FFmpeg', + 'binary' => $finder->find('ffmpeg') + ), ); } - protected static function discover_binary($binary, array $look_here = array()) - { - if (system_server::get_platform() == 'WINDOWS') { - return null; - } - - foreach ($look_here as $place) { - if (is_executable($place)) { - return $place; - } - } - - return exec(sprintf('which %s', $binary)); - } - public function check_mod_auth_token() { $registry = registry::get_instance(); @@ -473,7 +487,6 @@ class setup logger = $logger; + } protected function log($message) { @@ -47,30 +49,25 @@ class task_Scheduler return appbox::get_instance(\bootstrap::getCore())->get_connection(); } - /* + /** * @throws Exception if scheduler is already running * @todo doc all possible exception */ - public function run(\Monolog\Logger $logger) + public function run() { - $this->logger = $logger; - $appbox = appbox::get_instance(\bootstrap::getCore()); $registry = $appbox->get_registry(); - $nullfile = ''; - $system = system_server::get_platform(); - switch ($system) { - case "WINDOWS": - $nullfile = 'NUL'; - $this->method = self::METHOD_PROC_OPEN; - break; - default: - case "DARWIN": - case "LINUX": - $nullfile = '/dev/null'; - $this->method = self::METHOD_FORK; - break; + $this->method = self::METHOD_PROC_OPEN; + + $nullfile = '/dev/null'; + + if (defined('PHP_WINDOWS_VERSION_BUILD')) { + $nullfile = 'NUL'; + } + + if (function_exists('pcntl_fork')) { + $this->method = self::METHOD_FORK; } $lockdir = $registry->get('GV_RootPath') . 'tmp/locks/'; @@ -320,10 +317,11 @@ class task_Scheduler if ($this->method == self::METHOD_PROC_OPEN) { if ( ! $taskPoll[$tkey]["process"]) { - $tmpFile = tempnam(sys_get_temp_dir(), 'task'); - $descriptors[1] = array('file', $tmpFile, 'a+'); - $descriptors[2] = array('file', $tmpFile, 'a+'); + $nullfile = defined('PHP_WINDOWS_VERSION_BUILD') ? 'NUL' : '/dev/null'; + + $descriptors[1] = array('file', $nullfile, 'a+'); + $descriptors[2] = array('file', $nullfile, 'a+'); $taskPoll[$tkey]["process"] = proc_open( $taskPoll[$tkey]["cmd"] . ' ' . implode(' ', $taskPoll[$tkey]["args"]) diff --git a/lib/classes/task/abstract.class.php b/lib/classes/task/abstract.class.php index 9b74ead79e..0074d75303 100755 --- a/lib/classes/task/abstract.class.php +++ b/lib/classes/task/abstract.class.php @@ -283,26 +283,15 @@ abstract class task_abstract abstract public function help(); - public function __construct($taskid) + public function __construct($taskid, Logger $logger) { + $this->logger = $logger; + $this->taskid = $taskid; phrasea::use_i18n(Session_Handler::get_locale()); - $this->system = system_server::get_platform(); - $this->launched_by = array_key_exists("REQUEST_URI", $_SERVER) ? self::LAUCHED_BY_BROWSER : self::LAUCHED_BY_COMMANDLINE; - if ($this->system != "DARWIN" && $this->system != "WINDOWS" && $this->system != "LINUX") { - if ($this->launched_by == self::LAUCHED_BY_COMMANDLINE) { -// printf("Desole, ce programme ne fonctionne pas sous '" . $this->system . "'.\n"); - flush(); - } - exit(-1); - } else { - if ($this->launched_by == self::LAUCHED_BY_COMMANDLINE) { - flush(); - } - } try { $conn = connection::getPDOConnection(); @@ -496,10 +485,8 @@ abstract class task_abstract return $lockFD; } - final public function run($runner, $logger) + final public function run($runner) { - $this->logger = $logger; - $lockFD = $this->lockTask(); $this->setRunner($runner); @@ -680,7 +667,9 @@ abstract class task_abstract public function log($message) { - $this->logger->addInfo($message); + if ($this->logger) { + $this->logger->addInfo($message); + } return $this; } diff --git a/lib/classes/task/databoxAbstract.class.php b/lib/classes/task/databoxAbstract.class.php index 31a353678a..c735a599f3 100755 --- a/lib/classes/task/databoxAbstract.class.php +++ b/lib/classes/task/databoxAbstract.class.php @@ -16,10 +16,6 @@ */ abstract class task_databoxAbstract extends task_abstract { -// abstract public function help(); -// -// abstract public function getName(); - protected $mono_sbas_id; abstract protected function retrieveSbasContent(databox $databox); diff --git a/lib/classes/task/manager.class.php b/lib/classes/task/manager.class.php index c248e7e627..aee0d4786e 100755 --- a/lib/classes/task/manager.class.php +++ b/lib/classes/task/manager.class.php @@ -37,6 +37,8 @@ class task_manager return $this->tasks; } + $core = \bootstrap::getCore(); + $sql = "SELECT task2.* FROM task2 ORDER BY task_id ASC"; $stmt = $this->appbox->get_connection()->prepare($sql); $stmt->execute(); @@ -45,9 +47,6 @@ class task_manager $tasks = array(); - $appbox = \appbox::get_instance(\bootstrap::getCore()); - $lockdir = $appbox->get_registry()->get('GV_RootPath') . 'tmp/locks/'; - foreach ($rs as $row) { $row['pid'] = NULL; @@ -56,21 +55,7 @@ class task_manager continue; } try { -// if( ($lock = fopen( $lockdir . 'task.'.$row['task_id'].'.lock', 'a+')) ) -// { -// if (flock($lock, LOCK_SH | LOCK_NB) === FALSE) -// { -// // already locked : running ! -// $row['pid'] = fgets($lock, 512); -// } -// else -// { -// // can lock : not running -// flock($lock, LOCK_UN); -// } -// fclose($lock); -// } - $tasks[$row['task_id']] = new $classname($row['task_id']); + $tasks[$row['task_id']] = new $classname($row['task_id'], $core['monolog']); } catch (Exception $e) { } diff --git a/lib/classes/task/period/cindexer.class.php b/lib/classes/task/period/cindexer.class.php index 23caea3c6c..e9656f9a4d 100755 --- a/lib/classes/task/period/cindexer.class.php +++ b/lib/classes/task/period/cindexer.class.php @@ -202,7 +202,7 @@ class task_period_cindexer extends task_abstract public function printInterfaceJS() { $appname = 'phraseanet_indexer'; - if ($this->system == 'WINDOWS') { + if (defined('PHP_WINDOWS_VERSION_BUILD')) { $appname .= '.exe'; } ?> @@ -277,17 +277,17 @@ class task_period_cindexer extends task_abstract public function printInterfaceHTML() { $appname = 'phraseanet_indexer'; - if ($this->system == 'WINDOWS') { + if (defined('PHP_WINDOWS_VERSION_BUILD')) { $appname .= '.exe'; } ob_start(); ?>

-  :  +  :   / 
-  :  +  : 
 : 
@@ -299,7 +299,7 @@ class task_period_cindexer extends task_abstract

-  :  +  : 
 : 
@@ -310,20 +310,20 @@ class task_period_cindexer extends task_abstract
-  :  +  : 
 
-  :  +  : 



-  :
+  :
 
@@ -369,20 +369,12 @@ class task_period_cindexer extends task_abstract { $cmd = $this->binpath . 'phraseanet_indexer'; - switch ($this->system) { - case "WINDOWS": - $cmd .= '.exe'; - $nullfile = 'NUL'; - $this->method = self::METHOD_PROC_OPEN; - break; - default: - case "DARWIN": - case "LINUX": - $nullfile = '/dev/null'; - // $this->method = self::METHOD_FORK; - // $this->method = self::METHOD_EXEC; - $this->method = self::METHOD_PROC_OPEN; - break; + $nullfile = '/dev/null'; + $this->method = self::METHOD_PROC_OPEN; + + if (defined('PHP_WINDOWS_VERSION_BUILD')) { + $nullfile = '/dev/null'; + $cmd .= '.exe'; } if ( ! file_exists($cmd) || ! is_executable($cmd)) { @@ -470,7 +462,7 @@ class task_period_cindexer extends task_abstract private function run_with_proc_open($cmd, $args, $args_nopwd) { - $nullfile = $this->system == 'WINDOWS' ? 'NUL' : '/dev/null'; + $nullfile = defined('PHP_WINDOWS_VERSION_BUILD') ? 'NUL' : '/dev/null'; $descriptors = array(); $descriptors[1] = array("file", $nullfile, "a+"); diff --git a/tests/system/system_serverTest.php b/tests/system/system_serverTest.php index abb15fcb87..84a6eee989 100644 --- a/tests/system/system_serverTest.php +++ b/tests/system/system_serverTest.php @@ -41,9 +41,4 @@ class system_serverTest extends PhraseanetPHPUnitAbstract $this->assertFalse($this->objects['lighttpd']->is_apache()); } - public function testGet_platform() - { - $platform = system_server::get_platform(); - $this->assertRegExp('/[A-Z]+/', $platform); - } } diff --git a/tests/task/period/task_period_archiveTest.php b/tests/task/period/task_period_archiveTest.php index f38938cc8a..345b4bb3f9 100644 --- a/tests/task/period/task_period_archiveTest.php +++ b/tests/task/period/task_period_archiveTest.php @@ -2,10 +2,6 @@ require_once __DIR__ . '/../../PhraseanetPHPUnitAbstract.class.inc'; -/** - * Test class for task_period_archive. - * Generated by PHPUnit on 2012-05-22 at 15:54:27. - */ class task_period_archiveTest extends \PhraseanetPHPUnitAbstract { /** @@ -19,7 +15,7 @@ class task_period_archiveTest extends \PhraseanetPHPUnitAbstract $appbox = \appbox::get_instance(\bootstrap::getCore('test')); $task = \task_period_archive::create($appbox, 'task_period_archive'); - self::$object = new archiveTester($task->getID()); + self::$object = new archiveTester($task->getID(), self::$core['monolog']); } public static function tearDownAfterClass() diff --git a/www/admin/runscheduler.php b/www/admin/runscheduler.php index 9042b48b09..be82f880a3 100644 --- a/www/admin/runscheduler.php +++ b/www/admin/runscheduler.php @@ -39,43 +39,19 @@ set_time_limit(0); session_write_close(); ignore_user_abort(true); +$nullfile = '/dev/null'; -$system = system_server::get_platform(); -if ($system != "DARWIN" && $system != "WINDOWS" && $system != "LINUX") { - phrasea::headers(500); +if (defined('PHP_WINDOWS_VERSION_BUILD')) { + $nullfile = 'NUL'; } -$logdir = p4string::addEndSlash($registry->get('GV_RootPath') . 'logs'); $phpcli = $registry->get('GV_cli'); -$nullfile = ''; -switch ($system) { - case "DARWIN": - $cmd = $phpcli . ' -f ' . $registry->get('GV_RootPath') . "bin/console scheduler:start"; - $nullfile = '/dev/null'; - break; - case "LINUX": - $cmd = $phpcli . ' -f ' . $registry->get('GV_RootPath') . "bin/console scheduler:start"; - $nullfile = '/dev/null'; - break; - case "WINDOWS": - case "WINDOWS NT": - $cmd = $phpcli . ' -f ' . $registry->get('GV_RootPath') . "bin/console scheduler:start"; - $nullfile = 'NUL'; - break; -} +$cmd = $phpcli . ' -f ' . $registry->get('GV_RootPath') . "bin/console scheduler:start"; -//if ($logdir) -//{ -// $descriptors[1] = array("file", $logdir . "scheduler.log", "a+"); -// $descriptors[2] = array("file", $logdir . "scheduler.error.log", "a+"); -//} -//else -//{ $descriptors[1] = array("file", $nullfile, "a+"); $descriptors[2] = array("file", $nullfile, "a+"); -//} $pipes = null; $cwd = $registry->get('GV_RootPath') . "bin/"; diff --git a/www/admin/taskfacility.php b/www/admin/taskfacility.php index e59bcafe5f..d54294d7f3 100644 --- a/www/admin/taskfacility.php +++ b/www/admin/taskfacility.php @@ -14,13 +14,13 @@ * @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @link www.phraseanet.com */ -require_once dirname(dirname(__DIR__)) . "/lib/bootstrap.php"; +$Core = require_once dirname(dirname(__DIR__)) . "/lib/bootstrap.php"; $request = http_request::getInstance(); $parm = $request->get_parms('cls', 'taskid'); $cls = 'task_period_' . $parm['cls']; -$ztask = new $cls($parm['taskid']); +$ztask = new $cls($parm['taskid'], $Core['monolog']); echo $ztask->facility();