Open gregorydavidjenkins opened 4 months ago
We have recently run into this issue, too. It appears to be from the model expecting the type to be a string and the code setting it as an array at a couple spots in src/services/Jobs.php.
The addJob function, we moved Json::encode()
up to line 159, so it's now $job->settings = Json::encode($settings);
, then removed Json::encode()
from line 165, so it's just 'settings' => $job->settings,
.
The next change was in _createJobFromRecord function, we removed the last if statement and are just returning the job now, so it looks like this:
private function _createJobFromRecord(?JobRecord $jobRecord = null): ?Job
{
if (!$jobRecord) {
return null;
}
return new Job($jobRecord->toArray([
'id',
'type',
'date',
'context',
'settings'
]));
}
I don't recommend editing vendor files because changes will get overwritten, but if you can fork off of this or have another way of doing these until they fix these themselves, then that would be best.
I'm also having this issue, but sort of in the opposite direction! I'm adding a custom job from a plugin controller as described in the docs and getting an error because I'm passing in $settings
as an array (of useful values that I'll need in my custom job). I've temporarily switched the type of the $settings
property in the Job model to array. It looks like this will be updated in the Craft 5 release, but would love to see it in this version as well so I don't have to fork!
I have this same issue. Any sense of timing for a fix? Or am I better off switching to a different solution?
Same issue here. A simple fix with just the model fix on setting the $settings as an array not a string would be highly appriciated.
Describe the bug
When saving an entry I get this error.
TypeError: Cannot assign array to property verbb\scheduler\models\Job::$settings of type ?string in /var/www/vendor/verbb/scheduler/src/services/Jobs.php:159
Looks like the settings are getting passed as an array but it's expecting a string?
Steps to reproduce
Craft CMS version
4.5.5
Plugin version
3.0.0
Multi-site?
No
Additional context
Complete stack trace here:
TypeError: Cannot assign array to property verbb\scheduler\models\Job::$settings of type ?string in /var/www/vendor/verbb/scheduler/src/services/Jobs.php:159 Stack trace:
0 /var/www/vendor/verbb/scheduler/src/Scheduler.php(109): verbb\scheduler\services\Jobs->addJob('verbb\scheduler...', Object(DateTime), 'programmatic:17...', Array)
1 [internal function]: verbb\scheduler\Scheduler->verbb\scheduler{closure}(Object(craft\events\ElementEvent))
2 /var/www/vendor/yiisoft/yii2/base/Event.php(312): call_user_func(Object(Closure), Object(craft\events\ElementEvent))
3 /var/www/vendor/yiisoft/yii2/base/Component.php(642): yii\base\Event::trigger('craft\services\...', 'afterSaveElemen...', Object(craft\events\ElementEvent))
4 /var/www/vendor/craftcms/cms/src/services/Elements.php(3503): yii\base\Component->trigger('afterSaveElemen...', Object(craft\events\ElementEvent))
5 /var/www/vendor/craftcms/cms/src/services/Elements.php(1097): craft\services\Elements->_saveElementInternal(Object(craft\elements\Entry), true, false, true, Array, false, false)
6 /var/www/vendor/craftcms/cms/src/controllers/ElementsController.php(1051): craft\services\Elements->saveElement(Object(craft\elements\Entry), true, true, NULL, false, false)
7 [internal function]: craft\controllers\ElementsController->actionSave()
8 /var/www/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
9 /var/www/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
10 /var/www/vendor/yiisoft/yii2/base/Module.php(552): yii\base\Controller->runAction('save', Array)
11 /var/www/vendor/craftcms/cms/src/web/Application.php(304): yii\base\Module->runAction('elements/save', Array)
12 /var/www/vendor/craftcms/cms/src/web/Application.php(607): craft\web\Application->runAction('elements/save', Array)
13 /var/www/vendor/craftcms/cms/src/web/Application.php(283): craft\web\Application->_processActionRequest(Object(craft\web\Request))
14 /var/www/vendor/yiisoft/yii2/base/Application.php(384): craft\web\Application->handleRequest(Object(craft\web\Request))
15 /var/www/web/index.php(12): yii\base\Application->run()
16 {main}