Przeglądaj źródła

SQL : identifiant entier automatique pour les catégories et les flux

Implémentation de
https://github.com/marienfressinaud/FreshRSS/issues/262
La catégorie par défaut à le numéro 1.
Les numéros de catégories et de flux sont automatiques (1, 2, 3...)
L'installeur semble marcher.
Alexandre Alapetite 12 lat temu
rodzic
commit
e2d4f1a721

+ 1 - 1
app/controllers/feedController.php

@@ -175,7 +175,7 @@ class feedController extends ActionController {
 				$entries = $feed->entries ();
 
 				//For this feed, check last n entry IDs already in database
-				$existingIds = array_fill_keys ($entryDAO->listLastIdsByFeed ($feed->id (), count($entries) + 2), 1);
+				$existingIds = array_fill_keys ($entryDAO->listLastIdsByFeed ($feed->id (), count($entries) + 10), 1);
 
 				// ajout des articles en masse sans se soucier des erreurs
 				// On ne vérifie pas que l'article n'est pas déjà en BDD

+ 1 - 1
app/layout/aside_feed.phtml

@@ -16,7 +16,7 @@
 					<li class="input">
 						<select name="category" id="category">
 						<?php foreach ($this->categories as $cat) { ?>
-						<option value="<?php echo $cat->id (); ?>"<?php echo $cat->id () == '000000' ? ' selected="selected"' : ''; ?>>
+						<option value="<?php echo $cat->id (); ?>"<?php echo $cat->id () == 1 ? ' selected="selected"' : ''; ?>>
 							<?php echo $cat->name (); ?>
 						</option>
 						<?php } ?>

+ 6 - 11
app/models/Category.php

@@ -1,7 +1,7 @@
 <?php
 
 class Category extends Model {
-	private $id = false;
+	private $id = 0;
 	private $name;
 	private $color;
 	private $nbFeed = -1;
@@ -23,11 +23,7 @@ class Category extends Model {
 	}
 
 	public function id () {
-		if (!$this->id) {
-			return small_hash ($this->name . time () . Configuration::selApplication ());
-		} else {
-			return $this->id;
-		}
+		return $this->id;
 	}
 	public function name () {
 		return $this->name;
@@ -90,11 +86,10 @@ class Category extends Model {
 
 class CategoryDAO extends Model_pdo {
 	public function addCategory ($valuesTmp) {
-		$sql = 'INSERT INTO ' . $this->prefix . 'category (id, name, color) VALUES(?, ?, ?)';
+		$sql = 'INSERT INTO ' . $this->prefix . 'category (name, color) VALUES(?, ?)';
 		$stm = $this->bd->prepare ($sql);
 
 		$values = array (
-			$valuesTmp['id'],
 			substr($valuesTmp['name'], 0, 255),
 			substr($valuesTmp['color'], 0, 7),
 		);
@@ -196,7 +191,7 @@ class CategoryDAO extends Model_pdo {
 	}
 
 	public function getDefault () {
-		$sql = 'SELECT * FROM ' . $this->prefix . 'category WHERE id="000000"';
+		$sql = 'SELECT * FROM ' . $this->prefix . 'category WHERE id=1';
 		$stm = $this->bd->prepare ($sql);
 
 		$stm->execute ();
@@ -210,11 +205,11 @@ class CategoryDAO extends Model_pdo {
 		}
 	}
 	public function checkDefault () {
-		$def_cat = $this->searchById ('000000');
+		$def_cat = $this->searchById (1);
 
 		if ($def_cat === false) {
 			$cat = new Category (Translate::t ('default_category'));
-			$cat->_id ('000000');
+			$cat->_id (1);
 
 			$values = array (
 				'id' => $cat->id (),

+ 6 - 3
app/models/Entry.php

@@ -217,8 +217,12 @@ class EntryDAO extends Model_pdo {
 		} else {
 			$info = $stm->errorInfo();
 			if ((int)($info[0] / 1000) !== 23) {	//Filter out "SQLSTATE Class code 23: Constraint Violation" because of expected duplicate entries
-				Minz_Log::record ('SQL error ' . $info[0] . ': ' . $info[1] . ' ' . $info[2], Minz_Log::ERROR);
-			}
+				Minz_Log::record ('SQL error ' . $info[0] . ': ' . $info[1] . ' ' . $info[2]
+				. ' while adding entry in feed ' . $valuesTmp['id_feed'] . ' with title: ' . $valuesTmp['title'], Minz_Log::ERROR);
+			} /*else {
+				Minz_Log::record ('SQL error ' . $info[0] . ': ' . $info[1] . ' ' . $info[2]
+				. ' while adding entry in feed ' . $valuesTmp['id_feed'] . ' with title: ' . $valuesTmp['title'], Minz_Log::DEBUG);
+			}*/
 			return false;
 		}
 	}
@@ -272,7 +276,6 @@ class EntryDAO extends Model_pdo {
 		     . 'WHERE e.id=?';
 		$values = array ($is_read ? 1 : 0, $id);
 		$stm = $this->bd->prepare ($sql);
-
 		if ($stm && $stm->execute ($values)) {
 			return $stm->rowCount();
 		} else {

+ 4 - 9
app/models/Feed.php

@@ -1,9 +1,9 @@
 <?php
 
 class Feed extends Model {
-	private $id = null;
+	private $id = 0;
 	private $url;
-	private $category = '000000';
+	private $category = 1;
 	private $nbEntries = -1;
 	private $nbNotRead = -1;
 	private $entries = null;
@@ -26,11 +26,7 @@ class Feed extends Model {
 	}
 
 	public function id () {
-		if(is_null($this->id)) {
-			return small_hash ($this->url . Configuration::selApplication ());
-		} else {
-			return $this->id;
-		}
+		return $this->id;
 	}
 	public function url () {
 		return $this->url;
@@ -323,11 +319,10 @@ class Feed extends Model {
 
 class FeedDAO extends Model_pdo {
 	public function addFeed ($valuesTmp) {
-		$sql = 'INSERT INTO ' . $this->prefix . 'feed (id, url, category, name, website, description, lastUpdate, priority, httpAuth, error, keep_history) VALUES(?, ?, ?, ?, ?, ?, ?, 10, ?, 0, 0)';
+		$sql = 'INSERT INTO ' . $this->prefix . 'feed (url, category, name, website, description, lastUpdate, priority, httpAuth, error, keep_history) VALUES(?, ?, ?, ?, ?, ?, 10, ?, 0, 0)';
 		$stm = $this->bd->prepare ($sql);
 
 		$values = array (
-			$valuesTmp['id'],
 			substr($valuesTmp['url'], 0, 511),
 			$valuesTmp['category'],
 			substr($valuesTmp['name'], 0, 255),

+ 1 - 2
lib/SimplePie/SimplePie/Parser.php

@@ -132,7 +132,7 @@ class SimplePie_Parser
 			}
 		}
 
-		try
+		try	//FreshRSS
 		{
 			$dom = new DOMDocument();
 			$dom->recover = true;
@@ -140,7 +140,6 @@ class SimplePie_Parser
 			$dom->loadXML($data);
 			$this->encoding = $encoding = $dom->encoding = 'UTF-8';
 			$data = $dom->saveXML();
-			//file_put_contents('/home/alex/public_html/alexandre.alapetite.fr/prive/FreshRSS/log/parser.log', date('c') . ' ' . 'OK' . "\n", FILE_APPEND);
 		}
 		catch (Exception $e)
 		{

+ 4 - 4
public/install.php

@@ -11,7 +11,7 @@ if (isset ($_GET['step'])) {
 define ('SQL_REQ_CREATE_DB', 'CREATE DATABASE %s DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;');
 
 define ('SQL_REQ_CAT', 'CREATE TABLE IF NOT EXISTS `%scategory` (
-  `id` char(6) NOT NULL,
+  `id` SMALLINT NOT NULL AUTO_INCREMENT,	-- v0.7
   `name` varchar(255) NOT NULL,
   `color` char(7) NOT NULL,
   PRIMARY KEY (`id`),
@@ -19,9 +19,9 @@ define ('SQL_REQ_CAT', 'CREATE TABLE IF NOT EXISTS `%scategory` (
 );');
 
 define ('SQL_REQ_FEED', 'CREATE TABLE IF NOT EXISTS `%sfeed` (
-  `id` char(6) NOT NULL,
+  `id` SMALLINT NOT NULL AUTO_INCREMENT,	-- v0.7
   `url` varchar(511) NOT NULL,
-  `category` char(6) DEFAULT \'000000\',
+  `category` SMALLINT DEFAULT 0,	-- v0.7
   `name` varchar(255) NOT NULL,
   `website` varchar(255) NOT NULL,
   `description` text NOT NULL,
@@ -50,7 +50,7 @@ define ('SQL_REQ_ENTRY', 'CREATE TABLE IF NOT EXISTS `%sentry` (
   `date` int(11) NOT NULL,
   `is_read` boolean NOT NULL DEFAULT 0,
   `is_favorite` boolean NOT NULL DEFAULT 0,
-  `id_feed` char(6) NOT NULL,
+  `id_feed` SMALLINT NOT NULL,	-- v0.7
   `tags` varchar(1023) NOT NULL,
   PRIMARY KEY (`id`),
   FOREIGN KEY (`id_feed`) REFERENCES %sfeed(id) ON DELETE CASCADE ON UPDATE CASCADE,