You are here

form_styler.drush.inc in jQuery form styler 7.2

Same filename and directory in other branches
  1. 7 drush/form_styler.drush.inc

Drush integration for form_styler.

File

drush/form_styler.drush.inc
View source
<?php

/**
 * @file
 * Drush integration for form_styler.
 */

/**
 * The form_styler plugin URI.
 */
define('FORM_STYLER_DOWNLOAD_URI', 'https://github.com/Dimox/jQueryFormStyler/archive/master.zip');
define('FORM_STYLER_DOWNLOAD_PREFIX', 'form_styler-');

/**
 * Implements hook_drush_command().
 *
 * In this hook, you specify which commands your
 * drush module makes available, what it does and
 * description.
 *
 * Notice how this structure closely resembles how
 * you define menu hooks.
 *
 * See `drush topic docs-commands` for a list of recognized keys.
 */
function form_styler_drush_command() {
  $items = array();

  // The key in the $items array is the name of the command.
  $items['form-styler-plugin'] = array(
    'callback' => 'form_styler_plugin',
    'description' => dt('Download and install the Form styler plugin.'),
    'bootstrap' => DRUSH_BOOTSTRAP_DRUSH,
    'arguments' => array(
      'path' => dt('Optional. A path where to install the form styler plugin. If omitted Drush will use the default location.'),
    ),
    'aliases' => array(
      'fsplugin',
    ),
  );
  return $items;
}

/**
 * Implements hook_drush_help().
 *
 * This function is called whenever a drush user calls
 * 'drush help <name-of-your-command>'
 */
function form_styler_drush_help($section) {
  switch ($section) {
    case 'drush:form-styler-plugin':
      return dt('Download and install the Form styler plugin from Dimox/jQueryFormStyler, default location is sites/all/libraries.');
  }
}

/**
 * Implements drush_MODULE_pre_pm_enable().
 */
function drush_form_styler_pre_pm_enable() {
  $modules = drush_get_context('PM_ENABLE_MODULES');
  if (in_array('form_styler', $modules) && !drush_get_option('skip')) {
    form_styler_plugin();
  }
}

/**
 * Command to download the jQuery form styler plugin.
 */
function form_styler_plugin() {
  $args = func_get_args();
  if (!empty($args[0])) {
    $path = $args[0];
  }
  else {
    $path = 'sites/all/libraries';
  }

  // Create the path if it does not exist.
  if (!is_dir($path)) {
    drush_op('mkdir', $path);
    drush_log(dt('Directory @path was created', array(
      '@path' => $path,
    )), 'notice');
  }

  // Set the directory to the download location.
  $olddir = getcwd();
  chdir($path);

  // Download the zip archive.
  if ($filepath = drush_download_file(FORM_STYLER_DOWNLOAD_URI)) {
    $filename = basename($filepath);
    $dirname = FORM_STYLER_DOWNLOAD_PREFIX . basename($filepath, '.zip');
    $dirname = 'jQueryFormStyler-master';

    // Remove any existing jQuery form styler plugin directory.
    if (is_dir($dirname) || is_dir('jquery_form_styler')) {
      drush_delete_dir($dirname, TRUE);
      drush_delete_dir('jquery_form_styler', TRUE);
      drush_log(dt('A existing Form styler plugin was deleted from @path', array(
        '@path' => $path,
      )), 'notice');
    }

    // Decompress the zip archive.
    drush_tarball_extract($filename);

    // Change the directory name to "jquery_form_styler" if needed.
    if ($dirname != 'jquery_form_styler') {
      drush_move_dir($dirname, 'jquery_form_styler', TRUE);
      $dirname = 'jquery_form_styler';
    }
  }
  if (is_dir($dirname)) {
    drush_log(dt('Jquery form styler plugin has been installed in @path', array(
      '@path' => $path,
    )), 'success');
  }
  else {
    drush_log(dt('Drush was unable to install the Jquery form styler plugin to @path', array(
      '@path' => $path,
    )), 'error');
  }

  // Set working directory back to the previous working directory.
  chdir($olddir);
}

Functions

Namesort descending Description
drush_form_styler_pre_pm_enable Implements drush_MODULE_pre_pm_enable().
form_styler_drush_command Implements hook_drush_command().
form_styler_drush_help Implements hook_drush_help().
form_styler_plugin Command to download the jQuery form styler plugin.

Constants

Namesort descending Description
FORM_STYLER_DOWNLOAD_PREFIX
FORM_STYLER_DOWNLOAD_URI The form_styler plugin URI.