A free, self-hostable news aggregator…
Flux déplacés de catégories lors de la suppression de la leur (issue #28)
Marien Fressinaud1bee8ad9a7c0
diff --git a/app/controllers/configureController.php b/app/controllers/configureController.phpindex f4d1a38e7..d6d210099 100755--- a/app/controllers/configureController.php+++ b/app/controllers/configureController.php@@ -11,8 +11,11 @@ class configureController extends ActionController {}public function categorizeAction () {+ $feedDAO = new FeedDAO ();$catDAO = new CategoryDAO ();$catDAO->checkDefault ();+ $defaultCategory = $catDAO->getDefault ();+ $defaultId = $defaultCategory->id ();if (Request::isPost ()) {$cats = Request::param ('categories', array ());@@ -27,7 +30,8 @@ class configureController extends ActionController {'color' => $cat->color ());$catDAO->updateCategory ($ids[$key], $values);- } elseif ($ids[$key] != '000000') {+ } elseif ($ids[$key] != $defaultId) {+ $feedDAO->changeCategory ($ids[$key], $defaultId);$catDAO->deleteCategory ($ids[$key]);}}diff --git a/app/models/Feed.php b/app/models/Feed.phpindex 97cbe55d1..e519a91cb 100644--- a/app/models/Feed.php+++ b/app/models/Feed.php@@ -296,6 +296,30 @@ class FeedDAO extends Model_pdo {}}+ public function changeCategory ($idOldCat, $idNewCat) {+ $catDAO = new CategoryDAO ();+ $newCat = $catDAO->searchById ($idNewCat);+ if (!$newCat) {+ $newCat = $catDAO->getDefault ();+ }++ $sql = 'UPDATE feed SET category=? WHERE category=?';+ $stm = $this->bd->prepare ($sql);++ $values = array (+ $newCat->id (),+ $idOldCat+ );++ if ($stm && $stm->execute ($values)) {+ return true;+ } else {+ $info = $stm->errorInfo();+ Log::record ('SQL error : ' . $info[2], Log::ERROR);+ return false;+ }+ }+public function deleteFeed ($id) {$sql = 'DELETE FROM feed WHERE id=?';$stm = $this->bd->prepare ($sql);diff --git a/app/views/configure/feed.phtml b/app/views/configure/feed.phtmlindex 0d9c5cae6..33483f72d 100644--- a/app/views/configure/feed.phtml+++ b/app/views/configure/feed.phtml@@ -2,7 +2,7 @@<?php if ($this->flux) { ?><div class="post">- <a href="<?php echo _url ('index', 'index'); ?>"><?php echo Translate::t ('back_to_rss_feeds'); ?></a>+ <a href="<?php echo _url ('index', 'index'); ?>"><?php echo Translate::t ('back_to_rss_feeds'); ?></a> <?php echo Translate::t ('or'); ?> <a href="<?php echo _url ('index', 'index', 'get', 'f_' . $this->flux->id ()); ?>"><?php echo Translate::t ('filter'); ?></a><h1><?php echo $this->flux->name (); ?></h1><?php echo $this->flux->description (); ?>