studioespresso / craft-scout

Craft Scout provides a simple solution for adding full-text search to your entries. Scout will automatically keep your search indexes in sync with your entries.
MIT License
81 stars 54 forks source link

Getting an error related to $siteId having update to 3.3.1 from 3.2.1 #285

Closed icreatestuff closed 7 months ago

icreatestuff commented 7 months ago

Error from web.log file

2023-11-14 14:43:00 [web.ERROR] [TypeError] Cannot assign null to property rias\scout\jobs\IndexElement::$siteId of type int {
    "trace":[
        "#0 /srv/app/sbs/htdocs/vendor/yiisoft/yii2/base/BaseObject.php(107): yii\\BaseYii::configure(Object(rias\\scout\\jobs\\IndexElement), Array)",
        "#1 /srv/app/sbs/htdocs/vendor/studioespresso/craft-scout/src/Scout.php(171): yii\\base\\BaseObject->__construct(Array)",
        "#2 [internal function]: rias\\scout\\Scout->rias\\scout\\{closure}(Object(craft\\events\\ElementEvent))",
        "#3 /srv/app/sbs/htdocs/vendor/yiisoft/yii2/base/Event.php(312): call_user_func(Object(Closure), Object(craft\\events\\ElementEvent))",
        "#4 /srv/app/sbs/htdocs/vendor/yiisoft/yii2/base/Component.php(642): yii\\base\\Event::trigger('craft\\\\services\\\\...', 'afterSaveElemen...', Object(craft\\events\\ElementEvent))",
        "#5 /srv/app/sbs/htdocs/vendor/craftcms/cms/src/services/Elements.php(3530): yii\\base\\Component->trigger('afterSaveElemen...', Object(craft\\events\\ElementEvent))",
        "#6 /srv/app/sbs/htdocs/vendor/craftcms/cms/src/services/Elements.php(1098): craft\\services\\Elements->_saveElementInternal(Object(Solspace\\Freeform\\Elements\\Submission), true, false, true, Array, false, false)",
        "#7 /srv/app/sbs/htdocs/vendor/solspace/craft-freeform/packages/plugin/src/Services/SubmissionsService.php(203): craft\\services\\Elements->saveElement(Object(Solspace\\Freeform\\Elements\\Submission), true, true, true)",
        "#8 /srv/app/sbs/htdocs/vendor/solspace/craft-freeform/packages/plugin/src/Services/SubmissionsService.php(171): Solspace\\Freeform\\Services\\SubmissionsService->storeSubmission(Object(Solspace\\Freeform\\Form\\Types\\Regular), Object(Solspace\\Freeform\\Elements\\Submission))",
        "#9 /srv/app/sbs/htdocs/vendor/solspace/craft-freeform/packages/plugin/src/Controllers/SubmitController.php(64): Solspace\\Freeform\\Services\\SubmissionsService->handleSubmission(Object(Solspace\\Freeform\\Form\\Types\\Regular), Object(Solspace\\Freeform\\Elements\\Submission))",
        "#10 [internal function]: Solspace\\Freeform\\Controllers\\SubmitController->actionIndex()",
        "#11 /srv/app/sbs/htdocs/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)",
        "#12 /srv/app/sbs/htdocs/vendor/yiisoft/yii2/base/Controller.php(178): yii\\base\\InlineAction->runWithParams(Array)",
        "#13 /srv/app/sbs/htdocs/vendor/yiisoft/yii2/base/Module.php(552): yii\\base\\Controller->runAction('', Array)",
        "#14 /srv/app/sbs/htdocs/vendor/craftcms/cms/src/web/Application.php(305): yii\\base\\Module->runAction('freeform/submit', Array)",
        "#15 /srv/app/sbs/htdocs/vendor/craftcms/cms/src/web/Application.php(608): craft\\web\\Application->runAction('freeform/submit', Array)",
        "#16 /srv/app/sbs/htdocs/vendor/craftcms/cms/src/web/Application.php(284): craft\\web\\Application->_processActionRequest(Object(craft\\web\\Request))",
        "#17 /srv/app/sbs/htdocs/vendor/yiisoft/yii2/base/Application.php(384): craft\\web\\Application->handleRequest(Object(craft\\web\\Request))",
        "#18 /srv/app/sbs/htdocs/web/index.php(12): yii\\base\\Application->run()",
        "#19 {main}"
    ],
    "memory":12603320,
    "exception":"[object] (TypeError(code: 0): Cannot assign null to property rias\\scout\\jobs\\IndexElement::$siteId of type int at /srv/app/sbs/htdocs/vendor/yiisoft/yii2/BaseYii.php:558)"
} 

It looks to be related to when a Freeform submission is saved. At the moment this is causing some issues with those submission records and some behaviour that takes place after those elements are saved (e.g. connections to 3rd party integrations). I'm assuming it's an issue with Scout as the problem became apparent following an update from v3.2.1 to 3.3.1 but @kjmartens I'm looping you in here just in case it is an issue with Freeform.

Craft Pro 4.5.10 Scout 3.3.1 Freeform 4.1.12

janhenckens commented 7 months ago

Yep, I assumed the site & siteId property is always there in the event listener, which in hindsight is obviously wrong. Though I can't reproduce this with the latest version of Freeform - the submission has a siteId, even in an install that only has one site.

I've just released 3.3.2 which should fix this, can you give that a try and report back @icreatestuff? Thanks!

icreatestuff commented 7 months ago

Thanks @janhenckens, this update seems to have done the job 👍