nyeholt / silverstripe-workflow-actions

Additional actions for workflows
BSD 3-Clause "New" or "Revised" License
0 stars 5 forks source link

Undefined property: stdClass::$blockId #11

Open JamesDPC opened 3 years ago

JamesDPC commented 3 years ago

Hi folks

Getting an error with the following setup:

silverstripe/framework 4.8.0 dnadesign/silverstripe-elemental 4.6.0 symbiote-library/silverstripe-workflow-actions 1.4.1 silverstripe/graphql 3.5.0

It's blocking loading of elemental elements on page load (just get the animated SS logo in the elemental field). I don't recall seeing it on <= SS 4.6

[Notice] Undefined property: stdClass::$blockId
POST /admin/graphql

Line 53 in /path/to/vendor/symbiote-library/silverstripe-workflow-actions/src/Extension/WorkflowedElement.php

44         if (!Permission::checkMember($member, 'ADMIN')) {
45             return false;
46         }
47 
48         try {
49             $req = Controller::curr()->getRequest();
50             $data = json_decode($req->getBody());
51             if ($data) {
52                 $pub_action = ($data->operationName == 'PublishBlock');
53                 $cur_block = ($data->variables->blockId == $this->owner->ID);
54                 return ($pub_action && $cur_block);
55             }
56         } catch (\Exception $e) {
57             return false;
58         }
59     }

The JSON request to /admin/graphql:

{
    "operationName": "ReadBlocksForArea",
    "variables": {
        "id": 83
    },
    "query": "query ReadBlocksForArea($id: ID!) {\n  readOneElementalArea(filter: {id: {eq: $id}}, versioning: {mode: DRAFT}) {\n    elements {\n      id\n      title\n      blockSchema\n      isLiveVersion\n      isPublished\n      version\n      canCreate\n      canPublish\n      canUnpublish\n      canDelete\n      __typename\n    }\n    __typename\n  }\n}\n"
}
JamesDPC commented 3 years ago

I dug into this and it looks like canPublish is now called when the blocks are being read via https://github.com/silverstripe/silverstripe-elemental/blob/master/client/src/state/editor/readBlocksForAreaQuery.js and that was added between 4.6 and 4.8 somewhere deeper ( maybe in graphql or versioned modules ?) I can't see any recent changes in elemental that would do this.

I modified the canInlinePublish handling of the operation name and possible non-existence of blockId in the request: https://github.com/JamesDPC/silverstripe-workflow-actions/commit/518374586987445fb80e752ecfa339614d65bc3d

Will give that a burl and provide a PR if it appears stable.

MarcEspiard commented 2 years ago

@JamesDPC Hey, having the same issue, any chance you might submit that PR is the fix worked for you please?

JamesDPC commented 2 years ago

Looks like this was fixed in #12 and tagged as 1.4.2 :D