Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal error when saving theme option at site level #10714

Open
NateWr opened this issue Dec 16, 2024 · 1 comment
Open

Fatal error when saving theme option at site level #10714

NateWr opened this issue Dec 16, 2024 · 1 comment

Comments

@NateWr
Copy link
Contributor

NateWr commented Dec 16, 2024

Describe the bug
A fatal error is encountered when saving a theme option at the site level.

To Reproduce
Steps to reproduce the behavior:

  1. Make sure the site has more than one Hosted Journal.
  2. Go to Administration > Site Settings > Appearance > Theme
  3. Select Default Theme and save the form.
  4. See error

What application are you using?
main branch (3.5 pre-release)

Additional information
Error message:

Error: Call to a member function getId() on null in /lib/pkp/classes/plugins/ThemePlugin.php:665
Stack trace:
#0 /lib/pkp/classes/plugins/ThemePlugin.php(660): PKP\plugins\ThemePlugin->saveOption('typography', 'notoSans', NULL)
#1 /lib/pkp/api/v1/site/PKPSiteController.php(225): PKP\plugins\ThemePlugin->saveOption('typography', 'notoSans', NULL)
#2 /lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Routing/CallableDispatcher.php(40): PKP\API\v1\site\PKPSiteController->editTheme(Object(Illuminate\Http\Request), 'index', 'v1')
#3 /lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Routing/Route.php(243): Illuminate\Routing\CallableDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Closure))
#4 /lib/pkp/lib/vendor/laravel/framework/src/Illuminate/Routing/Route.php(214): Illuminate\Routing\Route->runCallable()
#5...
#6...
NateWr added a commit to NateWr/pkp-lib that referenced this issue Dec 16, 2024
@NateWr
Copy link
Contributor Author

NateWr commented Dec 16, 2024

The following PR fixes this issue, but I'm not sure about the side effects. The key code is ThemePlugin::saveOption(). In previous versions, it looked like this:

public function saveOption($name, $value, $contextId = null)
{
    // ...
    if (is_null($contextId)) {
        $context = Application::get()->getRequest()->getContext();
        $contextId = $context->getId();
    }
}

This worked because site-level theme options passed a $contextId of 0. In 3.5, they now pass null, so $context->getId() gets called without a context. This PR fixes this by checking if there is a request context. However, there is no way to know if null was passed to the function deliberately. In other words, there is no way to save a site-level theme option from a request with a context.

(This is probably bad practice anyway, though I can imagine some unusual use cases, like letting a journal manager self-select an option that is then compiled into an array of all journals that is saved at the site level.)

PR:
#10715

Tests:
pkp/ojs#4558

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant