You are here

function workbench_moderation_update_7004 in Workbench Moderation 7

Same name and namespace in other branches
  1. 7.3 workbench_moderation.install \workbench_moderation_update_7004()

Use "Published" instead of "Publish" and "Needs Review" instead of "Review" for state names.

File

./workbench_moderation.install, line 321
Install file for the Workbench Moderation module.

Code

function workbench_moderation_update_7004() {

  // Update workbench_moderation_states
  db_update('workbench_moderation_states')
    ->fields(array(
    'description' => 'Draft content is visible only to its author',
  ))
    ->condition('Name', 'Draft', '=')
    ->execute();
  db_update('workbench_moderation_states')
    ->fields(array(
    'Name' => 'Needs Review',
    'description' => 'Needs Review content is brought to the attention administrators and editors who may then publish it',
  ))
    ->condition('Name', 'Review', '=')
    ->execute();
  db_update('workbench_moderation_states')
    ->fields(array(
    'Name' => 'Published',
    // Normally we would use workbench_moderation_state_published(), but we can't guarantee that workbench_moderation is enabled.
    'description' => 'Published content is visible to the world',
  ))
    ->condition('Name', 'Publish', '=')
    ->execute();

  // Update workbench_moderation_transitions
  db_update('workbench_moderation_transitions')
    ->fields(array(
    'from_name' => 'Needs Review',
  ))
    ->condition('from_name', 'Review', '=')
    ->execute();
  db_update('workbench_moderation_transitions')
    ->fields(array(
    'to_name' => 'Needs Review',
  ))
    ->condition('to_name', 'Review', '=')
    ->execute();
  db_update('workbench_moderation_transitions')
    ->fields(array(
    'from_name' => 'Published',
  ))
    ->condition('from_name', 'Publish', '=')
    ->execute();
  db_update('workbench_moderation_transitions')
    ->fields(array(
    'to_name' => 'Published',
  ))
    ->condition('to_name', 'Publish', '=')
    ->execute();

  // Update workbench_moderation_node_history
  db_update('workbench_moderation_node_history')
    ->fields(array(
    'from_state' => 'Needs Review',
  ))
    ->condition('from_state', 'Review', '=')
    ->execute();
  db_update('workbench_moderation_node_history')
    ->fields(array(
    'state' => 'Needs Review',
  ))
    ->condition('state', 'Review', '=')
    ->execute();
  db_update('workbench_moderation_node_history')
    ->fields(array(
    'from_state' => 'Published',
  ))
    ->condition('from_state', 'Publish', '=')
    ->execute();
  db_update('workbench_moderation_node_history')
    ->fields(array(
    'state' => 'Published',
  ))
    ->condition('state', 'Publish', '=')
    ->execute();

  // Update role_permission table
  // Grab all of the workbench_moderation permissions
  $perms = db_select('role_permission', 'rp')
    ->fields('rp', array(
    'permission',
  ))
    ->condition('permission', '%moderate content from %', 'LIKE')
    ->execute()
    ->fetchCol();

  // This function doesn't need duplicates
  $perms = array_unique($perms);
  foreach ($perms as $key => $perm) {
    $new_perm = $perm;

    // Check that this permission hasn't had this change already
    if (!strpos($perm, 'Published')) {
      $new_perm = str_replace('Publish', 'Published', $perm);
    }

    // Check that this permission hasn't had this change already
    if (!strpos($new_perm, 'Needs Review')) {
      $new_perm = str_replace('Review', 'Needs Review', $new_perm);
    }

    //Update the records
    db_update('role_permission')
      ->fields(array(
      'permission' => $new_perm,
    ))
      ->condition('permission', $perm, '=')
      ->execute();
  }
  return t("Updated state names and transitions.");
}