mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-16 06:23:18 +00:00
fixes for windows
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2012 Alchemy
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -53,10 +53,11 @@ class task_period_outofdate extends task_abstract
|
||||
$dom = new DOMDocument();
|
||||
$dom->preserveWhiteSpace = false;
|
||||
$dom->formatOutput = true;
|
||||
if ($dom->loadXML($oldxml)) {
|
||||
if($dom->loadXML($oldxml))
|
||||
{
|
||||
$xmlchanged = false;
|
||||
// foreach($parm2 as $pname=>$pvalue)
|
||||
foreach (array(
|
||||
foreach(array(
|
||||
"str:sbas_id",
|
||||
"str:period",
|
||||
'str:field1',
|
||||
@@ -71,22 +72,27 @@ class task_period_outofdate extends task_abstract
|
||||
'str:coll1',
|
||||
'str:status2',
|
||||
'str:coll2'
|
||||
) as $pname) {
|
||||
) as $pname)
|
||||
{
|
||||
$ptype = substr($pname, 0, 3);
|
||||
$pname = substr($pname, 4);
|
||||
$pvalue = $parm2[$pname];
|
||||
if (($ns = $dom->getElementsByTagName($pname)->item(0))) {
|
||||
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))
|
||||
while(($n = $ns->firstChild))
|
||||
$ns->removeChild($n);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
// le champ n'existait pas dans le xml, on le cree
|
||||
$dom->documentElement->appendChild($dom->createTextNode("\t"));
|
||||
$ns = $dom->documentElement->appendChild($dom->createElement($pname));
|
||||
$dom->documentElement->appendChild($dom->createTextNode("\n"));
|
||||
}
|
||||
// on fixe sa valeur
|
||||
switch ($ptype) {
|
||||
switch($ptype)
|
||||
{
|
||||
case "str":
|
||||
$ns->appendChild($dom->createTextNode($pvalue));
|
||||
break;
|
||||
@@ -106,14 +112,15 @@ class task_period_outofdate extends task_abstract
|
||||
// ====================================================================
|
||||
public function xml2graphic($xml, $form)
|
||||
{
|
||||
if (($sxml = simplexml_load_string($xml))) { // in fact XML IS always valid here...
|
||||
if(($sxml = simplexml_load_string($xml))) // in fact XML IS always valid here...
|
||||
{
|
||||
// ... but we could check for safe values
|
||||
if ((int) ($sxml->period) < 10)
|
||||
if((int) ($sxml->period) < 10)
|
||||
$sxml->period = 10;
|
||||
elseif ((int) ($sxml->period) > 1440) // 1 jour
|
||||
elseif((int) ($sxml->period) > 1440) // 1 jour
|
||||
$sxml->period = 1440;
|
||||
|
||||
if ((string) ($sxml->delay) == '')
|
||||
if((string) ($sxml->delay) == '')
|
||||
$sxml->delay = 0;
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
@@ -158,7 +165,8 @@ class task_period_outofdate extends task_abstract
|
||||
|
||||
return("");
|
||||
}
|
||||
else { // ... so we NEVER come here
|
||||
else // ... so we NEVER come here
|
||||
{
|
||||
// bad xml
|
||||
return("BAD XML");
|
||||
}
|
||||
@@ -405,7 +413,8 @@ class task_period_outofdate extends task_abstract
|
||||
<select onchange="chgsbas(this);setDirty();" name="sbas_id">
|
||||
<option value="">...</option>
|
||||
<?php
|
||||
foreach ($sbas_list as $databox) {
|
||||
foreach($sbas_list as $databox)
|
||||
{
|
||||
$selected = '';
|
||||
print("\t\t\t\t<option value=\"" . $databox->get_sbas_id() . "\" $selected>" . p4string::MakeString($databox->get_viewname(), "form") . "</option>\n");
|
||||
}
|
||||
@@ -494,6 +503,7 @@ class task_period_outofdate extends task_abstract
|
||||
|
||||
return $out;
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
// $argt : command line args specifics to this task (optional)
|
||||
// ====================================================================
|
||||
@@ -508,6 +518,7 @@ class task_period_outofdate extends task_abstract
|
||||
{
|
||||
return(_("task::outofdate:deplacement de docs suivant valeurs de champs 'date'"));
|
||||
}
|
||||
|
||||
// ======================================================================================================
|
||||
// ===== run() : le code d'execution de la tache proprement dite
|
||||
// ======================================================================================================
|
||||
@@ -537,27 +548,32 @@ class task_period_outofdate extends task_abstract
|
||||
// ici la tache tourne tant qu'elle est active
|
||||
$last_exec = 0;
|
||||
$loop = 0;
|
||||
while ($this->running) {
|
||||
if ( ! $conn->ping()) {
|
||||
while($this->running)
|
||||
{
|
||||
if(!$conn->ping())
|
||||
{
|
||||
$this->log(("Warning : abox connection lost, restarting in 10 min."));
|
||||
for ($i = 0; $i < 60 * 10; $i ++ )
|
||||
for($i=0; $i<60 * 10; $i++)
|
||||
sleep(1);
|
||||
$this->running = false;
|
||||
|
||||
return(self::RETURNSTATUS_TORESTART);
|
||||
return(self::STATUS_TORESTART);
|
||||
}
|
||||
|
||||
try {
|
||||
try
|
||||
{
|
||||
$connbas = connection::getPDOConnection($this->sbas_id);
|
||||
if ( ! $connbas->ping())
|
||||
if(!$connbas->ping())
|
||||
throw new Exception('Mysql has gone away');
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
$this->log(("dbox connection lost, restarting in 10 min."));
|
||||
for ($i = 0; $i < 60 * 10; $i ++ )
|
||||
for($i=0; $i<60 * 10; $i++)
|
||||
sleep(1);
|
||||
$this->running = false;
|
||||
|
||||
return(self::RETURNSTATUS_TORESTART);
|
||||
return(self::STATUS_TORESTART);
|
||||
}
|
||||
|
||||
$this->set_last_exec_time();
|
||||
@@ -570,18 +586,24 @@ class task_period_outofdate extends task_abstract
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
if ($row) {
|
||||
if ($row['status'] == 'tostop') {
|
||||
$ret = self::RETURNSTATUS_STOPPED;
|
||||
if($row)
|
||||
{
|
||||
if($row['status'] == 'tostop')
|
||||
{
|
||||
$ret = self::STATUS_STOPPED;
|
||||
;
|
||||
$this->running = false;
|
||||
} else {
|
||||
if (($this->sxTaskSettings = simplexml_load_string($row['settings']))) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if(($this->sxTaskSettings = simplexml_load_string($row['settings'])))
|
||||
{
|
||||
$period = (int) ($this->sxTaskSettings->period);
|
||||
if ($period <= 0 || $period >= 24 * 60)
|
||||
if($period <= 0 || $period >= 24 * 60)
|
||||
$period = 60;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
$period = 60;
|
||||
}
|
||||
$this->connbas = connection::getPDOConnection($this->sbas_id);
|
||||
@@ -590,18 +612,20 @@ class task_period_outofdate extends task_abstract
|
||||
|
||||
$r = $this->doRecords();
|
||||
|
||||
switch ($r) {
|
||||
switch($r)
|
||||
{
|
||||
case 'WAIT':
|
||||
$ret = self::RETURNSTATUS_STOPPED;
|
||||
$ret = self::STATUS_STOPPED;
|
||||
$this->running = false;
|
||||
break;
|
||||
case 'BAD':
|
||||
$ret = self::RETURNSTATUS_STOPPED;
|
||||
$ret = self::STATUS_STOPPED;
|
||||
$this->running = false;
|
||||
break;
|
||||
case 'NORECSTODO':
|
||||
$duration = time() - $duration;
|
||||
if ($duration < $period) {
|
||||
if($duration < $period)
|
||||
{
|
||||
sleep($period - $duration);
|
||||
$conn = connection::getPDOConnection();
|
||||
}
|
||||
@@ -609,29 +633,29 @@ class task_period_outofdate extends task_abstract
|
||||
case 'MAXRECSDONE':
|
||||
case 'MAXMEMORY':
|
||||
case 'MAXLOOP':
|
||||
if ($row['status'] == self::STATUS_STARTED && $this->get_runner() !== self::RUNNER_MANUAL) {
|
||||
$ret = self::RETURNSTATUS_TORESTART;
|
||||
if($row['status'] == self::STATUS_STARTED && $this->get_runner() !== self::RUNNER_MANUAL)
|
||||
{
|
||||
$ret = self::STATUS_TORESTART;
|
||||
$this->running = false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if ($row['status'] == self::STATUS_STARTED) {
|
||||
$ret = self::RETURNSTATUS_STOPPED;
|
||||
if($row['status'] == self::STATUS_STARTED)
|
||||
{
|
||||
$ret = self::STATUS_STOPPED;
|
||||
$this->running = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$ret = 'stopped';
|
||||
}
|
||||
else
|
||||
{
|
||||
$ret = self::STATUS_STOPPED;
|
||||
$this->running = false;
|
||||
}
|
||||
$loop ++;
|
||||
$loop++;
|
||||
}
|
||||
|
||||
$this->return_value = $ret;
|
||||
|
||||
return($ret);
|
||||
}
|
||||
|
||||
function doRecords()
|
||||
@@ -642,21 +666,27 @@ class task_period_outofdate extends task_abstract
|
||||
$tsql = $this->calcSQL($this->sxTaskSettings);
|
||||
|
||||
$nchanged = 0;
|
||||
foreach ($tsql as $xsql) {
|
||||
try {
|
||||
foreach($tsql as $xsql)
|
||||
{
|
||||
try
|
||||
{
|
||||
$stmt = $this->connbas->prepare($xsql['sql']);
|
||||
if ($stmt->execute($xsql['params'])) {
|
||||
if($stmt->execute($xsql['params']))
|
||||
{
|
||||
$n = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
|
||||
$nchanged += $n;
|
||||
if ($n > 0)
|
||||
if($n > 0)
|
||||
$this->log(sprintf("SQL='%s' ; parms=%s - %s changes", $xsql['sql'], var_export($xsql['params']), $n));
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
$this->log(sprintf("ERROR SQL='%s' ; parms=%s", $xsql['sql'], var_export($xsql['params'], true)));
|
||||
}
|
||||
} catch (ErrorException $e) {
|
||||
}
|
||||
catch (ErrorException $e)
|
||||
{
|
||||
$this->log(sprintf("ERROR SQL='%s' ; parms=%s", $xsql['sql'], var_export($xsql['params'], true)));
|
||||
}
|
||||
}
|
||||
@@ -666,6 +696,7 @@ class task_period_outofdate extends task_abstract
|
||||
return($ret);
|
||||
}
|
||||
|
||||
|
||||
private function calcSQL($sxTaskSettings)
|
||||
{
|
||||
$ret = array();
|
||||
@@ -676,10 +707,12 @@ class task_period_outofdate extends task_abstract
|
||||
$field1 = $field2 = '';
|
||||
|
||||
// test : DATE 1
|
||||
if (($field1 = trim($this->sxTaskSettings->field1)) != '') {
|
||||
if(($field1 = trim($this->sxTaskSettings->field1)) != '')
|
||||
{
|
||||
$date1 = time();
|
||||
if (($delta = (int) ($this->sxTaskSettings->fieldDv1)) > 0) {
|
||||
if ($this->sxTaskSettings->fieldDs1 == '-')
|
||||
if(($delta = (int) ($this->sxTaskSettings->fieldDv1)) > 0)
|
||||
{
|
||||
if($this->sxTaskSettings->fieldDs1 == '-')
|
||||
$date1 += 86400 * $delta;
|
||||
else
|
||||
$date1 -= 86400 * $delta;
|
||||
@@ -687,10 +720,12 @@ class task_period_outofdate extends task_abstract
|
||||
$date1 = date("YmdHis", $date1);
|
||||
}
|
||||
// test : DATE 2
|
||||
if (($field2 = trim($this->sxTaskSettings->field2)) != '') {
|
||||
if(($field2 = trim($this->sxTaskSettings->field2)) != '')
|
||||
{
|
||||
$date2 = time();
|
||||
if (($delta = (int) ($this->sxTaskSettings->fieldDv2)) > 0) {
|
||||
if ($this->sxTaskSettings->fieldDs2 == '-')
|
||||
if(($delta = (int) ($this->sxTaskSettings->fieldDv2)) > 0)
|
||||
{
|
||||
if($this->sxTaskSettings->fieldDs2 == '-')
|
||||
$date2 += 86400 * $delta;
|
||||
else
|
||||
$date2 -= 86400 * $delta;
|
||||
@@ -700,22 +735,28 @@ class task_period_outofdate extends task_abstract
|
||||
|
||||
|
||||
$sqlset = $params = $tmp_params = array();
|
||||
for ($i = 0; $i <= 2; $i ++ ) {
|
||||
for($i = 0; $i <= 2; $i++)
|
||||
{
|
||||
$sqlwhere[$i] = '';
|
||||
$sqlset[$i] = '';
|
||||
$x = 'status' . $i;
|
||||
@list($tostat, $statval) = explode('_', (string) ($this->sxTaskSettings->{$x}));
|
||||
if ($tostat >= 4 && $tostat <= 63) {
|
||||
if ($statval == '0') {
|
||||
if($tostat >= 4 && $tostat <= 63)
|
||||
{
|
||||
if($statval == '0')
|
||||
{
|
||||
$sqlset[$i] = 'status=status & ~(1<<' . $tostat . ')';
|
||||
$sqlwhere[$i] .= '(status & (1<<' . $tostat . ') = 0)';
|
||||
} elseif ($statval == '1') {
|
||||
}
|
||||
elseif($statval == '1')
|
||||
{
|
||||
$sqlset[$i] = 'status=status|(1<<' . $tostat . ')';
|
||||
$sqlwhere[$i] .= '(status & (1<<' . $tostat . ') != 0)';
|
||||
}
|
||||
}
|
||||
$x = 'coll' . $i;
|
||||
if (($tocoll = (string) ($this->sxTaskSettings->{$x})) != '') {
|
||||
if(($tocoll = (string) ($this->sxTaskSettings->{$x})) != '')
|
||||
{
|
||||
$sqlset[$i] .= ( $sqlset[$i] ? ', ' : '') . ('coll_id = :coll_id_set' . $i);
|
||||
$sqlwhere[$i] .= ( $sqlwhere[$i] ? ' AND ' : '') . '(coll_id = :coll_id_where' . $i . ')';
|
||||
$tmp_params[':coll_id_set' . $i] = $tocoll;
|
||||
@@ -723,22 +764,29 @@ class task_period_outofdate extends task_abstract
|
||||
}
|
||||
}
|
||||
|
||||
if ($date1 && $sqlset[0]) {
|
||||
if($date1 && $sqlset[0])
|
||||
{
|
||||
$params = array();
|
||||
$params[':name1'] = $field1;
|
||||
$params[':date1'] = $date1;
|
||||
$params[':coll_id_set0'] = $tmp_params[':coll_id_set0'];
|
||||
|
||||
$w = 'p1.name = :name1 AND :date1 <= p1.value';
|
||||
if ($sqlwhere[1] && $sqlwhere[2]) {
|
||||
if($sqlwhere[1] && $sqlwhere[2])
|
||||
{
|
||||
$w .= ' AND ((' . $sqlwhere[1] . ') OR (' . $sqlwhere[2] . '))';
|
||||
$params[':coll_id_where1'] = $tmp_params[':coll_id_where1'];
|
||||
$params[':coll_id_where2'] = $tmp_params[':coll_id_where2'];
|
||||
} else {
|
||||
if ($sqlwhere[1]) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if($sqlwhere[1])
|
||||
{
|
||||
$w .= ' AND ' . $sqlwhere[1];
|
||||
$params[':coll_id_where1'] = $tmp_params[':coll_id_where1'];
|
||||
} elseif ($sqlwhere[2]) {
|
||||
}
|
||||
elseif($sqlwhere[2])
|
||||
{
|
||||
$w .= ' AND ' . $sqlwhere[2];
|
||||
$params[':coll_id_where2'] = $tmp_params[':coll_id_where2'];
|
||||
}
|
||||
@@ -748,11 +796,12 @@ class task_period_outofdate extends task_abstract
|
||||
SET " . $sqlset[0] .
|
||||
" WHERE " . $w;
|
||||
|
||||
$ret[] = array('sql' => $sql, 'params' => $params);
|
||||
$ret[] = array('sql'=>$sql, 'params'=>$params);
|
||||
}
|
||||
|
||||
|
||||
if ($date1 && $date2) {
|
||||
if($date1 && $date2)
|
||||
{
|
||||
$params = array();
|
||||
$params[':name1'] = $field1;
|
||||
$params[':name2'] = $field2;
|
||||
@@ -761,15 +810,21 @@ class task_period_outofdate extends task_abstract
|
||||
$params[':coll_id_set1'] = $tmp_params[':coll_id_set1'];
|
||||
|
||||
$w = 'p1.name = :name1 AND p2.name = :name2 AND :date1 > p1.value AND :date2 <= p2.value';
|
||||
if ($sqlwhere[0] && $sqlwhere[2]) {
|
||||
if($sqlwhere[0] && $sqlwhere[2])
|
||||
{
|
||||
$w .= ' AND ((' . $sqlwhere[0] . ') OR (' . $sqlwhere[2] . '))';
|
||||
$params[':coll_id_where0'] = $tmp_params[':coll_id_where0'];
|
||||
$params[':coll_id_where2'] = $tmp_params[':coll_id_where2'];
|
||||
} else {
|
||||
if ($sqlwhere[0]) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if($sqlwhere[0])
|
||||
{
|
||||
$w .= ' AND ' . $sqlwhere[0];
|
||||
$params[':coll_id_where0'] = $tmp_params[':coll_id_where0'];
|
||||
} elseif ($sqlwhere[2]) {
|
||||
}
|
||||
elseif($sqlwhere[2])
|
||||
{
|
||||
$w .= ' AND ' . $sqlwhere[2];
|
||||
$params[':coll_id_where2'] = $tmp_params[':coll_id_where2'];
|
||||
}
|
||||
@@ -780,26 +835,33 @@ class task_period_outofdate extends task_abstract
|
||||
SET " . $sqlset[1] .
|
||||
" WHERE " . $w;
|
||||
|
||||
$ret[] = array('sql' => $sql, 'params' => $params);
|
||||
$ret[] = array('sql'=>$sql, 'params'=>$params);
|
||||
}
|
||||
|
||||
|
||||
if ($date2 && $sqlset[2]) {
|
||||
if($date2 && $sqlset[2])
|
||||
{
|
||||
$params = array();
|
||||
$params[':name2'] = $field2;
|
||||
$params[':date2'] = $date2;
|
||||
$params[':coll_id_set2'] = $tmp_params[':coll_id_set2'];
|
||||
|
||||
$w = 'p2.name = :name2 AND :date2 > p2.value';
|
||||
if ($sqlwhere[0] && $sqlwhere[1]) {
|
||||
if($sqlwhere[0] && $sqlwhere[1])
|
||||
{
|
||||
$w .= ' AND ((' . $sqlwhere[0] . ') OR (' . $sqlwhere[1] . '))';
|
||||
$params[':coll_id_where0'] = $tmp_params[':coll_id_where0'];
|
||||
$params[':coll_id_where1'] = $tmp_params[':coll_id_where1'];
|
||||
} else {
|
||||
if ($sqlwhere[0]) {
|
||||
}
|
||||
else
|
||||
{
|
||||
if($sqlwhere[0])
|
||||
{
|
||||
$w .= ' AND ' . $sqlwhere[0];
|
||||
$params[':coll_id_where0'] = $tmp_params[':coll_id_where0'];
|
||||
} elseif ($sqlwhere[1]) {
|
||||
}
|
||||
elseif($sqlwhere[1])
|
||||
{
|
||||
$w .= ' AND ' . $sqlwhere[1];
|
||||
$params[':coll_id_where1'] = $tmp_params[':coll_id_where1'];
|
||||
}
|
||||
@@ -809,12 +871,14 @@ class task_period_outofdate extends task_abstract
|
||||
SET " . $sqlset[2] .
|
||||
" WHERE " . $w;
|
||||
|
||||
$ret[] = array('sql' => $sql, 'params' => $params);
|
||||
$ret[] = array('sql'=>$sql, 'params'=>$params);
|
||||
}
|
||||
|
||||
return($ret);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function facility()
|
||||
{
|
||||
$ret = NULL;
|
||||
@@ -826,7 +890,8 @@ class task_period_outofdate extends task_abstract
|
||||
|
||||
phrasea::headers(200, true, 'application/json', 'UTF-8', false);
|
||||
$ret = NULL;
|
||||
switch ($parm2['ACT']) {
|
||||
switch($parm2['ACT'])
|
||||
{
|
||||
case 'CALCSQL':
|
||||
$xml = $this->graphic2xml('<?xml version="1.0" encoding="UTF-8"?><tasksettings/>');
|
||||
$sxml = simplexml_load_string($xml);
|
||||
@@ -835,28 +900,34 @@ class task_period_outofdate extends task_abstract
|
||||
case 'GETBASE':
|
||||
$ret = array('date_fields' => array(), 'status_bits' => array(), 'collections' => array());
|
||||
|
||||
if ($parm2['bid'] != '') {
|
||||
if($parm2['bid'] != '')
|
||||
{
|
||||
$sbas_id = (int) $parm2['bid'];
|
||||
try {
|
||||
try
|
||||
{
|
||||
$databox = databox::get_instance($sbas_id);
|
||||
$meta_struct = $databox->get_meta_structure();
|
||||
|
||||
foreach ($meta_struct as $meta) {
|
||||
if (mb_strtolower($meta->get_type()) == 'date')
|
||||
foreach($meta_struct as $meta)
|
||||
{
|
||||
if(mb_strtolower($meta->get_type()) == 'date')
|
||||
$ret['date_fields'][] = $meta->get_name();
|
||||
}
|
||||
|
||||
$status = $databox->get_statusbits();
|
||||
foreach ($status as $n => $stat) {
|
||||
foreach($status as $n => $stat)
|
||||
{
|
||||
$labelon = $stat['labelon'] ? $stat['labelon'] : ($n . '-ON');
|
||||
$labeloff = $stat['labeloff'] ? $stat['labeloff'] : ($n . '-OFF');
|
||||
$ret['status_bits'][] = array('n' => $n, 'value' => 0, 'label' => $labeloff);
|
||||
$ret['status_bits'][] = array('n' => $n, 'value' => 1, 'label' => $labelon);
|
||||
}
|
||||
|
||||
foreach ($databox->get_collections() as $collection)
|
||||
foreach($databox->get_collections() as $collection)
|
||||
$ret['collections'][] = array('id' => $collection->get_coll_id(), 'name' => $collection->get_name());
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -865,4 +936,5 @@ class task_period_outofdate extends task_abstract
|
||||
print(json_encode($ret));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
Reference in New Issue
Block a user