Procházet zdrojové kódy

Permet de supprimer les articles d'un flux

Implémente https://github.com/marienfressinaud/FreshRSS/issues/311
Alexandre Alapetite před 12 roky
rodič
revize
0e4274fc00

+ 50 - 33
app/controllers/feedController.php

@@ -157,6 +157,21 @@ class feedController extends ActionController {
 		}
 	}
 
+	public function truncateAction () {
+		if (Request::isPost ()) {
+			$id = Request::param ('id');
+			$feedDAO = new FeedDAO ();
+			$n = $feedDAO->truncate($id);
+			$notif = array(
+				'type' => $n === false ? 'bad' : 'good',
+				'content' => Translate::t ('n_entries_deleted', $n)
+			);
+			Session::_param ('notification', $notif);
+			invalidateHttpCache();
+			Request::forward (array ('c' => 'configure', 'a' => 'feed', 'params' => array('id' => $id)), true);
+		}
+	}
+
 	public function actualizeAction () {
 		@set_time_limit(300);
 
@@ -356,44 +371,46 @@ class feedController extends ActionController {
 	}
 
 	public function deleteAction () {
-		$type = Request::param ('type', 'feed');
-		$id = Request::param ('id');
+		if (Request::isPost ()) {
+			$type = Request::param ('type', 'feed');
+			$id = Request::param ('id');
 
-		$feedDAO = new FeedDAO ();
-		if ($type == 'category') {
-			if ($feedDAO->deleteFeedByCategory ($id)) {
-				$notif = array (
-					'type' => 'good',
-					'content' => Translate::t ('category_emptied')
-				);
-				//TODO: Delete old favicons
-			} else {
-				$notif = array (
-					'type' => 'bad',
-					'content' => Translate::t ('error_occured')
-				);
-			}
-		} else {
-			if ($feedDAO->deleteFeed ($id)) {
-				$notif = array (
-					'type' => 'good',
-					'content' => Translate::t ('feed_deleted')
-				);
-				Feed::faviconDelete($id);
+			$feedDAO = new FeedDAO ();
+			if ($type == 'category') {
+				if ($feedDAO->deleteFeedByCategory ($id)) {
+					$notif = array (
+						'type' => 'good',
+						'content' => Translate::t ('category_emptied')
+					);
+					//TODO: Delete old favicons
+				} else {
+					$notif = array (
+						'type' => 'bad',
+						'content' => Translate::t ('error_occured')
+					);
+				}
 			} else {
-				$notif = array (
-					'type' => 'bad',
-					'content' => Translate::t ('error_occured')
-				);
+				if ($feedDAO->deleteFeed ($id)) {
+					$notif = array (
+						'type' => 'good',
+						'content' => Translate::t ('feed_deleted')
+					);
+					Feed::faviconDelete($id);
+				} else {
+					$notif = array (
+						'type' => 'bad',
+						'content' => Translate::t ('error_occured')
+					);
+				}
 			}
-		}
 
-		Session::_param ('notification', $notif);
+			Session::_param ('notification', $notif);
 
-		if ($type == 'category') {
-			Request::forward (array ('c' => 'configure', 'a' => 'categorize'), true);
-		} else {
-			Request::forward (array ('c' => 'configure', 'a' => 'feed'), true);
+			if ($type == 'category') {
+				Request::forward (array ('c' => 'configure', 'a' => 'categorize'), true);
+			} else {
+				Request::forward (array ('c' => 'configure', 'a' => 'feed'), true);
+			}
 		}
 	}
 

+ 3 - 1
app/i18n/en.php

@@ -85,6 +85,7 @@ return array (
 	'n_feeds_actualized'		=> '%d feeds have been updated',
 	'feeds_actualized'		=> 'RSS feeds have been updated',
 	'no_feed_actualized'		=> 'No RSS feed has been updated',
+	'n_entries_deleted'		=> '%d articles have been deleted',
 	'feeds_imported_with_errors'	=> 'Your feeds have been imported but some errors occurred',
 	'feeds_imported'		=> 'Your feeds have been imported and will now be updated',
 	'category_emptied'		=> 'Category has been emptied',
@@ -135,8 +136,9 @@ return array (
 	'feed_url'			=> 'Feed URL',
 	'articles'			=> 'articles',
 	'number_articles'		=> 'Number of articles',
-	'keep_history'			=> 'Keep history?',
+	'keep_history'			=> 'Keep old articles?',
 	'categorize'			=> 'Store in a category',
+	'truncate'			=> 'Delete all articles',
 	'advanced'			=> 'Advanced',
 	'show_in_all_flux'		=> 'Show in main stream',
 	'yes'				=> 'Yes',

+ 3 - 1
app/i18n/fr.php

@@ -85,6 +85,7 @@ return array (
 	'n_feeds_actualized'		=> '%d flux ont été mis à jour',
 	'feeds_actualized'		=> 'Les flux ont été mis à jour',
 	'no_feed_actualized'		=> 'Aucun flux n’a pu être mis à jour',
+	'n_entries_deleted'		=> '%d articles ont été supprimés',
 	'feeds_imported_with_errors'	=> 'Vos flux ont été importés mais des erreurs sont survenues',
 	'feeds_imported'		=> 'Vos flux ont été importés et vont maintenant être actualisés',
 	'category_emptied'		=> 'La catégorie a été vidée',
@@ -135,8 +136,9 @@ return array (
 	'feed_url'			=> 'URL du flux',
 	'articles'			=> 'articles',
 	'number_articles'		=> 'Nombre d’articles',
-	'keep_history'			=> 'Garder l’historique ?',
+	'keep_history'			=> 'Garder les vieux articles ?',
 	'categorize'			=> 'Ranger dans une catégorie',
+	'truncate'			=> 'Supprimer tous les articles',
 	'advanced'			=> 'Avancé',
 	'show_in_all_flux'		=> 'Afficher dans le flux principal',
 	'yes'				=> 'Oui',

+ 28 - 0
app/models/Feed.php

@@ -570,6 +570,34 @@ class FeedDAO extends Model_pdo {
 			return false;
 		}
 	}
+
+	public function truncate ($id) {
+		$sql = 'DELETE e.* FROM `' . $this->prefix . 'entry` e WHERE e.id_feed=?';
+		$stm = $this->bd->prepare($sql);
+		$values = array($id);
+		$this->bd->beginTransaction ();
+		if (!($stm && $stm->execute ($values))) {
+				$info = $stm->errorInfo();
+				Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR);
+				$this->bd->rollBack ();
+				return false;
+			}
+		$affected = $stm->rowCount();
+
+		$sql = 'UPDATE `' . $this->prefix . 'feed` f '
+			 . 'SET f.cache_nbEntries=0, f.cache_nbUnreads=0 WHERE f.id=?';
+		$values = array ($id);
+		$stm = $this->bd->prepare ($sql);
+		if (!($stm && $stm->execute ($values))) {
+			$info = $stm->errorInfo();
+			Minz_Log::record ('SQL error : ' . $info[2], Minz_Log::ERROR);
+			$this->bd->rollBack ();
+			return false;
+		}
+
+		$this->bd->commit ();
+		return $affected;
+	}
 }
 
 class HelperFeed {

+ 15 - 9
app/views/configure/feed.phtml

@@ -39,6 +39,18 @@
 				<a target="_blank" href="<?php echo $this->flux->url (); ?>"><?php echo RSSThemes::icon('link'); ?></a>
 			</div>
 		</div>
+		<div class="form-group">
+			<label class="group-name" for="category"><?php echo Translate::t ('category'); ?></label>
+			<div class="group-controls">
+				<select name="category" id="category">
+				<?php foreach ($this->categories as $cat) { ?>
+				<option value="<?php echo $cat->id (); ?>"<?php echo $cat->id ()== $this->flux->category () ? ' selected="selected"' : ''; ?>>
+					<?php echo $cat->name (); ?>
+				</option>
+				<?php } ?>
+				</select>
+			</div>
+		</div>
 		<div class="form-group">
 			<label class="group-name"></label>
 			<div class="group-controls">
@@ -59,15 +71,9 @@
 		</div>
 
 		<div class="form-group">
-			<label class="group-name" for="category"><?php echo Translate::t ('category'); ?></label>
+			<label class="group-name"></label>
 			<div class="group-controls">
-				<select name="category" id="category">
-				<?php foreach ($this->categories as $cat) { ?>
-				<option value="<?php echo $cat->id (); ?>"<?php echo $cat->id ()== $this->flux->category () ? ' selected="selected"' : ''; ?>>
-					<?php echo $cat->name (); ?>
-				</option>
-				<?php } ?>
-				</select>
+				<button class="btn btn-attention confirm" formmethod="post" formaction="<?php echo Url::display (array ('c' => 'feed', 'a' => 'truncate', 'params' => array ('id' => $this->flux->id ()))); ?>"><?php echo Translate::t ('truncate'); ?></button>
 			</div>
 		</div>
 
@@ -107,7 +113,7 @@
 		<div class="form-group form-actions">
 			<div class="group-controls">
 				<button class="btn btn-important"><?php echo Translate::t ('save'); ?></button>
-				<button class="btn btn-attention confirm" formaction="<?php echo Url::display (array ('c' => 'feed', 'a' => 'delete', 'params' => array ('id' => $this->flux->id ()))); ?>"><?php echo Translate::t ('delete'); ?></button>
+				<button class="btn btn-attention confirm" formmethod="post" formaction="<?php echo Url::display (array ('c' => 'feed', 'a' => 'delete', 'params' => array ('id' => $this->flux->id ()))); ?>"><?php echo Translate::t ('delete'); ?></button>
 			</div>
 		</div>
 	</form>