diff --git a/modules/tracker/controllers/components/ApiComponent.php b/modules/tracker/controllers/components/ApiComponent.php index 632fbc78b..78974f2ce 100644 --- a/modules/tracker/controllers/components/ApiComponent.php +++ b/modules/tracker/controllers/components/ApiComponent.php @@ -247,7 +247,7 @@ public function scalarAdd($args) if (isset($args['unit'])) { $unit = $args['unit']; } else { - $unit = null; + $unit = false; } /** @var Tracker_TrendModel $trendModel */ $trendModel = MidasLoader::loadModel('Trend', 'tracker'); diff --git a/modules/tracker/models/base/TrendModelBase.php b/modules/tracker/models/base/TrendModelBase.php index 91ec91988..b49a32914 100644 --- a/modules/tracker/models/base/TrendModelBase.php +++ b/modules/tracker/models/base/TrendModelBase.php @@ -75,17 +75,17 @@ public function __construct() } /** - * Return the trend DAO that matches the given the producer id, metric name, and associated items. + * Return the trend DAO that matches the given the producer id, metric name, associated items, and unit. * * @param int $producerId producer id * @param string $metricName metric name * @param null|int $configItemId configuration item id * @param null|int $testDatasetId test dataset item id * @param null|int $truthDatasetId truth dataset item id - * @param null|string $unit scalar value unit + * @param false|string $unit (Optional) scalar value unit, defaults to false * @return false|Tracker_TrendDao trend DAO or false if none exists */ - abstract public function getMatch($producerId, $metricName, $configItemId, $testDatasetId, $truthDatasetId, $unit); + abstract public function getMatch($producerId, $metricName, $configItemId, $testDatasetId, $truthDatasetId, $unit = false); /** * Return the trend DAOs that match the given associative array of database columns and values. @@ -129,7 +129,7 @@ public function save($trendDao) } /** - * Return the trend DAO that matches the given producer id, metric name, and associated items if it exists. + * Return the trend DAO that matches the given producer id, metric name, associated items, and unit, if the trend exists. * Otherwise, create the trend DAO. * * @param int $producerId producer id @@ -137,10 +137,10 @@ public function save($trendDao) * @param null|int $configItemId configuration item id * @param null|int $testDatasetId test dataset item id * @param null|int $truthDatasetId truth dataset item id - * @param null|string $unit scalar value unit + * @param false|string $unit (Optional) scalar value unit, defaults to false * @return Tracker_TrendDao trend DAO */ - public function createIfNeeded($producerId, $metricName, $configItemId, $testDatasetId, $truthDatasetId, $unit) + public function createIfNeeded($producerId, $metricName, $configItemId, $testDatasetId, $truthDatasetId, $unit = false) { $trendDao = $this->getMatch($producerId, $metricName, $configItemId, $testDatasetId, $truthDatasetId, $unit); @@ -150,7 +150,7 @@ public function createIfNeeded($producerId, $metricName, $configItemId, $testDat $trendDao->setProducerId($producerId); $trendDao->setMetricName($metricName); $trendDao->setDisplayName($metricName); - if (is_null($unit)) { + if ($unit === false) { $unit = ''; } $trendDao->setUnit($unit); diff --git a/modules/tracker/models/pdo/TrendModel.php b/modules/tracker/models/pdo/TrendModel.php index 88db47232..c8d64dc2f 100644 --- a/modules/tracker/models/pdo/TrendModel.php +++ b/modules/tracker/models/pdo/TrendModel.php @@ -24,17 +24,17 @@ class Tracker_TrendModel extends Tracker_TrendModelBase { /** - * Return the trend DAO that matches the given the producer id, metric name, and associated items. + * Return the trend DAO that matches the given the producer id, metric name, associated items, and unit. * * @param int $producerId producer id * @param string $metricName metric name * @param null|int $configItemId configuration item id * @param null|int $testDatasetId test dataset item id * @param null|int $truthDatasetId truth dataset item id - * @param null|string $unit scalar value unit + * @param false|string $unit (Optional) scalar value unit, defaults to false * @return false|Tracker_TrendDao trend DAO or false if none exists */ - public function getMatch($producerId, $metricName, $configItemId, $testDatasetId, $truthDatasetId, $unit) + public function getMatch($producerId, $metricName, $configItemId, $testDatasetId, $truthDatasetId, $unit = false) { $sql = $this->database->select()->setIntegrityCheck(false)->where('producer_id = ?', $producerId)->where( 'metric_name = ?', @@ -59,7 +59,7 @@ public function getMatch($producerId, $metricName, $configItemId, $testDatasetId $sql->where('test_dataset_id = ?', $testDatasetId); } - if (!is_null($unit) && ($unit !== '')) { + if ($unit !== false) { $sql->where('unit = ?', $unit); } diff --git a/modules/tracker/tests/controllers/ApiControllerTest.php b/modules/tracker/tests/controllers/ApiControllerTest.php index 550837060..6788a6325 100644 --- a/modules/tracker/tests/controllers/ApiControllerTest.php +++ b/modules/tracker/tests/controllers/ApiControllerTest.php @@ -75,10 +75,10 @@ public function testUploadScalarWithSubmission() * @param string $uuid the uuid of the submission * @param string $metric the metric name of the trend * @param float $value the scalar value - * @param string $unit the unit of the trend, defaults to false + * @param false|string $unit (Optional) the unit of the trend, defaults to false * @return mixed response object from the API */ - protected function _submitScalar($token, $uuid, $metric, $value, $unit = false) + private function _submitScalar($token, $uuid, $metric, $value, $unit = false) { $this->resetAll(); $this->params['method'] = 'midas.tracker.scalar.add';