Merge pull request #1095 from jygaulier/fix-phras-141

[3.8.6][PHRAS-141] Delete action is not taken into account for tasks
This commit is contained in:
Nicolas Le Goff
2014-08-19 16:43:26 +02:00

View File

@@ -366,7 +366,6 @@ class task_period_RecordMover extends task_appboxAbstract
switch ($task['action']) { switch ($task['action']) {
case 'UPDATE': case 'UPDATE':
// change collection ? // change collection ?
if (($x = (int) ($sxtask->to->coll['id'])) > 0) { if (($x = (int) ($sxtask->to->coll['id'])) > 0) {
$tmp['coll'] = $x; $tmp['coll'] = $x;
@@ -531,6 +530,8 @@ class task_period_RecordMover extends task_appboxAbstract
*/ */
private function calcUPDATE($sbas_id, &$sxtask, $playTest) private function calcUPDATE($sbas_id, &$sxtask, $playTest)
{ {
$connbas = connection::getPDOConnection($this->dependencyContainer, $sbas_id);
$tws = array(); // NEGATION of updates, used to build the 'test' sql $tws = array(); // NEGATION of updates, used to build the 'test' sql
// //
// set coll_id ? // set coll_id ?
@@ -542,35 +543,38 @@ class task_period_RecordMover extends task_appboxAbstract
$x = $sxtask->to->status['mask']; $x = $sxtask->to->status['mask'];
$mx = str_replace(' ', '0', ltrim(str_replace(array('0', 'x'), array(' ', ' '), $x))); $mx = str_replace(' ', '0', ltrim(str_replace(array('0', 'x'), array(' ', ' '), $x)));
$ma = str_replace(' ', '0', ltrim(str_replace(array('x', '0'), array(' ', '1'), $x))); $ma = str_replace(' ', '0', ltrim(str_replace(array('x', '0'), array(' ', '1'), $x)));
if ($mx && $ma) if ($mx && $ma) {
$tws[] = '((status ^ 0b' . $mx . ') & 0b' . $ma . ')!=0'; $tws[] = '((status ^ ' . $connbas->quote('0b'.$mx) . ') & ' . $connbas->quote('0b'.$ma) . ')!=0';
elseif ($mx) }
$tws[] = '(status ^ 0b' . $mx . ')!=0'; elseif ($mx) {
elseif ($ma) $tws[] = '(status ^ ' . $connbas->quote('0b'.$mx) . ')!=0';
$tws[] = '(status & 0b' . $ma . ')!=0'; }
elseif ($ma) {
$tws[] = '(status & ' . $connbas->quote('0b'.$ma) . ')!=0';
}
// compute the 'where' clause // compute the 'where' clause
list($tw, $join) = $this->calcWhere($sbas_id, $sxtask); list($tw, $join) = $this->calcWhere($sbas_id, $sxtask);
// ... complete the where to buid the TEST // ... complete the where to buid the TEST
if (count($tws) == 1) if (count($tws) == 1) {
$tw[] = $tws[0]; $tw[] = $tws[0];
elseif (count($tws) > 1) }
elseif (count($tws) > 1) {
$tw[] = '(' . implode(') OR (', $tws) . ')'; $tw[] = '(' . implode(') OR (', $tws) . ')';
if (count($tw) == 1) }
$where = $tw[0];
if (count($tw) > 1)
$where = '(' . implode(') AND (', $tw) . ')';
// build the TEST sql (select) // build the TEST sql (select)
$sql_test = 'SELECT record_id FROM record' . $join; $sql_test = 'SELECT record_id FROM record' . $join;
if (count($tw) > 0) if (count($tw) > 0) {
$sql_test .= ' WHERE ' . ((count($tw) == 1) ? $tw[0] : '(' . implode(') AND (', $tw) . ')'); $sql_test .= ' WHERE ' . ((count($tw) == 1) ? $tw[0] : '(' . implode(') AND (', $tw) . ')');
}
// build the real sql (select) // build the real sql (select)
$sql = 'SELECT record_id FROM record' . $join; $sql = 'SELECT record_id FROM record' . $join;
if (count($tw) > 0) if (count($tw) > 0) {
$sql .= ' WHERE ' . ((count($tw) == 1) ? $tw[0] : '(' . implode(') AND (', $tw) . ')'); $sql .= ' WHERE ' . ((count($tw) == 1) ? $tw[0] : '(' . implode(') AND (', $tw) . ')');
}
$ret = array( $ret = array(
'real' => array( 'real' => array(
@@ -606,15 +610,16 @@ class task_period_RecordMover extends task_appboxAbstract
list($tw, $join) = $this->calcWhere($sbas_id, $sxtask); list($tw, $join) = $this->calcWhere($sbas_id, $sxtask);
// build the TEST sql (select) // build the TEST sql (select)
$sql_test = 'SELECT SQL_CALC_FOUND_ROWS record_id FROM record' . $join; $sql_test = 'SELECT record_id FROM record' . $join;
if (count($tw) > 0) if (count($tw) > 0) {
$sql_test .= ' WHERE ' . ((count($tw) == 1) ? $tw[0] : '(' . implode(') AND (', $tw) . ')'); $sql_test .= ' WHERE ' . ((count($tw) == 1) ? $tw[0] : '(' . implode(') AND (', $tw) . ')');
$sql_test .= ' LIMIT 10'; }
// build the real sql (select) // build the real sql (select)
$sql = 'SELECT record_id FROM record' . $join; $sql = 'SELECT record_id FROM record' . $join;
if (count($tw) > 0) if (count($tw) > 0) {
$sql .= ' WHERE ' . ((count($tw) == 1) ? $tw[0] : '(' . implode(') AND (', $tw) . ')'); $sql .= ' WHERE ' . ((count($tw) == 1) ? $tw[0] : '(' . implode(') AND (', $tw) . ')');
}
$ret = array( $ret = array(
'real' => array( 'real' => array(
@@ -671,8 +676,9 @@ class task_period_RecordMover extends task_appboxAbstract
$ijoin++; $ijoin++;
$comp = strtoupper($x['compare']); $comp = strtoupper($x['compare']);
if (in_array($comp, array('<', '>', '<=', '>=', '=', '!='))) { if (in_array($comp, array('<', '>', '<=', '>=', '=', '!='))) {
$s = 'p' . $ijoin . '.name=\'' . $x['field'] . '\' AND p' . $ijoin . '.value' . $comp; $s = 'p' . $ijoin . '.name=' . $connbas->quote($x['field']) . ' AND p' . $ijoin . '.value' . $comp
$s .= '' . $connbas->quote($x['value']) . ''; . '' . $connbas->quote($x['value']) . '';
// $s = 'p' . $ijoin . '.name=? AND p' . $ijoin . '.value' . $comp . '?';
$tw[] = $s; $tw[] = $s;
$join .= ' INNER JOIN prop AS p' . $ijoin . ' USING(record_id)'; $join .= ' INNER JOIN prop AS p' . $ijoin . ' USING(record_id)';
@@ -687,12 +693,15 @@ class task_period_RecordMover extends task_appboxAbstract
$s = 'p' . $ijoin . '.name=\'' . $x['field'] . '\' AND NOW()'; $s = 'p' . $ijoin . '.name=\'' . $x['field'] . '\' AND NOW()';
$s .= strtoupper($x['direction']) == 'BEFORE' ? '<' : '>='; $s .= strtoupper($x['direction']) == 'BEFORE' ? '<' : '>=';
$delta = (int) ($x['delta']); $delta = (int) ($x['delta']);
if ($delta > 0) if ($delta > 0) {
$s .= '(p' . $ijoin . '.value+INTERVAL ' . $delta . ' DAY)'; $s .= '(p' . $ijoin . '.value+INTERVAL ' . $delta . ' DAY)';
elseif ($delta < 0) }
elseif ($delta < 0) {
$s .= '(p' . $ijoin . '.value-INTERVAL ' . -$delta . ' DAY)'; $s .= '(p' . $ijoin . '.value-INTERVAL ' . -$delta . ' DAY)';
else }
else {
$s .= 'p' . $ijoin . '.value'; $s .= 'p' . $ijoin . '.value';
}
$tw[] = $s; $tw[] = $s;
$join .= ' INNER JOIN prop AS p' . $ijoin . ' USING(record_id)'; $join .= ' INNER JOIN prop AS p' . $ijoin . ' USING(record_id)';
@@ -725,18 +734,11 @@ class task_period_RecordMover extends task_appboxAbstract
$mx = str_replace(' ', '0', ltrim(str_replace(array('0', 'x'), array(' ', ' '), $x))); $mx = str_replace(' ', '0', ltrim(str_replace(array('0', 'x'), array(' ', ' '), $x)));
$ma = str_replace(' ', '0', ltrim(str_replace(array('x', '0'), array(' ', '1'), $x))); $ma = str_replace(' ', '0', ltrim(str_replace(array('x', '0'), array(' ', '1'), $x)));
if ($mx && $ma) { if ($mx && $ma) {
$tw[] = '((status^0b' . $mx . ')&0b' . $ma . ')=0'; $tw[] = '((status ^ ' . $connbas->quote('0b'.$mx) . ') & ' . $connbas->quote('0b'.$ma) . ')=0';
} elseif ($mx) { } elseif ($mx) {
$tw[] = '(status^0b' . $mx . ')=0'; $tw[] = '(status ^ ' . $connbas->quote('0b'.$mx) . ')=0';
} elseif ($ma) { } elseif ($ma) {
$tw[] = '(status&0b' . $ma . ")=0"; $tw[] = '(status & ' . $connbas->quote('0b'.$ma) . ")=0";
}
if (count($tw) == 1) {
$where = $tw[0];
}
if (count($tw) > 1) {
$where = '(' . implode(') AND (', $tw) . ')';
} }
return array($tw, $join); return array($tw, $join);