mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
Refactor separator check
Add InvalidArgument Exception if name is invalid Remove unused method is_distinct
This commit is contained in:
@@ -103,7 +103,7 @@ class databox_field implements cache_cacheableInterface
|
|||||||
* @var boolean
|
* @var boolean
|
||||||
*/
|
*/
|
||||||
protected $Business;
|
protected $Business;
|
||||||
protected $renamed = false;
|
protected $renamed = false;
|
||||||
protected $metaToMerge = false;
|
protected $metaToMerge = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -200,19 +200,8 @@ class databox_field implements cache_cacheableInterface
|
|||||||
$this->dces_element = new $dc_class();
|
$this->dces_element = new $dc_class();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->multi)
|
$this->separator = self::checkMultiSeparator($row['separator'], $this->multi);
|
||||||
{
|
|
||||||
$separator = "";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$separator = $row['separator'];
|
|
||||||
|
|
||||||
if (strpos($separator, ';') === false)
|
|
||||||
$separator .= ';';
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->separator = $separator;
|
|
||||||
$this->thumbtitle = $row['thumbtitle'];
|
$this->thumbtitle = $row['thumbtitle'];
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@@ -441,7 +430,14 @@ class databox_field implements cache_cacheableInterface
|
|||||||
{
|
{
|
||||||
$previous_name = $this->name;
|
$previous_name = $this->name;
|
||||||
|
|
||||||
$this->name = self::generateName($name);
|
$name = self::generateName($name);
|
||||||
|
|
||||||
|
if($name === '')
|
||||||
|
{
|
||||||
|
throw new \Exception_InvalidArgument();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->name = $name;
|
||||||
|
|
||||||
if ($this->name !== $previous_name)
|
if ($this->name !== $previous_name)
|
||||||
{
|
{
|
||||||
@@ -592,13 +588,15 @@ class databox_field implements cache_cacheableInterface
|
|||||||
{
|
{
|
||||||
$multi = !!$multi;
|
$multi = !!$multi;
|
||||||
|
|
||||||
if($this->multi !== $multi && !$multi)
|
if ($this->multi !== $multi && !$multi)
|
||||||
{
|
{
|
||||||
$this->metaToMerge = true;
|
$this->metaToMerge = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->multi = $multi;
|
$this->multi = $multi;
|
||||||
|
|
||||||
|
$this->set_separator(';');
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -645,14 +643,26 @@ class databox_field implements cache_cacheableInterface
|
|||||||
*/
|
*/
|
||||||
public function set_separator($separator)
|
public function set_separator($separator)
|
||||||
{
|
{
|
||||||
if (strpos($separator, ';') === false)
|
$this->separator = self::checkMultiSeparator($separator, $this->multi);
|
||||||
$separator .= ';';
|
|
||||||
|
|
||||||
$this->separator = $separator;
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static function checkMultiSeparator($separator, $multi)
|
||||||
|
{
|
||||||
|
if (!$multi)
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strpos($separator, ';') === false)
|
||||||
|
{
|
||||||
|
$separator .= ';';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $separator;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param string $type
|
* @param string $type
|
||||||
@@ -746,15 +756,6 @@ class databox_field implements cache_cacheableInterface
|
|||||||
return $this->multi;
|
return $this->multi;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @return boolean
|
|
||||||
*/
|
|
||||||
public function is_distinct()
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return boolean
|
* @return boolean
|
||||||
@@ -827,12 +828,19 @@ class databox_field implements cache_cacheableInterface
|
|||||||
(`id`, `name`, `src`, `readonly`, `indexable`, `type`, `tbranch`,
|
(`id`, `name`, `src`, `readonly`, `indexable`, `type`, `tbranch`,
|
||||||
`thumbtitle`, `multi`, `business`,
|
`thumbtitle`, `multi`, `business`,
|
||||||
`report`, `sorter`)
|
`report`, `sorter`)
|
||||||
VALUES (null, :name, '', 0, 1, 'text', '',
|
VALUES (null, :name, '', 0, 1, 'string', '',
|
||||||
null, 0,
|
null, 0,
|
||||||
0, 1, :sorter)";
|
0, 1, :sorter)";
|
||||||
|
|
||||||
|
$name = self::generateName($name);
|
||||||
|
|
||||||
|
if($name === '')
|
||||||
|
{
|
||||||
|
throw new \Exception_InvalidArgument();
|
||||||
|
}
|
||||||
|
|
||||||
$stmt = $databox->get_connection()->prepare($sql);
|
$stmt = $databox->get_connection()->prepare($sql);
|
||||||
$stmt->execute(array(':name' => self::generateName($name), ':sorter' => $sorter));
|
$stmt->execute(array(':name' => $name, ':sorter' => $sorter));
|
||||||
$id = $databox->get_connection()->lastInsertId();
|
$id = $databox->get_connection()->lastInsertId();
|
||||||
$stmt->closeCursor();
|
$stmt->closeCursor();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user