get_parms(
'binpath', 'host', 'port', 'base', 'user', 'password', 'socket', 'use_sbas', 'nolog', 'clng', 'winsvc_run', 'charset'
);
$dom = new DOMDocument();
$dom->formatOutput = true;
if ($dom->loadXML($oldxml))
{
$xmlchanged = false;
foreach (array("str:binpath", "str:host", "str:port", "str:base", "str:user", "str:password", "str:socket", "boo:use_sbas", "boo:nolog", "str:clng", "boo:winsvc_run", "str:charset") as $pname)
{
$ptype = substr($pname, 0, 3);
$pname = substr($pname, 4);
$pvalue = $parm2[$pname];
if ($ns = $dom->getElementsByTagName($pname)->item(0))
{
// le champ existait dans le xml, on supprime son ancienne valeur (tout le contenu)
while (($n = $ns->firstChild))
$ns->removeChild($n);
}
else
{
// le champ n'existait pas dans le xml, on le cr�e
$ns = $dom->documentElement->appendChild($dom->createElement($pname));
}
// on fixe sa valeur
switch ($ptype)
{
case "str":
$ns->appendChild($dom->createTextNode($pvalue));
break;
case "boo":
$ns->appendChild($dom->createTextNode($pvalue ? '1' : '0'));
break;
}
$xmlchanged = true;
}
}
return($dom->saveXML());
}
/**
*
* @param string $xml
* @param string $form
* @return string
*/
public function xml2graphic($xml, $form)
{
if (($sxml = simplexml_load_string($xml))) // in fact XML IS always valid here...
{
?>
system == 'WINDOWS')
$appname .= '.exe';
?>
system == 'WINDOWS')
$appname .= '.exe';
ob_start();
?>
cmd
host = trim($sx_task_settings->host);
$this->port = trim($sx_task_settings->port);
$this->base = trim($sx_task_settings->base);
$this->user = trim($sx_task_settings->user);
$this->password = trim($sx_task_settings->password);
$this->socket = trim($sx_task_settings->socket);
$this->use_sbas = p4field::isyes(trim($sx_task_settings->use_sbas));
$this->charset = trim($sx_task_settings->charset);
$this->nolog = p4field::isyes(trim($sx_task_settings->nolog));
$this->winsvc_run = p4field::isyes(trim($sx_task_settings->winsvc_run));
$this->binpath = p4string::addEndSlash(trim($sx_task_settings->binpath));
parent::load_settings($sx_task_settings);
return $this;
}
/**
*
* @return string
*/
protected function run2()
{
$cmd = $this->binpath . 'phraseanet_indexer';
$nulfile = '/dev/null';
if ($this->system == 'WINDOWS')
{
$cmd .= '.exe';
$nulfile = 'nul';
}
if (!file_exists($cmd) || !is_executable($cmd))
{
$this->log(sprintf(_('task::cindexer:file \'%s\' does not exists'), $cmd));
return;
}
$cmd .= $this->host ? " -h=" . $this->host : '';
$cmd .= $this->port ? " -P=" . $this->port : '';
$cmd .= $this->base ? " -b=" . $this->base : '';
$cmd .= $this->user ? " -u=" . $this->user : '';
$cmd .= $this->password ? " -p=" . $this->password : '';
$cmd .= $this->socket ? " --socket=" . $this->socket : '';
$cmd .= $this->use_sbas ? " -o" : '';
$cmd .= $this->charset ? " --default-character-set=" . $this->charset : '';
$cmd .= $this->nolog ? " -n" : '';
$cmd .= $this->winsvc_run ? " --run" : '';
$registry = registry::get_instance();
$logdir = p4string::addEndSlash($registry->get('GV_RootPath') . 'logs');
$descriptors = array();
$descriptors[1] = array("file", $logdir . "/phraseanet_indexer_" . $this->get_task_id() . ".log", "a+");
$descriptors[2] = array("file", $logdir . "/phraseanet_indexer_" . $this->get_task_id() . ".error.log", "a+");
$pipes = array();
$this->log(sprintf('cmd=\'%s\'', $cmd));
$process = proc_open($cmd, $descriptors, $pipes, $this->binpath, null, array('bypass_shell' => true));
$pid = NULL;
if (is_resource($process))
{
$proc_status = proc_get_status($process);
if ($proc_status['running'])
$pid = $proc_status['pid'];
}
$qsent = '';
$timetokill = NULL;
$sock = NULL;
$this->running = true;
while ($this->running)
{
$this->check_task_status();
if ($this->task_status == self::STATUS_TOSTOP && $this->socket > 0)
{
// must quit task, so send 'Q' to port 127.0.0.1:XXXX to cindexer
if (!$qsent && (($sock = socket_create(AF_INET, SOCK_STREAM, 0)) !== false))
{
if (socket_connect($sock, '127.0.0.1', $this->socket) === true)
{
socket_write($sock, 'Q', 1);
socket_write($sock, "\r\n", strlen("\r\n"));
sleep(5);
$qsent = 'Q';
$timetokill = time() + 10;
}
else
{
socket_close($sock);
$sock = NULL;
}
}
}
$proc_status = proc_get_status($process);
if (!$proc_status['running'])
{
// the cindexer died
if ($qsent == 'Q')
$this->log(_('task::cindexer:the cindexer clean-quit'));
elseif ($qsent == 'K')
$this->log(_('task::cindexer:the cindexer has been killed'));
else
$this->log(_('task::cindexer:the cindexer crashed'));
$this->running = false;
}
else
{
if ($qsent == 'Q')
{
if (time() > $timetokill)
{
// must kill cindexer
$this->log(_('task::cindexer:killing the cindexer'));
$qsent = 'K';
proc_terminate($process); // sigint
}
}
}
sleep(5);
}
if ($sock)
{
socket_close($sock);
$sock = NULL;
}
foreach (array_keys($pipes) as $offset)
{
if (is_resource($pipes[$offset]))
fclose($pipes[$offset]);
}
proc_terminate($process); // sigint
proc_close($process);
return self::RETURNSTATUS_STOPPED;
}
}