diff options
| author | 2018-06-03 13:35:38 +0200 | |
|---|---|---|
| committer | 2018-06-03 13:35:38 +0200 | |
| commit | c0122003fe3031926546012b86a38b5187082613 (patch) | |
| tree | 5502841327e7775f280fbd12732b4e8b8b7be6ff /app/Models/CategoryDAO.php | |
| parent | 029f4107123f6c318584bf9a43da7118c318657f (diff) | |
| parent | be778c6bc2d8075e5a923153183b47507a2a71e3 (diff) | |
Merge pull request #1902 from FreshRSS/dev1.11.0
FreshRSS 1.11.0
Diffstat (limited to 'app/Models/CategoryDAO.php')
| -rw-r--r-- | app/Models/CategoryDAO.php | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php index 68db17db3..ef2c402a0 100644 --- a/app/Models/CategoryDAO.php +++ b/app/Models/CategoryDAO.php @@ -134,7 +134,11 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo implements FreshRSS_Searchable if (isset($cat[0])) { return $cat[0]; } else { - return false; + if (FreshRSS_Context::$isCli) { + fwrite(STDERR, 'FreshRSS database error: Default category not found!' . "\n"); + } + Minz_Log::error('FreshRSS database error: Default category not found!'); + return null; } } public function checkDefault() { @@ -144,13 +148,27 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo implements FreshRSS_Searchable $cat = new FreshRSS_Category(_t('gen.short.default_category')); $cat->_id(self::DEFAULTCATEGORYID); + $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');"; + } + $stm = $this->bd->prepare($sql); + $values = array( - 'id' => $cat->id(), - 'name' => $cat->name(), + $cat->id(), + $cat->name(), ); - $this->addCategory($values); + if ($stm && $stm->execute($values)) { + return $this->bd->lastInsertId('"' . $this->prefix . 'category_id_seq"'); + } else { + $info = $stm == null ? array(2 => 'syntax error') : $stm->errorInfo(); + Minz_Log::error('SQL error check default category: ' . json_encode($info)); + return false; + } } + return true; } public function count() { |
