You are here

function drush_hook_update_deploy_tools_site_deploy_n_set in Hook Update Deploy Tools 7

Same name and namespace in other branches
  1. 8 hook_update_deploy_tools.drush.inc \drush_hook_update_deploy_tools_site_deploy_n_set()

Set the update_N for a module.

Parameters

string $module_name: Machine name for the module to set.

int $set_to: (optional) the number of the _update_N to set. If left blank it will set it to the current value -1.

File

./hook_update_deploy_tools.drush.inc, line 385
Drush commands for Hook Deploy Update Tools.

Code

function drush_hook_update_deploy_tools_site_deploy_n_set($module_name, $set_to = FALSE) {
  $hook_n = drush_hook_update_deploy_tools_site_deploy_n_lookup($module_name);
  $vars = array(
    '!hook_n' => $hook_n,
    '@module' => $module_name,
  );
  if (!empty($hook_n)) {
    $lowest_version = floor(VERSION) * 1000;
    $highest_version = $lowest_version + 999;
    $set_to = !empty($set_to) ? $set_to : $hook_n - 1;
    $vars['!set_to'] = $set_to;

    // All other testing was done by site-deploy_n_lookup and _validate so go.
    if ($set_to >= $lowest_version && $set_to <= $highest_version) {
      $num_updated = db_update('system')
        ->expression('schema_version', $set_to)
        ->condition('name', $module_name)
        ->execute();
      $vars['!num_updated'] = $num_updated;
      if ($num_updated === 1) {
        $message = dt("@module: Last run hook_update_N was set from !hook_n to !set_to", $vars);
        drush_log($message, 'success');
      }
      else {
        $message = dt("@module: db_update returned !num_updated  set from !hook_n to !set_to. Should only have been 1.", $vars);
        drush_log($message, 'error');
      }
    }
    else {

      // Can not be set to a value that goes outside the current drupal version.
      $message = dt("@module: was at !hook_n and could not be set to !set_to because it would change versions.", $vars);
      drush_log($message, 'error');
    }
  }
  else {

    // There is no module to set the update_N on..
    $message = dt("There is nothing to set because @module has no recorded value..", $vars);
    drush_log($message, 'error');
  }
}