diff options
-rw-r--r-- | phpBB/common.php | 2 | ||||
-rw-r--r-- | phpBB/cron.php | 2 | ||||
-rw-r--r-- | phpBB/includes/cron/manager.php | 29 | ||||
-rw-r--r-- | tests/cron/manager_test.php | 2 |
4 files changed, 14 insertions, 21 deletions
diff --git a/phpBB/common.php b/phpBB/common.php index 00fc1a5cb7..e099a324bf 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -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); } diff --git a/phpBB/cron.php b/phpBB/cron.php index cdfd8d0fbe..9f13a9f462 100644 --- a/phpBB/cron.php +++ b/phpBB/cron.php @@ -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 { diff --git a/phpBB/includes/cron/manager.php b/phpBB/includes/cron/manager.php index d7d161793e..6be7d6ec0c 100644 --- a/phpBB/includes/cron/manager.php +++ b/phpBB/includes/cron/manager.php @@ -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) + $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($task_root_path)); + + foreach ($iterator as $fileinfo) { - // ignore ., .. and dot directories - // todo: change is_dir to account for symlinks - if ($mod[0] == '.' || !is_dir($tasks_root_path . $mod)) - { - continue; - } + $file = preg_replace("#^$task_root_path#", '', $fileinfo->getPathname()); - $dh2 = opendir($tasks_root_path . $mod); - while (($file = readdir($dh2)) !== false) + // 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); } /** diff --git a/tests/cron/manager_test.php b/tests/cron/manager_test.php index dcb3c6435a..39e052bd57 100644 --- a/tests/cron/manager_test.php +++ b/tests/cron/manager_test.php @@ -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() |