mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
silexing taskmanager & tasks
This commit is contained in:
@@ -101,6 +101,15 @@ abstract class task_abstract
|
||||
'set' => false, "values" => array(), "usage" => " (no help available)")
|
||||
);
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getClass()
|
||||
{
|
||||
return(get_class($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* get the state of the task (task_abstract::STATE_*)
|
||||
*
|
||||
@@ -227,7 +236,11 @@ abstract class task_abstract
|
||||
*/
|
||||
public function setSettings($settings)
|
||||
{
|
||||
if (@simplexml_load_string($settings) === FALSE) {
|
||||
$dom = new DOMDocument('1.0', 'UTF-8');
|
||||
$dom->preserveWhiteSpace = false;
|
||||
$dom->formatOutput = true;
|
||||
if(!@$dom->loadXML($settings))
|
||||
{
|
||||
throw new Exception_InvalidArgument('Bad XML');
|
||||
}
|
||||
|
||||
@@ -235,12 +248,12 @@ abstract class task_abstract
|
||||
|
||||
$sql = 'UPDATE task2 SET settings = :settings WHERE task_id = :taskid';
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array(':settings' => $settings, ':taskid' => $this->getID()));
|
||||
$stmt->execute(array(':settings' => $dom->saveXML(), ':taskid' => $this->getID()));
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->settings = $settings;
|
||||
|
||||
$this->loadSettings(simplexml_load_string($settings));
|
||||
$this->loadSettings(simplexml_load_string($dom->saveXML()));
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -788,6 +801,16 @@ abstract class task_abstract
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getInterfaceHTML()
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function graphic2xml($oldxml)
|
||||
{
|
||||
return $oldxml;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param appbox $appbox
|
||||
|
@@ -10,6 +10,7 @@
|
||||
*/
|
||||
|
||||
use \Monolog\Logger;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -126,6 +127,15 @@ class task_manager
|
||||
return $tasks[$task_id];
|
||||
}
|
||||
|
||||
public function getSchedulerProcess()
|
||||
{
|
||||
$phpcli = $this->appbox->get_registry()->get('GV_cli');
|
||||
|
||||
$cmd = $phpcli . ' -f ' . $this->appbox->get_registry()->get('GV_RootPath') . "bin/console scheduler:start";
|
||||
|
||||
return new Process($cmd);
|
||||
}
|
||||
|
||||
public function setSchedulerState($status)
|
||||
{
|
||||
$av_status = array(
|
||||
|
@@ -50,6 +50,7 @@ class task_period_RecordMover extends task_appboxAbstract
|
||||
$dom = new DOMDocument();
|
||||
$dom->preserveWhiteSpace = false;
|
||||
$dom->formatOutput = true;
|
||||
|
||||
if ($dom->loadXML($oldxml)) {
|
||||
$xmlchanged = false;
|
||||
// foreach($parm2 as $pname=>$pvalue)
|
||||
@@ -187,7 +188,6 @@ class task_period_RecordMover extends task_appboxAbstract
|
||||
|
||||
</script>
|
||||
<?php
|
||||
|
||||
return "";
|
||||
} else { // ... so we NEVER come here
|
||||
// bad xml
|
||||
@@ -260,40 +260,122 @@ class task_period_RecordMover extends task_appboxAbstract
|
||||
{
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
$(document).ready(
|
||||
function(){
|
||||
});
|
||||
function taskFillGraphic_<?php echo(get_class($this)); ?>(xmltxt)
|
||||
{
|
||||
if(xmltxt)
|
||||
{
|
||||
xml = $.parseXML(xmltxt);
|
||||
xml = $(xml);
|
||||
|
||||
(function( $ ){
|
||||
$.fn.serializeJSON=function() {
|
||||
var json = {};
|
||||
jQuery.map($(this).serializeArray(), function(n, i){
|
||||
json[n['name']] = n['value'];
|
||||
var isyes = function(v) {
|
||||
v = v.toUpperCase().trim();
|
||||
return v=='O' || v=='Y' || v=='OUI' || v=='YES' || v=='1';
|
||||
}
|
||||
|
||||
with(document.forms['graphicForm'])
|
||||
{
|
||||
period.value = xml.find("period").text();
|
||||
logsql.checked = isyes(xml.find("logsql").text());
|
||||
}
|
||||
|
||||
$("#sqlu").text("");
|
||||
$("#sqls").text("");
|
||||
$.ajax({ url: "/admin/task/<?php echo $this->getID() ?>/facility/"
|
||||
, data: {
|
||||
ACT: "CALCTEST",
|
||||
xml: xmltxt
|
||||
}
|
||||
, dataType:'json'
|
||||
, type:"POST"
|
||||
, async:true
|
||||
, success:function(data) {
|
||||
t = "";
|
||||
for (i in data.tasks) {
|
||||
t += "<div class=\"title\"> ";
|
||||
if(data.tasks[i].active)
|
||||
t += "<span class=\"active\"> X </span> ";
|
||||
else
|
||||
t += "<span class=\"notactive\"> X </span> ";
|
||||
if(data.tasks[i].name_htmlencoded)
|
||||
t += "<b>" + data.tasks[i].name_htmlencoded + "</b>";
|
||||
else
|
||||
t += "<b><i>sans nom</i></b>";
|
||||
|
||||
if(data.tasks[i].basename_htmlencoded)
|
||||
t += " (action=" + data.tasks[i].action + ' on ' + data.tasks[i].basename_htmlencoded + ')';
|
||||
else
|
||||
t += " (action=" + data.tasks[i].action + ' on <i>Unknown</i>)';
|
||||
t += "</div>";
|
||||
|
||||
if(data.tasks[i].err_htmlencoded) ;
|
||||
t += "<div class=\"err\">" + data.tasks[i].err_htmlencoded + "</div>";
|
||||
|
||||
t += "<div class=\"sql\">";
|
||||
|
||||
if(data.tasks[i].sql && data.tasks[i].sql.test.sql_htmlencoded)
|
||||
t += "<div class=\"sqltest\">" + data.tasks[i].sql.test.sql_htmlencoded + "</div>";
|
||||
t += "--> <span id=\"SQLRET"+i+"\"><i>wait...</i></span><br/>";
|
||||
|
||||
t += "</div>";
|
||||
}
|
||||
$("#sqla").html(t);
|
||||
|
||||
$.ajax({ url: "/admin/task/<?php echo $this->getID() ?>/facility/"
|
||||
, data: {
|
||||
ACT: "PLAYTEST",
|
||||
xml: xmltxt
|
||||
}
|
||||
, dataType:'json'
|
||||
, type:"POST"
|
||||
, async:true
|
||||
, success:function(data) {
|
||||
for (i in data.tasks) {
|
||||
if (data.tasks[i].sql) {
|
||||
if (data.tasks[i].sql.test.err) {
|
||||
$("#SQLRET"+i).html("err: " + data.tasks[i].sql.test.err);
|
||||
} else {
|
||||
t = '';
|
||||
for(j in data.tasks[i].sql.test.result.rids)
|
||||
t += (t?', ':'') + data.tasks[i].sql.test.result.rids[j];
|
||||
if(data.tasks[i].sql.test.result.rids.length < data.tasks[i].sql.test.result.n)
|
||||
t += ', ...';
|
||||
$("#SQLRET"+i).html("n=" + data.tasks[i].sql.test.result.n + ", rids:(" + t + ")");
|
||||
}
|
||||
} else {
|
||||
$("#SQLRET"+i).html("");
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return json;
|
||||
};
|
||||
})( jQuery );
|
||||
|
||||
|
||||
function chgxmltxt(textinput, fieldname)
|
||||
{
|
||||
var limits = { 'period':{min:1, 'max':1440} , 'delay':{min:0} } ;
|
||||
if (typeof(limits[fieldname])!='undefined') {
|
||||
var v = 0|textinput.value;
|
||||
if(limits[fieldname].min && v < limits[fieldname].min)
|
||||
v = limits[fieldname].min;
|
||||
else if(limits[fieldname].max && v > limits[fieldname].max)
|
||||
v = limits[fieldname].max;
|
||||
textinput.value = v;
|
||||
}
|
||||
setDirty();
|
||||
}
|
||||
function chgxmlck(checkinput, fieldname)
|
||||
{
|
||||
setDirty();
|
||||
}
|
||||
</script>
|
||||
|
||||
$(document).ready(function(){
|
||||
$("#graphicForm *").change(function(){
|
||||
var limits = {
|
||||
'period': {min:10, max:3600, allowempty:false}
|
||||
} ;
|
||||
var name = $(this).attr("name");
|
||||
if(name && limits[name])
|
||||
{
|
||||
var v = $(this).val();
|
||||
if(v != "" || !limits[name].allowempty)
|
||||
{
|
||||
v = 0|v;
|
||||
if(v < limits[name].min)
|
||||
$(this).val(limits[name].min);
|
||||
else if(v > limits[name].max)
|
||||
$(this).val(limits[name].max);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
|
||||
@@ -306,18 +388,17 @@ class task_period_RecordMover extends task_appboxAbstract
|
||||
{
|
||||
ob_start();
|
||||
?>
|
||||
<form name="graphicForm" onsubmit="return(false);" method="post">
|
||||
<form id="graphicForm" name="graphicForm" onsubmit="return(false);" method="post">
|
||||
<?php echo _('task::_common_:periodicite de la tache') ?>
|
||||
<input type="text" name="period" style="width:40px;" onchange="chgxmltxt(this, 'period');" value="" />
|
||||
<input type="text" name="period" style="width:40px;"" value="" />
|
||||
<?php echo _('task::_common_:secondes (unite temporelle)') ?>
|
||||
|
||||
<input type="checkbox" name="logsql" onchange="chgxmlck(this, 'logsql');" /> log changes
|
||||
|
||||
<input type="checkbox" name="logsql" /> log changes
|
||||
</form>
|
||||
<center>
|
||||
<div class="terminal" id="sqla"></div>
|
||||
</center>
|
||||
<?php
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
/**
|
||||
@@ -337,7 +418,7 @@ class task_period_RecordMover extends task_appboxAbstract
|
||||
{
|
||||
$this->maxrecs = 1000;
|
||||
$this->sxTaskSettings = @simplexml_load_string($this->getSettings());
|
||||
if ( ! $this->sxTaskSettings || !$this->sxTaskSettings->tasks) {
|
||||
if ( ! $this->sxTaskSettings || ! $this->sxTaskSettings->tasks) {
|
||||
return array();
|
||||
}
|
||||
|
||||
@@ -497,7 +578,7 @@ class task_period_RecordMover extends task_appboxAbstract
|
||||
|
||||
$ret = array(
|
||||
'name' => $sxtask['name'] ? (string) $sxtask['name'] : 'sans nom',
|
||||
'name_htmlencoded' => htmlentities($sxtask['name'] ? $sxtask['name'] : 'sans nom'),
|
||||
'name_htmlencoded' => \p4string::MakeString(($sxtask['name'] ? $sxtask['name'] : 'sans nom'), 'html'),
|
||||
'active' => trim($sxtask['active']) === '1',
|
||||
'sbas_id' => $sbas_id,
|
||||
'basename' => '',
|
||||
|
@@ -136,51 +136,6 @@ class task_period_archive extends task_abstract
|
||||
return $dom->saveXML();
|
||||
}
|
||||
|
||||
/**
|
||||
* fill the graphic form (using js) from xml
|
||||
*
|
||||
* @param string $xml
|
||||
* @param string $form
|
||||
*/
|
||||
public function xml2graphic($xml, $form)
|
||||
{
|
||||
// XML should always be valid here...
|
||||
if (($sxml = simplexml_load_string($xml)) != false) {
|
||||
// sanitize values
|
||||
if ((int) ($sxml->period) < 10) {
|
||||
$sxml->period = 10;
|
||||
} elseif ((int) ($sxml->period) > 3600) {
|
||||
$sxml->period = 3600;
|
||||
}
|
||||
if ((int) ($sxml->cold) < 5) {
|
||||
$sxml->cold = 5;
|
||||
} elseif ((int) ($sxml->cold) > 300) {
|
||||
$sxml->cold = 300;
|
||||
}
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
var i;
|
||||
var opts = <?php echo $form ?>.base_id.options;
|
||||
var basefound = 0;
|
||||
for (i=1; basefound==0 && i<opts.length; i++) {
|
||||
if(opts[i].value == "<?php echo \p4string::MakeString($sxml->base_id, "form") ?>")
|
||||
basefound = i;
|
||||
}
|
||||
opts[basefound].selected = true;
|
||||
<?php echo $form ?>.hotfolder.value = "<?php echo \p4string::MakeString($sxml->hotfolder, "js", '"') ?>";
|
||||
<?php echo $form ?>.period.value = "<?php echo \p4string::MakeString($sxml->period, "js", '"') ?>";
|
||||
<?php echo $form ?>.cold.value = "<?php echo \p4string::MakeString($sxml->cold, "js", '"') ?>";
|
||||
<?php echo $form ?>.move_archived.checked = <?php echo \p4field::isyes($sxml->move_archived) ? "true" : "false" ?>;
|
||||
<?php echo $form ?>.move_error.checked = <?php echo \p4field::isyes($sxml->move_error) ? "true" : "false" ?>;
|
||||
<?php echo $form ?>.delfolder.checked = <?php echo \p4field::isyes($sxml->delfolder) ? "true" : "false" ?>;
|
||||
<?php echo $form ?>.copy_spe.checked = <?php echo \p4field::isyes($sxml->copy_spe) ? "true" : "false" ?>;
|
||||
</script>
|
||||
<?php
|
||||
return "";
|
||||
} else {
|
||||
return "BAD XML";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return some javascript code for the graphic view
|
||||
@@ -189,19 +144,63 @@ class task_period_archive extends task_abstract
|
||||
{
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
function chgxmltxt(textinput, fieldname)
|
||||
function taskFillGraphic_<?php echo(get_class($this));?>(xml)
|
||||
{
|
||||
setDirty();
|
||||
}
|
||||
function chgxmlck(checkinput, fieldname)
|
||||
{
|
||||
setDirty();
|
||||
}
|
||||
function chgxmlpopup(popupinput, fieldname)
|
||||
{
|
||||
setDirty();
|
||||
if(xml)
|
||||
{
|
||||
xml = $.parseXML(xml);
|
||||
xml = $(xml);
|
||||
|
||||
var isyes = function(v) {
|
||||
v = v.toUpperCase().trim();
|
||||
return v=='O' || v=='Y' || v=='OUI' || v=='YES' || v=='1';
|
||||
}
|
||||
|
||||
with(document.forms['graphicForm'])
|
||||
{
|
||||
var i;
|
||||
var opts = base_id.options;
|
||||
var basefound = 0;
|
||||
for (i=1; basefound==0 && i<opts.length; i++) {
|
||||
if(opts[i].value == xml.find("base_id").text())
|
||||
basefound = i;
|
||||
}
|
||||
opts[basefound].selected = true;
|
||||
|
||||
hotfolder.value = xml.find("hotfolder").text();
|
||||
period.value = xml.find("period").text();
|
||||
cold.value = xml.find("cold").text();
|
||||
move_archived.checked = isyes(xml.find("move_archived").text());
|
||||
move_error.checked = isyes(xml.find("move_error").text());
|
||||
delfolder.checked = isyes(xml.find("delfolder").text());
|
||||
copy_spe.checked = isyes(xml.find("copy_spe").text());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready(function(){
|
||||
$("#graphicForm *").change(function(){
|
||||
var limits = {
|
||||
'period': {min:10, max:3600, allowempty:false} ,
|
||||
'cold': {min:5, max:300, allowempty:false}
|
||||
} ;
|
||||
var name = $(this).attr("name");
|
||||
if(name && limits[name])
|
||||
{
|
||||
var v = $(this).val();
|
||||
if(v != "" || !limits[name].allowempty)
|
||||
{
|
||||
v = 0|v;
|
||||
if(v < limits[name].min)
|
||||
$(this).val(limits[name].min);
|
||||
else if(v > limits[name].max)
|
||||
$(this).val(limits[name].max);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<?php
|
||||
return;
|
||||
}
|
||||
@@ -215,10 +214,10 @@ class task_period_archive extends task_abstract
|
||||
|
||||
ob_start();
|
||||
?>
|
||||
<form name="graphicForm" onsubmit="return(false);" method="post">
|
||||
<?php echo _('task::archive:archivage sur base/collection/') ?> :
|
||||
<form id="graphicForm" name="graphicForm" onsubmit="return(false);" method="post">
|
||||
<?php echo _('task::archive:archivage sur base/collection/') ?> :
|
||||
|
||||
<select onchange="chgxmlpopup(this, 'base_id');" name="base_id">
|
||||
<select name="base_id">
|
||||
<option value="">...</option>
|
||||
<?php
|
||||
foreach ($appbox->get_databoxes() as $databox) {
|
||||
@@ -238,14 +237,22 @@ class task_period_archive extends task_abstract
|
||||
<br/>
|
||||
<?php echo _('task::archive:delai de \'repos\' avant traitement') ?> :
|
||||
<input type="text" name="cold" style="width:40px;" onchange="chgxmltxt(this, 'cold');" value=""> <?php echo _('task::_common_:secondes (unite temporelle)') ?><br/>
|
||||
<?php echo _('task::_common_:hotfolder') ?>
|
||||
<input type="text" name="hotfolder" style="width:400px;" value=""><br/>
|
||||
<br/>
|
||||
<input type="checkbox" name="move_archived" onchange="chgxmlck(this, 'move_archived');"> <?php echo _('task::archive:deplacer les fichiers archives dans _archived') ?>
|
||||
<?php echo _('task::_common_:periodicite de la tache') ?> :
|
||||
<input type="text" name="period" style="width:40px;" value=""> <?php echo _('task::_common_:secondes (unite temporelle)') ?><br/>
|
||||
<br/>
|
||||
<?php echo _('task::archive:delai de \'repos\' avant traitement') ?> :
|
||||
<input type="text" name="cold" style="width:40px;" value=""> <?php echo _('task::_common_:secondes (unite temporelle)') ?><br/>
|
||||
<br/>
|
||||
<input type="checkbox" name="move_archived"> <?php echo _('task::archive:deplacer les fichiers archives dans _archived') ?>
|
||||
|
||||
<input type="checkbox" name="move_error" onchange="chgxmlck(this, 'move_error');"> <?php echo _('task::archive:deplacer les fichiers non-archives dans _error') ?><br/>
|
||||
<input type="checkbox" name="move_error"> <?php echo _('task::archive:deplacer les fichiers non-archives dans _error') ?><br/>
|
||||
<br/>
|
||||
<input type="checkbox" name="copy_spe" onchange="chgxmlck(this, 'copy_spe');"> <?php echo _('task::archive:copier les fichiers \'.phrasea.xml\' et \'.grouping.xml\' dans _archived') ?><br/>
|
||||
<input type="checkbox" name="copy_spe"> <?php echo _('task::archive:copier les fichiers \'.phrasea.xml\' et \'.grouping.xml\' dans _archived') ?><br/>
|
||||
<br/>
|
||||
<input type="checkbox" name="delfolder" onchange="chgxmlck(this, 'delfolder');"> <?php echo _('task::archive:supprimer les repertoires apres archivage') ?><br/>
|
||||
<input type="checkbox" name="delfolder"> <?php echo _('task::archive:supprimer les repertoires apres archivage') ?><br/>
|
||||
</form>
|
||||
<?php
|
||||
return ob_get_clean();
|
||||
|
@@ -141,7 +141,7 @@ class task_period_cindexer extends task_abstract
|
||||
$ns->removeChild($n);
|
||||
}
|
||||
} else {
|
||||
// le champ n'existait pas dans le xml, on le cr<EFBFBD>e
|
||||
// le champ n'existait pas dans le xml, on le cree
|
||||
$ns = $dom->documentElement->appendChild($dom->createElement($pname));
|
||||
}
|
||||
// on fixe sa valeur
|
||||
@@ -160,40 +160,6 @@ class task_period_cindexer extends task_abstract
|
||||
return($dom->saveXML());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $xml
|
||||
* @param string $form
|
||||
* @return string
|
||||
*/
|
||||
public function xml2graphic($xml, $form)
|
||||
{
|
||||
if (($sxml = simplexml_load_string($xml)) != FALSE) { // in fact XML IS always valid here...
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
<?php echo $form ?>.binpath.value = "<?php echo p4string::MakeString($sxml->binpath, "js", '"') ?>";
|
||||
<?php echo $form ?>.host.value = "<?php echo p4string::MakeString($sxml->host, "js", '"') ?>";
|
||||
<?php echo $form ?>.port.value = "<?php echo p4string::MakeString($sxml->port, "js", '"') ?>";
|
||||
<?php echo $form ?>.base.value = "<?php echo p4string::MakeString($sxml->base, "js", '"') ?>";
|
||||
<?php echo $form ?>.user.value = "<?php echo p4string::MakeString($sxml->user, "js", '"') ?>";
|
||||
<?php echo $form ?>.socket.value = "<?php echo p4string::MakeString($sxml->socket, "js", '"') ?>";
|
||||
<?php echo $form ?>.password.value = "<?php echo p4string::MakeString($sxml->password, "js", '"') ?>";
|
||||
<?php echo $form ?>.clng.value = "<?php echo p4string::MakeString($sxml->clng, "js", '"') ?>";
|
||||
<?php echo $form ?>.use_sbas.checked = <?php echo trim((string) $sxml->use_sbas) != '' ? (p4field::isyes($sxml->use_sbas) ? 'true' : 'false') : 'true' ?>;
|
||||
<?php echo $form ?>.nolog.checked = <?php echo p4field::isyes($sxml->nolog) ? 'true' : 'false' ?>;
|
||||
<?php echo $form ?>.winsvc_run.checked = <?php echo p4field::isyes($sxml->winsvc_run) ? 'true' : 'false' ?>;
|
||||
<?php echo $form ?>.charset.value = "<?php echo trim((string) $sxml->charset) != '' ? p4string::MakeString($sxml->charset, "js", '"') : 'utf8' ?>";
|
||||
<?php echo $form ?>.debugmask.value = "<?php echo trim((string) $sxml->debugmask) != '' ? p4string::MakeString($sxml->debugmask, "js", '"') : '0' ?>";
|
||||
parent.calccmd();
|
||||
</script>
|
||||
<?php
|
||||
|
||||
return("");
|
||||
} else { // ... so we NEVER come here
|
||||
// bad xml
|
||||
return("BAD XML");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -207,8 +173,37 @@ class task_period_cindexer extends task_abstract
|
||||
}
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
function calccmd()
|
||||
|
||||
function taskFillGraphic_<?php echo(get_class($this));?>(xml)
|
||||
{
|
||||
if(xml)
|
||||
{
|
||||
xml = $.parseXML(xml);
|
||||
xml = $(xml);
|
||||
|
||||
var isyes = function(v) {
|
||||
v = v.toUpperCase().trim();
|
||||
return v=='O' || v=='Y' || v=='OUI' || v=='YES' || v=='1';
|
||||
}
|
||||
|
||||
with(document.forms['graphicForm'])
|
||||
{
|
||||
binpath.value = xml.find("binpath").text();
|
||||
host.value = xml.find("host").text();
|
||||
port.value = xml.find("port").text();
|
||||
base.value = xml.find("base").text();
|
||||
user.value = xml.find("user").text();
|
||||
socket.value = xml.find("socket").text();
|
||||
password.value = xml.find("password").text();
|
||||
clng.value = xml.find("clng").text();
|
||||
use_sbas.checked = isyes(xml.find("use_sbas").text());
|
||||
nolog.checked = isyes(xml.find("nolog").text());
|
||||
winsvc_run.checked = isyes(xml.find("winsvc_run").text());
|
||||
charset.value = xml.find("charset").text();
|
||||
debugmask.value = 0|xml.find("debugmask").text();
|
||||
}
|
||||
}
|
||||
|
||||
var cmd = '';
|
||||
with(document.forms['graphicForm'])
|
||||
{
|
||||
@@ -238,23 +233,16 @@ class task_period_cindexer extends task_abstract
|
||||
if(winsvc_run.checked)
|
||||
cmd += " --run";
|
||||
}
|
||||
document.getElementById('cmd').innerHTML = cmd;
|
||||
}
|
||||
function chgxmltxt(textinput, fieldname)
|
||||
{
|
||||
calccmd();
|
||||
setDirty();
|
||||
}
|
||||
function chgxmlck(checkinput, fieldname)
|
||||
{
|
||||
calccmd();
|
||||
setDirty();
|
||||
}
|
||||
function chgxmlpopup(popupinput, fieldname)
|
||||
{
|
||||
calccmd();
|
||||
setDirty();
|
||||
$('#cmd').html(cmd);
|
||||
}
|
||||
|
||||
$(document).ready(function(){
|
||||
$("#graphicForm *").change(function(){
|
||||
// console.log($(this));
|
||||
taskFillGraphic_<?php echo(get_class($this));?>(null);
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
<?php
|
||||
|
||||
@@ -273,55 +261,47 @@ class task_period_cindexer extends task_abstract
|
||||
}
|
||||
ob_start();
|
||||
?>
|
||||
<form name="graphicForm" onsubmit="return(false);" method="post">
|
||||
<br/>
|
||||
<?php echo _('task::cindexer:executable') ?> :
|
||||
<input type="text" name="binpath" style="width:300px;" onchange="chgxmltxt(this, 'binpath');" value=""> / <?php echo $appname ?>
|
||||
<br/>
|
||||
<?php echo _('task::cindexer:host') ?> : <input type="text" name="host" style="width:100px;" onchange="chgxmltxt(this, 'host');" value="">
|
||||
<br/>
|
||||
<?php echo _('task::cindexer:port') ?> : <input type="text" name="port" style="width:100px;" onchange="chgxmltxt(this, 'port');" value="">
|
||||
<br/>
|
||||
<?php echo _('task::cindexer:base') ?> : <input type="text" name="base" style="width:200px;" onchange="chgxmltxt(this, 'base');" value="">
|
||||
<br/>
|
||||
<?php echo _('task::cindexer:user') ?> : <input type="text" name="user" style="width:200px;" onchange="chgxmltxt(this, 'user');" value="">
|
||||
<br/>
|
||||
<?php echo _('task::cindexer:password') ?> : <input type="password" name="password" style="width:200px;" onchange="chgxmltxt(this, 'password');" value="">
|
||||
<br/>
|
||||
<form id="graphicForm" name="graphicForm" onsubmit="return(false);" method="post">
|
||||
<?php echo _('task::cindexer:executable') ?> :
|
||||
<input type="text" name="binpath" style="width:300px;text-align: right" value=""> / <?php echo $appname ?>
|
||||
<br/>
|
||||
|
||||
<?php echo _('task::cindexer:control socket') ?> : <input type="text" name="socket" style="width:50px;" onchange="chgxmltxt(this, 'socket');" value="">
|
||||
<br/>
|
||||
<?php echo _('task::cindexer:Debug mask') ?> : <input type="text" name="debugmask" style="width:50px;" onchange="chgxmltxt(this, 'debugmask');" value="">
|
||||
<br/>
|
||||
<?php echo _('task::cindexer:host') ?> : <input type="text" name="host" style="width:100px;" value="">
|
||||
|
||||
<?php echo _('task::cindexer:port') ?> : <input type="text" name="port" style="width:50px;" value="">
|
||||
|
||||
<?php echo _('task::cindexer:base') ?> : <input type="text" name="base" style="width:100px;" value="">
|
||||
<br/>
|
||||
|
||||
<div style="display:none;">
|
||||
<input type="checkbox" name="use_sbas" onclick="chgxmlck(this, 'old');"> <?php echo _('task::cindexer:use table \'sbas\' (unchecked: use \'xbas\')') ?>
|
||||
<br/>
|
||||
</div>
|
||||
|
||||
<?php echo _('task::cindexer:MySQL charset') ?> : <input type="text" name="charset" style="width:100px;" onchange="chgxmltxt(this, 'charset');" value="">
|
||||
<?php echo _('task::cindexer:user') ?> : <input type="text" name="user" style="width:100px;" value="">
|
||||
|
||||
<?php echo _('task::cindexer:password') ?> : <input type="password" name="password" style="width:100px;" value="">
|
||||
<br/>
|
||||
|
||||
<input type="checkbox" name="nolog" onclick="chgxmlck(this, 'nolog');"> <?php echo _('task::cindexer:do not (sys)log, but out to console)') ?>
|
||||
<?php echo _('task::cindexer:MySQL charset') ?> : <input type="text" name="charset" style="width:100px;" value="">
|
||||
<br/>
|
||||
|
||||
<?php echo _('task::cindexer:default language for new candidates') ?> : <input type="text" name="clng" style="width:50px;" onchange="chgxmltxt(this, 'clng');" value="">
|
||||
<br/>
|
||||
<?php echo _('task::cindexer:control socket') ?> : <input type="text" name="socket" style="width:50px;" value="">
|
||||
|
||||
<?php echo _('task::cindexer:Debug mask') ?> : <input type="text" name="debugmask" style="width:50px;" value="">
|
||||
<br/>
|
||||
|
||||
<hr/>
|
||||
|
||||
<br/>
|
||||
<?php echo _('task::cindexer:windows specific') ?> :<br/>
|
||||
<input type="checkbox" name="winsvc_run" onclick="chgxmlck(this, 'run');"> <?php echo _('task::cindexer:run as application, not as service') ?>
|
||||
<input type="checkbox" name="use_sbas"> <?php echo _('task::cindexer:use table \'sbas\' (unchecked: use \'xbas\')') ?>
|
||||
<br/>
|
||||
|
||||
<?php echo _('task::cindexer:default language for new candidates') ?> : <input type="text" name="clng" style="width:50px;" value="">
|
||||
<br/>
|
||||
|
||||
<input type="checkbox" name="nolog"> <?php echo _('task::cindexer:do not (sys)log, but out to console)') ?>
|
||||
<br/>
|
||||
|
||||
|
||||
<?php echo _('task::cindexer:windows specific') ?> :<br/>
|
||||
<input type="checkbox" name="winsvc_run"> <?php echo _('task::cindexer:run as application, not as service') ?>
|
||||
</form>
|
||||
<br>
|
||||
|
||||
<center>
|
||||
<div style="margin:10px; padding:5px; border:1px #000000 solid; font-family:monospace; font-size:16px; text-align:left; color:#00e000; background-color:#404040" id="cmd">cmd</div>
|
||||
<div style="margin:10px; padding:5px; border:1px #000000 solid; font-family:monospace; font-size:14px; text-align:left; color:#00e000; background-color:#404040" id="cmd">cmd</div>
|
||||
</center>
|
||||
<?php
|
||||
|
||||
|
616
lib/classes/task/period/cindexer.class_bkp.php
Normal file
616
lib/classes/task/period/cindexer.class_bkp.php
Normal file
@@ -0,0 +1,616 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class task_period_cindexer extends task_abstract
|
||||
{
|
||||
// how to execute indexer (choose in 'run2' method)
|
||||
private $method;
|
||||
|
||||
const METHOD_FORK = 'METHOD_FORK';
|
||||
const METHOD_EXEC = 'METHOD_EXEC';
|
||||
const METHOD_PROC_OPEN = 'METHOD_PROC_OPEN';
|
||||
const ERR_EXECUTABLE_NOT_FOUND = 2; // aka ENOENT (No such file or directory)
|
||||
const ERR_CRASHED = 14; // aka EFAULT (Bad address)
|
||||
const ERR_CANT_FORK = 3; // aka ESRCH (No such process)
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $host;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $port;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $base;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $password;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $socket;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $use_sbas;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $charset;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $debugmask;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $nolog;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $winsvc_run;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $binpath;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return(_("task::cindexer:Indexation"));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function help()
|
||||
{
|
||||
return(_("task::cindexer:indexing records"));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $oldxml
|
||||
* @return string
|
||||
*/
|
||||
public function graphic2xml($oldxml)
|
||||
{
|
||||
$request = http_request::getInstance();
|
||||
|
||||
$parm2 = $request->get_parms(
|
||||
'binpath', 'host', 'port', 'base', 'user', 'password', 'socket', 'use_sbas', 'nolog', 'clng', 'winsvc_run', 'charset', 'debugmask'
|
||||
);
|
||||
$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", 'str:debugmask') as $pname) {
|
||||
$ptype = substr($pname, 0, 3);
|
||||
$pname = substr($pname, 4);
|
||||
$pvalue = $parm2[$pname];
|
||||
if (($ns = $dom->getElementsByTagName($pname)->item(0)) != NULL) {
|
||||
// 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<63>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)) != FALSE) { // in fact XML IS always valid here...
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
<?php echo $form ?>.binpath.value = "<?php echo p4string::MakeString($sxml->binpath, "js", '"') ?>";
|
||||
<?php echo $form ?>.host.value = "<?php echo p4string::MakeString($sxml->host, "js", '"') ?>";
|
||||
<?php echo $form ?>.port.value = "<?php echo p4string::MakeString($sxml->port, "js", '"') ?>";
|
||||
<?php echo $form ?>.base.value = "<?php echo p4string::MakeString($sxml->base, "js", '"') ?>";
|
||||
<?php echo $form ?>.user.value = "<?php echo p4string::MakeString($sxml->user, "js", '"') ?>";
|
||||
<?php echo $form ?>.socket.value = "<?php echo p4string::MakeString($sxml->socket, "js", '"') ?>";
|
||||
<?php echo $form ?>.password.value = "<?php echo p4string::MakeString($sxml->password, "js", '"') ?>";
|
||||
<?php echo $form ?>.clng.value = "<?php echo p4string::MakeString($sxml->clng, "js", '"') ?>";
|
||||
<?php echo $form ?>.use_sbas.checked = <?php echo trim((string) $sxml->use_sbas) != '' ? (p4field::isyes($sxml->use_sbas) ? 'true' : 'false') : 'true' ?>;
|
||||
<?php echo $form ?>.nolog.checked = <?php echo p4field::isyes($sxml->nolog) ? 'true' : 'false' ?>;
|
||||
<?php echo $form ?>.winsvc_run.checked = <?php echo p4field::isyes($sxml->winsvc_run) ? 'true' : 'false' ?>;
|
||||
<?php echo $form ?>.charset.value = "<?php echo trim((string) $sxml->charset) != '' ? p4string::MakeString($sxml->charset, "js", '"') : 'utf8' ?>";
|
||||
<?php echo $form ?>.debugmask.value = "<?php echo trim((string) $sxml->debugmask) != '' ? p4string::MakeString($sxml->debugmask, "js", '"') : '0' ?>";
|
||||
parent.calccmd();
|
||||
</script>
|
||||
<?php
|
||||
|
||||
return("");
|
||||
} else { // ... so we NEVER come here
|
||||
// bad xml
|
||||
return("BAD XML");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function printInterfaceJS()
|
||||
{
|
||||
$appname = 'phraseanet_indexer';
|
||||
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
|
||||
$appname .= '.exe';
|
||||
}
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
function calccmd()
|
||||
{
|
||||
var cmd = '';
|
||||
with(document.forms['graphicForm'])
|
||||
{
|
||||
cmd += binpath.value + "/<?php echo $appname ?>";
|
||||
if(host.value)
|
||||
cmd += " -h=" + host.value;
|
||||
if(port.value)
|
||||
cmd += " -P=" + port.value;
|
||||
if(base.value)
|
||||
cmd += " -b=" + base.value;
|
||||
if(user.value)
|
||||
cmd += " -u=" + user.value;
|
||||
if(password.value)
|
||||
cmd += " -p=" + password.value;
|
||||
if(socket.value)
|
||||
cmd += " --socket=" + socket.value;
|
||||
if(charset.value)
|
||||
cmd += " --default-character-set=" + charset.value;
|
||||
if(use_sbas.checked)
|
||||
cmd += " -o";
|
||||
if(nolog.checked)
|
||||
cmd += " -n";
|
||||
if(clng.value)
|
||||
cmd += " -c=" + clng.value;
|
||||
if(debugmask.value)
|
||||
cmd += " -d=" + debugmask.value;
|
||||
if(winsvc_run.checked)
|
||||
cmd += " --run";
|
||||
}
|
||||
document.getElementById('cmd').innerHTML = cmd;
|
||||
}
|
||||
function chgxmltxt(textinput, fieldname)
|
||||
{
|
||||
calccmd();
|
||||
setDirty();
|
||||
}
|
||||
function chgxmlck(checkinput, fieldname)
|
||||
{
|
||||
calccmd();
|
||||
setDirty();
|
||||
}
|
||||
function chgxmlpopup(popupinput, fieldname)
|
||||
{
|
||||
calccmd();
|
||||
setDirty();
|
||||
}
|
||||
</script>
|
||||
<?php
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return return
|
||||
*/
|
||||
public function getInterfaceHTML()
|
||||
{
|
||||
$appname = 'phraseanet_indexer';
|
||||
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
|
||||
$appname .= '.exe';
|
||||
}
|
||||
ob_start();
|
||||
?>
|
||||
<form name="graphicForm" onsubmit="return(false);" method="post">
|
||||
<br/>
|
||||
<?php echo _('task::cindexer:executable') ?> :
|
||||
<input type="text" name="binpath" style="width:300px;" onchange="chgxmltxt(this, 'binpath');" value=""> / <?php echo $appname ?>
|
||||
<br/>
|
||||
<?php echo _('task::cindexer:host') ?> : <input type="text" name="host" style="width:100px;" onchange="chgxmltxt(this, 'host');" value="">
|
||||
<br/>
|
||||
<?php echo _('task::cindexer:port') ?> : <input type="text" name="port" style="width:100px;" onchange="chgxmltxt(this, 'port');" value="">
|
||||
<br/>
|
||||
<?php echo _('task::cindexer:base') ?> : <input type="text" name="base" style="width:200px;" onchange="chgxmltxt(this, 'base');" value="">
|
||||
<br/>
|
||||
<?php echo _('task::cindexer:user') ?> : <input type="text" name="user" style="width:200px;" onchange="chgxmltxt(this, 'user');" value="">
|
||||
<br/>
|
||||
<?php echo _('task::cindexer:password') ?> : <input type="password" name="password" style="width:200px;" onchange="chgxmltxt(this, 'password');" value="">
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<?php echo _('task::cindexer:control socket') ?> : <input type="text" name="socket" style="width:50px;" onchange="chgxmltxt(this, 'socket');" value="">
|
||||
<br/>
|
||||
<?php echo _('task::cindexer:Debug mask') ?> : <input type="text" name="debugmask" style="width:50px;" onchange="chgxmltxt(this, 'debugmask');" value="">
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<div style="display:none;">
|
||||
<input type="checkbox" name="use_sbas" onclick="chgxmlck(this, 'old');"> <?php echo _('task::cindexer:use table \'sbas\' (unchecked: use \'xbas\')') ?>
|
||||
<br/>
|
||||
</div>
|
||||
|
||||
<?php echo _('task::cindexer:MySQL charset') ?> : <input type="text" name="charset" style="width:100px;" onchange="chgxmltxt(this, 'charset');" value="">
|
||||
<br/>
|
||||
|
||||
<input type="checkbox" name="nolog" onclick="chgxmlck(this, 'nolog');"> <?php echo _('task::cindexer:do not (sys)log, but out to console)') ?>
|
||||
<br/>
|
||||
|
||||
<?php echo _('task::cindexer:default language for new candidates') ?> : <input type="text" name="clng" style="width:50px;" onchange="chgxmltxt(this, 'clng');" value="">
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<hr/>
|
||||
|
||||
<br/>
|
||||
<?php echo _('task::cindexer:windows specific') ?> :<br/>
|
||||
<input type="checkbox" name="winsvc_run" onclick="chgxmlck(this, 'run');"> <?php echo _('task::cindexer:run as application, not as service') ?>
|
||||
<br/>
|
||||
|
||||
</form>
|
||||
<br>
|
||||
<center>
|
||||
<div style="margin:10px; padding:5px; border:1px #000000 solid; font-family:monospace; font-size:16px; text-align:left; color:#00e000; background-color:#404040" id="cmd">cmd</div>
|
||||
</center>
|
||||
<?php
|
||||
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param SimpleXMLElement $sx_task_settings
|
||||
* @return task_cindexer
|
||||
*/
|
||||
protected function loadSettings(SimpleXMLElement $sx_task_settings)
|
||||
{
|
||||
$this->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->debugmask = (int) (trim($sx_task_settings->debugmask));
|
||||
$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::loadSettings($sx_task_settings);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function run2()
|
||||
{
|
||||
$cmd = $this->binpath . 'phraseanet_indexer';
|
||||
|
||||
$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)) {
|
||||
$this->setState(self::STATE_STOPPED);
|
||||
$this->log(sprintf(_('task::cindexer:file \'%s\' does not exists'), $cmd));
|
||||
throw new Exception('cindexer executable not found', self::ERR_EXECUTABLE_NOT_FOUND);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$args = array();
|
||||
$args_nopwd = array();
|
||||
if ($this->host) {
|
||||
$args[] = '-h=' . $this->host;
|
||||
$args_nopwd[] = '-h=' . $this->host;
|
||||
}
|
||||
if ($this->port) {
|
||||
$args[] = '-P=' . $this->port;
|
||||
$args_nopwd[] = '-P=' . $this->port;
|
||||
}
|
||||
if ($this->base) {
|
||||
$args[] = '-b=' . $this->base;
|
||||
$args_nopwd[] = '-b=' . $this->base;
|
||||
}
|
||||
if ($this->user) {
|
||||
$args[] = '-u=' . $this->user;
|
||||
$args_nopwd[] = '-u=' . $this->user;
|
||||
}
|
||||
if ($this->password) {
|
||||
$args[] = '-p=' . $this->password;
|
||||
$args_nopwd[] = '-p=******';
|
||||
}
|
||||
if ($this->socket) {
|
||||
$args[] = '--socket=' . $this->socket;
|
||||
$args_nopwd[] = '--socket=' . $this->socket;
|
||||
}
|
||||
if ($this->use_sbas) {
|
||||
$args[] = '-o';
|
||||
$args_nopwd[] = '-o';
|
||||
}
|
||||
if ($this->charset) {
|
||||
$args[] = '--default-character-set=' . $this->charset;
|
||||
$args_nopwd[] = '--default-character-set=' . $this->charset;
|
||||
}
|
||||
if ($this->debugmask > 0) {
|
||||
$args[] = '-d=' . $this->debugmask;
|
||||
$args_nopwd[] = '-d=' . $this->debugmask;
|
||||
}
|
||||
if ($this->nolog) {
|
||||
$args[] = '-n';
|
||||
$args_nopwd[] = '-n';
|
||||
}
|
||||
if ($this->winsvc_run) {
|
||||
$args[] = '--run';
|
||||
$args_nopwd[] = '--run';
|
||||
}
|
||||
|
||||
$registry = registry::get_instance();
|
||||
$logdir = p4string::addEndSlash($registry->get('GV_RootPath') . 'logs');
|
||||
|
||||
$this->new_status = NULL; // new status to set at the end
|
||||
$this->exception = NULL; // exception to throw at the end
|
||||
|
||||
$this->log(sprintf("running cindexer with method %s", $this->method));
|
||||
switch ($this->method) {
|
||||
case self::METHOD_PROC_OPEN:
|
||||
$this->run_with_proc_open($cmd, $args, $args_nopwd);
|
||||
break;
|
||||
case self::METHOD_FORK:
|
||||
$this->run_with_fork($cmd, $args, $args_nopwd);
|
||||
break;
|
||||
case self::METHOD_EXEC:
|
||||
$this->run_with_exec($cmd, $args, $args_nopwd);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($this->new_status !== NULL) {
|
||||
$this->setState($this->new_status);
|
||||
}
|
||||
|
||||
if ($this->exception) {
|
||||
throw $this->exception;
|
||||
}
|
||||
}
|
||||
|
||||
private function run_with_proc_open($cmd, $args, $args_nopwd)
|
||||
{
|
||||
$nullfile = defined('PHP_WINDOWS_VERSION_BUILD') ? 'NUL' : '/dev/null';
|
||||
|
||||
$descriptors = array();
|
||||
$descriptors[1] = array("file", $nullfile, "a+");
|
||||
$descriptors[2] = array("file", $nullfile, "a+");
|
||||
|
||||
$pipes = array();
|
||||
|
||||
$this->log(sprintf('cmd=\'%s %s\'', $cmd, implode(' ', $args_nopwd)));
|
||||
|
||||
$process = proc_open($cmd . ' ' . implode(' ', $args), $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) {
|
||||
if ($this->getState() == self::STATE_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"));
|
||||
for ($i = 0; $this->running && $i < 5; $i ++ ) {
|
||||
sleep(1);
|
||||
}
|
||||
$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'));
|
||||
$this->new_status = self::STATE_STOPPED;
|
||||
} elseif ($qsent == 'K') {
|
||||
$this->log(_('task::cindexer:the cindexer has been killed'));
|
||||
$this->new_status = self::STATE_STOPPED;
|
||||
} else {
|
||||
$this->log(_('task::cindexer:the cindexer crashed'));
|
||||
$this->exception = new Exception('cindexer crashed', self::ERR_CRASHED);
|
||||
// do not change the status so scheduler may restart it
|
||||
}
|
||||
$this->running = false;
|
||||
} else {
|
||||
// the cindexer is still alive
|
||||
if ($qsent == 'Q') {
|
||||
if (time() > $timetokill) {
|
||||
// must kill cindexer
|
||||
$this->log(_('task::cindexer:killing the cindexer'));
|
||||
$qsent = 'K';
|
||||
proc_terminate($process); // sigint
|
||||
}
|
||||
}
|
||||
}
|
||||
for ($i = 0; $this->running && $i < 5; $i ++ ) {
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private function run_with_fork($cmd, $args, $args_nopwd)
|
||||
{
|
||||
$pid = pcntl_fork();
|
||||
if ($pid == -1) {
|
||||
$this->exception = new Exception('cindexer can\'t fork', self::ERR_CANT_FORK);
|
||||
} elseif ($pid == 0) {
|
||||
// child
|
||||
umask(0);
|
||||
if (($err = posix_setsid()) < 0) {
|
||||
$this->exception = new Exception('cindexer can\'t detach from terminal', $err);
|
||||
} else {
|
||||
chdir(dirname(__FILE__));
|
||||
pcntl_exec($cmd, $args);
|
||||
sleep(2);
|
||||
}
|
||||
} else {
|
||||
// parent
|
||||
$this->running = true;
|
||||
|
||||
$sigsent = NULL;
|
||||
while ($this->running) {
|
||||
// is the cindexer alive ?
|
||||
if ( ! posix_kill($pid, 0)) {
|
||||
// dead...
|
||||
if ($sigsent === NULL) {
|
||||
// but it's not my fault
|
||||
$this->log(_('task::cindexer:the cindexer crashed'));
|
||||
$this->exception = new Exception('cindexer crashed', self::ERR_CRASHED);
|
||||
// do not change the status so scheduler may restart it
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->getState() == self::STATE_TOSTOP) {
|
||||
posix_kill($pid, ($sigsent = SIGINT));
|
||||
$timetokill = time() + 10;
|
||||
sleep(2);
|
||||
}
|
||||
|
||||
$status = NULL;
|
||||
if (pcntl_wait($status, WNOHANG) == $pid) {
|
||||
// child (indexer) has exited
|
||||
if ($sigsent == SIGINT) {
|
||||
$this->log(_('task::cindexer:the cindexer clean-quit'));
|
||||
$this->new_status = self::STATE_STOPPED;
|
||||
} elseif ($sigsent == SIGKILL) {
|
||||
$this->log(_('task::cindexer:the cindexer has been killed'));
|
||||
$this->new_status = self::STATE_STOPPED;
|
||||
} else {
|
||||
$this->log(_('task::cindexer:the cindexer crashed'));
|
||||
$this->exception = new Exception('cindexer crashed', self::ERR_CRASHED);
|
||||
// do not change the status so scheduler may restart it
|
||||
}
|
||||
$this->running = false;
|
||||
} else {
|
||||
if ($sigsent == SIGINT && time() > $timetokill) {
|
||||
// must kill cindexer
|
||||
$this->log(_('task::cindexer:killing the cindexer'));
|
||||
posix_kill($pid, ($sigsent = SIGKILL));
|
||||
}
|
||||
sleep(2);
|
||||
}
|
||||
} // while running
|
||||
}
|
||||
}
|
||||
|
||||
private function run_with_exec($cmd, $args, $args_nopwd)
|
||||
{
|
||||
pcntl_exec($cmd, $args);
|
||||
sleep(2);
|
||||
}
|
||||
}
|
@@ -83,31 +83,6 @@ class task_period_ftp extends task_appboxAbstract
|
||||
return($dom->saveXML());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $xml
|
||||
* @param string $form
|
||||
* @return string
|
||||
*/
|
||||
public function xml2graphic($xml, $form)
|
||||
{
|
||||
if (($sxml = simplexml_load_string($xml)) != FALSE) { // in fact XML IS always valid here...
|
||||
// ... but we could check for safe values (ex. 0 < period < 3600)
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
<?php echo $form ?>.proxy.value = "<?php echo p4string::MakeString($sxml->proxy, "js", '"') ?>";
|
||||
<?php echo $form ?>.proxyport.value = "<?php echo p4string::MakeString($sxml->proxyport, "js", '"') ?>";
|
||||
<?php echo $form ?>.period.value = "<?php echo p4string::MakeString($sxml->period, "js", '"') ?>";
|
||||
</script>
|
||||
<?php
|
||||
|
||||
return("");
|
||||
} else { // ... so we NEVER come here
|
||||
// bad xml
|
||||
return("BAD XML");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return void
|
||||
@@ -116,20 +91,42 @@ class task_period_ftp extends task_appboxAbstract
|
||||
{
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
function chgxmltxt(textinput, fieldname)
|
||||
function taskFillGraphic_<?php echo(get_class($this));?>(xml)
|
||||
{
|
||||
setDirty();
|
||||
if(xml)
|
||||
{
|
||||
xml = $.parseXML(xml);
|
||||
xml = $(xml);
|
||||
|
||||
with(document.forms['graphicForm'])
|
||||
{
|
||||
proxy.value = xml.find("proxy").text();
|
||||
proxyport.value = xml.find("proxyport").text();
|
||||
period.value = xml.find("period").text();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function chgxmlck(checkinput, fieldname)
|
||||
{
|
||||
setDirty();
|
||||
}
|
||||
|
||||
function chgxmlpopup(popupinput, fieldname)
|
||||
{
|
||||
setDirty();
|
||||
}
|
||||
$(document).ready(function(){
|
||||
$("#graphicForm *").change(function(){
|
||||
var limits = {
|
||||
'period': {min:10, max:3600, allowempty:false}
|
||||
} ;
|
||||
var name = $(this).attr("name");
|
||||
if(name && limits[name])
|
||||
{
|
||||
var v = $(this).val();
|
||||
if(v != "" || !limits[name].allowempty)
|
||||
{
|
||||
v = 0|v;
|
||||
if(v < limits[name].min)
|
||||
$(this).val(limits[name].min);
|
||||
else if(v > limits[name].max)
|
||||
$(this).val(limits[name].max);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
|
||||
@@ -144,18 +141,18 @@ class task_period_ftp extends task_appboxAbstract
|
||||
{
|
||||
ob_start();
|
||||
?>
|
||||
<form name="graphicForm" onsubmit="return(false);" method="post">
|
||||
<form id="graphicForm" name="graphicForm" onsubmit="return(false);" method="post">
|
||||
<br/>
|
||||
<?php echo('task::ftp:proxy') ?>
|
||||
<input type="text" name="proxy" style="width:400px;" onchange="chgxmltxt(this, 'proxy');"><br/>
|
||||
<?php echo _('task::ftp:proxy') ?>
|
||||
<input type="text" name="proxy" style="width:400px;"><br/>
|
||||
<br/>
|
||||
<?php echo('task::ftp:proxy port') ?>
|
||||
<input type="text" name="proxyport" style="width:400px;" onchange="chgxmltxt(this, 'proxyport');"><br/>
|
||||
<?php echo _('task::ftp:proxy port') ?>
|
||||
<input type="text" name="proxyport" style="width:400px;"><br/>
|
||||
<br/>
|
||||
|
||||
<?php echo('task::_common_:periodicite de la tache') ?> :
|
||||
<input type="text" name="period" style="width:40px;" onchange="chgxmltxt(this, 'period');">
|
||||
<?php echo('task::_common_:secondes (unite temporelle)') ?><br/>
|
||||
<?php echo _('task::_common_:periodicite de la tache') ?> :
|
||||
<input type="text" name="period" style="width:40px;">
|
||||
<?php echo _('task::_common_:secondes (unite temporelle)') ?><br/>
|
||||
</form>
|
||||
<?php
|
||||
|
||||
|
@@ -51,110 +51,6 @@ class task_period_subdef extends task_databoxAbstract
|
||||
return(_('task::subdef:creation des sous definitions'));
|
||||
}
|
||||
|
||||
/**
|
||||
* must return the xml (text) version of the form
|
||||
*
|
||||
* @param string $oldxml
|
||||
* @return string
|
||||
*/
|
||||
public function graphic2xml($oldxml)
|
||||
{
|
||||
$request = http_request::getInstance();
|
||||
|
||||
$parm2 = $request->get_parms(
|
||||
'period'
|
||||
, 'flush'
|
||||
, 'maxrecs'
|
||||
, 'maxmegs'
|
||||
);
|
||||
$dom = new DOMDocument();
|
||||
$dom->preserveWhiteSpace = false;
|
||||
$dom->formatOutput = true;
|
||||
if ($dom->loadXML($oldxml)) {
|
||||
$xmlchanged = false;
|
||||
|
||||
foreach (array("str:period", "str:flush", "str:maxrecs", "str:maxmegs") as $pname) {
|
||||
$ptype = substr($pname, 0, 3);
|
||||
$pname = substr($pname, 4);
|
||||
$pvalue = $parm2[$pname];
|
||||
if (($ns = $dom->getElementsByTagName($pname)->item(0)) != NULL) {
|
||||
while (($n = $ns->firstChild)) {
|
||||
$ns->removeChild($n);
|
||||
}
|
||||
} else {
|
||||
$ns = $dom->documentElement->appendChild($dom->createElement($pname));
|
||||
}
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
* must fill the graphic form (using js) from xml
|
||||
*
|
||||
* @param string $xml
|
||||
* @param string $form
|
||||
* @return string
|
||||
*/
|
||||
public function xml2graphic($xml, $form)
|
||||
{
|
||||
if (($sxml = simplexml_load_string($xml)) != FALSE) {
|
||||
if ((int) ($sxml->period) < 10) {
|
||||
$sxml->period = 10;
|
||||
} elseif ((int) ($sxml->period) > 300) {
|
||||
$sxml->period = 300;
|
||||
}
|
||||
|
||||
if ((string) ($sxml->flush) == '') {
|
||||
$sxml->flush = 10;
|
||||
} elseif ((int) ($sxml->flush) < 1) {
|
||||
$sxml->flush = 1;
|
||||
} elseif ((int) ($sxml->flush) > 100) {
|
||||
$sxml->flush = 100;
|
||||
}
|
||||
|
||||
if ((string) ($sxml->maxrecs) == '') {
|
||||
$sxml->maxrecs = 100;
|
||||
}
|
||||
if ((int) ($sxml->maxrecs) < 10) {
|
||||
$sxml->maxrecs = 10;
|
||||
} elseif ((int) ($sxml->maxrecs) > 500) {
|
||||
$sxml->maxrecs = 500;
|
||||
}
|
||||
|
||||
if ((string) ($sxml->maxmegs) == '') {
|
||||
$sxml->maxmegs = 6;
|
||||
}
|
||||
if ((int) ($sxml->maxmegs) < 3) {
|
||||
$sxml->maxmegs = 3;
|
||||
} elseif ((int) ($sxml->maxmegs) > 32) {
|
||||
$sxml->maxmegs = 32;
|
||||
}
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
<?php echo $form ?>.period.value = "<?php echo p4string::MakeString($sxml->period, "js", '"') ?>";
|
||||
<?php echo $form ?>.flush.value = "<?php echo p4string::MakeString($sxml->flush, "js", '"') ?>";
|
||||
<?php echo $form ?>.maxrecs.value = "<?php echo p4string::MakeString($sxml->maxrecs, "js", '"') ?>";
|
||||
<?php echo $form ?>.maxmegs.value = "<?php echo p4string::MakeString($sxml->maxmegs, "js", '"') ?>";
|
||||
</script>
|
||||
|
||||
<?php
|
||||
|
||||
return("");
|
||||
} else {
|
||||
return("BAD XML");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -165,40 +61,46 @@ class task_period_subdef extends task_databoxAbstract
|
||||
{
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
function chgxmltxt(textinput, fieldname)
|
||||
function taskFillGraphic_<?php echo(get_class($this));?>(xml)
|
||||
{
|
||||
var limits = { 'period':{min:1, 'max':300} , 'flush':{min:1, 'max':100} , 'maxrecs':{min:10, 'max':1000} , 'maxmegs':{min:2, 'max':100} } ;
|
||||
if (typeof(limits[fieldname])!='undefined') {
|
||||
var v = 0|textinput.value;
|
||||
if(v < limits[fieldname].min)
|
||||
v = limits[fieldname].min;
|
||||
else if(v > limits[fieldname].max)
|
||||
v = limits[fieldname].max;
|
||||
textinput.value = v;
|
||||
if(xml)
|
||||
{
|
||||
xml = $.parseXML(xml);
|
||||
xml = $(xml);
|
||||
|
||||
with(document.forms['graphicForm'])
|
||||
{
|
||||
period.value = xml.find("period").text();
|
||||
flush.value = xml.find("flush").text();
|
||||
maxrecs.value = xml.find("maxrecs").text();
|
||||
maxmegs.value = xml.find("maxmegs").text();
|
||||
}
|
||||
}
|
||||
setDirty();
|
||||
}
|
||||
function chgxmlck_die(ck)
|
||||
{
|
||||
if (ck.checked) {
|
||||
if(document.forms['graphicForm'].maxrecs.value == "")
|
||||
document.forms['graphicForm'].maxrecs.value = 500;
|
||||
if(document.forms['graphicForm'].maxmegs.value == "")
|
||||
document.forms['graphicForm'].maxmegs.value = 4;
|
||||
document.forms['graphicForm'].maxrecs.disabled = document.forms['graphicForm'].maxmegs.disabled = false;
|
||||
} else {
|
||||
document.forms['graphicForm'].maxrecs.disabled = document.forms['graphicForm'].maxmegs.disabled = true;
|
||||
}
|
||||
setDirty();
|
||||
}
|
||||
function chgxmlck(checkinput, fieldname)
|
||||
{
|
||||
setDirty();
|
||||
}
|
||||
function chgxmlpopup(popupinput, fieldname)
|
||||
{
|
||||
setDirty();
|
||||
}
|
||||
|
||||
$(document).ready(function(){
|
||||
$("#graphicForm *").change(function(){
|
||||
var limits = {
|
||||
'period': {min:1, max:300, allowempty:false} ,
|
||||
'flush': {min:1, max:100, allowempty:false} ,
|
||||
'maxrecs':{min:10, max:1000, allowempty:true} ,
|
||||
'maxmegs':{min:2, max:100, allowempty:true}
|
||||
} ;
|
||||
var name = $(this).attr("name");
|
||||
if(name && limits[name])
|
||||
{
|
||||
var v = $(this).val();
|
||||
if(v != "" || !limits[name].allowempty)
|
||||
{
|
||||
v = 0|v;
|
||||
if(v < limits[name].min)
|
||||
$(this).val(limits[name].min);
|
||||
else if(v > limits[name].max)
|
||||
$(this).val(limits[name].max);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<?php
|
||||
}
|
||||
@@ -212,20 +114,19 @@ class task_period_subdef extends task_databoxAbstract
|
||||
{
|
||||
ob_start();
|
||||
?>
|
||||
<form name="graphicForm" onsubmit="return(false);" method="post">
|
||||
<form id="graphicForm" name="graphicForm" onsubmit="return(false);" method="post">
|
||||
<br/>
|
||||
<?php echo _('task::_common_:periodicite de la tache') ?> :
|
||||
<input type="text" name="period" style="width:40px;" onchange="chgxmltxt(this, 'period');" value="">
|
||||
<input type="text" name="period" style="width:40px;" value="">
|
||||
<?php echo _('task::_common_:secondes (unite temporelle)') ?><br/>
|
||||
<br/>
|
||||
<?php echo sprintf(_("task::_common_:passer tous les %s records a l'etape suivante"), '<input type="text" name="flush" style="width:40px;" onchange="chgxmltxt(this, \'flush\');" value="">'); ?>
|
||||
<?php echo sprintf(_("task::_common_:passer tous les %s records a l'etape suivante"), '<input type="text" name="flush" style="width:40px;" value="">'); ?>
|
||||
<br/>
|
||||
<br/>
|
||||
<?php echo _('task::_common_:relancer la tache tous les') ?>
|
||||
<input type="text" name="maxrecs" style="width:40px;" onchange="chgxmltxt(this, 'maxrecs');" value="">
|
||||
<input type="text" name="maxrecs" style="width:40px;" value="">
|
||||
<?php echo _('task::_common_:records, ou si la memoire depasse') ?>
|
||||
<input type="text" name="maxmegs" style="width:40px;" onchange="chgxmltxt(this, 'maxmegs');" value="">
|
||||
Mo
|
||||
<input type="text" name="maxmegs" style="width:40px;" value=""> Mo
|
||||
<br/>
|
||||
</form>
|
||||
<?php
|
||||
|
Reference in New Issue
Block a user