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

Issue with Matrix afterDelete() and sessions when none is available #2821

Closed
engram-design opened this issue Apr 27, 2018 · 3 comments
Closed

Comments

@engram-design
Copy link
Contributor

Not so much an issue, but maybe a general discussion on the best approach? The short of the issue is that in Feed Me, when updating an element that has a Matrix field, which in turn has element fields, there's an error being thrown:

session_start(): Cannot send session cookie - headers already sent by (output started at /vendor/yiisoft/yii2/web/Response.php:414) - Session.php:137

This is only when triggering a task through the queue. Running it directly (with a logged in session) works just fine.

After much trial an error, I've isolated it to the following code in elements/MatrixBlock.php:

public function afterDelete()
{
    if (!Craft::$app->getRequest()->getIsConsoleRequest()) {
        // Tell the browser to forget about this block
        $session = Craft::$app->getSession();
        $session->addAssetBundleFlash(MatrixAsset::class);
        $session->addJsFlash('Craft.MatrixInput.forgetCollapsedBlockId('.$this->id.');');
    }

    parent::afterDelete();
}

And I can see why this would happen, and why its throwing the error. So rather than suggest modifying this function (even with a try-catch), is there some may to masquerade requests as if they were console commands? Or would there be a better approach for this?

Apologies if this is not the right platform for discussion.

@brandonkelly
Copy link
Member

I just fixed this yesterday ;) 27eaf6e (original issue reported is #2813)

@engram-design
Copy link
Contributor Author

Awesome, sorry didn't even see that! Thanks @brandonkelly

@engram-design
Copy link
Contributor Author

@brandonkelly Hate to bring this issue up from the dead, but seems like its come back!

See https://github.com/craftcms/cms/blob/develop/src/services/Matrix.php#L720 or:

if (!Craft::$app->getRequest()->getIsConsoleRequest() && !empty($collapsedBlockIds)) {
    ...
}

Referencing 27eaf6e and add && !Craft::$app->getResponse()->isSent to the appropriate line fixes this.

I have submitted a PR for consideration - #3217

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

2 participants