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

Page can no longer be published after a page break with fields has been deleted #996

Open
Oliver996 opened this issue Jul 30, 2020 · 15 comments

Comments

@Oliver996
Copy link

When I have two page breaks with fields and I delete one I can no longer publish the userformpage. The error I get is "Uncaught Error: Call to a member function publishSingle() on null". What is the problem in this case.
We use SilverStripe 4.6 and Userform 5.6.
We normally not use page breaks, but we automatically add the spamprotectionfield when none has been add. Because our user always forget to add this field. And for some reason it's added in a new page break, after i deleted the page break i had the error.
Other small question would it be not nice to have this function in the modul, that the spamprotectionfield is add automatically? As yml config option?

@maxime-rainville
Copy link

Thanks for reporting this issue. I had a go at replicating it on a stock-standard site, but didn't managed to.

Can you share the logic you use to automatically add the SPAM protection field?

@nicolas-cusan
Copy link

@maxime-rainville I am having the same issue. To reproduce:

  1. Create some form fields
  2. Publish the form page
  3. Remove one field via the delete action in the Gridfield
  4. Navigate to a field edit form (dismiss the prompt telling you the changes on the page will be lost)
  5. Navigate back to the form page
  6. Try and save
  7. Check the Network tab in the inspector to see the error

The error seems to stem from the fact the page is not published after a change (in this case deletion) is performed on a form field.

@Oliver996
Copy link
Author

@maxime-rainville

    function onBeforeWrite() {
        if($this->owner->Fields()->count() > 0){
            if(class_exists("SilverStripe\SpamProtection\EditableSpamProtectionField")){
                $spam_check = false;
                $fields = $this->owner->Fields();
                $parent_class = "";
                foreach ($fields as $field) {
                    $classname_check = $field->ClassName;
                    $parent_class = $field->ParentClass;
                    if($classname_check == "SilverStripe\SpamProtection\EditableSpamProtectionField"){
                        $spam_check = true;
                    }
                }
                if($spam_check !== true){
                    $id = $this->owner->ID;
                    if($id && !empty($parent_class)){
                        $spam = new EditableSpamProtectionField();
                        $spam->Name = $this->generateName();
                        $spam->ParentClass = $parent_class;
                        $spam->ParentID = $id;
                        $spam->write();
                        $spam->publishRecursive();
                    }
                }
            }
        }
    }

This is the code I use for adding the spamfield. But when I remove the extension I still have the same problem with the forms.
I also found somehting else, when I create a new Form and publish it after or before i add fields it creates 2 pages under "Form Fields". When I have this 2 pages i can publish the page, but when i delete one of them i can no longer publish the page.
Other Modules I use are subsites und fluent.

@maxime-rainville
Copy link

maxime-rainville commented Nov 13, 2020

I tried replicating the steps described by @nicolas-cusan but didn't seem to get anywhere. Here's what I did. Can you tell me if I'm missing anything? https://youtu.be/msJb6kkccL4

I also found somehting else, when I create a new Form and publish it after or before i add fields it creates 2 pages under "Form Fields".

I think we already have an issue for that. #975

@Oliver996
Copy link
Author

It's similar to #975. But can you still publish the page after you delete one of the steps and does this happen with all the fields or only with the file upload field? In my case it happens with every field I add to the form.

@nicolas-cusan
Copy link

@maxime-rainville thank you for looking into it. Here ist the reproduction of the issue in a quick gif.

out

@maxime-rainville
Copy link

@nicolas-cusan Any chance you could post that stack trace at the end of your GIF?

@guyvanbael
Copy link
Contributor

guyvanbael commented Jan 27, 2021

@maxime-rainville Workaround. Unplublishing the page and then publish again sets the page back to “published” and gives no error ... maybe this can shine a light on the issue???? Issue occurs whenever a form field is deleted and you try to publish the form.
Update: but unpublishing and then republishing triggers another issue #967

@guyvanbael
Copy link
Contributor

guyvanbael commented Jan 28, 2021

@maxime-rainville This was my trace

