You are here

function fontawesome_drush_lib_download in Font Awesome Icons 7

Same name and namespace in other branches
  1. 7.3 drush/fontawesome.drush.inc \fontawesome_drush_lib_download()
  2. 7.2 drush/fontawesome.drush.inc \fontawesome_drush_lib_download()

Example drush command callback.

This is where the action takes place.

In this function, all of Drupals API is (usually) available, including any functions you have added in your own modules/themes.

To print something to the terminal window, use drush_print().

1 call to fontawesome_drush_lib_download()
drush_fontawesome_post_pm_enable in drush/fontawesome.drush.inc
Implements drush_MODULE_post_COMMAND().
1 string reference to 'fontawesome_drush_lib_download'
fontawesome_drush_command in drush/fontawesome.drush.inc
Implementation of hook_drush_command().

File

drush/fontawesome.drush.inc, line 68
drush integration for fontawesome.

Code

function fontawesome_drush_lib_download() {
  $args = func_get_args();
  if ($args[0]) {
    $path = $args[0];
  }
  else {

    //we have dependencies on libraries module so no need to check for that

    //TODO: any way to get path for libraries directory?

    //Just in case if it is site specific? e.g. sites/domain.com/libraries ?
    $path = drush_get_context('DRUSH_DRUPAL_ROOT') . '/sites/all/libraries/fontawesome';
  }

  // Create the path if it does not exist yet. Added substr check for preventing
  // any wrong attempts or hacks !
  if (substr($path, -11) == 'fontawesome' && !is_dir($path)) {
    drush_mkdir($path);
  }
  if (is_dir($path . '/css')) {
    drush_log(dt('Fontawesome already present at @path. No download required.', array(
      '@path' => $path,
    )), 'ok');
  }
  elseif (drush_op('chdir', $path) && drush_shell_exec('wget ' . FONTAWESOME_DOWNLOAD_URL . '  -O fontawesome.zip') && drush_shell_exec('unzip fontawesome.zip') && drush_shell_exec('mv font-awesome/* .') && drush_shell_exec('rm -rf fontawesome.zip') && drush_shell_exec('rm -rf font-awesome')) {
    drush_log(dt('The latest Fontawesome library has been downloaded to @path', array(
      '@path' => $path,
    )), 'success');
  }
  else {
    drush_log(dt('Drush was unable to download the Fontawesome library to @path', array(
      '@path' => $path,
    )), 'error');
  }
}