actions_synchronize($actions_in_code = array(), $delete_orphans = FALSE)
drupal/includes/actions.inc, line 249
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(TRUE);
}
$actions_in_db = db_query("SELECT aid, callback, description FROM {actions} WHERE parameters = ''")->fetchAllAssoc('callback', PDO::FETCH_ASSOC);
// 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_insert('actions')
->fields(array(
'aid' => $callback,
'type' => $array['type'],
'callback' => $callback,
'parameters' => '',
'description' => $array['description'],
))
->execute();
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_keys($actions_in_db);
if ($delete_orphans) {
$results = db_select('actions')
->addField('actions', 'aid')
->addField('actions', 'description')
->condition('callback', $orphaned, 'IN')
->execute();
foreach ($results as $action) {
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);
$orphans = implode(', ', $orphaned);
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);
}
}
}