XF 2.3 Error around XF\Job\JobResult::newResume

BoostN

Well-known member
Hello, I'm trying to update my add-on for XF2.3, and I'm getting this error log a handful times a day.

  • TypeError: XF\Job\JobResult::newResume(): Argument #3 ($statusMessage) must be of type string, null given, called in /home/nginx/domains/XXXXXXXXXXXXX.com/public/forum/src/XF/Job/AbstractJob.php on line 72
  • src/XF/Job/JobResult.php:34
  • Generated by: Unknown account
  • Jul 30, 2024 at 9:10 AM

Code:
Stack trace
#0 src/XF/Job/AbstractJob.php(72): XF\Job\JobResult::newResume(70786, Array, NULL, true)
#1 src/addons/BoostN/SendySync/Job/SendySync.php(142): XF\Job\AbstractJob->resume()
#2 src/XF/Job/Manager.php(275): BoostN\SendySync\Job\SendySync->run(8)
#3 src/XF/Job/Manager.php(205): XF\Job\Manager->runJobInternal(Array, 8)
#4 src/XF/Job/Manager.php(89): XF\Job\Manager->runJobEntry(Array, 8)
#5 job.php(46): XF\Job\Manager->runQueue(false, 8)
#6 {main}
Request state
array(4) {
  ["url"] => string(14) "/forum/job.php"
  ["referrer"] => string(35) "https://www.XXXXXXXXXX.com/forum/"
  ["_GET"] => array(0) {
  }
  ["_POST"] => array(0) {
  }
}

My Job Code:
PHP:
<?php

namespace BoostN\SendySync\Job;

use XF\Job\AbstractJob;

class SendySync extends AbstractJob
{
    protected $defaultData = [
        'start' => 0,
        'batch' => 100,
        'max' => null
    ];

    public function run($maxRunTime)
    {
        $app = \XF::app();
        $startTime = microtime(true);


        $db = $this->app->db();
        $em = $this->app->em();


        $ids = $db->fetchAllColumn($db->limit(
            "
                SELECT user_id
                FROM xf_user
                WHERE user_id > ?
                ORDER BY user_id
            ", $this->data['batch']
        ), $this->data['start']);
        if (!$ids)
        {
            return $this->complete();
        }

        if ($this->data['max'] === null)
        {
            $this->data['max'] = $db->fetchOne("SELECT MAX(user_id) FROM xf_user");
        }

        $done = 0;

        foreach ($ids AS $id)
        {
            //CODE REMOVED
            switch($sResult){
                case "NoListId":
                    $sendyRepo->setSendyStatus($user, 0);
                    $sendyRepo->createLog("cron", "NoListId", $user->user_id, $user->username, $sResult);
                    break;

                default:
                    \XF::logError("Cron Job Error: Default Break");
                    $sendyRepo->createLog("cron", "defaultError", $user->user_id, $user->username, $sResult);

                    break;
            }

            $done++;

            if (microtime(true) - $startTime >= $maxRunTime)
            {
                break;
            }

        }
        $this->data['batch'] = $this->calculateOptimalBatch($this->data['batch'], $done, $startTime, $maxRunTime, 1000);

        return $this->resume();
    }

    public function getStatusMessage()
    {
        $actionPhrase = \XF::phrase('rebuilding');
        $typePhrase = 'Rebuilding Users Sendy Data';
    }

    public function canCancel()
    {
        return true;
    }

    public function canTriggerByChoice()
    {
        return true;
    }
}

...any ideas here?
 
sounds like
newResume(70786, Array, NULL, true)

this NULL can't be null, needs to be` ""` (an empty string) instead.

this is a php 8 thing.

common work around is the null coalesce:



so you could use $yourvar ?? '' instead of just $yourvar there.
 
I added a return with a default value as you have mentioned:

PHP:
public function getStatusMessage()
    {
        $actionPhrase = \XF::phrase('rebuilding');
        $typePhrase = 'Rebuilding Users Sendy Data';
        return $actionPhrase . '... ' . $typePhrase ?? '';
    }

Seems like that might be the fix?!?!
 
Back
Top Bottom