Просмотр исходного кода

Fix problem when deleting default category

This is not allowed!

See https://github.com/marienfressinaud/FreshRSS/issues/646
Marien Fressinaud 11 лет назад
Родитель
Сommit
f400621f44

+ 4 - 0
app/Controllers/categoryController.php

@@ -123,6 +123,10 @@ class FreshRSS_category_Controller extends Minz_ActionController {
 				Minz_Request::bad(_t('category_no_id'), $url_redirect);
 			}
 
+			if ($id === $default_category->id()) {
+				Minz_Request::bad(_t('category_not_delete_default'), $url_redirect);
+			}
+
 			if ($feedDAO->changeCategory($id, $default_category->id()) === false) {
 				Minz_Request::bad(_t('error_occurred'), $url_redirect);
 			}

+ 1 - 0
app/Controllers/subscriptionController.php

@@ -19,6 +19,7 @@ class FreshRSS_subscription_Controller extends Minz_ActionController {
 
 		$catDAO = new FreshRSS_CategoryDAO();
 
+		$catDAO->checkDefault();
 		$this->view->categories = $catDAO->listCategories(false);
 		$this->view->default_category = $catDAO->getDefault();
 	}

+ 9 - 3
app/views/subscription/index.phtml

@@ -82,9 +82,14 @@
 
 						<li class="item"><a href="<?php echo _url('index', 'index', 'get', 'c_' . $cat->id()); ?>"><?php echo _t('filter'); ?></a></li>
 
-						<li class="separator"></li>
+						<?php
+							$no_feed = empty($feeds);
+							$is_default = ($cat->id() === $this->default_category->id());
 
-						<?php if (!empty($feeds)) { ?>
+							if (!$no_feed || !$is_default) {
+						?>
+						<li class="separator"></li>
+						<?php } if (!$no_feed) { ?>
 						<li class="item">
 							<button class="as-link confirm"
 							        data-str-confirm="<?php echo _t('confirm_action_feed_cat'); ?>"
@@ -93,7 +98,7 @@
 							        formaction="<?php echo _url('category', 'empty', 'id', $cat->id()); ?>">
 							        <?php echo _t('ask_empty'); ?></button>
 						</li>
-						<?php } ?>
+						<?php } if (!$is_default) { ?>
 						<li class="item">
 							<button class="as-link confirm"
 							        data-str-confirm="<?php echo _t('confirm_action_feed_cat'); ?>"
@@ -102,6 +107,7 @@
 							        formaction="<?php echo _url('category', 'delete', 'id', $cat->id()); ?>">
 							        <?php echo _t('delete'); ?></button>
 						</li>
+						<?php } ?>
 					</ul>
 				</div>
 			</form>