SilverStripe\Versioned\ChangeSetItem->publish()
ChangeSet.php:141
SilverStripe\Versioned\ChangeSet->SilverStripe\Versioned\{closure}()
call_user_func(Closure)
Database.php:695
SilverStripe\ORM\Connect\Database->withTransaction(Closure)
ChangeSet.php:160
SilverStripe\Versioned\ChangeSet->publish(1)
RecursivePublishable.php:90
SilverStripe\Versioned\RecursivePublishable->SilverStripe\Versioned\{closure}()
DBDatetime.php:227
SilverStripe\ORM\FieldType\DBDatetime::withFixedNow(2021-01-27 09:31:02, Closure)
RecursivePublishable.php:98
SilverStripe\Versioned\RecursivePublishable->publishRecursive()
call_user_func_array(Array, Array)
Extensible.php:144
SilverStripe\View\ViewableData->SilverStripe\Core\{closure}(SilverStripe\UserForms\Model\UserDefinedForm, Array)
CustomMethods.php:61
SilverStripe\View\ViewableData->__call(publishRecursive, Array)
CMSMain.php:1801
SilverStripe\CMS\Controllers\CMSMain->save(Array, SilverStripe\Forms\Form)
CMSMain.php:2019
SilverStripe\CMS\Controllers\CMSMain->publish(Array, SilverStripe\Forms\Form, SilverStripe\Control\HTTPRequest, SilverStripe\Admin\LeftAndMainFormRequestHandler)
FormRequestHandler.php:530
SilverStripe\Forms\FormRequestHandler->invokeFormHandler(SilverStripe\CMS\Controllers\CMSPageEditController, publish, SilverStripe\Control\HTTPRequest, Array)
FormRequestHandler.php:231
SilverStripe\Forms\FormRequestHandler->httpSubmission(SilverStripe\Control\HTTPRequest)
RequestHandler.php:323
SilverStripe\Control\RequestHandler->handleAction(SilverStripe\Control\HTTPRequest, httpSubmission)
RequestHandler.php:202
SilverStripe\Control\RequestHandler->handleRequest(SilverStripe\Control\HTTPRequest)
RequestHandler.php:226
SilverStripe\Control\RequestHandler->handleRequest(SilverStripe\Control\HTTPRequest)
Controller.php:212
SilverStripe\Control\Controller->handleRequest(SilverStripe\Control\HTTPRequest)
LeftAndMain.php:766
SilverStripe\Admin\LeftAndMain->handleRequest(SilverStripe\Control\HTTPRequest)
AdminRootController.php:123
SilverStripe\Admin\AdminRootController->handleRequest(SilverStripe\Control\HTTPRequest)
Director.php:360
SilverStripe\Control\Director->SilverStripe\Control\{closure}(SilverStripe\Control\HTTPRequest)
DetectLocaleMiddleware.php:122
TractorCow\Fluent\Middleware\DetectLocaleMiddleware->TractorCow\Fluent\Middleware\{closure}(TractorCow\Fluent\State\FluentState)
FluentState.php:152
TractorCow\Fluent\State\FluentState->withState(Closure)
DetectLocaleMiddleware.php:123
TractorCow\Fluent\Middleware\DetectLocaleMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62
SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
InitStateMiddleware.php:51
TractorCow\Fluent\Middleware\InitStateMiddleware->TractorCow\Fluent\Middleware\{closure}(TractorCow\Fluent\State\FluentState)
FluentState.php:152
TractorCow\Fluent\State\FluentState->withState(Closure)
InitStateMiddleware.php:52
TractorCow\Fluent\Middleware\InitStateMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62
SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
VersionedHTTPMiddleware.php:41
SilverStripe\Versioned\VersionedHTTPMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62
SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
ConfirmationMiddleware.php:254
SilverStripe\Control\Middleware\ConfirmationMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62
SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
ConfirmationMiddleware.php:254
SilverStripe\Control\Middleware\ConfirmationMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62
SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
PasswordExpirationMiddleware.php:84
SilverStripe\Security\PasswordExpirationMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62
SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
BasicAuthMiddleware.php:68
SilverStripe\Security\BasicAuthMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62
SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
AuthenticationMiddleware.php:61
SilverStripe\Security\AuthenticationMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62
SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
ExecMetricMiddleware.php:20
SilverStripe\Control\Middleware\ExecMetricMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62
SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
TrailingSlashRedirector.php:102
Axllent\TrailingSlash\Middleware\TrailingSlashRedirector->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62
SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
CanonicalURLMiddleware.php:190
SilverStripe\Control\Middleware\CanonicalURLMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62
SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
HTTPCacheControlMiddleware.php:42
SilverStripe\Control\Middleware\HTTPCacheControlMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62
SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
ChangeDetectionMiddleware.php:28
SilverStripe\Control\Middleware\ChangeDetectionMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62
SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
FlushMiddleware.php:27
SilverStripe\Control\Middleware\FlushMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62
SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
RequestProcessor.php:66
SilverStripe\Control\RequestProcessor->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62
SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
SessionMiddleware.php:20
SilverStripe\Control\Middleware\SessionMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62
SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
AllowedHostsMiddleware.php:60
SilverStripe\Control\Middleware\AllowedHostsMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62
SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
TrustedProxyMiddleware.php:176
SilverStripe\Control\Middleware\TrustedProxyMiddleware->process(SilverStripe\Control\HTTPRequest, Closure)
HTTPMiddlewareAware.php:62
SilverStripe\Control\Director->SilverStripe\Control\Middleware\{closure}(SilverStripe\Control\HTTPRequest)
HTTPMiddlewareAware.php:65
SilverStripe\Control\Director->callMiddleware(SilverStripe\Control\HTTPRequest, Closure)
Director.php:369
SilverStripe\Control\Director->handleRequest(SilverStripe\Control\HTTPRequest)
HTTPApplication.php:117
SilverStripe\Control\HTTPApplication::SilverStripe\Control\{closure}(SilverStripe\Control\HTTPRequest)
call_user_func(Closure, SilverStripe\Control\HTTPRequest)
HTTPApplication.php:136
SilverStripe\Control\HTTPApplication->SilverStripe\Control\{closure}(SilverStripe\Control\HTTPRequest)
HTTPMiddlewareAware.php:65
SilverStripe\Control\HTTPApplication->callMiddleware(SilverStripe\Control\HTTPRequest, Closure)
HTTPApplication.php:137
SilverStripe\Control\HTTPApplication->execute(SilverStripe\Control\HTTPRequest, Closure, )
HTTPApplication.php:118
SilverStripe\Control\HTTPApplication->handle(SilverStripe\Control\HTTPRequest)
index.php:24

@guyvanbael
Copy link
Contributor

@maxime-rainville could this be fluent-related? Just tested on a clean silverstripe 4.7.1 and Userforms 5.8.2 and all is working ok. After adding the fluent module. The issue is showing up

@adrexia
Copy link

adrexia commented Aug 10, 2021

I've commented on the ticket in the fluent module too, but this can be fixed in this module by using the archive action of the gridfield, instead of the delete action:

$config->addComponent(new GridFieldArchiveAction(), GridFieldDeleteAction::class);

Could we change the Userforms gridfield to use archive rather than delete, or is there a reason for this?

@adrexia
Copy link

adrexia commented Aug 12, 2021

Notably the DetailForm doesn't allow delete - it uses unpublish & unpublish and archive. I'd suggest that this module should check if versioned is enabled, and use the Archive action when it is. For now I have fixed it in the relevant project with an extension on UserDefinedForm.

@chrispenny
Copy link
Contributor

Came across this issue as well. The workaround provided above looked to work!

@PVerberkmoes
Copy link

Note: You will need to unpublish and republish the form page for the workaroud to work

@jcsiegrist
Copy link

The Problem with the workaround is that in order to work all translations need to be unpublished. But unpublishing translations loses all the field translations!

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

10 participants