Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.1] Hooks list add support for leading backslash namespaces #8372

Open
wants to merge 2 commits into
base: release-2.1
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: Add a check to see if a file was already loaded
  • Loading branch information
MissAllSunday committed Dec 24, 2024
commit 9797a8b838e8895ef8731399940ddcd563dff03e
18 changes: 16 additions & 2 deletions Sources/ManageMaintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -2109,10 +2109,11 @@ function get_integration_hooks_data($start, $per_page, $sort, $filtered_hooks, $
foreach ($filtered_hooks as $hook => $functions)
foreach ($functions as $rawFunc)
{
$hookParsedData = parse_integration_hook($hook, $rawFunc);
$hookParsedData = parse_integration_hook($hook, $rawFunc, $function_list);

// Handle hooks pointing outside the sources directory.
$absPath_clean = rtrim($hookParsedData['absPath'], '!');

if ($absPath_clean != '' && !isset($files[$absPath_clean]) && file_exists($absPath_clean))
$function_list += get_defined_functions_in_file($absPath_clean);

Expand Down Expand Up @@ -2167,9 +2168,10 @@ function get_integration_hooks()
*
* @param string $hook
* @param string $rawData A string as it was saved to the DB.
* @param array $functionList A list of functions found on previously parsed files
* @return array everything found in the string itself
*/
function parse_integration_hook(string $hook, string $rawData)
function parse_integration_hook(string $hook, string $rawData, array $functionList)
{
global $boarddir, $settings, $sourcedir;

Expand Down Expand Up @@ -2227,6 +2229,18 @@ function parse_integration_hook(string $hook, string $rawData)
else
$hookData['call'] = $hookData['pureFunc'] = $modFunc;

$hookData['call'] = ltrim($hookData['call'], '\\');

// One last chance, perhaps the file was included in another way
if ($hookData['absPath'] === '' && isset($functionList[$hookData['call']]))
{
$hookData['absPath'] = strtr(strtr(trim($functionList[$hookData['call']]), [
'$boarddir' => $boarddir,
'$sourcedir' => $sourcedir,
'$themedir' => $settings['theme_dir'] ?? ''
]), '\\', '/');
}

return $hookData;
}

Expand Down
Loading