Skip to content

Instantly share code, notes, and snippets.

@kalabro
Created November 12, 2012 12:15
Show Gist options
  • Save kalabro/4059050 to your computer and use it in GitHub Desktop.
Save kalabro/4059050 to your computer and use it in GitHub Desktop.
Drupal 7: download missing modules with Drush
#!/usr/bin/env drush
<?php
/**
* Download modules which are not found on disk but exist in system table.
* Tested on Drupal 7.
*/
$result = db_query('SELECT * FROM system ORDER BY name');
foreach ($result as $record) {
if (!file_exists($record->filename)) {
$path = drupal_get_filename($record->type, $record->name);
if (empty($path)) {
// Project not found in Drupal installation.
// Trying to download.
if (drush_invoke_process('@self', 'dl', array($record->name))) {
$downloaded_projects[] = $record->name;
}
}
}
}
registry_rebuild();
if (!empty($downloaded_projects)) {
drush_log(dt('Downloaded @projects', array('@projects' => implode(', ', $downloaded_projects))), 'ok');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment