mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-11 22:08:54 +00:00
[feature/system-cron] Use a RecursiveDirectoryIterator instead of readdir.
PHPBB3-9596
This commit is contained in:
parent
9bc62056b2
commit
7a8233020b
4 changed files with 15 additions and 22 deletions
|
@ -242,5 +242,5 @@ foreach ($cache->obtain_hooks() as $hook)
|
||||||
|
|
||||||
if (!$config['use_system_cron'])
|
if (!$config['use_system_cron'])
|
||||||
{
|
{
|
||||||
$cron = new phpbb_cron_manager();
|
$cron = new phpbb_cron_manager($phpbb_root_path, $phpEx);
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,7 @@ if ($config['use_system_cron'])
|
||||||
{
|
{
|
||||||
$use_shutdown_function = false;
|
$use_shutdown_function = false;
|
||||||
|
|
||||||
$cron = new phpbb_cron_manager();
|
$cron = new phpbb_cron_manager($phpbb_root_path, $phpEx);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -72,35 +72,28 @@ class phpbb_cron_manager
|
||||||
*/
|
*/
|
||||||
public function find_cron_task_names()
|
public function find_cron_task_names()
|
||||||
{
|
{
|
||||||
$tasks_root_path = $this->phpbb_root_path . 'includes/cron/task/';
|
$task_root_path = $this->phpbb_root_path . 'includes/cron/task/';
|
||||||
|
|
||||||
$task_names = array();
|
$task_names = array();
|
||||||
$ext = '.' . $this->phpEx;
|
$ext = '.' . $this->phpEx;
|
||||||
$ext_length = strlen($ext);
|
$ext_length = strlen($ext);
|
||||||
|
|
||||||
$dh = opendir($tasks_root_path);
|
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($task_root_path));
|
||||||
while (($mod = readdir($dh)) !== false)
|
|
||||||
{
|
|
||||||
// ignore ., .. and dot directories
|
|
||||||
// todo: change is_dir to account for symlinks
|
|
||||||
if ($mod[0] == '.' || !is_dir($tasks_root_path . $mod))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$dh2 = opendir($tasks_root_path . $mod);
|
foreach ($iterator as $fileinfo)
|
||||||
while (($file = readdir($dh2)) !== false)
|
|
||||||
{
|
{
|
||||||
$task_name = substr($file, 0, -$ext_length);
|
$file = preg_replace("#^$task_root_path#", '', $fileinfo->getPathname());
|
||||||
if (substr($file, -$ext_length) == $ext && $this->is_valid_name($mod) && $this->is_valid_name($task_name))
|
|
||||||
|
// skip directories and files direclty in the task root path
|
||||||
|
if ($fileinfo->isFile() && strpos($file, '/') !== false)
|
||||||
{
|
{
|
||||||
$full_task_name = $mod . '_' . $task_name;
|
$task_name = str_replace('/', '_', substr($file, 0, -$ext_length));
|
||||||
$task_names[] = $full_task_name;
|
if (substr($file, -$ext_length) == $ext && $this->is_valid_name($task_name))
|
||||||
|
{
|
||||||
|
$task_names[] = $task_name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
closedir($dh2);
|
|
||||||
}
|
}
|
||||||
closedir($dh);
|
|
||||||
|
|
||||||
return $task_names;
|
return $task_names;
|
||||||
}
|
}
|
||||||
|
@ -115,7 +108,7 @@ class phpbb_cron_manager
|
||||||
*/
|
*/
|
||||||
public function is_valid_name($name)
|
public function is_valid_name($name)
|
||||||
{
|
{
|
||||||
return (bool) preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $name);
|
return preg_match('/^[a-zA-Z][a-zA-Z0-9_]*$/', $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -11,7 +11,7 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
$this->manager = new phpbb_cron_manager();
|
$this->manager = new phpbb_cron_manager(__DIR__ . '/../../phpBB/', 'php');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_manager_finds_shipped_tasks()
|
public function test_manager_finds_shipped_tasks()
|
||||||
|
|
Loading…
Add table
Reference in a new issue