| Drupal | PHP Cross Reference | Content Management Systems |
1 <?php 2 3 /** 4 * Implements hook_trigger_info(). 5 */ 6 function actions_loop_test_trigger_info() { 7 return array( 8 'actions_loop_test' => array( 9 'watchdog' => array( 10 'label' => t('When a message is logged'), 11 ), 12 ), 13 ); 14 } 15 16 /** 17 * Implements hook_watchdog(). 18 */ 19 function actions_loop_test_watchdog(array $log_entry) { 20 // If the triggering actions are not explicitly enabled, abort. 21 if (empty($_GET['trigger_actions_on_watchdog'])) { 22 return; 23 } 24 // Get all the action ids assigned to the trigger on the watchdog hook's 25 // "run" event. 26 $aids = trigger_get_assigned_actions('watchdog'); 27 // We can pass in any applicable information in $context. There isn't much in 28 // this case, but we'll pass in the hook name as the bare minimum. 29 $context = array( 30 'hook' => 'watchdog', 31 ); 32 // Fire the actions on the associated object ($log_entry) and the context 33 // variable. 34 actions_do(array_keys($aids), $log_entry, $context); 35 } 36 37 /** 38 * Implements hook_init(). 39 */ 40 function actions_loop_test_init() { 41 if (!empty($_GET['trigger_actions_on_watchdog'])) { 42 watchdog_skip_semaphore('actions_loop_test', 'Triggering action loop'); 43 } 44 } 45 46 /** 47 * Implements hook_action_info(). 48 */ 49 function actions_loop_test_action_info() { 50 return array( 51 'actions_loop_test_log' => array( 52 'label' => t('Write a message to the log.'), 53 'type' => 'system', 54 'configurable' => FALSE, 55 'triggers' => array('any'), 56 ), 57 ); 58 } 59 60 /** 61 * Write a message to the log. 62 */ 63 function actions_loop_test_log() { 64 $count = &drupal_static(__FUNCTION__, 0); 65 $count++; 66 watchdog_skip_semaphore('actions_loop_test', "Test log #$count"); 67 } 68 69 /** 70 * Replacement of the watchdog() function that eliminates the use of semaphores 71 * so that we can test the abortion of an action loop. 72 */ 73 function watchdog_skip_semaphore($type, $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = NULL) { 74 global $user, $base_root; 75 76 // Prepare the fields to be logged 77 $log_entry = array( 78 'type' => $type, 79 'message' => $message, 80 'variables' => $variables, 81 'severity' => $severity, 82 'link' => $link, 83 'user' => $user, 84 'uid' => isset($user->uid) ? $user->uid : 0, 85 'request_uri' => $base_root . request_uri(), 86 'referer' => $_SERVER['HTTP_REFERER'], 87 'ip' => ip_address(), 88 'timestamp' => REQUEST_TIME, 89 ); 90 91 // Call the logging hooks to log/process the message 92 foreach (module_implements('watchdog') as $module) { 93 module_invoke($module, 'watchdog', $log_entry); 94 } 95 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
title