1.เพิ่ม config ค่าใน migrations/install_test_selenium.php ดังนี้
โค้ด: เลือกทั้งหมด
array('config.add', array('cron_task_custom_last_gc', 0)), // last run
array('config.add', array('cron_task_custom_gc', (60))),
2.เพิ่มโคดลงใน config/services.yml
โค้ด: เลือกทั้งหมด
services:
mindphp.test_selenium.cron.task.cron_task:
class: mindphp\test_selenium\cron\task\cron_task
arguments:
- @config
calls:
- [set_name, [cron.task.cron_task]]
tags:
- { name: cron.task }
mindphp.test_selenium.listener:
class: mindphp\test_selenium\event\listener
arguments:
- @config
- @service_container
tags:
- { name: event.listener }
โค้ด: เลือกทั้งหมด
<?php
namespace mindphp\test_selenium\cron\task;
class cron_task extends \phpbb\cron\task\base
{
protected $config;
public function __construct(\phpbb\config\config $config)
{
$this->config = $config;
}
public function run()
{
$this->config->set('cron_task_custom_last_gc', time());
}
public function should_run()
{
return $this->config['cron_task_custom_last_gc'] < time() - $this->config['cron_task_custom_gc'];
}
}
<?php
/* Put your header comments here. */
namespace mindphp\test_selenium\event;
/**
* @ignore
*/
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class listener implements EventSubscriberInterface {
protected $config;
protected $phpbb_container;
public function __construct(\phpbb\config\config $config, $phpbb_container) {
$this->config = $config;
$this->phpbb_container = $phpbb_container;
}
static public function getSubscribedEvents() {
return array(
'boardtools.cronstatus.modify_cron_task' => 'add_my_cron_task',
'boardtools.cronstatus.modify_cron_config' => 'modify_cronlock',
);
}
public function add_my_cron_task($event) {
// print_r($event);
// exit();
if ($event['task_name'] === 'cron.task.cron_task_test') {
$last_task_date = $this->config['cron_task_custom_last_gc'];
$task_interval = $this->config['cron_task_custom_gc'];
$event['task_date'] = $last_task_date;
$event['new_task_date'] = $last_task_date + $task_interval;
}
}
public function modify_cronlock($event) {
$last_task_date = $this->config['cron_task_custom_last_gc'];
echo $last_task_date;
if (isset($event['last_task_date'])) {
if ($last_task_date >= $event['last_task_date']) {
$event['cronlock'] = 'cron_task'; // The name of our Cron Job.
$event['last_task_date'] = $last_task_date; // Update the time.
}
}
else if ($last_task_date >= $this->phpbb_container->get('boardtools.cronstatus.listener')->maxValueInArray($event['rows'], 'config_value')) {
$event['cronlock'] = 'cron_task'; // The name of our Cron Job.
$rows = $event['rows'];
$rows[] = array(
"config_name" => "cron_task_last_gc", // Any name ending with '_last_gc'.
"config_value" => $last_task_date
);
$event['rows'] = $rows;
}
}
}
โดยโดคเหล่านี้ผมได้นำมาทำตามจาก https://www.phpbb.com/customise/db/exte ... s/faq/1746
ซึ่งผมอยากทราบว่า ถ้าหากต้องการที่จะทดสอบว่า สิ่งที่เขียนนี้ถูกต้องหรือไม จะต้องทำอย่างไรครับ