Remove platform detection

This commit is contained in:
Romain Neutron
2012-05-24 14:52:20 +02:00
parent a3c87fdf10
commit 2b7c196d13
13 changed files with 106 additions and 185 deletions

View File

@@ -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)

View File

@@ -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()));

View File

@@ -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
</form>
<?php
return;
}

View File

@@ -76,24 +76,4 @@ class system_server
return false;
}
/**
* Return server platform name
*
* @staticvar string $_system
* @return string
*/
public static function get_platform()
{
static $_system = NULL;
if ($_system === NULL) {
$_system = strtoupper(php_uname('s'));
if ($_system == 'WINDOWS NT') {
$_system = 'WINDOWS';
}
}
return($_system);
}
}

View File

@@ -9,21 +9,20 @@
* file that was distributed with this source code.
*/
use Monolog\Logger;
use Symfony\Component\Console\Output\OutputInterface;
/**
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class task_Scheduler
{
const TASKDELAYTOQUIT = 60;
// how to schedule tasks (choose in 'run' method)
const METHOD_FORK = 'METHOD_FORK';
const METHOD_PROC_OPEN = 'METHOD_PROC_OPEN';
const ERR_ALREADY_RUNNING = 114; // aka EALREADY (Operation already in progress)
/**
@@ -32,8 +31,11 @@ class task_Scheduler
*/
private $logger;
private $method;
private $input;
protected $output;
public function __construct(Logger $logger)
{
$this->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';
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$nullfile = 'NUL';
}
if (function_exists('pcntl_fork')) {
$this->method = self::METHOD_FORK;
break;
}
$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"])

View File

@@ -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)
{
if ($this->logger) {
$this->logger->addInfo($message);
}
return $this;
}

View File

@@ -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);

View File

@@ -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) {
}

View File

@@ -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,7 +277,7 @@ 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();
@@ -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;
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+");

View File

@@ -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);
}
}

View File

@@ -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()

View File

@@ -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/";

View File

@@ -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();