piecemaker.drush.inc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * @file
  4. * Drush integration for the piecemaker module.
  5. */
  6. /**
  7. * Implements hook_drush_command().
  8. */
  9. function piecemaker_drush_command() {
  10. $items['piecemaker-download'] = array(
  11. 'description' => dt('Downloads the Piecemaker library from https://github.com/arcaneadam/Piecemaker-Drupal.'),
  12. 'aliases' => array('pmkdl'),
  13. );
  14. return $items;
  15. }
  16. /**
  17. * Implementation of hook_drush_help().
  18. */
  19. function piecemaker_drush_help($section) {
  20. switch ($section) {
  21. case 'drush:piecemaker-download':
  22. return dt('Downloads the Piecemaker library from https://github.com/arcaneadam/Piecemaker-Drupal. Places it in the libraries directory. Skips download if library already present. This all happens automatically if you enable piecemaker using drush.');
  23. }
  24. }
  25. /**
  26. * A command callback. Download the Piecemaker library using git.
  27. */
  28. function drush_piecemaker_download() {
  29. $path = drush_get_context('DRUSH_DRUPAL_ROOT');
  30. $path .= '/'. libraries_get_path('piecemaker');
  31. // If we have the libraries module go ahead and make the path.
  32. if (!is_dir($path)) {
  33. drush_mkdir($path);
  34. }
  35. $version = '7.x-1.x';
  36. $url = "https://github.com/arcaneadam/Piecemaker-Drupal/zipball/{$version}";
  37. $filepath = $path . '/piecemaker.zip';
  38. if (file_exists($path . '/piecemaker.swf')) {
  39. drush_log('Piecemaker already present. No download required.', 'ok');
  40. return;
  41. }
  42. //Download the file
  43. if (!drush_shell_exec('curl -L -o %s ' . $url, $filepath)) {
  44. return drush_set_error('PIECEMAKER_FETCH', dt('Drush was unable to download the Piecemaker library to @path.', array('@path' => $filepath)));
  45. }
  46. // Unzip it the file -- using the "update" option to avoid being prompted
  47. // about overwriting files.
  48. if (!drush_shell_exec("unzip -u {$filepath} -d {$path}")) {
  49. return drush_set_error('PIECEMAKER_UNTAR', dt('Drush was unable to untar the archive @path.', array('@path' => $filepath)));
  50. }
  51. if (!drush_shell_exec("mv {$path}/arcaneadam-Piecemaker-Drupal*/* {$path}")) {
  52. return drush_set_error('PIECEMAKER_MV', dt('Drush was unable to move the files to the appropriate directory'));
  53. }
  54. drush_shell_exec("rm -fR {$path}/arcaneadam-Piecemaker-Drupal*");
  55. drush_log(dt('Piecemaker library has been installed to @path.', array('@path' => $path)), 'success');
  56. }
  57. /**
  58. * Implements drush_MODULE_post_COMMAND().
  59. */
  60. function drush_piecemaker_post_pm_enable() {
  61. $modules = func_get_args();
  62. if (in_array('piecemaker', $modules)) {
  63. drush_piecemaker_download();
  64. }
  65. }