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 #81 from niels-nijens/improve-create-workspace-task
Browse files Browse the repository at this point in the history
Improvements to CreateWorkspaceTask
  • Loading branch information
niels-nijens committed Dec 15, 2015
2 parents ca24e31 + b6dfd4a commit dba7088
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/Task/CreateWorkspaceTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public static function getSubscribedEvents()
array('onPrepareWorkspaceConstructWorkspaceInstance', 10),
array('onPrepareWorkspaceCreateWorkspace', 0),
),
AccompliEvents::GET_WORKSPACE => array(
array('onPrepareWorkspaceConstructWorkspaceInstance', 10),
),
);
}

Expand Down Expand Up @@ -127,13 +130,13 @@ public function onPrepareWorkspaceCreateWorkspace(WorkspaceEvent $event, $eventN
foreach ($directories as $directory) {
$context = array('directory' => $directory, 'event.task.action' => TaskInterface::ACTION_IN_PROGRESS);

$eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Creating directory "{directory}".', $eventName, $this, $context));
$eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::DEBUG, 'Creating directory "{directory}".', $eventName, $this, $context));
if ($connection->isDirectory($directory) === false) {
if ($connection->createDirectory($directory)) {
$context['event.task.action'] = TaskInterface::ACTION_COMPLETED;
$context['output.resetLine'] = true;

$eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Created directory "{directory}".', $eventName, $this, $context));
$eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::DEBUG, 'Created directory "{directory}".', $eventName, $this, $context));
} else {
$context['event.task.action'] = TaskInterface::ACTION_FAILED;
$context['output.resetLine'] = true;
Expand All @@ -144,7 +147,7 @@ public function onPrepareWorkspaceCreateWorkspace(WorkspaceEvent $event, $eventN
$context['event.task.action'] = TaskInterface::ACTION_COMPLETED;
$context['output.resetLine'] = true;

$eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::INFO, 'Directory "{directory}" exists.', $eventName, $this, $context));
$eventDispatcher->dispatch(AccompliEvents::LOG, new LogEvent(LogLevel::DEBUG, 'Directory "{directory}" exists.', $eventName, $this, $context));
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Task/CreateWorkspaceTaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
class CreateWorkspaceTaskTest extends PHPUnit_Framework_TestCase
{
/**
* Tests if CreateWorkspaceTask::getSubscribedEvents returns an array with at least a AccompliEvents::PREPARE_WORKSPACE key.
* Tests if CreateWorkspaceTask::getSubscribedEvents returns an array with at least a AccompliEvents::PREPARE_WORKSPACE and AccompliEvents::GET_WORKSPACE key.
*/
public function testGetSubscribedEvents()
{
$this->assertInternalType('array', CreateWorkspaceTask::getSubscribedEvents());
$this->assertArrayHasKey(AccompliEvents::PREPARE_WORKSPACE, CreateWorkspaceTask::getSubscribedEvents());
$this->assertArrayHasKey(AccompliEvents::GET_WORKSPACE, CreateWorkspaceTask::getSubscribedEvents());
}

/**
Expand Down

0 comments on commit dba7088

Please sign in to comment.