Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #145 from niels-nijens/composer-binary-install
Browse files Browse the repository at this point in the history
Change installation of Composer binary to upload and self-update
  • Loading branch information
niels-nijens committed May 4, 2016
2 parents e9f7fab + 6be6cff commit d94a02a
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 81 deletions.
13 changes: 13 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
preset: symfony

linting: true

enabled:
- ordered_use

disabled:
- unneeded_control_parentheses

finder:
not-name:
- "*.phar"
Binary file added src/Resources/Composer/composer.phar
Binary file not shown.
46 changes: 21 additions & 25 deletions src/Task/ComposerInstallTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,37 +67,33 @@ public function onPrepareWorkspaceInstallComposer(WorkspaceEvent $event, $eventN
$connection = $this->ensureConnection($host);

$workspace = $event->getWorkspace();
if ($workspace instanceof Workspace) {
if ($connection->isFile($host->getPath().'/composer.phar') === false) {
$eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Installing the Composer binary.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_IN_PROGRESS)));

$connection->changeWorkingDirectory($host->getPath());
$result = $connection->executeCommand('php -r "readfile(\'https://getcomposer.org/installer\');" | php');
if ($result->isSuccessful() && $connection->isFile($host->getPath().'/composer.phar')) {
$eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Installed the Composer binary.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_COMPLETED, 'output.resetLine' => true)));
} else {
throw new TaskCommandExecutionException('Failed installing the Composer binary.', $result, $this);
}

$eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::DEBUG, "{separator} Command output:{separator}\n{command.result}{separator}", $eventName, $this, array('command.result' => $result->getOutput(), 'separator' => "\n=================\n")));
} else {
$eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Updating the Composer binary.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_IN_PROGRESS)));
if ($workspace instanceof Workspace === false) {
throw new TaskRuntimeException('The workspace of the host has not been created.', $this);
}

$connection->changeWorkingDirectory($host->getPath());
$result = $connection->executeCommand('php composer.phar self-update');
if ($result->isSuccessful()) {
$eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Updated the Composer binary.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_COMPLETED, 'output.resetLine' => true)));
} else {
$eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::WARNING, 'Failed updating the Composer binary.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_FAILED)));
}
if ($connection->isFile($host->getPath().'/composer.phar') === false) {
$eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Installing the Composer binary...', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_IN_PROGRESS)));

$eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::DEBUG, "{separator} Command output:{separator}\n{command.result}{separator}", $eventName, $this, array('command.result' => $result->getOutput(), 'separator' => "\n=================\n")));
$connection->changeWorkingDirectory($host->getPath());
$connection->putFile(__DIR__.'/../Resources/Composer/composer.phar', $host->getPath().'/composer.phar');
if ($connection->isFile($host->getPath().'/composer.phar')) {
$eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Installed the Composer binary.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_COMPLETED, 'output.resetLine' => true)));
} else {
throw new TaskRuntimeException('Failed installing the Composer binary.', $this);
}
}

return;
$eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Updating the Composer binary.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_IN_PROGRESS)));

$connection->changeWorkingDirectory($host->getPath());
$result = $connection->executeCommand('php composer.phar self-update');
if ($result->isSuccessful()) {
$eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Updated the Composer binary.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_COMPLETED, 'output.resetLine' => true)));
} else {
$eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::WARNING, 'Failed updating the Composer binary.', $eventName, $this, array('event.task.action' => TaskInterface::ACTION_FAILED)));
}

throw new TaskRuntimeException('The workspace of the host has not been created.', $this);
$eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::DEBUG, "{separator} Command output:{separator}\n{command.result}{separator}", $eventName, $this, array('command.result' => $result->getOutput(), 'separator' => "\n=================\n")));
}

/**
Expand Down
Loading

0 comments on commit d94a02a

Please sign in to comment.