summaryrefslogtreecommitdiff
path: root/app/Models/CategoryDAO.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2018-10-28 09:49:10 +0100
committerGravatar GitHub <noreply@github.com> 2018-10-28 09:49:10 +0100
commite04804d0f67dd43fd3f072b9a127768ee7b7b56c (patch)
treea49023ed25aab7fb1c1aafe749f7d462de0027b2 /app/Models/CategoryDAO.php
parent44bd07e506ade204151c276fdc05994d51efdd7a (diff)
parent4234dfe0d72b61fe931d2c76a1d8a335ce65a209 (diff)
Merge pull request #2049 from FreshRSS/dev1.12.0
FreshRSS 1.12.0
Diffstat (limited to 'app/Models/CategoryDAO.php')
-rw-r--r--app/Models/CategoryDAO.php17
1 files changed, 12 insertions, 5 deletions
diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php
index cf6b3bae3..ba7eb765e 100644
--- a/app/Models/CategoryDAO.php
+++ b/app/Models/CategoryDAO.php
@@ -5,11 +5,15 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo implements FreshRSS_Searchable
const DEFAULTCATEGORYID = 1;
public function addCategory($valuesTmp) {
- $sql = 'INSERT INTO `' . $this->prefix . 'category`(name) VALUES(?)';
+ $sql = 'INSERT INTO `' . $this->prefix . 'category`(name) '
+ . 'SELECT * FROM (SELECT TRIM(?)) c2 ' //TRIM() to provide a type hint as text for PostgreSQL
+ . 'WHERE NOT EXISTS (SELECT 1 FROM `' . $this->prefix . 'tag` WHERE name = TRIM(?))'; //No tag of the same name
$stm = $this->bd->prepare($sql);
+ $valuesTmp['name'] = mb_strcut(trim($valuesTmp['name']), 0, FreshRSS_DatabaseDAO::LENGTH_INDEX_UNICODE, 'UTF-8');
$values = array(
- mb_strcut($valuesTmp['name'], 0, 255, 'UTF-8'),
+ $valuesTmp['name'],
+ $valuesTmp['name'],
);
if ($stm && $stm->execute($values)) {
@@ -35,12 +39,15 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo implements FreshRSS_Searchable
}
public function updateCategory($id, $valuesTmp) {
- $sql = 'UPDATE `' . $this->prefix . 'category` SET name=? WHERE id=?';
+ $sql = 'UPDATE `' . $this->prefix . 'category` SET name=? WHERE id=? '
+ . 'AND NOT EXISTS (SELECT 1 FROM `' . $this->prefix . 'tag` WHERE name = ?)'; //No tag of the same name
$stm = $this->bd->prepare($sql);
+ $valuesTmp['name'] = mb_strcut(trim($valuesTmp['name']), 0, FreshRSS_DatabaseDAO::LENGTH_INDEX_UNICODE, 'UTF-8');
$values = array(
$valuesTmp['name'],
- $id
+ $id,
+ $valuesTmp['name'],
);
if ($stm && $stm->execute($values)) {
@@ -151,7 +158,7 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo implements FreshRSS_Searchable
$sql = 'INSERT INTO `' . $this->prefix . 'category`(id, name) VALUES(?, ?)';
if (parent::$sharedDbType === 'pgsql') {
//Force call to nextval()
- $sql .= " RETURNING nextval('" . $this->prefix . "category_id_seq');";
+ $sql .= ' RETURNING nextval(\'"' . $this->prefix . 'category_id_seq"\');';
}
$stm = $this->bd->prepare($sql);