Mercurial > defr > drupal > core
comparison includes/actions.inc @ 11:589fb7c02327 6.5
Drupal 6.5
author | Franck Deroche <webmaster@defr.org> |
---|---|
date | Tue, 23 Dec 2008 14:32:19 +0100 |
parents | acef7ccb09b5 |
children | 8b6c45761e01 |
comparison
equal
deleted
inserted
replaced
10:6f15c9d74937 | 11:589fb7c02327 |
---|---|
1 <?php | 1 <?php |
2 // $Id: actions.inc,v 1.8.2.3 2008/08/12 06:57:31 dries Exp $ | 2 // $Id: actions.inc,v 1.8.2.4 2008/09/05 09:29:22 dries Exp $ |
3 | 3 |
4 /** | 4 /** |
5 * @file | 5 * @file |
6 * This is the actions engine for executing stored actions. | 6 * This is the actions engine for executing stored actions. |
7 */ | 7 */ |
52 if (is_array($action_ids)) { | 52 if (is_array($action_ids)) { |
53 $where = array(); | 53 $where = array(); |
54 $where_values = array(); | 54 $where_values = array(); |
55 foreach ($action_ids as $action_id) { | 55 foreach ($action_ids as $action_id) { |
56 if (is_numeric($action_id)) { | 56 if (is_numeric($action_id)) { |
57 $where[] = 'OR aid = %d'; | 57 $where[] = "OR aid = '%s'"; |
58 $where_values[] = $action_id; | 58 $where_values[] = $action_id; |
59 } | 59 } |
60 elseif (isset($available_actions[$action_id])) { | 60 elseif (isset($available_actions[$action_id])) { |
61 $actions[$action_id] = $available_actions[$action_id]; | 61 $actions[$action_id] = $available_actions[$action_id]; |
62 } | 62 } |
91 } | 91 } |
92 // Optimized execution of single action. | 92 // Optimized execution of single action. |
93 else { | 93 else { |
94 // If it's a configurable action, retrieve stored parameters. | 94 // If it's a configurable action, retrieve stored parameters. |
95 if (is_numeric($action_ids)) { | 95 if (is_numeric($action_ids)) { |
96 $action = db_fetch_object(db_query("SELECT * FROM {actions} WHERE aid = %d", $action_ids)); | 96 $action = db_fetch_object(db_query("SELECT * FROM {actions} WHERE aid = '%s'", $action_ids)); |
97 $function = $action->callback; | 97 $function = $action->callback; |
98 $context = array_merge($context, unserialize($action->parameters)); | 98 $context = array_merge($context, unserialize($action->parameters)); |
99 $result[$action_ids] = $function($object, $context, $a1, $a2); | 99 $result[$action_ids] = $function($object, $context, $a1, $a2); |
100 } | 100 } |
101 // Singleton action; $action_ids is the function name. | 101 // Singleton action; $action_ids is the function name. |
236 return $function; | 236 return $function; |
237 } | 237 } |
238 } | 238 } |
239 | 239 |
240 // Must be an instance; must check database. | 240 // Must be an instance; must check database. |
241 $aid = db_result(db_query("SELECT aid FROM {actions} WHERE MD5(aid) = '%s' AND parameters != ''", $hash)); | 241 $aid = db_result(db_query("SELECT aid FROM {actions} WHERE MD5(aid) = '%s' AND parameters <> ''", $hash)); |
242 return $aid; | 242 return $aid; |
243 } | 243 } |
244 | 244 |
245 /** | 245 /** |
246 * Synchronize actions that are provided by modules. | 246 * Synchronize actions that are provided by modules. |
323 * The ID of the action. | 323 * The ID of the action. |
324 */ | 324 */ |
325 function actions_save($function, $type, $params, $desc, $aid = NULL) { | 325 function actions_save($function, $type, $params, $desc, $aid = NULL) { |
326 $serialized = serialize($params); | 326 $serialized = serialize($params); |
327 if ($aid) { | 327 if ($aid) { |
328 db_query("UPDATE {actions} SET callback = '%s', type = '%s', parameters = '%s', description = '%s' WHERE aid = %d", $function, $type, $serialized, $desc, $aid); | 328 db_query("UPDATE {actions} SET callback = '%s', type = '%s', parameters = '%s', description = '%s' WHERE aid = '%s'", $function, $type, $serialized, $desc, $aid); |
329 watchdog('actions', 'Action %action saved.', array('%action' => $desc)); | 329 watchdog('actions', 'Action %action saved.', array('%action' => $desc)); |
330 } | 330 } |
331 else { | 331 else { |
332 // aid is the callback for singleton actions so we need to keep a | 332 // aid is the callback for singleton actions so we need to keep a |
333 // separate table for numeric aids. | 333 // separate table for numeric aids. |
334 db_query('INSERT INTO {actions_aid} VALUES (default)'); | 334 db_query('INSERT INTO {actions_aid} VALUES (default)'); |
335 $aid = db_last_insert_id('actions_aid', 'aid'); | 335 $aid = db_last_insert_id('actions_aid', 'aid'); |
336 db_query("INSERT INTO {actions} (aid, callback, type, parameters, description) VALUES (%d, '%s', '%s', '%s', '%s')", $aid, $function, $type, $serialized, $desc); | 336 db_query("INSERT INTO {actions} (aid, callback, type, parameters, description) VALUES ('%s', '%s', '%s', '%s', '%s')", $aid, $function, $type, $serialized, $desc); |
337 watchdog('actions', 'Action %action created.', array('%action' => $desc)); | 337 watchdog('actions', 'Action %action created.', array('%action' => $desc)); |
338 } | 338 } |
339 | 339 |
340 return $aid; | 340 return $aid; |
341 } | 341 } |
348 * | 348 * |
349 * @return | 349 * @return |
350 * The appropriate action row from the database as an object. | 350 * The appropriate action row from the database as an object. |
351 */ | 351 */ |
352 function actions_load($aid) { | 352 function actions_load($aid) { |
353 return db_fetch_object(db_query("SELECT * FROM {actions} WHERE aid = %d", $aid)); | 353 return db_fetch_object(db_query("SELECT * FROM {actions} WHERE aid = '%s'", $aid)); |
354 } | 354 } |
355 | 355 |
356 /** | 356 /** |
357 * Delete a single action from the database. | 357 * Delete a single action from the database. |
358 * | 358 * |
359 * @param $aid | 359 * @param $aid |
360 * integer The ID of the action to delete. | 360 * integer The ID of the action to delete. |
361 */ | 361 */ |
362 function actions_delete($aid) { | 362 function actions_delete($aid) { |
363 db_query("DELETE FROM {actions} WHERE aid = %d", $aid); | 363 db_query("DELETE FROM {actions} WHERE aid = '%s'", $aid); |
364 module_invoke_all('actions_delete', $aid); | 364 module_invoke_all('actions_delete', $aid); |
365 } | 365 } |