You are here

function drush_kaltura_client_install in Kaltura 7.3

Same name and namespace in other branches
  1. 7.2 kaltura.drush.inc \drush_kaltura_client_install()

Command to download and install the Kaltura client library.

1 string reference to 'drush_kaltura_client_install'
kaltura_drush_command in ./kaltura.drush.inc
Implements hook_drush_command().

File

./kaltura.drush.inc, line 43
Drush integration for kaltura.

Code

function drush_kaltura_client_install() {
  $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 archive.
  if ($filepath = drush_download_file(KALTURA_DOWNLOAD_URI)) {
    $filename = basename($filepath);
    $dirname = KALTURA_DOWNLOAD_PREFIX . basename($filepath, '.tar.gz');

    // Remove any existing Kaltura client directory.
    if (is_dir($dirname) || is_dir('KalturaClient')) {
      drush_delete_dir($dirname, TRUE);
      drush_delete_dir('KalturaClient', TRUE);
      drush_log(dt('An existing Kaltura client library was deleted from @path', array(
        '@path' => $path,
      )), 'notice');
    }

    // Decompress the archive.
    drush_tarball_extract($filename, $dirname);

    // Change the directory to "KalturaClient" if needed.
    drush_move_dir($dirname . '/php5', 'KalturaClient', TRUE);
    drush_delete_dir($dirname, TRUE);
    $dirname = 'KalturaClient';
  }
  if (isset($dirname) && is_dir($dirname)) {
    drush_log(dt('Kaltura client library has been installed in @path', array(
      '@path' => $path,
    )), 'success');
  }
  else {
    drush_log(dt('Drush was unable to install the Kaltura client library to @path', array(
      '@path' => $path,
    )), 'error');
  }

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