You are here

function drush_patterns_run in Patterns 7

Same name and namespace in other branches
  1. 6.2 patterns.drush.inc \drush_patterns_run()
  2. 7.2 patterns.drush.inc \drush_patterns_run()

Imports, enables, and runs the specified pattern file

Parameters

string pattern file pathname:

string optional machine readable pattern name:

1 string reference to 'drush_patterns_run'
patterns_drush_command in ./patterns.drush.inc
Implements hook_drush_command().

File

./patterns.drush.inc, line 373
Drush Patterns module commands

Code

function drush_patterns_run($name, $format = PATTERNS_FORMAT_UNKNOWN, $mode = 'php', $params = array()) {
  drush_print(dt('Running pattern: ' . $name));
  $pattern = patterns_get_pattern($name);
  if (!$pattern) {
    if (!drush_file_not_empty($name)) {
      return drush_set_error(dt('Pattern was not found in the database nor in the file system.'));
    }
    if (!drush_confirm(dt("Pattern '{$name}' has not been imported. Do you want to import it now? "))) {
      return drush_print(dt('patterns-run has been canceled.'));
    }
    $format = patterns_drush_get_file_format($file, $format);
    if (!$format) {
      return drush_set_error('Invalid pattern format. Aborting');
    }
    $result = patterns_io_import_file($name, $format);
    if (!$result) {
      return drush_set_error(dt('Importing pattern failed'));
    }
    $name = patterns_io_get_name_from_file($name);

    // Check if the file has a valid extension
    // and in case add the format at the end
    if (!_patterns_io_file_has_valid_extension($name)) {
      $name = $name . '.' . $format;
    }
    $pattern = patterns_get_pattern($name);
  }
  return drush_patterns_run_pattern($pattern, $mode, $params);
}