瀏覽代碼

Fever integer type for numbers (#2946)

* Fever integer type for feed ID

#Fix
https://github.com/FreshRSS/FreshRSS/issues/2940#issuecomment-623022435

* Fix feed_id

* Ensure string for entry ID

To be compatible with 32-bit platforms.
Before, the type was inconsistent depending on architecture + database

* Integer for entry count functions
Alexandre Alapetite 6 年之前
父節點
當前提交
b1aac20839
共有 5 個文件被更改,包括 10 次插入10 次删除
  1. 1 1
      app/Models/Category.php
  2. 1 1
      app/Models/Entry.php
  3. 6 6
      app/Models/EntryDAO.php
  4. 1 1
      app/Models/Feed.php
  5. 1 1
      p/api/fever.php

+ 1 - 1
app/Models/Category.php

@@ -78,7 +78,7 @@ class FreshRSS_Category extends Minz_Model {
 	}
 	}
 
 
 	public function _id($id) {
 	public function _id($id) {
-		$this->id = $id;
+		$this->id = intval($id);
 		if ($id == FreshRSS_CategoryDAO::DEFAULTCATEGORYID) {
 		if ($id == FreshRSS_CategoryDAO::DEFAULTCATEGORYID) {
 			$this->_name(_t('gen.short.default_category'));
 			$this->_name(_t('gen.short.default_category'));
 		}
 		}

+ 1 - 1
app/Models/Entry.php

@@ -212,7 +212,7 @@ class FreshRSS_Entry extends Minz_Model {
 	}
 	}
 	private function _feedId($value) {
 	private function _feedId($value) {
 		$this->feed = null;
 		$this->feed = null;
-		$this->feedId = $value;
+		$this->feedId = intval($value);
 	}
 	}
 	public function _tags($value) {
 	public function _tags($value) {
 		$this->hash = null;
 		$this->hash = null;

+ 6 - 6
app/Models/EntryDAO.php

@@ -1031,8 +1031,8 @@ SQL;
 		}
 		}
 		$res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
 		$res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
 		rsort($res);
 		rsort($res);
-		$all = empty($res[0]) ? 0 : $res[0];
-		$unread = empty($res[1]) ? 0 : $res[1];
+		$all = empty($res[0]) ? 0 : intval($res[0]);
+		$unread = empty($res[1]) ? 0 : intval($res[1]);
 		return array('all' => $all, 'unread' => $unread, 'read' => $all - $unread);
 		return array('all' => $all, 'unread' => $unread, 'read' => $all - $unread);
 	}
 	}
 
 
@@ -1047,7 +1047,7 @@ SQL;
 			return false;
 			return false;
 		}
 		}
 		$res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
 		$res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
-		return isset($res[0]) ? $res[0] : 0;
+		return isset($res[0]) ? intval($res[0]) : 0;
 	}
 	}
 
 
 	public function countNotRead($minPriority = null) {
 	public function countNotRead($minPriority = null) {
@@ -1061,7 +1061,7 @@ SQL;
 		}
 		}
 		$stm = $this->pdo->query($sql);
 		$stm = $this->pdo->query($sql);
 		$res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
 		$res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
-		return $res[0];
+		return isset($res[0]) ? intval($res[0]) : 0;
 	}
 	}
 
 
 	public function countUnreadReadFavorites() {
 	public function countUnreadReadFavorites() {
@@ -1089,8 +1089,8 @@ SQL;
 		$stm->execute();
 		$stm->execute();
 		$res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
 		$res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
 		rsort($res);
 		rsort($res);
-		$all = empty($res[0]) ? 0 : $res[0];
-		$unread = empty($res[1]) ? 0 : $res[1];
+		$all = empty($res[0]) ? 0 : intval($res[0]);
+		$unread = empty($res[1]) ? 0 : intval($res[1]);
 		return array('all' => $all, 'unread' => $unread, 'read' => $all - $unread);
 		return array('all' => $all, 'unread' => $unread, 'read' => $all - $unread);
 	}
 	}
 
 

+ 1 - 1
app/Models/Feed.php

@@ -180,7 +180,7 @@ class FreshRSS_Feed extends Minz_Model {
 	}
 	}
 
 
 	public function _id($value) {
 	public function _id($value) {
-		$this->id = $value;
+		$this->id = intval($value);
 	}
 	}
 	public function _url($value, $validate = true) {
 	public function _url($value, $validate = true) {
 		$this->hash = null;
 		$this->hash = null;

+ 1 - 1
p/api/fever.php

@@ -536,7 +536,7 @@ class FeverAPI
 				continue;
 				continue;
 			}
 			}
 			$items[] = array(
 			$items[] = array(
-				'id' => $entry->id(),
+				'id' => '' . $entry->id(),
 				'feed_id' => $entry->feed(false),
 				'feed_id' => $entry->feed(false),
 				'title' => escapeToUnicodeAlternative($entry->title(), false),
 				'title' => escapeToUnicodeAlternative($entry->title(), false),
 				'author' => escapeToUnicodeAlternative(trim($entry->authors(true), '; '), false),
 				'author' => escapeToUnicodeAlternative(trim($entry->authors(true), '; '), false),