Skip to content

Fix extensions in actualize_script#5243

Merged
Alkarex merged 9 commits intoFreshRSS:edgefrom
Alkarex:fix-actualize-extension-user-maintenance
Apr 4, 2023
Merged

Fix extensions in actualize_script#5243
Alkarex merged 9 commits intoFreshRSS:edgefrom
Alkarex:fix-actualize-extension-user-maintenance

Conversation

@Alkarex
Copy link
Copy Markdown
Member

@Alkarex Alkarex commented Mar 30, 2023

Follow-up of #3440

Fix multiple bugs:

  • The extension hook was called before registering all the extensions for the current user
  • During a cron job to refresh feeds, extensions enabled by a previous user risked being enabled for another user.
  • During a cron job to refresh feeds, system extensions were enabled multiple times
  • And more details (see comments)

Contributes to #4112

Follow-up of FreshRSS#3440

The hook was called before registering all the extensions for the current user
@Alkarex Alkarex added the Bug (confirmed) 🐞 issues that are reproducible label Mar 30, 2023
@Alkarex Alkarex added this to the 1.22.0 milestone Mar 30, 2023
@Alkarex
Copy link
Copy Markdown
Member Author

Alkarex commented Mar 30, 2023

@aledeg If you are around, do you happen to have a test case for that?


Minz_ExtensionManager::callHook('freshrss_user_maintenance');

$app->init();
Copy link
Copy Markdown
Member Author

@Alkarex Alkarex Mar 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User extensions are first registered in $app->init();

@aledeg
Copy link
Copy Markdown
Member

aledeg commented Mar 30, 2023

@aledeg If you are around, do you happen to have a test case for that?

Not at the moment. I was meaning to create one to do backend stuff but never took the time.

@Alkarex Alkarex changed the title Fix extension freshrss_user_maintenance in actualize_script Fix extensions in actualize_script Apr 1, 2023
Comment on lines +146 to +150
$ext_list = array_filter($ext_list, function($key) use($type) {
// Remove from list the extensions that have disappeared or changed type
$extension = Minz_ExtensionManager::findExtension($key);
return $extension !== null && $extension->getType() === $type;
}, ARRAY_FILTER_USE_KEY);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We had a case of when extensions were deleted, they would stay enabled for ever in the configuration.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would also do strange things with extensions that have changed type (e.g. enable an extension, which should not)

*/
public static function init() {
public static function init(): void {
self::reset();
Copy link
Copy Markdown
Member Author

@Alkarex Alkarex Apr 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

During a cron job to refresh feeds, extensions enabled by a previous user risked being enabled for another user.
Furthermore, system extensions were enabled multiple times.

Comment on lines +242 to +244
if ($onlyOfType !== null && $ext->getType() !== $onlyOfType) {
// Do not enable an extension of the wrong type
return;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case of extensions changing type (from user to system or vice versa), we risked enabling wrongly or two times an extension

if ($res === true) {
$ext_list = $conf->extensions_enabled;
$legacyKey = array_search($ext_name, $ext_list, true);
if ($legacyKey !== false) { //Legacy format FreshRSS < 1.11.1
Copy link
Copy Markdown
Member Author

@Alkarex Alkarex Apr 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed support for 5 year-old configuration syntax for FreshRSS < 1.11.1.
Automatically updated by just saving the configuration

Comment on lines -94 to -110
/**
* List of enabled extensions.
*/
private $extensions_enabled = [];

public function removeExtension($ext_name) {
unset($this->extensions_enabled[$ext_name]);
$legacyKey = array_search($ext_name, $this->extensions_enabled, true);
if ($legacyKey !== false) { //Legacy format FreshRSS < 1.11.1
unset($this->extensions_enabled[$legacyKey]);
}
}
public function addExtension($ext_name) {
if (!isset($this->extensions_enabled[$ext_name])) {
$this->extensions_enabled[$ext_name] = true;
}
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently dead code, unused

@Alkarex
Copy link
Copy Markdown
Member Author

Alkarex commented Apr 1, 2023

Digging into the extensions code, there were multiple bugs, some a bit severe.

@aledeg and @Frenzie It would be great if you could give a try to this PR with some of your extensions, at least your own use cases.

Comment on lines +86 to 88
* @return void
*/
abstract public function init();
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: We should not change the signature of methods supposed to be overridden

@Alkarex
Copy link
Copy Markdown
Member Author

Alkarex commented Apr 2, 2023

Ping @marienfressinaud also, if you could give a quick try at this PR with your extensions

@Alkarex
Copy link
Copy Markdown
Member Author

Alkarex commented Apr 4, 2023

Let's merge to start testing a bit more widely (Marien is not available in the coming days but will test a bit later)

@Alkarex Alkarex merged commit 36aa012 into FreshRSS:edge Apr 4, 2023
@Alkarex Alkarex deleted the fix-actualize-extension-user-maintenance branch April 4, 2023 08:23
@marienfressinaud
Copy link
Copy Markdown
Member

It took me some time, but it seems to work fine for my extensions 👍

@Alkarex
Copy link
Copy Markdown
Member Author

Alkarex commented Aug 8, 2023

Excellent :-) I will try to prepare a new release in the coming days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug (confirmed) 🐞 issues that are reproducible Important 🔥

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants