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