summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--includes/actions.inc158
-rw-r--r--includes/install.inc1
-rw-r--r--install.php4
-rw-r--r--modules/actions/actions.install4
-rw-r--r--modules/actions/actions.module481
-rw-r--r--modules/actions/actions.schema10
-rw-r--r--modules/system/system.admin.inc3
-rw-r--r--modules/system/system.install29
-rw-r--r--modules/system/system.module298
-rw-r--r--modules/system/system.schema18
-rw-r--r--modules/user/user.module2
11 files changed, 541 insertions, 467 deletions
diff --git a/includes/actions.inc b/includes/actions.inc
index 28ec1078a..2c2e41afd 100644
--- a/includes/actions.inc
+++ b/includes/actions.inc
@@ -7,6 +7,8 @@
*/
/**
+ * Perform a given list of actions by executing their callback functions.
+ *
* Given the IDs of actions to perform, find out what the callbacks
* for the actions are by querying the database. Then call each callback
* using the function call $function('do', $object, $context, $a1, $2)
@@ -116,8 +118,8 @@ function actions_do($action_ids, $object = NULL, $context = NULL, $a1 = NULL, $a
* 'description' => t('Save node'),
* 'configurable' => FALSE,
* 'hooks' => array(
- * 'nodeapi' => array('delete','insert','update', 'view'),
- * 'comment' => array('delete','insert','update', 'view'),
+ * 'nodeapi' => array('delete', 'insert', 'update', 'view'),
+ * 'comment' => array('delete', 'insert', 'update', 'view'),
* )
* )
* );
@@ -130,26 +132,40 @@ function actions_do($action_ids, $object = NULL, $context = NULL, $a1 = NULL, $a
* validation and submission functions. The hooks the action supports
* are declared in the 'hooks' array.
*
+ * @param $reset
+ * Reset the action info static cache.
+ *
* @return
* An associative array keyed on function name. The value of each key is
* an array containing information about the action, such as type of
* action and description of the action, e.g.,
*
- * $actions['actions_node_publish'] = ('description' => 'Publish a node' ... )
+ * @code
+ * $actions['node_publish_action'] = array(
+ * 'type' => 'node',
+ * 'description' => t('Publish post'),
+ * 'configurable' => FALSE,
+ * 'hooks' => array(
+ * 'nodeapi' => array('presave', 'insert', 'update', 'view'),
+ * 'comment' => array('delete', 'insert', 'update', 'view'),
+ * ),
+ * );
+ * @endcode
*/
-function actions_list() {
+function actions_list($reset = FALSE) {
static $actions;
- if (isset($actions)) {
- return $actions;
+ if (!isset($actions) || $reset) {
+ $actions = module_invoke_all('action_info');
+ drupal_alter('action_info', $actions);
}
- $actions = module_invoke_all('action_info');
- drupal_alter('action_info', $actions);
- return $actions;
+ // See module_implements for explanations of this cast.
+ return (array)$actions;
}
/**
* Retrieve all action instances from the database.
+ *
* Compare with actions_list() which gathers actions by
* invoking hook_action_info(). The two are synchronized
* by visiting /admin/build/actions (when actions.module is
@@ -176,6 +192,7 @@ function actions_get_all_actions() {
/**
* Create an associative array keyed by md5 hashes of function names.
+ *
* Hashes are used to prevent actual function names from going out into
* HTML forms and coming back.
*
@@ -204,6 +221,7 @@ function actions_actions_map($actions) {
/**
* Given an md5 hash of a function name, return the function name.
+ *
* Faster than actions_actions_map() when you only need the function name.
*
* @param $hash
@@ -224,3 +242,125 @@ function actions_function_lookup($hash) {
$aid = db_result(db_query("SELECT aid FROM {actions} WHERE MD5(aid) = '%s' AND parameters != ''", $hash));
return $aid;
}
+
+/**
+ * Synchronize actions that are provided by modules.
+ *
+ * They are synchronized with actions that are stored in the actions table.
+ * This is necessary so that actions that do not require configuration can
+ * receive action IDs. This is not necessarily the best approach,
+ * but it is the most straightforward.
+ */
+function actions_synchronize($actions_in_code = array(), $delete_orphans = FALSE) {
+ if (!$actions_in_code) {
+ $actions_in_code = actions_list();
+ }
+ $actions_in_db = array();
+ $result = db_query("SELECT * FROM {actions} WHERE parameters = ''");
+ while ($action = db_fetch_object($result)) {
+ $actions_in_db[$action->callback] = array('aid' => $action->aid, 'description' => $action->description);
+ }
+
+ // Go through all the actions provided by modules.
+ foreach ($actions_in_code as $callback => $array) {
+ // Ignore configurable actions since their instances get put in
+ // when the user adds the action.
+ if (!$array['configurable']) {
+ // If we already have an action ID for this action, no need to assign aid.
+ if (array_key_exists($callback, $actions_in_db)) {
+ unset($actions_in_db[$callback]);
+ }
+ else {
+ // This is a new singleton that we don't have an aid for; assign one.
+ db_query("INSERT INTO {actions} (aid, type, callback, parameters, description) VALUES ('%s', '%s', '%s', '%s', '%s')", $callback, $array['type'], $callback, '', $array['description']);
+ watchdog('actions', t("Action '%action' added.", array('%action' => filter_xss_admin($array['description']))));
+ }
+ }
+ }
+
+ // Any actions that we have left in $actions_in_db are orphaned.
+ if ($actions_in_db) {
+ $orphaned = array();
+ $placeholder = array();
+
+ foreach ($actions_in_db as $callback => $array) {
+ $orphaned[] = $callback;
+ $placeholder[] = "'%s'";
+ }
+
+ $orphans = implode(', ', $orphaned);
+
+ if ($delete_orphans) {
+ $placeholders = implode(', ', $placeholder);
+ $results = db_query("SELECT a.aid, a.description FROM {actions} a WHERE callback IN ($placeholders)", $orphaned);
+ while ($action = db_fetch_object($results)) {
+ actions_delete($action->aid);
+ watchdog('actions', t("Removed orphaned action '%action' from database.", array('%action' => filter_xss_admin($action->description))));
+ }
+ }
+ else {
+ $link = l(t('Remove orphaned actions'), 'admin/build/actions/orphan');
+ $count = count($actions_in_db);
+ watchdog('actions', format_plural($count, 'One orphaned action (%orphans) exists in the actions table. !link', '@count orphaned actions (%orphans) exist in the actions table. !link', array('@count' => $count, '%orphans' => $orphans, '!link' => $link), 'warning'));
+ }
+ }
+}
+
+/**
+ * Save an action and its associated user-supplied parameter values to the database.
+ *
+ * @param $function
+ * The name of the function to be called when this action is performed.
+ * @param $params
+ * An associative array with parameter names as keys and parameter values
+ * as values.
+ * @param $desc
+ * A user-supplied description of this particular action, e.g., 'Send
+ * e-mail to Jim'.
+ * @param $aid
+ * The ID of this action. If omitted, a new action is created.
+ *
+ * @return
+ * The ID of the action.
+ */
+function actions_save($function, $type, $params, $desc, $aid = NULL) {
+ $serialized = serialize($params);
+ if ($aid) {
+ db_query("UPDATE {actions} SET callback = '%s', type = '%s', parameters = '%s', description = '%s' WHERE aid = %d", $function, $type, $serialized, $desc, $aid);
+ watchdog('actions', 'Action %action saved.', array('%action' => $desc));
+ }
+ else {
+ // aid is the callback for singleton actions so we need to keep a
+ // separate table for numeric aids.
+ db_query('INSERT INTO {actions_aid} () VALUES ()');
+ $aid = db_last_insert_id('actions_aid', 'aid');
+ db_query("INSERT INTO {actions} (aid, callback, type, parameters, description) VALUES (%d, '%s', '%s', '%s', '%s')", $aid, $function, $type, $serialized, $desc);
+ watchdog('actions', 'Action %action created.', array('%action' => $desc));
+ }
+
+ return $aid;
+}
+
+/**
+ * Retrieve a single action from the database.
+ *
+ * @param $aid
+ * integer The ID of the action to retrieve.
+ *
+ * @return
+ * The appropriate action row from the database as an object.
+ */
+function actions_load($aid) {
+ return db_fetch_object(db_query("SELECT * FROM {actions} WHERE aid = %d", $aid));
+}
+
+/**
+ * Delete a single action from the database.
+ *
+ * @param $aid
+ * integer The ID of the action to delete.
+ */
+function actions_delete($aid) {
+ db_query("DELETE FROM {actions} WHERE aid = %d", $aid);
+ module_invoke_all('actions_delete', $aid);
+}
diff --git a/includes/install.inc b/includes/install.inc
index c7241eacb..6d273bac8 100644
--- a/includes/install.inc
+++ b/includes/install.inc
@@ -321,7 +321,6 @@ function drupal_install_profile($profile, $module_list) {
drupal_install_modules($module_list);
}
-
/**
* Calls the install function and updates the system table for a given list of
* modules.
diff --git a/install.php b/install.php
index 603db7db5..59ad4ba5c 100644
--- a/install.php
+++ b/install.php
@@ -731,6 +731,10 @@ function install_tasks($profile, $task) {
// Rebuild menu to get content type links registered by the profile,
// and possibly any other menu items created through the tasks.
menu_rebuild();
+
+ // Register actions declared by any modules.
+ actions_synchronize();
+
variable_set('install_profile', $profile);
}
diff --git a/modules/actions/actions.install b/modules/actions/actions.install
index 8047d60d3..fecb8757e 100644
--- a/modules/actions/actions.install
+++ b/modules/actions/actions.install
@@ -7,11 +7,8 @@
function actions_install() {
// Create tables.
drupal_install_schema('actions');
- variable_set('actions_next_id', 0);
// Do initial synchronization of actions in code and the database.
- // For that we need to run code from actions.module.
- drupal_load('module', 'actions');
actions_synchronize(actions_list());
}
@@ -21,5 +18,4 @@ function actions_install() {
function actions_uninstall() {
// Remove tables.
drupal_uninstall_schema('actions');
- variable_del('actions_next_id');
}
diff --git a/modules/actions/actions.module b/modules/actions/actions.module
index 331fe2267..d4b790426 100644
--- a/modules/actions/actions.module
+++ b/modules/actions/actions.module
@@ -2,24 +2,18 @@
// $Id$
/**
-* @file
-* Enables functions to be stored and executed at a later time when
-* triggered by other modules or by one of Drupal's core API hooks.
-*/
+ * @file
+ * Enables functions to be stored and executed at a later time when
+ * triggered by other modules or by one of Drupal's core API hooks.
+ */
/**
-* Implementation of hook_help().
-*/
-function actions_help($section) {
+ * Implementation of hook_help().
+ */
+function actions_help($path, $arg) {
$output = '';
$explanation = t('Actions are functions that Drupal can execute when certain events happen, such as when a post is added or a user logs in.');
- switch ($section) {
- case 'admin/build/actions/manage':
- $output = '<p>'. $explanation .' '. t('This page lists all actions that are available. Simple actions that do not require any configuration are listed automatically. Actions that need to be configured are listed in the dropdown below. To add an advanced action, select the action and click the <em>Configure</em> button. After completing the configuration form, the action will be available for use by Drupal.') .'</p>';
- break;
- case 'admin/build/actions/config':
- $output = '<p>'. t('This is where you configure a certain action that will be performed at some time in the future. For example, you might configure an action to send email to your friend Joe. You would modify the description field, below, to read %send to remind you of that. The description you provide will be used to identify this action; for example, when assigning an action to a Drupal event such as a new comment being posted.', array('%send' => t('Send email to Joe'))) .'</p>';
- break;
+ switch ($path) {
case 'admin/build/actions/assign/comment':
$output = '<p>'. $explanation .' '. t('Below you can assign actions to run when certain comment-related operations happen. For example, you could promote a post to the front page when a comment is added.') .'</p>';
break;
@@ -38,27 +32,14 @@ function actions_help($section) {
}
/**
-* Implementation of hook_menu().
-*/
+ * Implementation of hook_menu().
+ */
function actions_menu() {
- $items['admin/build/actions'] = array(
- 'title' => 'Actions',
- 'description' => 'Manage the actions defined for your site.',
- 'access arguments' => array('administer actions'),
- 'page callback' => 'actions_assign'
- );
- $items['admin/build/actions/manage'] = array(
- 'title' => 'Manage actions',
- 'description' => 'Manage the actions defined for your site.',
- 'page callback' => 'actions_manage',
- 'type' => MENU_LOCAL_TASK,
- 'weight' => 2,
- );
$items['admin/build/actions/assign'] = array(
'title' => 'Assign actions',
'description' => 'Tell Drupal when to execute actions.',
'page callback' => 'actions_assign',
- 'type' => MENU_DEFAULT_LOCAL_TASK,
+ 'type' => MENU_LOCAL_TASK,
);
$items['admin/build/actions/assign/node'] = array(
'title' => 'Content',
@@ -119,32 +100,8 @@ function actions_menu() {
'page arguments' => array('actions_unassign'),
'type' => MENU_CALLBACK,
);
- $items['admin/build/actions/config'] = array(
- 'title' => 'Configure an action',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('actions_configure'),
- 'type' => MENU_CALLBACK,
- );
- $items['admin/build/actions/delete'] = array(
- 'title' => 'Delete action',
- 'description' => 'Delete an action.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('actions_delete_form'),
- 'type' => MENU_CALLBACK,
- );
- $items['admin/build/actions/orphan'] = array(
- 'title' => 'Remove orphans',
- 'page callback' => 'actions_remove_orphans',
- 'type' => MENU_CALLBACK,
- );
- return $items;
-}
-/**
-* Implementation of hook_perm().
-*/
-function actions_perm() {
- return array('administer actions');
+ return $items;
}
/**
@@ -154,371 +111,7 @@ function actions_access_check($module) {
return (module_exists($module) && user_access('administer actions'));
}
-/**
- * Menu callback.
- * Display an overview of available and configured actions.
- */
-function actions_manage() {
- $output = '';
- $actions = actions_list();
- actions_synchronize($actions);
- $actions_map = actions_actions_map($actions);
- $options = array(t('Choose an advanced action'));
- $unconfigurable = array();
-
- foreach ($actions_map as $key => $array) {
- if ($array['configurable']) {
- $options[$key] = $array['description'] .'...';
- }
- else {
- $unconfigurable[] = $array;
- }
- }
-
- $row = array();
- $instances_present = db_fetch_object(db_query("SELECT aid FROM {actions} WHERE parameters != ''"));
- $header = array(
- array('data' => t('Action Type'), 'field' => 'type'),
- array('data' => t('Description'), 'field' => 'description'),
- array('data' => $instances_present ? t('Operations') : '', 'colspan' => '2')
- );
- $sql = 'SELECT * FROM {actions}';
- $result = pager_query($sql . tablesort_sql($header), 50);
- while ($action = db_fetch_object($result)) {
- $row[] = array(
- array('data' => $action->type),
- array('data' => $action->description),
- array('data' => $action->parameters ? l(t('configure'), "admin/build/actions/config/$action->aid") : ''),
- array('data' => $action->parameters ? l(t('delete'), "admin/build/actions/delete/$action->aid") : '')
- );
- }
- if ($row) {
- $pager = theme('pager', NULL, 50, 0);
- if (!empty($pager)) {
- $row[] = array(array('data' => $pager, 'colspan' => '3'));
- }
- $output .= '<h3>'. t('Actions available to Drupal:') .'</h3>';
- $output .= theme('table', $header, $row);
- }
-
- if ($actions_map) {
- $output .= '<p>'. drupal_get_form('actions_manage_form', $options) .'</p>';
- }
-
- return $output;
-}
-
-/**
- * Define the form for the actions overview page.
- *
- * @param $options
- * An array of configurable actions.
- * @return
- * Form definition.
- */
-function actions_manage_form($form_state, $options = array()) {
- $form['parent'] = array(
- '#type' => 'fieldset',
- '#title' => t('Make a new advanced action available'),
- '#prefix' => '<div class="container-inline">',
- '#suffix' => '</div>',
- );
- $form['parent']['action'] = array(
- '#type' => 'select',
- '#default_value' => '',
- '#options' => $options,
- '#description' => '',
- );
- $form['parent']['buttons']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Configure'),
- );
- return $form;
-}
-
-function actions_manage_form_submit($form, &$form_state) {
- if ($form_state['values']['action']) {
- $form_state['redirect'] = 'admin/build/actions/config/'. $form_state['values']['action'];
- }
-}
-
-/**
- * Menu callback. Create the form for configuration of a single action.
- * We provide the "Description" field. The rest of the form
- * is provided by the action. We then provide the Save button.
- * Because we are combining unknown form elements with the action
- * configuration form, we use actions_ prefix on our elements.
- *
- * @param $action
- * md5 hash of action ID or an integer. If it's an md5 hash, we
- * are creating a new instance. If it's an integer, we're editing
- * an existing instance.
- */
-function actions_configure($form_state, $action = NULL) {
- if ($action === NULL) {
- drupal_goto('admin/build/actions');
- }
-
- $actions_map = actions_actions_map(actions_list());
- $edit = array();
-
- // Numeric action denotes saved instance of a configurable action;
- // else we are creating a new action instance.
- if (is_numeric($action)) {
- $aid = $action;
- // Load stored parameter values from database.
- $data = db_fetch_object(db_query("SELECT * FROM {actions} WHERE aid = %d", intval($aid)));
- $edit['actions_description'] = $data->description;
- $edit['actions_type'] = $data->type;
- $function = $data->callback;
- $action = md5($data->callback);
- $params = unserialize($data->parameters);
- if ($params) {
- foreach ($params as $name => $val) {
- $edit[$name] = $val;
- }
- }
- }
- else {
- $function = $actions_map[$action]['callback'];
- $edit['actions_description'] = $actions_map[$action]['description'];
- $edit['actions_type'] = $actions_map[$action]['type'];
- }
-
-
- $form['actions_description'] = array(
- '#type' => 'textfield',
- '#title' => t('Description'),
- '#default_value' => $edit['actions_description'],
- '#size' => '70',
- '#maxlength' => '255',
- '#description' => t('A unique description for this configuration of this action. This will be used to describe this action when assigning actions.'),
- '#weight' => -10
- );
- $action_form = $function .'_form';
- $form = array_merge($form, $action_form($edit));
- $form['actions_type'] = array(
- '#type' => 'value',
- '#value' => $edit['actions_type'],
- );
- $form['actions_action'] = array(
- '#type' => 'hidden',
- '#value' => $action,
- );
- // $aid is set when configuring an existing action instance.
- if (isset($aid)) {
- $form['actions_aid'] = array(
- '#type' => 'hidden',
- '#value' => $aid,
- );
- }
- $form['actions_configured'] = array(
- '#type' => 'hidden',
- '#value' => '1',
- );
- $form['buttons']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Save'),
- '#weight' => 13
- );
-
- return $form;
-}
-
-function actions_configure_validate($form, $form_state) {
- $function = actions_function_lookup($form_state['values']['actions_action']) . '_validate';
- // Hand off validation to the action.
- if (function_exists($function)) {
- $function($form, $form_state);
- }
-}
-
-function actions_configure_submit($form, &$form_state) {
- $function = actions_function_lookup($form_state['values']['actions_action']);
- $submit_function = $function .'_submit';
-
- // Action will return keyed array of values to store.
- $params = $submit_function($form, $form_state);
- $aid = isset($form_state['values']['actions_aid']) ? $form_state['values']['actions_aid'] : NULL;
-
- actions_save($function, $form_state['values']['actions_type'], $params, $form_state['values']['actions_description'], $aid);
- drupal_set_message(t('The action has been successfully saved.'));
-
- $form_state['redirect'] = 'admin/build/actions/manage';
-}
-
-/**
- * Create the form for confirmation of deleting an action.
- *
- * @param $aid
- * The action ID.
- */
-function actions_delete_form($form_state, $aid) {
- if (!$aid) {
- drupal_goto('admin/build/actions');
- }
- $action = actions_load($aid);
-
- drupal_delete_initiate('action', $aid);
- drupal_delete_add_callback(array('actions_delete_form_post' => array($action)));
- actions_delete($aid);
-
- return drupal_delete_confirm(
- array(
- 'question' => t('Are you sure you want to delete the action %action?', array('%action' => $action->description)),
- 'destination' => 'admin/build/actions/manage',
- 'description' => t('This cannot be undone.'),
- )
- );
-}
-
-/**
- * Post-deletion operations for action deletion.
- */
-function actions_delete_form_post($action) {
- $t_args = array('%aid' => $action->aid, '%action' => $action->description);
- watchdog('user', 'Deleted action %aid (%action)', $t_args);
- drupal_set_message(t('Action %action was deleted.', $t_args));
-}
-
-/**
- * Save an action and its associated user-supplied parameter values to
- * the database.
- *
- * @param $function
- * The name of the function to be called when this action is performed.
- * @param $params
- * An associative array with parameter names as keys and parameter values
- * as values.
- * @param $desc
- * A user-supplied description of this particular action, e.g., 'Send
- * e-mail to Jim'.
- * @param $aid
- * The ID of this action. If omitted, a new action is created.
- *
- * @return
- * The ID of the action.
- */
-function actions_save($function, $type, $params, $desc, $aid = NULL) {
- $serialized = serialize($params);
- if ($aid) {
- db_query("UPDATE {actions} SET callback = '%s', type = '%s', parameters = '%s', description = '%s' WHERE aid = %d", $function, $type, $serialized, $desc, $aid);
- watchdog('user', 'Action %action saved.', array('%action' => $desc));
- }
- else {
- $aid = variable_get('actions_next_id', 0);
- $aid = $aid + 1;
- variable_set('actions_next_id', $aid);
- db_query("INSERT INTO {actions} (aid, callback, type, parameters, description) VALUES (%d, '%s', '%s', '%s', '%s')", $aid, $function, $type, $serialized, $desc);
- watchdog('user', 'Action %action created.', array('%action' => $desc));
- }
-
- return $aid;
-}
-
-/**
- * Retrieve a single action from the database.
- *
- * @param $aid
- * integer The ID of the action to retrieve.
- *
- * @return
- * The appropriate action row from the database as an object.
- */
-function actions_load($aid) {
- return db_fetch_object(db_query("SELECT * FROM {actions} WHERE aid = %d", $aid));
-}
-
-/**
- * Delete a single action from the database.
- *
- * @param $aid
- * integer The ID of the action to delete.
- */
-function actions_delete($aid) {
- drupal_delete_add_query("DELETE FROM {actions} WHERE aid = %d", $aid);
- drupal_delete_add_query("DELETE FROM {actions_assignments} WHERE aid = %d", $aid);
-}
-
-/**
- * Synchronize actions that are provided by modules with actions
- * that are stored in the actions table. This is necessary so that
- * actions that do not require configuration can receive action IDs.
- * This is not necessarily the best approach, but it is the most
- * straightforward.
- */
-function actions_synchronize($actions_in_code = array(), $delete_orphans = FALSE) {
- if (!$actions_in_code) {
- $actions_in_code = actions_list();
- }
- $actions_in_db = array();
- $result = db_query("SELECT * FROM {actions} WHERE parameters = ''");
- while ($action = db_fetch_object($result)) {
- $actions_in_db[$action->callback] = array('aid' => $action->aid, 'description' => $action->description);
- }
-
- // Go through all the actions provided by modules.
- foreach ($actions_in_code as $callback => $array) {
- // Ignore configurable actions since their instances get put in
- // when the user adds the action.
- if (!$array['configurable']) {
- // If we already have an action ID for this action, no need to assign aid.
- if (array_key_exists($callback, $actions_in_db)) {
- unset($actions_in_db[$callback]);
- }
- else {
- // This is a new singleton that we don't have an aid for; assign one.
- db_query("INSERT INTO {actions} (aid, type, callback, parameters, description) VALUES ('%s', '%s', '%s', '%s', '%s')", $callback, $array['type'], $callback, '', $array['description']);
- drupal_set_message(t("Action '%action' added.", array('%action' => filter_xss_admin($array['description']))));
- }
- }
- }
-
- // Any actions that we have left in $actions_in_db are orphaned.
- if ($actions_in_db) {
- $orphaned = array();
- $placeholder = array();
-
- foreach ($actions_in_db as $callback => $array) {
- $orphaned[] = $callback;
- $placeholder[] = "'%s'";
- }
-
- $orphans = implode(', ', $orphaned);
-
- if ($delete_orphans) {
- $placeholders = implode(', ', $placeholder);
- drupal_delete_initiate('action_delete_orphans', $orphans);
- drupal_delete_add_callback(array('action_delete_orphans_post' => array($orphaned)));
- drupal_delete_add_query("DELETE FROM {actions} WHERE callback IN ($placeholders)", $orphaned);
- drupal_delete_execute();
- }
- else {
- $link = l(t('Remove orphaned actions'), 'admin/build/actions/orphan');
- $count = count($actions_in_db);
- drupal_set_message(format_plural($count, 'One orphaned action (%orphans) exists in the actions table. !link', '@count orphaned actions (%orphans) exist in the actions table. !link', array('@count' => $count, '%orphans' => $orphans, '!link' => $link), 'warning'));
- }
- }
-}
-
-/**
- * Post-deletion operations for deleting action orphans.
- */
-function action_delete_orphans_post($orphaned) {
- foreach ($orphaned as $callback) {
- drupal_set_message(t("Deleted orphaned action (%action).", array('%action' => $callback)));
- }
-}
-
-/**
- * Menu callback. Remove any actions that are in the database but not supported
- * by any currently enabled module.
- */
-function actions_remove_orphans() {
- actions_synchronize(actions_list(), TRUE);
- drupal_goto('admin/build/actions/manage');
-}
/**
* Get the actions that have already been defined for this
@@ -620,7 +213,7 @@ function actions_assign_form($form_state, $hook, $op, $description) {
foreach ($actions as $aid => $description) {
$form[$op]['assigned']['#value'][$aid] = array(
'description' => $description,
- 'link' => l(t('remove'), "admin/build/actions/assign/remove/$hook/$op/" . md5($aid))
+ 'link' => l(t('remove'), "admin/build/actions/assign/remove/$hook/$op/". md5($aid))
);
}
@@ -650,7 +243,7 @@ function actions_assign_form($form_state, $hook, $op, $description) {
function actions_assign_form_submit($form, $form_state) {
$form_values = $form_state['values'];
- if (isset($form_values['aid']) && $form_values['aid'] != '0') {
+ if (!empty($form_values['aid'])) {
$aid = actions_function_lookup($form_values['aid']);
$weight = db_result(db_query("SELECT MAX(weight) FROM {actions_assignments} WHERE hook = '%s' AND op = '%s'", $form_values['hook'], $form_values['operation']));
db_query("INSERT INTO {actions_assignments} values ('%s', '%s', '%s', %d)", $form_values['hook'], $form_values['operation'], $aid, $weight + 1);
@@ -755,28 +348,46 @@ function actions_unassign($form_state, $hook = NULL, $op = NULL, $aid = NULL) {
drupal_goto('admin/build/actions/assign');
}
+ $form['hook'] = array(
+ '#type' => 'value',
+ '#value' => $hook,
+ );
+ $form['operation'] = array(
+ '#type' => 'value',
+ '#value' => $op,
+ );
+ $form['aid'] = array(
+ '#type' => 'value',
+ '#value' => $aid,
+ );
+
$action = actions_function_lookup($aid);
$actions = actions_get_all_actions();
- drupal_delete_initiate('action_assignment', $hook .'_'. $op .'_'. $action);
- drupal_delete_add_callback(array('actions_assign_remove_post' => array($action, $actions)));
- drupal_delete_add_query("DELETE FROM {actions_assignments} WHERE hook = '%s' AND op = '%s' AND aid = '%s'", $hook, $op, $action);
-
$destination = 'admin/build/actions/assign/'. ($hook == 'nodeapi' ? 'node' : $hook);
- return drupal_delete_confirm(
- array(
- 'question' => t('Are you sure you want to remove the action %title?', array('%title' => $actions[$action]['description'])),
- 'destination' => $destination,
- 'description' => t('You can assign it again later if you wish.'),
- 'yes' => t('Remove'),
- )
+ return confirm_form($form,
+ t('Are you sure you want to remove the action %title?', array('%title' => $actions[$action]['description'])),
+ $destination,
+ t('You can assign it again later if you wish.'),
+ t('Remove'), t('Cancel')
);
}
-function actions_unassign_post($action, $actions) {
- watchdog('actions', 'Action %action has been unassigned.', array('%action' => check_plain($actions[$action]['description'])));
- drupal_set_message(t('Action %action has been unassigned.', array('%action' => $actions[$action]['description'])));
+function actions_unassign_submit($form, &$form_state) {
+ $form_values = $form_state['values'];
+ if ($form_values['confirm'] == 1) {
+ $aid = actions_function_lookup($form_values['aid']);
+ db_query("DELETE FROM {actions_assignments} WHERE hook = '%s' AND op = '%s' AND aid = '%s'", $form_values['hook'], $form_values['operation'], $aid);
+ $actions = actions_get_all_actions();
+ watchdog('actions', 'Action %action has been unassigned.', array('%action' => check_plain($actions[$aid]['description'])));
+ drupal_set_message(t('Action %action has been unassigned.', array('%action' => $actions[$aid]['description'])));
+ $hook = $form_values['hook'] == 'nodeapi' ? 'node' : $form_values['hook'];
+ $form_state['redirect'] = 'admin/build/actions/assign/'. $hook;
+ }
+ else {
+ drupal_goto('admin/build/actions');
+ }
}
/**
diff --git a/modules/actions/actions.schema b/modules/actions/actions.schema
index 516e2ced3..748f0c78c 100644
--- a/modules/actions/actions.schema
+++ b/modules/actions/actions.schema
@@ -2,16 +2,6 @@
// $Id$
function actions_schema() {
- $schema['actions'] = array(
- 'fields' => array(
- 'aid' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '0'),
- 'type' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
- 'callback' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
- 'parameters' => array('type' => 'text', 'not null' => TRUE, 'size' => 'big'),
- 'description' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '0'),
- ),
- 'primary key' => array('aid'),
- );
$schema['actions_assignments'] = array(
'fields' => array(
'hook' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
diff --git a/modules/system/system.admin.inc b/modules/system/system.admin.inc
index 57dec37e6..fb71b4762 100644
--- a/modules/system/system.admin.inc
+++ b/modules/system/system.admin.inc
@@ -817,6 +817,9 @@ function system_modules_submit($form, &$form_state) {
// path after that.
module_invoke('locale', 'system_update', $new_modules);
+ // Synchronize to catch any actions that were added or removed.
+ actions_synchronize();
+
return;
}
diff --git a/modules/system/system.install b/modules/system/system.install
index 79f732b85..46e2a6fd6 100644
--- a/modules/system/system.install
+++ b/modules/system/system.install
@@ -3561,6 +3561,35 @@ function system_update_6029() {
}
/**
+ * Add the tables required by actions.inc.
+ */
+function system_update_6030() {
+ $ret = array();
+ $schema['actions'] = array(
+ 'fields' => array(
+ 'aid' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '0'),
+ 'type' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
+ 'callback' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+ 'parameters' => array('type' => 'text', 'not null' => TRUE, 'size' => 'big'),
+ 'description' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '0'),
+ ),
+ 'primary key' => array('aid'),
+ );
+
+ $schema['actions_aid'] = array(
+ 'fields' => array(
+ 'aid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
+ ),
+ 'primary key' => array('aid'),
+ );
+
+ db_create_table($ret, 'actions', $schema['actions']);
+ db_create_table($ret, 'actions_aid', $schema['actions_aid']);
+
+ return $ret;
+}
+
+/**
* @} End of "defgroup updates-5.x-to-6.x"
* The next series of updates should start at 7000.
*/
diff --git a/modules/system/system.module b/modules/system/system.module
index 12130332c..87d82ebfb 100644
--- a/modules/system/system.module
+++ b/modules/system/system.module
@@ -52,6 +52,14 @@ function system_help($path, $arg) {
return $output;
case 'admin/build/modules/uninstall':
return '<p>'. t('The uninstall process removes all data related to a module. To uninstall a module, you must first disable it. Not all modules support this feature.') .'</p>';
+ case 'admin/build/actions':
+ case 'admin/build/actions/manage':
+ $explanation = t('Actions are functions that Drupal can execute when certain events happen, such as when a post is added or a user logs in.');
+ $output = '<p>'. $explanation .' '. t('A module, such as the actions module, may assign these actions to the specific events that will trigger them.') .'</p>';
+ $output .= '<p>'. t('This page lists all actions that are available. Simple actions that do not require any configuration are listed automatically. Advanced actions that need to be configured are listed in the dropdown below. To add an advanced action, select the action and click the <em>Configure</em> button. After completing the configuration form, the action will be available for use by Drupal.') .'</p>';
+ return $output;
+ case 'admin/build/actions/config':
+ return '<p>'. t('This is where you configure a certain action that will be performed at some time in the future. For example, you might configure an action to send email to your friend Joe. You would modify the description field, below, to read %send to remind you of that. The description you provide will be used to identify this action; for example, when assigning an action to a Drupal event such as a new comment being posted.', array('%send' => t('Send email to Joe'))) .'</p>';
case 'admin/logs/status':
return '<p>'. t("Here you can find a short overview of your Drupal site's parameters as well as any problems detected with your installation. It is useful to copy/paste this information when you need support.") .'</p>';
}
@@ -101,7 +109,7 @@ function system_theme() {
* Implementation of hook_perm().
*/
function system_perm() {
- return array('administer site configuration', 'access administration pages', 'select different theme', 'administer files');
+ return array('administer site configuration', 'access administration pages', 'administer actions', 'select different theme', 'administer files');
}
/**
@@ -264,6 +272,39 @@ function system_menu() {
'type' => MENU_CALLBACK,
);
+ // Actions:
+ $items['admin/build/actions'] = array(
+ 'title' => 'Actions',
+ 'description' => 'Manage the actions defined for your site.',
+ 'access arguments' => array('administer actions'),
+ 'page callback' => 'system_actions_manage'
+ );
+ $items['admin/build/actions/manage'] = array(
+ 'title' => 'Manage actions',
+ 'description' => 'Manage the actions defined for your site.',
+ 'page callback' => 'system_actions_manage',
+ 'type' => MENU_DEFAULT_LOCAL_TASK,
+ 'weight' => -2,
+ );
+ $items['admin/build/actions/config'] = array(
+ 'title' => 'Configure an action',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('system_actions_configure'),
+ 'type' => MENU_CALLBACK,
+ );
+ $items['admin/build/actions/delete/%actions'] = array(
+ 'title' => 'Delete action',
+ 'description' => 'Delete an action.',
+ 'page callback' => 'drupal_get_form',
+ 'page arguments' => array('system_actions_delete_form', 4),
+ 'type' => MENU_CALLBACK,
+ );
+ $items['admin/build/actions/orphan'] = array(
+ 'title' => 'Remove orphans',
+ 'page callback' => 'system_actions_remove_orphans',
+ 'type' => MENU_CALLBACK,
+ );
+
// Settings:
$items['admin/settings/site-information'] = array(
'title' => 'Site information',
@@ -1078,6 +1119,252 @@ function system_action_info() {
}
/**
+ * Menu callback. Display an overview of available and configured actions.
+ */
+function system_actions_manage() {
+ $output = '';
+ $actions = actions_list();
+ actions_synchronize($actions);
+ $actions_map = actions_actions_map($actions);
+ $options = array(t('Choose an advanced action'));
+ $unconfigurable = array();
+
+ foreach ($actions_map as $key => $array) {
+ if ($array['configurable']) {
+ $options[$key] = $array['description'] .'...';
+ }
+ else {
+ $unconfigurable[] = $array;
+ }
+ }
+
+ $row = array();
+ $instances_present = db_fetch_object(db_query("SELECT aid FROM {actions} WHERE parameters != ''"));
+ $header = array(
+ array('data' => t('Action Type'), 'field' => 'type'),
+ array('data' => t('Description'), 'field' => 'description'),
+ array('data' => $instances_present ? t('Operations') : '', 'colspan' => '2')
+ );
+ $sql = 'SELECT * FROM {actions}';
+ $result = pager_query($sql . tablesort_sql($header), 50);
+ while ($action = db_fetch_object($result)) {
+ $row[] = array(
+ array('data' => $action->type),
+ array('data' => $action->description),
+ array('data' => $action->parameters ? l(t('configure'), "admin/build/actions/config/$action->aid") : ''),
+ array('data' => $action->parameters ? l(t('delete'), "admin/build/actions/delete/$action->aid") : '')
+ );
+ }
+
+ if ($row) {
+ $pager = theme('pager', NULL, 50, 0);
+ if (!empty($pager)) {
+ $row[] = array(array('data' => $pager, 'colspan' => '3'));
+ }
+ $output .= '<h3>'. t('Actions available to Drupal:') .'</h3>';
+ $output .= theme('table', $header, $row);
+ }
+
+ if ($actions_map) {
+ $output .= '<p>'. drupal_get_form('system_actions_manage_form', $options) .'</p>';
+ }
+
+ return $output;
+}
+
+/**
+ * Define the form for the actions overview page.
+ *
+ * @param $options
+ * An array of configurable actions.
+ * @return
+ * Form definition.
+ */
+function system_actions_manage_form($form_state, $options = array()) {
+ $form['parent'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Make a new advanced action available'),
+ '#prefix' => '<div class="container-inline">',
+ '#suffix' => '</div>',
+ );
+ $form['parent']['action'] = array(
+ '#type' => 'select',
+ '#default_value' => '',
+ '#options' => $options,
+ '#description' => '',
+ );
+ $form['parent']['buttons']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Configure'),
+ );
+ return $form;
+}
+
+function system_actions_manage_form_submit($form, &$form_state) {
+ if ($form_state['values']['action']) {
+ $form_state['redirect'] = 'admin/build/actions/config/'. $form_state['values']['action'];
+ }
+}
+
+/**
+ * Menu callback. Create the form for configuration of a single action.
+ *
+ * We provide the "Description" field. The rest of the form
+ * is provided by the action. We then provide the Save button.
+ * Because we are combining unknown form elements with the action
+ * configuration form, we use actions_ prefix on our elements.
+ *
+ * @param $action
+ * md5 hash of action ID or an integer. If it's an md5 hash, we
+ * are creating a new instance. If it's an integer, we're editing
+ * an existing instance.
+ * @return
+ * Form definition.
+ */
+function system_actions_configure($form_state, $action = NULL) {
+ if ($action === NULL) {
+ drupal_goto('admin/build/actions');
+ }
+
+ $actions_map = actions_actions_map(actions_list());
+ $edit = array();
+
+ // Numeric action denotes saved instance of a configurable action;
+ // else we are creating a new action instance.
+ if (is_numeric($action)) {
+ $aid = $action;
+ // Load stored parameter values from database.
+ $data = db_fetch_object(db_query("SELECT * FROM {actions} WHERE aid = %d", intval($aid)));
+ $edit['actions_description'] = $data->description;
+ $edit['actions_type'] = $data->type;
+ $function = $data->callback;
+ $action = md5($data->callback);
+ $params = unserialize($data->parameters);
+ if ($params) {
+ foreach ($params as $name => $val) {
+ $edit[$name] = $val;
+ }
+ }
+ }
+ else {
+ $function = $actions_map[$action]['callback'];
+ $edit['actions_description'] = $actions_map[$action]['description'];
+ $edit['actions_type'] = $actions_map[$action]['type'];
+ }
+
+
+ $form['actions_description'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Description'),
+ '#default_value' => $edit['actions_description'],
+ '#size' => '70',
+ '#maxlength' => '255',
+ '#description' => t('A unique description for this configuration of this action. This will be used to describe this action when assigning actions.'),
+ '#weight' => -10
+ );
+ $action_form = $function .'_form';
+ $form = array_merge($form, $action_form($edit));
+ $form['actions_type'] = array(
+ '#type' => 'value',
+ '#value' => $edit['actions_type'],
+ );
+ $form['actions_action'] = array(
+ '#type' => 'hidden',
+ '#value' => $action,
+ );
+ // $aid is set when configuring an existing action instance.
+ if (isset($aid)) {
+ $form['actions_aid'] = array(
+ '#type' => 'hidden',
+ '#value' => $aid,
+ );
+ }
+ $form['actions_configured'] = array(
+ '#type' => 'hidden',
+ '#value' => '1',
+ );
+ $form['buttons']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Save'),
+ '#weight' => 13
+ );
+
+ return $form;
+}
+
+function system_actions_configure_validate($form, $form_state) {
+ $function = actions_function_lookup($form_state['values']['actions_action']) .'_validate';
+ // Hand off validation to the action.
+ if (function_exists($function)) {
+ $function($form, $form_state);
+ }
+}
+
+function system_actions_configure_submit($form, &$form_state) {
+ $function = actions_function_lookup($form_state['values']['actions_action']);
+ $submit_function = $function .'_submit';
+
+ // Action will return keyed array of values to store.
+ $params = $submit_function($form, $form_state);
+ $aid = isset($form_state['values']['actions_aid']) ? $form_state['values']['actions_aid'] : NULL;
+
+ actions_save($function, $form_state['values']['actions_type'], $params, $form_state['values']['actions_description'], $aid);
+ drupal_set_message(t('The action has been successfully saved.'));
+
+ $form_state['redirect'] = 'admin/build/actions/manage';
+}
+
+/**
+ * Create the form for confirmation of deleting an action.
+ *
+ * @param $aid
+ * The action ID.
+ */
+function system_actions_delete_form($form_state, $action) {
+
+ $form['aid'] = array(
+ '#type' => 'hidden',
+ '#value' => $action->aid,
+ );
+ return confirm_form($form,
+ t('Are you sure you want to delete the action %action?', array('%action' => $action->description)),
+ 'admin/build/actions/manage',
+ t('This cannot be undone.'),
+ t('Delete'), t('Cancel')
+ );
+}
+
+/**
+ * Post-deletion operations for action deletion.
+ */
+function system_actions_delete_form_submit($form, &$form_state) {
+ $aid = $form_state['values']['aid'];
+ $action = actions_load($aid);
+ actions_delete($aid);
+ $description = check_plain($action->description);
+ watchdog('user', 'Deleted action %aid (%action)', array('%aid' => $aid, '%action' => $description));
+ drupal_set_message(t('Action %action was deleted', array('%action' => $description)));
+ $form_state['redirect'] = 'admin/build/actions/manage';
+}
+/**
+ * Post-deletion operations for deleting action orphans.
+ */
+function system_action_delete_orphans_post($orphaned) {
+ foreach ($orphaned as $callback) {
+ drupal_set_message(t("Deleted orphaned action (%action).", array('%action' => $callback)));
+ }
+}
+
+/**
+ * Remove actions that are in the database but not supported by any enabled module.
+ *
+ */
+function system_actions_remove_orphans() {
+ actions_synchronize(actions_list(), TRUE);
+ drupal_goto('admin/build/actions/manage');
+}
+
+/**
* Return a form definition so the Send email action can be configured.
*
* @param $context
@@ -1146,8 +1433,7 @@ function system_send_email_action_submit($form, $form_state) {
}
/**
- * Implementation of a configurable Drupal action.
- * Sends an email.
+ * Implementation of a configurable Drupal action. Sends an email.
*/
function system_send_email_action($object, $context) {
global $user;
@@ -1253,8 +1539,7 @@ function system_message_action_submit($form, $form_state) {
}
/**
- * Implementation of a configurable Drupal action.
- * Sends a configurable message to the current user's screen.
+ * A configurable Drupal action. Sends a message to the current user's screen.
*/
function system_message_action(&$object, $context = array()) {
global $user;
@@ -1311,8 +1596,7 @@ function system_message_action(&$object, $context = array()) {
}
/**
- * Implementation of a configurable Drupal action.
- * Redirect user to a URL.
+ * Implementation of a configurable Drupal action. Redirect user to a URL.
*/
function system_goto_action_form($context) {
$form['url'] = array(
diff --git a/modules/system/system.schema b/modules/system/system.schema
index 9e05060f1..e3e9a7e0a 100644
--- a/modules/system/system.schema
+++ b/modules/system/system.schema
@@ -2,6 +2,24 @@
// $Id$
function system_schema() {
+ $schema['actions'] = array(
+ 'fields' => array(
+ 'aid' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '0'),
+ 'type' => array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => ''),
+ 'callback' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
+ 'parameters' => array('type' => 'text', 'not null' => TRUE, 'size' => 'big'),
+ 'description' => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => '0'),
+ ),
+ 'primary key' => array('aid'),
+ );
+
+ $schema['actions_aid'] = array(
+ 'fields' => array(
+ 'aid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
+ ),
+ 'primary key' => array('aid'),
+ );
+
$schema['batch'] = array(
'fields' => array(
'bid' => array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
diff --git a/modules/user/user.module b/modules/user/user.module
index 3c57fea1e..12bc84784 100644
--- a/modules/user/user.module
+++ b/modules/user/user.module
@@ -3433,7 +3433,7 @@ function user_action_info() {
'comment' => array('view', 'insert', 'update', 'delete'),
'user' => array('logout'),
)
- )
+ ),
);
}