Skip to content

Programmatically deleting drafts in hook throws error #1232

@robinscholz

Description

@robinscholz

Describe the bug
Trying to programmatically delete subpage drafts within a page.changeStatus:after hook, throws the following error: SyntaxError: Unexpected token T in JSON at position 0

3/5 pages get deleted, 2/5 (identical) don’t.

Here is the config.php

'page.changeStatus:after' => function ($newPage, $oldPage) {
            if($newPage->intendedTemplate() == 'project' && $newPage->status() == 'unlisted') {
                foreach($newPage->drafts() as $phase) {
                    try {
                        $phase->delete();
                        echo 'The page has been deleted';
                    } catch(Exception $e) {
                        echo $e->getMessage();
                    }
                }   
            }
        }

To Reproduce
Steps to reproduce the behavior:

  1. Add subpages to parent page
  2. Change status from listed to unlisted for parent page through the panel
  3. See error

Expected behavior
All pages should be deleted.

Kirby Version
3.0.0-beta-6.22

Desktop (please complete the following information):

  • OS: OSX
  • Browser Chrome
  • Version 70

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions