aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2013-08-22 11:11:22 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2013-08-22 11:11:22 +0200
commit9642fbb2211368f8063f657d34e043b311df4718 (patch)
tree4d96db6ced2888b730afb43dbe5523a980781940
parent48f8401c8b9f22342f319692a5fda5da58cc75ed (diff)
Fix issue #118 : option pour garder historique
*** ATTENTION, MODIFICATION DE LA BDD *** Cette option permet de garder les vieux articles d'un flux en même s'ils sont plus vieux que la limite des X mois d'historique (3 par défaut) Les modifications de la base de données : - ajout du champ "keep_history int(1) DEFAULT 0" à la table feed - suppression des champs "is_public" et "lastUpdate" de la table entry (n'étaient plus utilisés de toute façon)
-rwxr-xr-xapp/controllers/configureController.php9
-rwxr-xr-xapp/controllers/feedController.php6
-rw-r--r--app/i18n/en.php1
-rw-r--r--app/i18n/fr.php1
-rwxr-xr-xapp/models/Entry.php39
-rw-r--r--app/models/Feed.php15
-rw-r--r--app/views/configure/feed.phtml4
-rw-r--r--public/install.php7
8 files changed, 39 insertions, 43 deletions
diff --git a/app/controllers/configureController.php b/app/controllers/configureController.php
index 6ebc13f39..6396dbfeb 100755
--- a/app/controllers/configureController.php
+++ b/app/controllers/configureController.php
@@ -92,12 +92,18 @@ class configureController extends ActionController {
if (Request::isPost () && $this->view->flux) {
$name = Request::param ('name', '');
+ $hist = Request::param ('keep_history', 'no');
$cat = Request::param ('category', 0);
$path = Request::param ('path_entries', '');
$priority = Request::param ('priority', 0);
$user = Request::param ('http_user', '');
$pass = Request::param ('http_pass', '');
+ $keep_history = false;
+ if ($hist == 'yes') {
+ $keep_history = true;
+ }
+
$httpAuth = '';
if ($user != '' || $pass != '') {
$httpAuth = $user . ':' . $pass;
@@ -108,7 +114,8 @@ class configureController extends ActionController {
'category' => $cat,
'pathEntries' => $path,
'priority' => $priority,
- 'httpAuth' => $httpAuth
+ 'httpAuth' => $httpAuth,
+ 'keep_history' => $keep_history
);
if ($feedDAO->updateFeed ($id, $values)) {
diff --git a/app/controllers/feedController.php b/app/controllers/feedController.php
index 21ea2aadd..18a46f322 100755
--- a/app/controllers/feedController.php
+++ b/app/controllers/feedController.php
@@ -69,7 +69,8 @@ class feedController extends ActionController {
// on ajoute les articles en masse sans vérification
foreach ($entries as $entry) {
- if ($entry->date (true) >= $date_min) {
+ if ($entry->date (true) >= $date_min ||
+ $feed->keepHistory ()) {
$values = $entry->toArray ();
$entryDAO->addEntry ($values);
}
@@ -150,7 +151,8 @@ class feedController extends ActionController {
// La BDD refusera l'ajout de son côté car l'id doit être
// unique
foreach ($entries as $entry) {
- if ($entry->date (true) >= $date_min) {
+ if ($entry->date (true) >= $date_min ||
+ $feed->keepHistory ()) {
$values = $entry->toArray ();
$entryDAO->addEntry ($values);
}
diff --git a/app/i18n/en.php b/app/i18n/en.php
index a5b331e41..341e14ca7 100644
--- a/app/i18n/en.php
+++ b/app/i18n/en.php
@@ -129,6 +129,7 @@ return array (
'website_url' => 'Website URL',
'feed_url' => 'Feed URL',
'number_articles' => 'Number of articles',
+ 'keep_history' => 'Keep history?',
'categorize' => 'Store in a category',
'advanced' => 'Advanced',
'show_in_all_flux' => 'Show in principal stream',
diff --git a/app/i18n/fr.php b/app/i18n/fr.php
index 071cb8dd4..394c86f6e 100644
--- a/app/i18n/fr.php
+++ b/app/i18n/fr.php
@@ -129,6 +129,7 @@ return array (
'website_url' => 'URL du site',
'feed_url' => 'URL du flux',
'number_articles' => 'Nombre d\'articles',
+ 'keep_history' => 'Garder l\'historique ?',
'categorize' => 'Ranger dans une catégorie',
'advanced' => 'Avancé',
'show_in_all_flux' => 'Afficher dans le flux principal',
diff --git a/app/models/Entry.php b/app/models/Entry.php
index 1d08f09da..c247c6362 100755
--- a/app/models/Entry.php
+++ b/app/models/Entry.php
@@ -11,14 +11,11 @@ class Entry extends Model {
private $date;
private $is_read;
private $is_favorite;
- private $is_public;
private $feed;
private $tags;
- private $lastUpdate;
public function __construct ($feed = '', $guid = '', $title = '', $author = '', $content = '',
- $link = '', $pubdate = 0, $is_read = false, $is_favorite = false,
- $is_public = false) {
+ $link = '', $pubdate = 0, $is_read = false, $is_favorite = false) {
$this->_guid ($guid);
$this->_title ($title);
$this->_author ($author);
@@ -27,9 +24,7 @@ class Entry extends Model {
$this->_date ($pubdate);
$this->_isRead ($is_read);
$this->_isFavorite ($is_favorite);
- $this->_isPublic ($is_public);
$this->_feed ($feed);
- $this->_lastUpdate ($pubdate);
$this->_tags (array ());
}
@@ -72,9 +67,6 @@ class Entry extends Model {
public function isFavorite () {
return $this->is_favorite;
}
- public function isPublic () {
- return $this->is_public;
- }
public function feed ($object = false) {
if ($object) {
$feedDAO = new FeedDAO ();
@@ -94,13 +86,6 @@ class Entry extends Model {
return $this->tags;
}
}
- public function lastUpdate ($raw = false) {
- if ($raw) {
- return $this->lastUpdate;
- } else {
- return timestamptodate ($this->lastUpdate);
- }
- }
public function _id ($value) {
$this->id = $value;
@@ -133,9 +118,6 @@ class Entry extends Model {
public function _isFavorite ($value) {
$this->is_favorite = $value;
}
- public function _isPublic ($value) {
- $this->is_public = $value;
- }
public function _feed ($value) {
$this->feed = $value;
}
@@ -152,13 +134,6 @@ class Entry extends Model {
$this->tags = $value;
}
- public function _lastUpdate ($value) {
- if (is_int (intval ($value))) {
- $this->lastUpdate = $value;
- } else {
- $this->lastUpdate = $this->date (true);
- }
- }
public function isDay ($day) {
$date = getdate ();
@@ -212,9 +187,7 @@ class Entry extends Model {
'date' => $this->date (true),
'is_read' => $this->isRead (),
'is_favorite' => $this->isFavorite (),
- 'is_public' => $this->isPublic (),
'id_feed' => $this->feed (),
- 'lastUpdate' => $this->lastUpdate (true),
'tags' => $this->tags (true)
);
}
@@ -222,7 +195,7 @@ class Entry extends Model {
class EntryDAO extends Model_pdo {
public function addEntry ($valuesTmp) {
- $sql = 'INSERT INTO ' . $this->prefix . 'entry(id, guid, title, author, content, link, date, is_read, is_favorite, is_public, id_feed, lastUpdate, tags) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
+ $sql = 'INSERT INTO ' . $this->prefix . 'entry(id, guid, title, author, content, link, date, is_read, is_favorite, id_feed, tags) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
$stm = $this->bd->prepare ($sql);
$values = array (
@@ -235,9 +208,7 @@ class EntryDAO extends Model_pdo {
$valuesTmp['date'],
$valuesTmp['is_read'],
$valuesTmp['is_favorite'],
- $valuesTmp['is_public'],
$valuesTmp['id_feed'],
- $valuesTmp['lastUpdate'],
$valuesTmp['tags'],
);
@@ -350,7 +321,7 @@ class EntryDAO extends Model_pdo {
public function cleanOldEntries ($nb_month) {
$date = 60 * 60 * 24 * 30 * $nb_month;
- $sql = 'DELETE FROM ' . $this->prefix . 'entry WHERE date <= ? AND is_favorite = 0';
+ $sql = 'DELETE e.* FROM ' . $this->prefix . 'entry e INNER JOIN ' . $this->prefix . 'feed f ON e.id_feed = f.id WHERE e.date <= ? AND e.is_favorite = 0 AND f.keep_history = 0';
$stm = $this->bd->prepare ($sql);
$values = array (
@@ -557,11 +528,9 @@ class HelperEntry {
$dao['link'],
$dao['date'],
$dao['is_read'],
- $dao['is_favorite'],
- $dao['is_public']
+ $dao['is_favorite']
);
- $entry->_lastUpdate ($dao['lastUpdate']);
$entry->_tags ($dao['tags']);
if (isset ($dao['id'])) {
diff --git a/app/models/Feed.php b/app/models/Feed.php
index 40394fa46..678809af6 100644
--- a/app/models/Feed.php
+++ b/app/models/Feed.php
@@ -13,6 +13,7 @@ class Feed extends Model {
private $pathEntries = '';
private $httpAuth = '';
private $error = false;
+ private $keep_history = false;
public function __construct ($url) {
$this->_url ($url);
@@ -73,6 +74,9 @@ class Feed extends Model {
public function inError () {
return $this->error;
}
+ public function keepHistory () {
+ return $this->keep_history;
+ }
public function nbEntries () {
$feedDAO = new FeedDAO ();
return $feedDAO->countEntries ($this->id ());
@@ -150,6 +154,14 @@ class Feed extends Model {
}
$this->error = $value;
}
+ public function _keepHistory ($value) {
+ if ($value) {
+ $value = true;
+ } else {
+ $value = false;
+ }
+ $this->keep_history = $value;
+ }
public function load () {
if (!is_null ($this->url)) {
@@ -242,7 +254,7 @@ 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) VALUES(?, ?, ?, ?, ?, ?, ?, 10, ?, 0)';
+ $sql = 'INSERT INTO ' . $this->prefix . 'feed (id, url, category, name, website, description, lastUpdate, priority, httpAuth, error, keep_history) VALUES(?, ?, ?, ?, ?, ?, ?, 10, ?, 0, 0)';
$stm = $this->bd->prepare ($sql);
$values = array (
@@ -493,6 +505,7 @@ class HelperFeed {
$list[$key]->_pathEntries ($dao['pathEntries']);
$list[$key]->_httpAuth (base64_decode ($dao['httpAuth']));
$list[$key]->_error ($dao['error']);
+ $list[$key]->_keepHistory ($dao['keep_history']);
if (isset ($dao['id'])) {
$list[$key]->_id ($dao['id']);
diff --git a/app/views/configure/feed.phtml b/app/views/configure/feed.phtml
index d2d978f54..a96965fe1 100644
--- a/app/views/configure/feed.phtml
+++ b/app/views/configure/feed.phtml
@@ -43,6 +43,10 @@
<label class="group-name"><?php echo Translate::t ('number_articles'); ?></label>
<div class="group-controls">
<span class="control"><?php echo $this->flux->nbEntries (); ?></span>
+ <label class="checkbox" for="keep_history">
+ <input type="checkbox" name="keep_history" id="keep_history" value="yes"<?php echo $this->flux->keepHistory () == 'yes' ? ' checked="checked"' : ''; ?> />
+ <?php echo Translate::t ('keep_history'); ?>
+ </label>
</div>
</div>
diff --git a/public/install.php b/public/install.php
index 31c96fb39..3e2d7b0f9 100644
--- a/public/install.php
+++ b/public/install.php
@@ -27,6 +27,7 @@ define ('SQL_REQ_FEED', 'CREATE TABLE IF NOT EXISTS `%sfeed` (
`pathEntries` varchar(500) DEFAULT NULL,
`httpAuth` varchar(500) DEFAULT NULL,
`error` int(1) NOT NULL DEFAULT \'0\',
+ `keep_history` int(1) NOT NULL DEFAULT \'0\',
PRIMARY KEY (`id`),
FOREIGN KEY (`category`) REFERENCES %scategory(id) ON DELETE SET NULL ON UPDATE CASCADE
);');
@@ -39,12 +40,10 @@ define ('SQL_REQ_ENTRY', 'CREATE TABLE IF NOT EXISTS `%sentry` (
`content` text NOT NULL,
`link` text NOT NULL,
`date` int(11) NOT NULL,
- `is_read` int(11) NOT NULL,
- `is_favorite` int(11) NOT NULL,
- `is_public` int(1) NOT NULL,
+ `is_read` int(11) NOT NULL DEFAULT \'0\',
+ `is_favorite` int(11) NOT NULL DEFAULT \'0\',
`id_feed` varchar(6) NOT NULL,
`tags` text NOT NULL,
- `lastUpdate` int(11) NOT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`id_feed`) REFERENCES %sfeed(id) ON DELETE CASCADE ON UPDATE CASCADE
);');