Skip to main content

Scheduled Attribute Recruitment

In some cases, there may be a requirement that attribute recruitment runs, for example, once per night.
In this case, a CLI command must be developed that can be set up as a cron job.

<?php

namespace App\Command;

use Pimcore\Console\AbstractCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Twocream\ProductAttributeBundle\Components\Queue\Items\RecruitmentQueueItem;

class ScheduledAttributeRecruitingCommand extends AbstractCommand
{
protected ?RecruitmentQueueItem $attributeRecruitment;

public function __construct(?RecruitmentQueueItem $attributeRecruitment = null, $name = null)
{
$this->attributeRecruitment = $attributeRecruitment;

parent::__construct($name);
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->attributeRecruitment->execute(null, null, true);

return AbstractCommand::SUCCESS;
}
}