mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
[feature/system-cron] rewrite cron manager to use autoloading
PHPBB3-9596
This commit is contained in:
parent
5a075c3dca
commit
0aa491ffa2
1 changed files with 28 additions and 40 deletions
|
@ -29,15 +29,15 @@ class cron_manager
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$task_files = $this->find_cron_task_files();
|
$task_names = $this->find_cron_task_names();
|
||||||
$this->load_tasks($task_files);
|
$this->load_tasks($task_names);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds cron task files.
|
* Finds cron task files.
|
||||||
*
|
*
|
||||||
* A cron task file must follow the naming convention:
|
* A cron task file must follow the naming convention:
|
||||||
* includes/cron/tasks/$mod/$name.php.
|
* includes/cron/task/$mod/$name.php.
|
||||||
* $mod is core for tasks that are part of phpbb.
|
* $mod is core for tasks that are part of phpbb.
|
||||||
* Modifications should use their name as $mod.
|
* Modifications should use their name as $mod.
|
||||||
* $name is the name of the cron task.
|
* $name is the name of the cron task.
|
||||||
|
@ -45,43 +45,41 @@ class cron_manager
|
||||||
*
|
*
|
||||||
* Todo: consider caching found task file list in global cache.
|
* Todo: consider caching found task file list in global cache.
|
||||||
*/
|
*/
|
||||||
public function find_cron_task_files()
|
public function find_cron_task_names()
|
||||||
{
|
{
|
||||||
global $phpbb_root_path, $phpEx;
|
global $phpbb_root_path, $phpEx;
|
||||||
|
|
||||||
$tasks_root_path = $phpbb_root_path . 'includes/cron/task';
|
$tasks_root_path = $phpbb_root_path . 'includes/cron/task/';
|
||||||
$dir = opendir($tasks_root_path);
|
|
||||||
$task_dirs = array();
|
$task_names = array();
|
||||||
while (($entry = readdir($dir)) !== false)
|
$ext = '.' . $phpEx;
|
||||||
|
$ext_length = strlen($ext);
|
||||||
|
|
||||||
|
$dh = opendir($tasks_root_path);
|
||||||
|
while (($mod = readdir($dh)) !== false)
|
||||||
{
|
{
|
||||||
// ignore ., .. and dot directories
|
// ignore ., .. and dot directories
|
||||||
// todo: change is_dir to account for symlinks
|
// todo: change is_dir to account for symlinks
|
||||||
if ($entry[0] == '.' || !is_dir("$tasks_root_path/$entry"))
|
if ($mod[0] == '.' || !is_dir($tasks_root_path . $mod))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$task_dirs[] = $entry;
|
|
||||||
}
|
|
||||||
closedir($dir);
|
|
||||||
|
|
||||||
$ext = '.' . $phpEx;
|
$dh2 = opendir($tasks_root_path . $mod);
|
||||||
$ext_length = strlen($ext);
|
while (($file = readdir($dh2)) !== false)
|
||||||
$task_files = array();
|
|
||||||
foreach ($task_dirs as $task_dir)
|
|
||||||
{
|
{
|
||||||
$path = $phpbb_root_path . 'includes/cron/tasks/' . $task_dir;
|
$task_name = substr($file, 0, -$ext_length);
|
||||||
$dir = opendir($path);
|
if (substr($file, -$ext_length) == $ext && $this->is_valid_name($mod) && $this->is_valid_name($task_name))
|
||||||
while (($entry = readdir($dir)) !== false)
|
|
||||||
{
|
{
|
||||||
if (substr($entry, -$ext_length) == $ext)
|
$full_task_name = $mod . '_' . $task_name;
|
||||||
{
|
$task_names[] = $full_task_name;
|
||||||
$task_file = substr($entry, 0, -$ext_length);
|
|
||||||
$task_files[] = array($task_dir, $task_file);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir($dir);
|
closedir($dh2);
|
||||||
}
|
}
|
||||||
return $task_files;
|
closedir($dh);
|
||||||
|
|
||||||
|
return $task_names;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -92,26 +90,16 @@ class cron_manager
|
||||||
return preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $name);
|
return preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function load_tasks($task_files)
|
public function load_tasks($task_names)
|
||||||
{
|
{
|
||||||
global $phpbb_root_path, $phpEx;
|
foreach ($task_names as $task_name)
|
||||||
|
|
||||||
foreach ($task_files as $task_file)
|
|
||||||
{
|
{
|
||||||
list($mod, $filename) = $task_file;
|
$class = "cron_task_$task_name";
|
||||||
if ($this->is_valid_name($mod) && $this->is_valid_name($filename))
|
$task = new $class();
|
||||||
{
|
$wrapper = new cron_task_wrapper($task);
|
||||||
$class = "cron_task_${mod}_${filename}";
|
|
||||||
if (!class_exists($class))
|
|
||||||
{
|
|
||||||
include($phpbb_root_path . "includes/cron/tasks/$mod/$filename.$phpEx");
|
|
||||||
}
|
|
||||||
$object = new $class;
|
|
||||||
$wrapper = new cron_task_wrapper($object);
|
|
||||||
$this->tasks[] = $wrapper;
|
$this->tasks[] = $wrapper;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds a task that is ready to run.
|
* Finds a task that is ready to run.
|
||||||
|
|
Loading…
Add table
Reference in a new issue