function drush_pm_update_lock

8.0.x pm.drush.inc drush_pm_update_lock(&$projects, $projects_to_lock, $projects_to_unlock, $lock_message = NULL)
6.x pm.drush.inc drush_pm_update_lock(&$projects, $projects_to_lock, $projects_to_unlock, $lock_message = NULL)
7.x pm.drush.inc drush_pm_update_lock(&$projects, $projects_to_lock, $projects_to_unlock, $lock_message = NULL)
4.x pm.drush.inc drush_pm_update_lock(&$projects, $projects_to_lock, $projects_to_unlock, $lock_message = NULL)
5.x pm.drush.inc drush_pm_update_lock(&$projects, $projects_to_lock, $projects_to_unlock, $lock_message = NULL)
master pm.drush.inc drush_pm_update_lock(&$projects, $projects_to_lock, $projects_to_unlock, $lock_message = NULL)

Update the locked status of all of the candidate projects to be updated.

Parameters

array &$projects: The projects array from pm_updatecode. $project['locked'] will be set for every file where a persistent lockfile can be found. The 'lock' and 'unlock' operations are processed first.

array $projects_to_lock: A list of projects to create peristent lock files for

array $projects_to_unlock: A list of projects to clear the persistent lock on

string $lock_message: The reason the project is being locked; stored in the lockfile.

Return value

array A list of projects that are locked.

1 call to drush_pm_update_lock()
drush_pm_updatestatus in commands/pm/updatestatus.pm.inc
Command callback. Displays update status info of installed projects.

File

commands/pm/pm.drush.inc, line 1947
The drush Project Manager

Code

function drush_pm_update_lock(&$projects, $projects_to_lock, $projects_to_unlock, $lock_message = NULL) {
  $locked_result = array();

  // Warn about ambiguous lock / unlock values
  if ($projects_to_lock == array('1')) {
    $projects_to_lock = array();
    drush_log(dt('Ignoring --lock with no value.'), LogLevel::WARNING);
  }
  if ($projects_to_unlock == array('1')) {
    $projects_to_unlock = array();
    drush_log(dt('Ignoring --unlock with no value.'), LogLevel::WARNING);
  }

  // Log if we are going to lock or unlock anything
  if (!empty($projects_to_unlock)) {
    drush_log(dt('Unlocking !projects', array('!projects' => implode(',', $projects_to_unlock))), LogLevel::OK);
  }
  if (!empty($projects_to_lock)) {
    drush_log(dt('Locking !projects', array('!projects' => implode(',', $projects_to_lock))), LogLevel::OK);
  }

  $drupal_root = drush_get_context('DRUSH_DRUPAL_ROOT');
  foreach ($projects as $name => $project) {
    $message = NULL;
    if (isset($project['path'])) {
      if ($name == 'drupal') {
        $lockfile = $drupal_root . '/.drush-lock-update';
      }
      else {
        $lockfile = $drupal_root . '/' . $project['path'] . '/.drush-lock-update';
      }

      // Remove the lock file if the --unlock option was specified
      if (((in_array($name, $projects_to_unlock)) || (in_array('all', $projects_to_unlock))) && (file_exists($lockfile))) {
        drush_op('unlink', $lockfile);
      }

      // Create the lock file if the --lock option was specified
      if ((in_array($name, $projects_to_lock)) || (in_array('all', $projects_to_lock))) {
        drush_op('file_put_contents', $lockfile, $lock_message != NULL ? $lock_message : "Locked via drush.");
        // Note that the project is locked.  This will work even if we are simulated,
        // or if we get permission denied from the file_put_contents.
        // If the lock is -not- simulated or transient, then the lock message will be
        // read from the lock file below.
        $message = drush_get_context('DRUSH_SIMULATE') ? 'Simulated lock.' : 'Transient lock.';
      }

      // If the persistent lock file exists, then mark the project as locked.
      if (file_exists($lockfile)) {
        $message = trim(file_get_contents($lockfile));
      }
    }

    // If there is a message set, then mark the project as locked.
    if (isset($message)) {
      $projects[$name]['locked'] = !empty($message) ? $message : "Locked.";
      $locked_result[$name] = $project;
    }
  }

  return $locked_result;
}