summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2013-11-18 23:04:43 +0100
committerGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2013-11-18 23:04:43 +0100
commite2d4f1a7214591a47a46272a7a62e320eea029ce (patch)
treebb028ce493c74247e771c623d0a3f13ca4981ec2
parent082246d13f524aa646d5aedf49ae7e3b6c621d6c (diff)
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.
-rwxr-xr-xapp/controllers/feedController.php2
-rw-r--r--app/layout/aside_feed.phtml2
-rwxr-xr-xapp/models/Category.php17
-rwxr-xr-xapp/models/Entry.php9
-rw-r--r--app/models/Feed.php13
-rw-r--r--lib/SimplePie/SimplePie/Parser.php3
-rw-r--r--public/install.php8
7 files changed, 23 insertions, 31 deletions
diff --git a/app/controllers/feedController.php b/app/controllers/feedController.php
index 5c905e6da..73d13063d 100755
--- a/app/controllers/feedController.php
+++ b/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
diff --git a/app/layout/aside_feed.phtml b/app/layout/aside_feed.phtml
index 49767740b..f737d1e31 100644
--- a/app/layout/aside_feed.phtml
+++ b/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 } ?>
diff --git a/app/models/Category.php b/app/models/Category.php
index 6e61b5a0e..1ae324ace 100755
--- a/app/models/Category.php
+++ b/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 (),
diff --git a/app/models/Entry.php b/app/models/Entry.php
index 052e5abff..684b1921a 100755
--- a/app/models/Entry.php
+++ b/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 {
diff --git a/app/models/Feed.php b/app/models/Feed.php
index 549603664..46ba7bd47 100644
--- a/app/models/Feed.php
+++ b/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),
diff --git a/lib/SimplePie/SimplePie/Parser.php b/lib/SimplePie/SimplePie/Parser.php
index 72878c25a..c4c732787 100644
--- a/lib/SimplePie/SimplePie/Parser.php
+++ b/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)
{
diff --git a/public/install.php b/public/install.php
index d2c74b87b..b244bfa80 100644
--- a/public/install.php
+++ b/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,