Browse Source

Log if hook execution failed

Signed-off-by: Suki <[email protected]>
Suki 11 years ago
parent
commit
b9bee139bc
2 changed files with 18 additions and 3 deletions
  1. 14 3
      Sources/Subs.php
  2. 4 0
      Themes/default/languages/Errors.english.php

+ 14 - 3
Sources/Subs.php

@@ -4021,11 +4021,14 @@ function smf_seed_generator()
  */
 function call_integration_hook($hook, $parameters = array())
 {
-	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug, $context;
+	global $modSettings, $settings, $boarddir, $sourcedir, $db_show_debug;
+	global $context, $txt;
 
 	if ($db_show_debug === true)
 		$context['debug']['hooks'][] = $hook;
 
+	 loadLanguage('Errors');
+
 	$results = array();
 	if (empty($modSettings[$hook]))
 		return $results;
@@ -4060,11 +4063,15 @@ function call_integration_hook($hook, $parameters = array())
 				if (file_exists($absPath))
 					require_once($absPath);
 
+				// No? tell the admin about it.
+				else
+					log_error(sprintf($txt['hook_fail_loading_file'], $absPath), 'general');
+
 				// Check if a new object will be created.
 				if (strpos($call[1], '#') !== false)
 					$call = array(new $call[0], $func);
 
-				// No? then this is a call to a static method.
+				// Right then, this is a call to a static method.
 				else
 					$call = array($call[0], $func);
 			}
@@ -4088,6 +4095,10 @@ function call_integration_hook($hook, $parameters = array())
 		// Is it valid?
 		if (is_callable($call))
 			$results[$function] = call_user_func_array($call, $parameters);
+
+		// Whatever it was suppose to call, it failed :(
+		elseif (!empty($func) && !empty($absPath))
+			log_error(sprintf($txt['hook_fail_call_to'], $func, $absPath), 'general');
 	}
 
 	return $results;
@@ -4097,7 +4108,7 @@ function call_integration_hook($hook, $parameters = array())
  * Add a function for integration hook.
  * does nothing if the function is already added.
  *
- * @param string $hook The complete hook name
+ * @param string $hook The complete hook name.
  * @param string $function Function name, can be a call to a method via Class::method.
  * @param string $file Must include one of the following wildcards: $boarddir, $sourcedir, $themedir, example: $sourcedir/Test.php
  * @param bool $object Boolean Indicates if your class will be instantiated when its respective hook is called, your function must be a method.

+ 4 - 0
Themes/default/languages/Errors.english.php

@@ -422,6 +422,10 @@ $txt['email_no_template'] = 'The email template &quot;%1$s&quot; could not be fo
 $txt['search_api_missing'] = 'The search API could not be found. Please contact the admin to check they have uploaded the correct files.';
 $txt['search_api_not_compatible'] = 'The selected search API the forum is using is out of date - falling back to standard search. Please check file %1$s.';
 
+// Handling hook calls
+$txt['hook_fail_loading_file'] = 'Hook call: The file at path: %s could not be loaded.';
+$txt['hook_fail_call_to'] = 'Hook call: function "%1$s" in file %2$s could not be called.';
+
 // Restore topic/posts
 $txt['cannot_restore_first_post'] = 'You cannot restore the first post in a topic.';
 $txt['parent_topic_missing'] = 'The parent topic of the post you are trying to restore has been deleted.';