actions_synchronize

Versions
6
actions_synchronize($actions_in_code = array(), $delete_orphans = FALSE)
7
actions_synchronize($delete_orphans = FALSE)

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.

▾ 6 functions call actions_synchronize()

admin_menu_toggle_modules in contrib-6/admin_menu/admin_menu.inc
Menu callback; Enable/disable developer modules.
og_actions_disable in contrib-6/og/modules/og_actions/og_actions.install
system_actions_manage in drupal-6/modules/system/system.module
Menu callback. Display an overview of available and configured actions.
system_actions_remove_orphans in drupal-6/modules/system/system.module
Remove actions that are in the database but not supported by any enabled module.
system_modules_submit in drupal-6/modules/system/system.admin.inc
Submit callback; handles modules form submission.
trigger_install in drupal-6/modules/trigger/trigger.install
Implementation of hook_install().

Code

drupal-6/includes/actions.inc, line 308

<?php
function actions_synchronize($actions_in_code = array(), $delete_orphans = FALSE) {
  if (!$actions_in_code) {
    $actions_in_code = actions_list(TRUE);
  }
  $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', "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', "Removed orphaned action '%action' from database.", array('%action' => filter_xss_admin($action->description)));
      }
    }
    else {
      $link = l(t('Remove orphaned actions'), 'admin/settings/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), WATCHDOG_WARNING);
    }
  }
}
?>

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options