0

I created an update task for table tx_scheduler_task: Old tasks get removed, new ones should be add.

I stumbled upon a problem in my attempt to write data to the field serialized_task_object.

$queryBuilder = $this->getDbQueryBuilder();
$queryBuilder
    ->insert('tx_scheduler_task')
    ->values(
        [
            'uid' => 1337,
            'nextexecution' => 1337,
            'serialized_task_object' => 'I_DO_NOT_KNOW_WHAT_TO_WRITE_HERE',
            'lastexecution_context' => 'CLI'

        ]
    )
    ->execute();

I created all new needed tasks inside development environment and copied the content to the update task for exmaple: "O:51:"TYPO3\CMS\Scheduler\Task\TableGarbageCollectionTask":10:s:9:"allTables";b:1;s:12:"numberOfDays";i: ..."

The update task just runs fine, but whatever I did I recieved the following error when I opened the module scheduler: "(1/1) TypeError get_class() expects parameter 1 to be object, bool given"

This string needs to be converted, casted to blob? Can some tell me how? I tried hex2bin, pack and read too much other things. I also looked inside typo3/sysext/scheduler/Classes/Scheduler.php but did not understand, how it is written or how to use ['serialized_task_object' => Connection::PARAM_LOB] inside my insert().

I know, that I can easily create a sql dump of tx_scheduler_task and import this inside staging or live. In this attempt I would like to use only TYPO3 update wizards.

2 Answers 2

1

To modify scheduler tasks you can use the class TYPO3\CMS\Scheduler\Scheduler. Here you have various methods like addTask or removeTask which should be used to modify the database.

For your Upgrade Wizard you could use something like this:

$myTask = new \TYPO3\CMS\Scheduler\Task\IpAnonymizationTask();
$myTask->setDescription("My IP Anonymization Task");
// call other methods here to fully define the task

$scheduler = new \TYPO3\CMS\Scheduler\Scheduler();
$scheduler->addTask($myTask);

To delete existing tasks you have to list them by a query, there is no such method currently. An example you can find at the TYPO3\CMS\Scheduler\Controller\SchedulerModuleController.

Sign up to request clarification or add additional context in comments.

Comments

0

I suggest not going those this road but use the symfony commands. Those can be run via backend as well and are far better deployable.

Check out https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/CommandControllers/Index.html for the docs.

Working example from tt_address:

Configuration/Commands.php

return [
    'ttaddress:geocode' => [
        'class' => \FriendsOfTYPO3\TtAddress\Command\GeocodeCommand::class,
        'schedulable' => true,
    ],
];

and the command itself

<?php
declare(strict_types=1);

namespace FriendsOfTYPO3\TtAddress\Command;


use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
 * Command for geocoding coordinates
 */
class GeocodeCommand extends Command
{

    /**
     * Defines the allowed options for this command
     *
     * @inheritdoc
     */
    protected function configure()
    {
        $this
            ->setDescription('Geocode tt_address records')
            ->addArgument(
                'key',
                InputArgument::REQUIRED,
                'Google Maps key for geocoding'
            );
    }

    /**
     * Geocode all records
     *
     * @inheritdoc
     * @return int
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        // do stuff
        return 0;
    }
}

2 Comments

I can not see how your response helps me nor does it answer any of my questions.
Instead of using tasks with serialization you can also use commands for you CLI code - that's all

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.