Browse Source

Fix search in shared user queries (#8789)

The internal search was shown in the UI as the user search.
This was due to the lazy nature of the Generator. Improve the try/catch behaviour at the same time.

How to test:
* Make a user query with a search parameter
* Share the user query as HTML
* Observe the search field (should be empty with this PR,  while it contained the internal search before)
Alexandre Alapetite 1 week ago
parent
commit
c2619d9a26
2 changed files with 6 additions and 3 deletions
  1. 3 2
      app/Controllers/indexController.php
  2. 3 1
      p/api/query.php

+ 3 - 2
app/Controllers/indexController.php

@@ -258,6 +258,7 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController {
 
 
 		try {
 		try {
 			$this->view->entries = FreshRSS_index_Controller::listEntriesByContext();
 			$this->view->entries = FreshRSS_index_Controller::listEntriesByContext();
+			$this->view->entries->current();	// Init the generator to catch potential exceptions
 		} catch (FreshRSS_EntriesGetter_Exception $e) {
 		} catch (FreshRSS_EntriesGetter_Exception $e) {
 			Minz_Log::notice($e->getMessage());
 			Minz_Log::notice($e->getMessage());
 			Minz_Error::error(404);
 			Minz_Error::error(404);
@@ -335,10 +336,10 @@ class FreshRSS_index_Controller extends FreshRSS_ActionController {
 	/**
 	/**
 	 * This method returns a list of entries based on the Context object.
 	 * This method returns a list of entries based on the Context object.
 	 * @param int $postsPerPage override `FreshRSS_Context::$number`
 	 * @param int $postsPerPage override `FreshRSS_Context::$number`
-	 * @return Traversable<FreshRSS_Entry>
+	 * @return Generator<FreshRSS_Entry>
 	 * @throws FreshRSS_EntriesGetter_Exception
 	 * @throws FreshRSS_EntriesGetter_Exception
 	 */
 	 */
-	public static function listEntriesByContext(?int $postsPerPage = null): Traversable {
+	public static function listEntriesByContext(?int $postsPerPage = null): Generator {
 		$entryDAO = FreshRSS_Factory::createEntryDao();
 		$entryDAO = FreshRSS_Factory::createEntryDao();
 
 
 		$get = FreshRSS_Context::currentGet(true);
 		$get = FreshRSS_Context::currentGet(true);

+ 3 - 1
p/api/query.php

@@ -117,8 +117,10 @@ $view = new FreshRSS_View();
 
 
 try {
 try {
 	FreshRSS_Context::updateUsingRequest(false);
 	FreshRSS_Context::updateUsingRequest(false);
-	Minz_Request::_param('search', $userSearch->toString());	// Restore user search
 	$view->entries = FreshRSS_index_Controller::listEntriesByContext();
 	$view->entries = FreshRSS_index_Controller::listEntriesByContext();
+	$view->entries->current();	// Init the generator to consume the aggregated search and catch potential exceptions
+	Minz_Request::_param('search', $userSearch->toString());	// Restore user search for display and exports
+	FreshRSS_Context::$search = $userSearch;	// Restore user search for display and exports
 } catch (Minz_Exception) {
 } catch (Minz_Exception) {
 	Minz_Error::error(400, 'Bad user query!');
 	Minz_Error::error(400, 'Bad user query!');
 	die();
 	die();