From d670bf1e72d92c3bbeeca874f6a042f4e3a74007 Mon Sep 17 00:00:00 2001 From: KleinMann <47398070+rnkln@users.noreply.github.com> Date: Thu, 18 Sep 2025 23:44:17 +0200 Subject: Add `entry_before_update` and `entry_before_add` hooks (#7977) Discussion: https://github.com/FreshRSS/FreshRSS/discussions/7973 Changes proposed in this pull request: - Add new extension hook "entry_before_add" - Add new extension hook "entry_before_update" How to test the feature manually: 1. Create extension that uses the hooks and confirm they are invoked correctly. Extension to use for testing https://github.com/rnkln/freshrss-xExtension-Discord/pull/2 --- app/Controllers/feedController.php | 12 ++++++++++++ app/Controllers/importExportController.php | 13 +++++++++++++ 2 files changed, 25 insertions(+) (limited to 'app') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index a7c1d15bc..a63109c31 100644 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -639,6 +639,12 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController { // If the entry has changed, there is a good chance for the full content to have changed as well. $entry->loadCompleteContent(true); + $entry = Minz_ExtensionManager::callHook('entry_before_update', $entry); + if (!($entry instanceof FreshRSS_Entry)) { + // An extension has returned a null value, there is nothing to insert. + continue; + } + $entryDAO->updateEntry($entry->toArray()); } } else { @@ -672,6 +678,12 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController { $feed->pubSubHubbubError(true); } + $entry = Minz_ExtensionManager::callHook('entry_before_add', $entry); + if (!($entry instanceof FreshRSS_Entry)) { + // An extension has returned a null value, there is nothing to insert. + continue; + } + if ($entryDAO->addEntry($entry->toArray(), true)) { $nbNewArticles++; } diff --git a/app/Controllers/importExportController.php b/app/Controllers/importExportController.php index 6ecd9b501..9f9f6b2bd 100644 --- a/app/Controllers/importExportController.php +++ b/app/Controllers/importExportController.php @@ -485,9 +485,22 @@ class FreshRSS_importExport_Controller extends FreshRSS_ActionController { } if (isset($existingHashForGuids['f_' . $feed_id][$entry->guid()])) { + $entry = Minz_ExtensionManager::callHook('entry_before_update', $entry); + if (!($entry instanceof FreshRSS_Entry)) { + // An extension has returned a null value, there is nothing to insert. + continue; + } + $ok = $this->entryDAO->updateEntry($entry->toArray()); } else { $entry->_lastSeen(time()); + + $entry = Minz_ExtensionManager::callHook('entry_before_add', $entry); + if (!($entry instanceof FreshRSS_Entry)) { + // An extension has returned a null value, there is nothing to insert. + continue; + } + $ok = $this->entryDAO->addEntry($entry->toArray()); } -- cgit v1.2.3