1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-04-13 20:32:11 +02:00

[feature/system-cron] Use a RecursiveDirectoryIterator instead of readdir.

PHPBB3-9596
This commit is contained in:
Nils Adermann 2011-01-13 00:07:40 +01:00 committed by Oleg Pudeyev
parent 9bc62056b2
commit 7a8233020b
4 changed files with 15 additions and 22 deletions

View File

@ -242,5 +242,5 @@ foreach ($cache->obtain_hooks() as $hook)
if (!$config['use_system_cron'])
{
$cron = new phpbb_cron_manager();
$cron = new phpbb_cron_manager($phpbb_root_path, $phpEx);
}

View File

@ -63,7 +63,7 @@ if ($config['use_system_cron'])
{
$use_shutdown_function = false;
$cron = new phpbb_cron_manager();
$cron = new phpbb_cron_manager($phpbb_root_path, $phpEx);
}
else
{

View File

@ -72,35 +72,28 @@ class phpbb_cron_manager
*/
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();
$ext = '.' . $this->phpEx;
$ext_length = strlen($ext);
$dh = opendir($tasks_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;
}
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($task_root_path));
$dh2 = opendir($tasks_root_path . $mod);
while (($file = readdir($dh2)) !== false)
foreach ($iterator as $fileinfo)
{
$file = preg_replace("#^$task_root_path#", '', $fileinfo->getPathname());
// skip directories and files direclty in the task root path
if ($fileinfo->isFile() && strpos($file, '/') !== false)
{
$task_name = substr($file, 0, -$ext_length);
if (substr($file, -$ext_length) == $ext && $this->is_valid_name($mod) && $this->is_valid_name($task_name))
$task_name = str_replace('/', '_', substr($file, 0, -$ext_length));
if (substr($file, -$ext_length) == $ext && $this->is_valid_name($task_name))
{
$full_task_name = $mod . '_' . $task_name;
$task_names[] = $full_task_name;
$task_names[] = $task_name;
}
}
closedir($dh2);
}
closedir($dh);
return $task_names;
}
@ -115,7 +108,7 @@ class phpbb_cron_manager
*/
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);
}
/**

View File

@ -11,7 +11,7 @@ class phpbb_cron_manager_test extends PHPUnit_Framework_TestCase
{
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()