Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
Merge pull request #132 from midasplatform/cleave_tracker_params_pt2
Browse files Browse the repository at this point in the history
Cleave tracker params pt2
  • Loading branch information
jamiesnape committed Oct 5, 2015
2 parents 4f83b1f + 3daa7bc commit 3f6f093
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 7 deletions.
2 changes: 1 addition & 1 deletion modules/tracker/controllers/ScalarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function detailsAction()

$this->view->isAdmin = $this->Tracker_Scalar->policyCheck($scalarDao, $this->userSession->Dao, MIDAS_POLICY_ADMIN);
$this->view->scalar = $scalarDao;
$this->view->extraParams = json_decode($scalarDao->getParams(), true);
$this->view->extraParams = $scalarDao->getParams();
$this->view->extraUrls = json_decode($scalarDao->getExtraUrls(), true);

$revisionUrl = $scalarDao->getTrend()->getProducer()->getRevisionUrl();
Expand Down
1 change: 0 additions & 1 deletion modules/tracker/database/mysql/1.2.2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ CREATE TABLE IF NOT EXISTS `tracker_scalar` (
`official` tinyint(4) NOT NULL DEFAULT '1',
`build_results_url` text NOT NULL,
`branch` varchar(255) NOT NULL DEFAULT '',
`params` text,
`extra_urls` text,
PRIMARY KEY (`scalar_id`),
KEY (`trend_id`),
Expand Down
1 change: 0 additions & 1 deletion modules/tracker/database/pgsql/1.2.2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ CREATE TABLE IF NOT EXISTS "tracker_scalar" (
"official" smallint NOT NULL DEFAULT 1::smallint,
"build_results_url" text NOT NULL,
"branch" character varying(255) NOT NULL DEFAULT ''::character varying,
"params" text,
"extra_urls" text
);

Expand Down
1 change: 0 additions & 1 deletion modules/tracker/database/sqlite/1.2.2.sql
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ CREATE TABLE IF NOT EXISTS "tracker_scalar" (
"official" INTEGER NOT NULL DEFAULT 1,
"build_results_url" TEXT NOT NULL,
"branch" TEXT NOT NULL DEFAULT '',
"params" TEXT,
"extra_urls" TEXT
);

Expand Down
34 changes: 34 additions & 0 deletions modules/tracker/database/upgrade/1.2.2.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public function mysql()
PRIMARY KEY (`param_id`),
KEY (`param_name`)
) DEFAULT CHARSET=utf8;");
$this->migrateScalarParams();
$this->db->query('ALTER TABLE `tracker_scalar` DROP `params`;');
}

/** Upgrade a PostgreSQL database. */
Expand All @@ -50,5 +52,37 @@ public function pgsql()
numeric_value double precision);"
);
$this->db->query('CREATE INDEX tracker_param_param_name_idx ON tracker_param (param_name);');
$this->migrateScalarParams();
$this->db->query('ALTER TABLE tracker_scalar DROP COLUMN params;');
}

/** Migrate tracker_scalar params to tracker_param. */
private function migrateScalarParams()
{
$count = 0;
$logger = Zend_Registry::get('logger');
$logger->debug('migrateScalarParams');
/** @var Tracker_ParamModel $paramModel */
$paramModel = MidasLoader::loadModel('Param', $this->moduleName);
$uresult = $this->db->query('SELECT scalar_id, params FROM tracker_scalar WHERE params IS NOT NULL;');
if ($uresult !== false) {
while ($row = $uresult->fetch(PDO::FETCH_ASSOC)) {
if ($count % 1000 === 0) {
$logger->debug('Count '.$count);
}
++$count;
$scalarId = $row['scalar_id'];
$params = $row['params'];
$params = json_decode($params, true);
foreach ($params as $paramName => $paramValue) {
/** @var Tracker_ParamDao $paramDao */
$paramDao = MidasLoader::newDao('ParamDao', $this->moduleName);
$paramDao->setScalarId($scalarId);
$paramDao->setParamName($paramName);
$paramDao->setParamValue($paramValue);
$paramModel->save($paramDao);
}
}
}
}
}
2 changes: 1 addition & 1 deletion modules/tracker/models/dao/ParamDao.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function setParamValue($paramValue)
* Get the value of the param, regardless of its type, returning either a
* numeric or a string.
*
* @return float|int|string.
* @return float|int|string|null.
*/
public function getParamValue()
{
Expand Down
4 changes: 2 additions & 2 deletions modules/tracker/views/scalar/details.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ if (count($this->extraParams)) {
<tbody>
<?php
/** @var Tracker_ParamDao $param */
foreach ($this->extraParams as $key => $value) {
echo '<tr><th>'.$this->escape($key).':</th><td>'.$this->escape($value).'</td></tr>';
foreach ($this->extraParams as $param) {
echo '<tr><th>'.$this->escape($param->getParamName()).':</th><td>'.$this->escape($param->getParamValue()).'</td></tr>';
}
?>
</tbody>
Expand Down

0 comments on commit 3f6f093

Please sign in to comment.