Renaming key / value columns in build_meta with meta_key / meta_value to avoid SQL errors.

This commit is contained in:
Dan Cryer 2013-10-08 13:00:38 +01:00
parent 524a0cc58a
commit 56b8a57efd
4 changed files with 34 additions and 34 deletions

View file

@ -35,8 +35,8 @@ class BuildMetaBase extends Model
'id' => null,
'project_id' => null,
'build_id' => null,
'key' => null,
'value' => null,
'meta_key' => null,
'meta_value' => null,
);
/**
@ -46,8 +46,8 @@ class BuildMetaBase extends Model
'id' => 'getId',
'project_id' => 'getProjectId',
'build_id' => 'getBuildId',
'key' => 'getKey',
'value' => 'getValue',
'meta_key' => 'getMetaKey',
'meta_value' => 'getMetaValue',
'Build' => 'getBuild',
);
@ -58,8 +58,8 @@ class BuildMetaBase extends Model
'id' => 'setId',
'project_id' => 'setProjectId',
'build_id' => 'setBuildId',
'key' => 'setKey',
'value' => 'setValue',
'meta_key' => 'setMetaKey',
'meta_value' => 'setMetaValue',
'Build' => 'setBuild',
);
@ -85,12 +85,12 @@ class BuildMetaBase extends Model
'nullable' => true,
'default' => null,
),
'key' => array(
'meta_key' => array(
'type' => 'varchar',
'length' => '255',
'default' => '',
),
'value' => array(
'meta_value' => array(
'type' => 'text',
'length' => '',
'nullable' => true,
@ -103,7 +103,7 @@ class BuildMetaBase extends Model
*/
public $indexes = array(
'PRIMARY' => array('unique' => true, 'columns' => 'id'),
'idx_meta_id' => array('unique' => true, 'columns' => 'build_id, key'),
'idx_meta_id' => array('unique' => true, 'columns' => 'build_id, meta_key'),
);
/**
@ -160,26 +160,26 @@ class BuildMetaBase extends Model
}
/**
* Get the value of Key / key.
* Get the value of MetaKey / meta_key.
*
* @return string
*/
public function getKey()
public function getMetaKey()
{
$rtn = $this->data['key'];
$rtn = $this->data['meta_key'];
return $rtn;
}
/**
* Get the value of Value / value.
* Get the value of MetaValue / meta_value.
*
* @return string
*/
public function getValue()
public function getMetaValue()
{
$rtn = $this->data['value'];
$rtn = $this->data['meta_value'];
return $rtn;
@ -242,40 +242,40 @@ class BuildMetaBase extends Model
}
/**
* Set the value of Key / key.
* Set the value of MetaKey / meta_key.
*
* Must not be null.
* @param $value string
*/
public function setKey($value)
public function setMetaKey($value)
{
$this->_validateNotNull('Key', $value);
$this->_validateString('Key', $value);
if ($this->data['key'] === $value) {
$this->_validateNotNull('MetaKey', $value);
$this->_validateString('MetaKey', $value);
if ($this->data['meta_key'] === $value) {
return;
}
$this->data['key'] = $value;
$this->data['meta_key'] = $value;
$this->_setModified('key');
$this->_setModified('meta_key');
}
/**
* Set the value of Value / value.
* Set the value of MetaValue / meta_value.
*
* @param $value string
*/
public function setValue($value)
public function setMetaValue($value)
{
$this->_validateString('Value', $value);
if ($this->data['value'] === $value) {
$this->_validateString('MetaValue', $value);
if ($this->data['meta_value'] === $value) {
return;
}
$this->data['value'] = $value;
$this->data['meta_value'] = $value;
$this->_setModified('value');
$this->_setModified('meta_value');
}
/**

View file

@ -51,7 +51,7 @@ class BuildStore extends BuildStoreBase
public function getMeta($key, $projectId, $buildId = null, $numResults = 1)
{
$and = $numResults > 1 ? ' AND (`build_id` <= :buildId) ' : ' AND (`build_id` = :buildId) ';
$query = 'SELECT `build_id`, `key`, `value` FROM `build_meta` WHERE `key` = :key AND `project_id` = :projectId ' . $and . ' ORDER BY id DESC LIMIT :numResults';
$query = 'SELECT `build_id`, `meta_key`, `meta_value` FROM `build_meta` WHERE `meta_key` = :key AND `project_id` = :projectId ' . $and . ' ORDER BY id DESC LIMIT :numResults';
$stmt = \b8\Database::getConnection('read')->prepare($query);
$stmt->bindValue(':key', $key, \PDO::PARAM_STR);
@ -64,7 +64,7 @@ class BuildStore extends BuildStoreBase
$rtn = array_reverse($rtn);
$rtn = array_map(function($item) {
$item['value'] = json_decode($item['value'], true);
$item['meta_value'] = json_decode($item['meta_value'], true);
return $item;
}, $rtn);
@ -81,7 +81,7 @@ class BuildStore extends BuildStoreBase
public function setMeta($projectId, $buildId, $key, $value)
{
$query = 'REPLACE INTO build_meta (project_id, build_id, `key`, `value`) VALUES (:projectId, :buildId, :key, :value)';
$query = 'REPLACE INTO build_meta (project_id, build_id, `meta_key`, `meta_value`) VALUES (:projectId, :buildId, :key, :value)';
$stmt = \b8\Database::getConnection('read')->prepare($query);
$stmt->bindValue(':key', $key, \PDO::PARAM_STR);

View file

@ -46,7 +46,7 @@ var locPlugin = PHPCI.UiPlugin.extend({
var data = [["Build", "Lines", "Comment Lines", "Non-Comment Lines", "Logical Lines"]];
for (var idx in build) {
data.push(['Build ' + build[idx].build_id, parseInt(build[idx].value.LOC), parseInt(build[idx].value.CLOC), parseInt(build[idx].value.NCLOC), parseInt(build[idx].value.LLOC)]);
data.push(['Build ' + build[idx].build_id, parseInt(build[idx].meta_value.LOC), parseInt(build[idx].meta_value.CLOC), parseInt(build[idx].meta_value.NCLOC), parseInt(build[idx].meta_value.LLOC)]);
}
var data = google.visualization.arrayToDataTable(data);

View file

@ -42,8 +42,8 @@ var plugin = PHPCI.UiPlugin.extend({
for (var i in build) {
var buildId = build[i]['build_id'];
var metaKey = build[i]['key'];
var metaVal = build[i]['value'];
var metaKey = build[i]['meta_key'];
var metaVal = build[i]['meta_value'];
if (!self.data[buildId]) {
self.data[buildId] = {};