Skip to content

Commit

Permalink
fix: Add a check to see if a file was already loaded
Browse files Browse the repository at this point in the history
  • Loading branch information
MissAllSunday committed Dec 24, 2024
1 parent b9e0009 commit 9797a8b
Showing 1 changed file with 16 additions and 2 deletions.
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

0 comments on commit 9797a8b

Please sign in to comment.