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

Versioned::use_session Fallback breaks page editing #51

Closed
Cheddam opened this issue Aug 21, 2018 · 6 comments
Closed

Versioned::use_session Fallback breaks page editing #51

Cheddam opened this issue Aug 21, 2018 · 6 comments

Comments

@Cheddam
Copy link
Member

Cheddam commented Aug 21, 2018

The use_session fallback introduced in SilverStripe 4.2 is intended to maintain the existing behaviour of the framework / CMS, by storing the stage in the session as before.

When this fallback is enabled and silverstripe-versioned-admin is installed (as a dependency of silverstripe-elemental in my case), attempting to open a page for editing in the CMS results in the following error:

[Emergency] Uncaught InvalidArgumentException: Invalid stage name ""
GET /admin/pages/edit/show/9018
Line 160 in /var/www/mysite/www/vendor/silverstripe/versioned/src/ReadingMode.php

Source
151 
152     /**
153      * Validate the stage is valid, throwing an exception if it's not
154      *
155      * @param string $stage
156      */
157     public static function validateStage($stage)
158     {
159         if (!in_array($stage, [Versioned::LIVE, Versioned::DRAFT])) {
160             throw new InvalidArgumentException("Invalid stage name \"{$stage}\"");
161         }
162     }
163 }
Trace
SilverStripe\Versioned\ReadingMode::validateStage() 
Versioned.php:2148
SilverStripe\Versioned\Versioned::set_stage() 
HistoryControllerFactory.php:35
SilverStripe\VersionedAdmin\Controllers\HistoryControllerFactory->create(SilverStripe\CMS\Controllers\CMSPageHistoryController, Array) 
Injector.php:585
SilverStripe\Core\Injector\Injector->instantiate(Array, SilverStripe\CMS\Controllers\CMSPageHistoryController, singleton) 
Injector.php:993
SilverStripe\Core\Injector\Injector->getNamedService(SilverStripe\CMS\Controllers\CMSPageHistoryController, 1, Array) 
Injector.php:946
SilverStripe\Core\Injector\Injector->get(SilverStripe\CMS\Controllers\CMSPageHistoryController) 
LeftAndMain.php:290
SilverStripe\Admin\LeftAndMain->getCombinedClientConfig() 
LeftAndMain.php:673
SilverStripe\Admin\LeftAndMain->init() 
CMSMain.php:179
...

This issue can be temporarily alleviated by appending the stage to the URL (e.g. ?stage=Stage).

A somewhat similar issue with the asset-admin module has been raised here.

@robbieaverill
Copy link
Contributor

@Cheddam could you add steps to reproduce please?

@Cheddam
Copy link
Member Author

Cheddam commented Aug 21, 2018

@robbieaverill Slightly trickier than I'd thought:

  1. Fresh install of SS 4.2 + Elemental 3
  2. Add Elemental <-> Page config and use_session setting to app/_config/mysite.yml:
Page:
  extensions:
    - DNADesign\Elemental\Extensions\ElementalPageExtension

SilverStripe\Versioned\Versioned:
  use_session: true
  1. dev/build, open CMS
  2. Open a page and edit it... switch between different pages for a bit until you get the first 500 response
  3. Observe constant 500s from page edit view loads unless a stage GET param is passed

@robbieaverill
Copy link
Contributor

Thanks!

@dhensby
Copy link
Contributor

dhensby commented Aug 21, 2018

Yeah, we became a lot less forgiving with stage names in that fix, I think... which has caused a little bit of pain here and there.

@ScopeyNZ
Copy link
Contributor

ScopeyNZ commented Aug 21, 2018

We fixed a bunch of issues with tests that threw this exception after the 4.2 release. This section:

https://github.com/silverstripe/silverstripe-versioned-admin/blob/master/src/Controllers/HistoryControllerFactory.php#L32-L35

Will need to use SiteTree::get_one_by_stage instead... I'll PR this tomorrow unless somebody beats me to it.

@ScopeyNZ
Copy link
Contributor

PR at #52

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

No branches or pull requests

4 participants