Browse Source

API rename feed

Alexandre Alapetite 9 years ago
parent
commit
6a812b0d31
2 changed files with 21 additions and 10 deletions
  1. 9 3
      app/Controllers/feedController.php
  2. 12 7
      p/api/greader.php

+ 9 - 3
app/Controllers/feedController.php

@@ -492,6 +492,14 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
 		return $updated_feeds;
 	}
 
+	public static function renameFeed($feed_id, $feed_name) {
+		if ($feed_id <= 0 || $feed_name == '') {
+			return false;
+		}
+		$feedDAO = FreshRSS_Factory::createFeedDao();
+		return $feedDAO->updateFeed($feed_id, array('name' => $feed_name));
+	}
+
 	public static function moveFeed($feed_id, $cat_id) {
 		if ($feed_id <= 0) {
 			return false;
@@ -504,9 +512,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
 			$cat_id = $def_cat->id();
 		}
 		$feedDAO = FreshRSS_Factory::createFeedDao();
-		$feed = $feedDAO->searchById($feed_id);
-		return $feed && ($feed->category() == $cat_id ||
-			$feedDAO->updateFeed($feed_id, array('category' => $cat_id)));
+		return $feedDAO->updateFeed($feed_id, array('category' => $cat_id));
 	}
 
 	/**

+ 12 - 7
p/api/greader.php

@@ -325,27 +325,32 @@ function subscriptionEdit($streamNames, $titles, $action, $add = '', $remove = '
 				case 'subscribe':
 					if ($feedId <= 0) {
 						//TODO
+						notImplemented();
 					} else {
 						badRequest();
 					}
 					break;
 				case 'unsubscribe':
-					if ($feedId > 0 && FreshRSS_feed_Controller::deleteFeed($feedId)) {
-						exit('OK');
-					} else {
+					if (!($feedId > 0 && FreshRSS_feed_Controller::deleteFeed($feedId))) {
 						badRequest();
 					}
 					break;
 				case 'edit':
-					if ($feedId > 0 && FreshRSS_feed_Controller::moveFeed($feedId, $addCatId)) {
-						exit('OK');
+					if ($feedId > 0) {
+						if ($addCatId > 0) {
+							FreshRSS_feed_Controller::moveFeed($feedId, $addCatId);
+						}
+						if ($title != '') {
+							FreshRSS_feed_Controller::renameFeed($feedId, $title);
+						}
+					} else {
+						badRequest();
 					}
-					badRequest();
 					break;
 			}
 		}
 	}
-	notImplemented();
+	exit('OK');
 }
 
 function unreadCount() {	//http://blog.martindoms.com/2009/10/16/using-the-google-reader-api-part-2/#unread-count