โดยผมได้ทดสอบสร้าง Event cron ที่ใช้สำหรับการสร้างโฟลเดอขึ้นมา ดังนี้
1. ในโฟลเดอ config ได้สร้างไฟล์ services.yml โดยมีโคดดังนี้
โค้ด: เลือกทั้งหมด
services:
forumhulp.cron.deleteinactiveusers:
class: forumhulp\deleteinactiveusers\cron\task\core\delete_inactive_users
arguments:
- @user
- @config
- @config_text
- @dbal.conn
- @log
- %core.root_path%
- %core.php_ext%
calls:
- [set_name, [forumhulp.cron.delete_inactive_users]]
tags:
- { name: cron.task }
forumhulp.deleteinactiveusers.listener:
class: forumhulp\deleteinactiveusers\event\listener
arguments:
- @controller.helper
tags:
- { name: event.listener }
โค้ด: เลือกทั้งหมด
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class listener implements EventSubscriberInterface {
protected $helper;
public function __construct(\phpbb\controller\helper $helper) {
$this->helper = $helper;
}
static public function getSubscribedEvents() {
return array(
'core.acp_board_config_edit_add' => 'load_config_on_setup',
);
}
public function load_config_on_setup($event) {
if ($event['mode'] == 'features') {
$display_vars = $event['display_vars'];
// ส่วววนี้เป็นส่วนสำหรับเรียกใช้งาน cron
$add_config_var['delete_inactive_users_days'] = [
'lang' => 'INACTIVE_USERS_DAYS',
'validate' => 'int',
'type' => 'custom',
'function' => __NAMESPACE__ . '\listener::delete_users_options',
'explain' => true
];
$display_vars['vars'] = phpbb_insert_config_array($display_vars['vars'], $add_config_var, array('after' => 'allow_quick_reply'));
$event['display_vars'] = array('title' => $display_vars['title'], 'vars' => $display_vars['vars']);
}
}
}
3. สร้าง โฟลเดอร์ cron / task / core แล้วสร้างไฟล์ชื่อ delete_inactive_users.php
โค้ด: เลือกทั้งหมด
<?php
namespace forumhulp\deleteinactiveusers\cron\task\core;
class delete_inactive_users extends \phpbb\cron\task\base {
protected $user;
protected $config;
protected $config_text;
protected $db;
protected $log;
protected $phpbb_root_path;
protected $php_ext;
public function __construct(\phpbb\user $user, \phpbb\config\config $config, \phpbb\config\db_text $config_text, \phpbb\db\driver\driver_interface $db, \phpbb\log\log $log, $phpbb_root_path, $php_ext) {
$this->user = $user;
$this->config = $config;
$this->config_text = $config_text;
$this->db = $db;
$this->log = $log;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
}
public function run() {
// ส่วนนี้ไว้สำหรับการสร้างโฟลเดอร์
$path_img = './images/test';
if (!file_exists($path_img)) {
mkdir($path_img);
chmod($path_img, 0777);
}
}
public function is_runnable() {
return (bool) $this->config['delete_inactive_users_days'];
}
public function should_run() {
return $this->config['delete_inactive_users_last_gc'] < time() - $this->config['delete_inactive_users_gc'];
}
}
โดยปัญหาก็คือ ไม่มีการสร้างโฟลเดอร์ตามที่ต้อง จึงอย่า่งทราบว่าจะปรับแก้ไขอย่างไรครับ
โดยผมได้ลองศึกษาการสร้าง cron มาจาก https://www.phpbb.com/customise/db/exte ... s/faq/1746
และได้ทดลองนำ Extension จาก ครับ