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

Allow hooks to silently fail. #5410

Merged
merged 1 commit into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions Sources/Packages.php
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,10 @@ function PackageInstall()
}
elseif ($action['type'] == 'hook' && isset($action['hook'], $action['function']))
{
// Set the system to ignore hooks, but only if it wasn't changed before.
if (!isset($context['ignore_hook_errors']))
MissAllSunday marked this conversation as resolved.
Show resolved Hide resolved
$context['ignore_hook_errors'] = true;

if ($action['reverse'])
remove_integration_function($action['hook'], $action['function'], true, $action['include_file'], $action['object']);
else
Expand Down
12 changes: 8 additions & 4 deletions Sources/Subs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2072,7 +2072,7 @@ function parse_bbc($message, $smileys = true, $cache_id = '', $parse_tags = arra
foreach ($section as $code)
$alltags[] = $code['tag'];
}
$alltags_regex = '(?>\b' . build_regex(array_unique($alltags)) . '\b|' . build_regex(array_keys($itemcodes)) . ')';
$alltags_regex = '(?' . '>\b' . build_regex(array_unique($alltags)) . '\b|' . build_regex(array_keys($itemcodes)) . ')';
}

$pos = -1;
Expand Down Expand Up @@ -4832,7 +4832,9 @@ function call_integration_hook($hook, $parameters = array())
// Is it valid?
if (!empty($call))
$results[$function] = call_user_func_array($call, $parameters);

// This failed, but we want to do so silently.
elseif (!empty($function) && !empty($context['ignore_hook_errors']))
return $results;
// Whatever it was suppose to call, it failed :(
elseif (!empty($function))
{
Expand All @@ -4845,7 +4847,6 @@ function call_integration_hook($hook, $parameters = array())
$absPath = empty($settings['theme_dir']) ? (strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir))) : (strtr(trim($file), array('$boarddir' => $boarddir, '$sourcedir' => $sourcedir, '$themedir' => $settings['theme_dir'])));
log_error(sprintf($txt['hook_fail_call_to'], $string, $absPath), 'general');
}

// "Assume" the file resides on $boarddir somewhere...
else
log_error(sprintf($txt['hook_fail_call_to'], $function, $boarddir), 'general');
Expand Down Expand Up @@ -5052,8 +5053,11 @@ function call_helper($string, $return = false)
else
$func = $string;

// We can't call this helper, but we want to silently ignore this.
if (!is_callable($func, false, $callable_name) && !empty($context['ignore_hook_errors']))
return false;
// Right, we got what we need, time to do some checks.
if (!is_callable($func, false, $callable_name))
elseif (!is_callable($func, false, $callable_name))
{
loadLanguage('Errors');
log_error(sprintf($txt['sub_action_fail'], $callable_name), 'general');
Expand Down