Skip to content

Commit

Permalink
fixes for column-length changes in pimcore
Browse files Browse the repository at this point in the history
  • Loading branch information
dpfaffenbauer committed Nov 28, 2017
1 parent 266dd02 commit b3171dd
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 11 deletions.
32 changes: 25 additions & 7 deletions lib/CoreShop/Model/Object/ClassDefinition/Data/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,38 @@ class Select extends Model\Object\ClassDefinition\Data\Select
*/
public $allowEmpty = false;

/**
* Correct old column definitions (e.g varchar(255)) to the new format
* @param $type
*/
protected function correctColumnDefinition($type)
{
preg_match("/(.*)\((\d+)\)/i", $this->$type, $matches);
if ($matches[2]) {
$this->{"set" . ucfirst($type)}($matches[1]);
if ($matches[2] > 190) {
$matches[2] = 190;
}
$this->setColumnLength($matches[2] <= 190 ? $matches[2] : 190);
}
}

/**
* @return string
*/
public function getColumnType()
{
return $this->columnType;
$this->correctColumnDefinition('columnType');
return $this->columnType . "(" . $this->getColumnLength() . ")";
}

/**
* @return string
*/
public function getQueryColumnType()
{
return $this->queryColumnType;
$this->correctColumnDefinition('queryColumnType');
return $this->queryColumnType . "(" . $this->getColumnLength() . ")";
}

/**
Expand Down Expand Up @@ -130,7 +148,7 @@ public function getDataForResource($data, $object = null, $params = [])
public function getDataFromResource($data, $object = null, $params = [])
{
if (intval($data) > 0) {
return call_user_func($this->getPhpdocType().'::getById', $data);
return call_user_func($this->getPhpdocType() . '::getById', $data);
}

return null;
Expand All @@ -141,7 +159,7 @@ public function getDataFromResource($data, $object = null, $params = [])
*
* @see Object\ClassDefinition\Data::getDataForQueryResource
*
* @param AbstractModel $data
* @param AbstractModel $data
* @param null|Model\Object\AbstractObject $object
* @param mixed $params
*
Expand All @@ -161,7 +179,7 @@ public function getDataForQueryResource($data, $object = null, $params = [])
*
* @see Object\ClassDefinition\Data::getDataForEditmode
*
* @param AbstractModel $data
* @param AbstractModel $data
* @param null|Model\Object\AbstractObject $object
* @param mixed $params
*
Expand All @@ -175,9 +193,9 @@ public function getDataForEditmode($data, $object = null, $params = [])
/**
* @see Model\Object\ClassDefinition\Data::getDataFromEditmode
*
* @param int $data
* @param int $data
* @param null|Model\Object\AbstractObject $object
* @param array $params
* @param array $params
*
* @return string
*/
Expand Down
31 changes: 27 additions & 4 deletions lib/Pimcore/Model/Object/ClassDefinition/Data/CoreShopLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,52 @@ class CoreShopLanguage extends Model\Object\ClassDefinition\Data\Select
*
* @var string
*/
public $queryColumnType = 'varchar(255)';
public $queryColumnType = 'varchar';

/**
* @var string
*/
public $columnLength = '255';

/**
* Type for the column.
*
* @var string
*/
public $columnType = 'varchar(255)';
public $columnType = 'varchar';

/**
* Correct old column definitions (e.g varchar(255)) to the new format
* @param $type
*/
protected function correctColumnDefinition($type)
{
preg_match("/(.*)\((\d+)\)/i", $this->$type, $matches);
if ($matches[2]) {
$this->{"set" . ucfirst($type)}($matches[1]);
if ($matches[2] > 190) {
$matches[2] = 190;
}
$this->setColumnLength($matches[2] <= 190 ? $matches[2] : 190);
}
}

/**
* @return string
*/
public function getColumnType()
{
return $this->columnType;
$this->correctColumnDefinition('columnType');
return $this->columnType . "(" . $this->getColumnLength() . ")";
}

/**
* @return string
*/
public function getQueryColumnType()
{
return $this->queryColumnType;
$this->correctColumnDefinition('queryColumnType');
return $this->queryColumnType . "(" . $this->getColumnLength() . ")";
}

/** True if change is allowed in edit mode.
Expand Down

0 comments on commit b3171dd

Please sign in to comment.