Skip to content

Commit

Permalink
refs matomo-org#4706 while having a look on this issue I noticed anot…
Browse files Browse the repository at this point in the history
…her issue with this method. There were codepaths that were never reached. For instance if columnToSumValue is a string the check for being false as well cannot work
  • Loading branch information
tsteur committed May 9, 2014
1 parent eb9b78e commit f008cad
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions core/DataTable/Row.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Exception;
use Piwik\DataTable;
use Piwik\Log;
use Piwik\Metrics;

/**
Expand Down Expand Up @@ -455,8 +456,10 @@ public function sumRow(Row $rowToSum, $enableCopyMetadata = true, $aggregationOp
{
$thisColumnValue = $this->getColumn($columnToSumName);

$operation = (is_array($aggregationOperations) && isset($aggregationOperations[$columnToSumName]) ?
strtolower($aggregationOperations[$columnToSumName]) : 'sum');
$operation = 'sum';
if (is_array($aggregationOperations) && isset($aggregationOperations[$columnToSumName])) {
$operation = strtolower($aggregationOperations[$columnToSumName]);
}

// max_actions is a core metric that is generated in ArchiveProcess_Day. Therefore, it can be
// present in any data table and is not part of the $aggregationOperations mechanism.
Expand All @@ -466,6 +469,7 @@ public function sumRow(Row $rowToSum, $enableCopyMetadata = true, $aggregationOp
if(empty($operation)) {
throw new Exception("Unknown aggregation operation for column $columnToSumName.");
}

$newValue = $this->getColumnValuesMerged($operation, $thisColumnValue, $columnToSumValue);

$this->setColumn($columnToSumName, $newValue);
Expand Down Expand Up @@ -558,10 +562,15 @@ protected function sumRowArray($thisColumnValue, $columnToSumValue)
return $thisColumnValue + $columnToSumValue;
}

if ($columnToSumValue === false) {
return $thisColumnValue;
}

if ($thisColumnValue === false) {
return $columnToSumValue;
}

if (is_array($columnToSumValue)) {
if ($thisColumnValue == false) {
return $columnToSumValue;
}
$newValue = $thisColumnValue;
foreach ($columnToSumValue as $arrayIndex => $arrayValue) {
if (!isset($newValue[$arrayIndex])) {
Expand All @@ -573,14 +582,8 @@ protected function sumRowArray($thisColumnValue, $columnToSumValue)
}

if (is_string($columnToSumValue)) {
if ($thisColumnValue === false) {
return $columnToSumValue;
} else if ($columnToSumValue === false) {
return $thisColumnValue;
} else {
throw new Exception("Trying to add two strings in DataTable\Row::sumRowArray: "
. "'$thisColumnValue' + '$columnToSumValue'" . " for row " . $this->__toString());
}
throw new Exception("Trying to add two strings in DataTable\Row::sumRowArray: "
. "'$thisColumnValue' + '$columnToSumValue'" . " for row " . $this->__toString());
}

return 0;
Expand Down

0 comments on commit f008cad

Please sign in to comment.