You are here

function _ftools_drush_exec_unlink_file in Features Tools 7.2

Executes a given unlink file

1 call to _ftools_drush_exec_unlink_file()
drush_ftools_exec_unlink in ./ftools.drush.inc
Execute a unlink file Optionally accept a list of unlink files to execute, separated by whitespaces.

File

./ftools.drush.inc, line 105

Code

function _ftools_drush_exec_unlink_file($args) {
  module_load_include('module', 'ftools', 'ftools');

  // Determine if -y was supplied. If so, we can filter out needless output
  // from this command.
  $skip_confirmation = drush_get_context('DRUSH_AFFIRMATIVE');

  // Parse list of arguments.
  $files = array();
  foreach ($args as $arg) {
    $files[] = $arg;
  }

  // Process files.
  $available_files = _ftools_get_unlink_files();
  foreach ($files as $delta => $file) {

    //does this file exist?
    $basename = false;
    foreach ($available_files as $available_file) {
      if ($available_file->filename == $file || $available_file->name == $file) {
        $file_url = $available_file->uri;
        $basename = basename($file_url, '.inc');
        break;
      }
    }
    $dt_args['@file'] = $file;
    if (!$basename) {
      drush_log(dt('File @file does not exists. Skipped execution.', $dt_args), 'error');
      continue;
    }
    $confirmation_message = 'Do you really want to execute the unlink file for @file?';
    if ($skip_confirmation || drush_confirm(dt($confirmation_message, $dt_args))) {

      //if the file ends with .inc we remove this
      $base_name = basename($file, '.inc');

      //Execute the unlink
      _ftools_exec_unlink($base_name);
      drush_log(dt('Executed unlink file for @file.', $dt_args), 'ok');
    }
    else {
      drush_log(dt('Skipping @file.', $dt_args), 'ok');
    }
  }
}