function drush_composer_manager in Composer Manager 6
Same name and namespace in other branches
- 6.2 composer_manager.drush.inc \drush_composer_manager()
- 7.2 composer_manager.drush.inc \drush_composer_manager()
- 7 composer_manager.drush.inc \drush_composer_manager()
Executes a Composer command on Composer Manager's composer.json file.
Parameters
$command: Which command to execute on Composer Manager's composer.json file.
1 call to drush_composer_manager()
- drush_composer_manager_write_if_changed in ./
composer_manager.drush.inc - If one or more extensions being acted on contain a composer.json file, prompt the user to automatically run Composer's update command.
File
- ./
composer_manager.drush.inc, line 41 - Drush hook implementations for the Composer Manager module.
Code
function drush_composer_manager($command = 'install') {
$uri = variable_get('composer_manager_file_dir', file_directory_path() . '/composer');
if (!($dir = realpath($uri))) {
return drush_set_error(dt('Error resolving path: @uri', array(
'@uri' => $uri,
)));
}
// Check to see if the composer.json file is available.
if (!file_exists($dir . '/composer.json')) {
// Ask the user would like to install Drush Composer.
if (drush_confirm(dt('The composer.json file is missing. Would you like to re-build it?'))) {
if (drush_invoke('composer-rebuild-file') === FALSE) {
return FALSE;
}
}
else {
return drush_set_error(dt('Missing composer.json file: Run `drush composer-rebuild-file`.'));
}
}
// Check if Drush Composer is available.
if (!drush_is_command('composer')) {
// Ask the user would like to install Drush Composer.
if (!drush_confirm(dt('Download and install the Drush Composer extension?'))) {
drush_print(dt('Installation of the Drush Composer extension was aborted.'));
return TRUE;
}
// Download the Drush extension.
if (drush_invoke('dl', array(
'composer-8.x-1.x',
)) === FALSE) {
return drush_set_error(dt('Failed installing the Drush Composer extension. Install it manually by following the instructions on the project page: http://drupal.org/project/composer'));
}
// Clear the caches by reloading the available command files.
_drush_find_commandfiles(DRUSH_BOOTSTRAP_DRUSH);
}
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$dir = str_replace('\\', '/', $dir);
}
// Generate the command arguments to pass to Drush Composer.
$drush_arguments = drush_get_arguments();
if ($drush_arguments && $drush_arguments[0] === 'composer-manager') {
$arguments = $drush_arguments;
array_shift($arguments);
// exclude drush main command, composer-manager
$arguments[] = '--working-dir=' . escapeshellcmd($dir);
}
else {
$arguments = array(
$command,
// The use of escapeshellcmd rather than escapeshellarg is necessary to
// avoid enclosing the value in quotes, which is incompatible with the way
// Composer validates that the working directory exists.
'--working-dir=' . escapeshellcmd($dir),
);
}
$composer_result = drush_invoke('composer', $arguments);
// Allow modules to perform post-composer install tasks.
if ($command == 'install' || $command == 'update') {
module_invoke_all('composer_dependencies_install');
}
return $composer_result;
}