aboutsummaryrefslogtreecommitdiff
path: root/app/Models/EntryDAO.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Models/EntryDAO.php')
-rw-r--r--app/Models/EntryDAO.php67
1 files changed, 32 insertions, 35 deletions
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php
index 6a00e2108..e22650f0d 100644
--- a/app/Models/EntryDAO.php
+++ b/app/Models/EntryDAO.php
@@ -138,10 +138,7 @@ SQL;
return false;
}
- /**
- * @var PDOStatement|null|false
- */
- private $addEntryPrepared = false;
+ private PDOStatement|null|false $addEntryPrepared = null;
/** @param array{'id':string,'guid':string,'title':string,'author':string,'content':string,'link':string,'date':int,'lastSeen':int,'hash':string,
* 'is_read':bool|int|null,'is_favorite':bool|int|null,'id_feed':int,'tags':string,'attributes'?:null|string|array<string,mixed>} $valuesTmp */
@@ -158,7 +155,7 @@ SQL;
. ', :is_read, :is_favorite, :id_feed, :tags, :attributes)');
$this->addEntryPrepared = $this->pdo->prepare($sql);
}
- if ($this->addEntryPrepared) {
+ if ($this->addEntryPrepared != false) {
$this->addEntryPrepared->bindParam(':id', $valuesTmp['id']);
$valuesTmp['guid'] = substr($valuesTmp['guid'], 0, 767);
$valuesTmp['guid'] = safe_ascii($valuesTmp['guid']);
@@ -200,10 +197,10 @@ SQL;
$this->addEntryPrepared->bindParam(':hash', $valuesTmp['hashBin']);
}
}
- if ($this->addEntryPrepared && $this->addEntryPrepared->execute()) {
+ if ($this->addEntryPrepared != false && $this->addEntryPrepared->execute()) {
return true;
} else {
- $info = $this->addEntryPrepared == null ? $this->pdo->errorInfo() : $this->addEntryPrepared->errorInfo();
+ $info = $this->addEntryPrepared == false ? $this->pdo->errorInfo() : $this->addEntryPrepared->errorInfo();
if ($this->autoUpdateDb($info)) {
$this->addEntryPrepared = null;
return $this->addEntry($valuesTmp);
@@ -240,7 +237,7 @@ SQL;
return $result;
}
- private ?PDOStatement $updateEntryPrepared = null;
+ private PDOStatement|null|false $updateEntryPrepared = null;
/** @param array{'id':string,'guid':string,'title':string,'author':string,'content':string,'link':string,'date':int,'lastSeen':int,'hash':string,
* 'is_read':bool|int|null,'is_favorite':bool|int|null,'id_feed':int,'tags':string,'attributes':array<string,mixed>} $valuesTmp */
@@ -252,7 +249,7 @@ SQL;
$valuesTmp['is_favorite'] = null;
}
- if ($this->updateEntryPrepared === null) {
+ if ($this->updateEntryPrepared == null) {
$sql = 'UPDATE `_entry` '
. 'SET title=:title, author=:author, '
. (static::isCompressed() ? 'content_bin=COMPRESS(:content)' : 'content=:content')
@@ -262,9 +259,9 @@ SQL;
. ', is_favorite=COALESCE(:is_favorite, is_favorite)'
. ', tags=:tags, attributes=:attributes '
. 'WHERE id_feed=:id_feed AND guid=:guid';
- $this->updateEntryPrepared = $this->pdo->prepare($sql) ?: null;
+ $this->updateEntryPrepared = $this->pdo->prepare($sql);
}
- if ($this->updateEntryPrepared) {
+ if ($this->updateEntryPrepared != false) {
$valuesTmp['guid'] = substr($valuesTmp['guid'], 0, 767);
$valuesTmp['guid'] = safe_ascii($valuesTmp['guid']);
$this->updateEntryPrepared->bindParam(':guid', $valuesTmp['guid']);
@@ -309,10 +306,10 @@ SQL;
}
}
- if ($this->updateEntryPrepared && $this->updateEntryPrepared->execute()) {
+ if ($this->updateEntryPrepared != false && $this->updateEntryPrepared->execute()) {
return true;
} else {
- $info = $this->updateEntryPrepared == null ? $this->pdo->errorInfo() : $this->updateEntryPrepared->errorInfo();
+ $info = $this->updateEntryPrepared == false ? $this->pdo->errorInfo() : $this->updateEntryPrepared->errorInfo();
if ($this->autoUpdateDb($info)) {
return $this->updateEntry($valuesTmp);
}
@@ -367,7 +364,7 @@ SQL;
if ($stm !== false && $stm->execute($values)) {
return $stm->rowCount();
} else {
- $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
+ $info = $stm === false ? $this->pdo->errorInfo() : $stm->errorInfo();
Minz_Log::error('SQL error ' . __METHOD__ . json_encode($info));
return false;
}
@@ -406,7 +403,7 @@ SQL;
if ($stm !== false && $stm->execute($values)) {
return true;
} else {
- $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
+ $info = $stm === false ? $this->pdo->errorInfo() : $stm->errorInfo();
Minz_Log::error('SQL error ' . __METHOD__ . json_encode($info));
return false;
}
@@ -444,8 +441,8 @@ SQL;
$values = [$is_read ? 1 : 0];
$values = array_merge($values, $ids);
$stm = $this->pdo->prepare($sql);
- if (!($stm && $stm->execute($values))) {
- $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
+ if ($stm === false || !$stm->execute($values)) {
+ $info = $stm === false ? $this->pdo->errorInfo() : $stm->errorInfo();
Minz_Log::error('SQL error ' . __METHOD__ . ' A ' . json_encode($info));
return false;
}
@@ -465,7 +462,7 @@ SQL;
if ($stm !== false && $stm->execute($values)) {
return $stm->rowCount();
} else {
- $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
+ $info = $stm === false ? $this->pdo->errorInfo() : $stm->errorInfo();
Minz_Log::error('SQL error ' . __METHOD__ . ' B ' . json_encode($info));
return false;
}
@@ -514,8 +511,8 @@ SQL;
[$searchValues, $search] = $this->sqlListEntriesWhere('', $filters, $state);
$stm = $this->pdo->prepare($sql . $search);
- if (!($stm && $stm->execute(array_merge($values, $searchValues)))) {
- $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
+ if ($stm === false || !$stm->execute(array_merge($values, $searchValues))) {
+ $info = $stm === false ? $this->pdo->errorInfo() : $stm->errorInfo();
Minz_Log::error('SQL error ' . __METHOD__ . json_encode($info));
return false;
}
@@ -555,8 +552,8 @@ SQL;
[$searchValues, $search] = $this->sqlListEntriesWhere('', $filters, $state);
$stm = $this->pdo->prepare($sql . $search);
- if (!($stm && $stm->execute(array_merge($values, $searchValues)))) {
- $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
+ if ($stm === false || !$stm->execute(array_merge($values, $searchValues))) {
+ $info = $stm === false ? $this->pdo->errorInfo() : $stm->errorInfo();
Minz_Log::error('SQL error ' . __METHOD__ . json_encode($info));
return false;
}
@@ -597,8 +594,8 @@ SQL;
[$searchValues, $search] = $this->sqlListEntriesWhere('', $filters, $state);
$stm = $this->pdo->prepare($sql . $search);
- if (!($stm && $stm->execute(array_merge($values, $searchValues)))) {
- $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
+ if ($stm === false || !$stm->execute(array_merge($values, $searchValues))) {
+ $info = $stm === false ? $this->pdo->errorInfo() : $stm->errorInfo();
Minz_Log::error('SQL error ' . __METHOD__ . json_encode($info) . ' with SQL: ' . $sql . $search);
$this->pdo->rollBack();
return false;
@@ -613,7 +610,7 @@ SQL;
if (!($stm !== false &&
$stm->bindParam(':id', $id_feed, PDO::PARAM_INT) &&
$stm->execute())) {
- $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
+ $info = $stm === false ? $this->pdo->errorInfo() : $stm->errorInfo();
Minz_Log::error('SQL error ' . __METHOD__ . json_encode($info));
$this->pdo->rollBack();
return false;
@@ -655,8 +652,8 @@ SQL;
[$searchValues, $search] = $this->sqlListEntriesWhere('e.', $filters, $state);
$stm = $this->pdo->prepare($sql . $search);
- if (!($stm && $stm->execute(array_merge($values, $searchValues)))) {
- $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
+ if ($stm === false || !$stm->execute(array_merge($values, $searchValues))) {
+ $info = $stm === false ? $this->pdo->errorInfo() : $stm->errorInfo();
Minz_Log::error('SQL error ' . __METHOD__ . json_encode($info));
return false;
}
@@ -721,7 +718,7 @@ SQL;
if ($stm !== false && $stm->execute($params)) {
return $stm->rowCount();
} else {
- $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
+ $info = $stm === false ? $this->pdo->errorInfo() : $stm->errorInfo();
if ($this->autoUpdateDb($info)) {
return $this->cleanOldEntries($id_feed, $options);
}
@@ -1144,7 +1141,7 @@ SQL;
$search .= 'AND ' . $alias . 'id >= ? ';
$values[] = $date_min . '000000';
}
- if ($filters && count($filters->searches()) > 0) {
+ if ($filters !== null && count($filters->searches()) > 0) {
[$filterValues, $filterSearch] = self::sqlBooleanSearch($alias, $filters);
$filterSearch = trim($filterSearch);
if ($filterSearch !== '') {
@@ -1252,7 +1249,7 @@ SQL;
if ($stm !== false && $stm->execute($values)) {
return $stm;
} else {
- $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
+ $info = $stm === false ? $this->pdo->errorInfo() : $stm->errorInfo();
if ($this->autoUpdateDb($info)) {
return $this->listWhereRaw($type, $id, $state, $order, $limit, $offset, $firstId, $filters, $date_min);
}
@@ -1272,7 +1269,7 @@ SQL;
string $order = 'DESC', int $limit = 1, int $offset = 0, string $firstId = '',
?FreshRSS_BooleanSearch $filters = null, int $date_min = 0): Traversable {
$stm = $this->listWhereRaw($type, $id, $state, $order, $limit, $offset, $firstId, $filters, $date_min);
- if ($stm) {
+ if ($stm !== false) {
while ($row = $stm->fetch(PDO::FETCH_ASSOC)) {
if (is_array($row)) {
/** @var array{'id':string,'id_feed':int,'guid':string,'title':string,'author':string,'content':string,'link':string,'date':int,
@@ -1343,7 +1340,7 @@ SQL;
/** @var array<numeric-string> $res */
return $res;
}
- $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
+ $info = $stm === false ? $this->pdo->errorInfo() : $stm->errorInfo();
Minz_Log::error('SQL error ' . __METHOD__ . json_encode($info));
return null;
}
@@ -1377,7 +1374,7 @@ SQL;
}
return $result;
} else {
- $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
+ $info = $stm === false ? $this->pdo->errorInfo() : $stm->errorInfo();
if ($this->autoUpdateDb($info)) {
return $this->listHashForFeedGuids($id_feed, $guids);
}
@@ -1413,7 +1410,7 @@ SQL;
if ($stm !== false && $stm->execute($values)) {
return $stm->rowCount();
} else {
- $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
+ $info = $stm === false ? $this->pdo->errorInfo() : $stm->errorInfo();
if ($this->autoUpdateDb($info)) {
return $this->updateLastSeen($id_feed, $guids);
}
@@ -1448,7 +1445,7 @@ SQL;
$stm->execute()) {
return $stm->rowCount();
} else {
- $info = $stm == null ? $this->pdo->errorInfo() : $stm->errorInfo();
+ $info = $stm === false ? $this->pdo->errorInfo() : $stm->errorInfo();
Minz_Log::error('SQL error ' . __METHOD__ . json_encode($info) . ' while updating feed ' . $id_feed);
return false;
}