Skip to content

Commit

Permalink
Fix changing a dataset column datatype
Browse files Browse the repository at this point in the history
  • Loading branch information
dasgarner committed Jun 5, 2017
1 parent 1ef57ae commit 13f504e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions lib/Entity/DataSetColumn.php
Expand Up @@ -267,6 +267,7 @@ private function add()
/**
* Edit
* @param array $options
* @throws InvalidArgumentException
*/
private function edit($options)
{
Expand All @@ -291,12 +292,18 @@ private function edit($options)
'dataSetColumnId' => $this->dataSetColumnId
]);

if ($options['rebuilding'] && $this->dataSetColumnTypeId == 1) {
$this->getStore()->isolated('ALTER TABLE `dataset_' . $this->dataSetId . '` ADD `' . $this->heading . '` ' . $this->sqlDataType() . ' NULL', []);
try {

} else if ($this->dataSetColumnTypeId == 1 && $this->hasPropertyChanged('heading')) {
$sql = 'ALTER TABLE `dataset_' . $this->dataSetId . '` CHANGE `' . $this->getOriginalValue('heading') . '` `' . $this->heading . '` ' . $this->sqlDataType() . ' NULL DEFAULT NULL';
$this->getStore()->isolated($sql, []);
if ($options['rebuilding'] && $this->dataSetColumnTypeId == 1) {
$this->getStore()->isolated('ALTER TABLE `dataset_' . $this->dataSetId . '` ADD `' . $this->heading . '` ' . $this->sqlDataType() . ' NULL', []);

} else if ($this->dataSetColumnTypeId == 1 && ($this->hasPropertyChanged('heading') || $this->hasPropertyChanged('dataTypeId'))) {
$sql = 'ALTER TABLE `dataset_' . $this->dataSetId . '` CHANGE `' . $this->getOriginalValue('heading') . '` `' . $this->heading . '` ' . $this->sqlDataType() . ' NULL DEFAULT NULL';
$this->getStore()->isolated($sql, []);
}
} catch (\PDOException $PDOException) {
$this->getLog()->error('Unable to change DataSetColumn because ' . $PDOException->getMessage());
throw new InvalidArgumentException(__('Existing data is incompatible with your new configuration'), 'dataSetData');
}
}

Expand Down

0 comments on commit 13f504e

Please sign in to comment.