You are here

function drush_fullcalendar_plugin in FullCalendar 6

Same name and namespace in other branches
  1. 6.2 includes/fullcalendar.drush.inc \drush_fullcalendar_plugin()
  2. 7.2 includes/fullcalendar.drush.inc \drush_fullcalendar_plugin()
  3. 7 fullcalendar.drush.inc \drush_fullcalendar_plugin()

Commands to download the FullCalendar plugin.

File

./fullcalendar.drush.inc, line 44
Drush integration for FullCalendar.

Code

function drush_fullcalendar_plugin($path = 'sites/all/libraries') {
  if (!drush_shell_exec('type unzip')) {
    return drush_set_error(dt('Missing dependency: unzip. Install it before using this command.'));
  }

  // 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);
  $filename = basename(FULLCALENDAR_DOWNLOAD_URI);
  $dirname = basename(FULLCALENDAR_DOWNLOAD_URI, '.zip');

  // Remove any existing FullCalendar plugin directory
  if (is_dir($dirname)) {
    drush_log(dt('A existing FullCalendar plugin was overwritten at @path', array(
      '@path' => $path,
    )), 'notice');
  }

  // Remove any existing FullCalendar plugin zip archive
  if (is_file($filename)) {
    drush_op('unlink', $filename);
  }

  // Download the zip archive
  if (!drush_shell_exec('wget ' . FULLCALENDAR_DOWNLOAD_URI)) {
    drush_shell_exec('curl -O ' . FULLCALENDAR_DOWNLOAD_URI);
  }
  if (is_file($filename)) {

    // Decompress the zip archive
    drush_shell_exec('unzip -qq -o ' . $filename);

    // Remove the zip archive
    drush_op('unlink', $filename);
    if (is_dir('fullcalendar')) {
      drush_shell_exec('rm -rf fullcalendar');
    }
    drush_shell_exec('mv ' . $dirname . '/fullcalendar fullcalendar');
    drush_shell_exec('rm -rf ' . $dirname);
  }

  // Set working directory back to the previous working directory.
  chdir($olddir);
  if (is_dir($path . '/fullcalendar')) {
    drush_log(dt('FullCalendar plugin has been downloaded to @path', array(
      '@path' => $path,
    )), 'success');
  }
  else {
    drush_log(dt('Drush was unable to download the FullCalendar plugin to @path', array(
      '@path' => $path,
    )), 'error');
  }
}