-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AL-885, AL-911 - Added backup:info command, expiry to backup:list #1676
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Pantheon\Terminus\Commands\Backup; | ||
|
||
use Consolidation\OutputFormatters\StructuredData\PropertyList; | ||
|
||
/** | ||
* Class InfoCommand | ||
* @package Pantheon\Terminus\Commands\Backup | ||
*/ | ||
class InfoCommand extends SingleBackupCommand | ||
{ | ||
/** | ||
* Displays information about a specific backup or the latest backup. | ||
* | ||
* @authorize | ||
* | ||
* @command backup:info | ||
* | ||
* @field-labels | ||
* file: Filename | ||
* size: Size | ||
* date: Date | ||
* expiry: Expiry | ||
* initiator: Initiator | ||
* url: URL | ||
* @return PropertyList | ||
* | ||
* @param string $site_env Site & environment in the format `site-name.env` | ||
* @option string $file [filename.tgz] Name of backup file | ||
* @option string $element [all|code|files|database|db] Backup element to retrieve | ||
* | ||
* @usage <site>.<env> Displays information about the most recent backup of any type in <site>'s <env> environment. | ||
* @usage <site>.<env> --file=<file_name> Displays information about the backup with the file name <file_name> in <site>'s <env> environment. | ||
* @usage <site>.<env> --element=<element> Displays information about the most recent <element> backup in <site>'s <env> environment. | ||
*/ | ||
public function info($site_env, array $options = ['file' => null, 'element' => 'all',]) | ||
{ | ||
$backup = $this->getBackup($site_env, $options); | ||
return new PropertyList(array_merge($backup->serialize(), ['url' => $backup->getUrl(),])); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Pantheon\Terminus\Commands\Backup; | ||
|
||
use Pantheon\Terminus\Exceptions\TerminusNotFoundException; | ||
|
||
abstract class SingleBackupCommand extends BackupCommand | ||
{ | ||
|
||
/** | ||
* @param $site_env | ||
* @param array $options | ||
* @return Backup | ||
* @throws TerminusNotFoundException | ||
*/ | ||
protected function getBackup($site_env, array $options = ['file' => null, 'element' => 'all',]) | ||
{ | ||
list($site, $env) = $this->getSiteEnv($site_env); | ||
|
||
if (isset($options['file']) && !is_null($file_name = $options['file'])) { | ||
$backup = $env->getBackups()->getBackupByFileName($file_name); | ||
} else { | ||
$element = isset($options['element']) ? $this->getElement($options['element']) : null; | ||
$backups = $env->getBackups()->getFinishedBackups($element); | ||
if (empty($backups)) { | ||
throw new TerminusNotFoundException( | ||
'No backups available. Create one with `terminus backup:create {site}.{env}`', | ||
['site' => $site->get('name'), 'env' => $env->id,] | ||
); | ||
} | ||
$backup = array_shift($backups); | ||
} | ||
return $backup; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
Feature: Get a particular backup for a site | ||
In order to secure my site against failures | ||
As a user | ||
I need to be able to get information about a backup that has been made | ||
|
||
Background: I am authenticated and have a site named [[test_site_name]] | ||
Given I am authenticated | ||
And a site named "[[test_site_name]]" | ||
|
||
@vcr backup-get-file.yml | ||
Scenario: Gets information about the latest code backup made | ||
When I run "terminus backup:info [[test_site_name]].dev --element=code" | ||
Then I should get: "----------- -----------------------------------------------------" | ||
And I should get: "Filename [[test_site_name]]_dev_2016-08-18T23-16-20_UTC_code.tar.gz" | ||
And I should get: "Size 31.8MB" | ||
And I should get: "Date 2016-08-18 23:16:30" | ||
And I should get: "Expiry 2017-08-19 05:02:06" | ||
And I should get: "Initiator manual" | ||
And I should get: "----------- -----------------------------------------------------" | ||
|
||
@vcr backup-get-file.yml | ||
Scenario: Gets informtion about a backup selected by filename | ||
When I run "terminus backup:info [[test_site_name]].dev --file=[[test_site_name]]_dev_2016-08-18T23-16-20_UTC_code.tar.gz" | ||
Then I should get: "----------- -----------------------------------------------------" | ||
And I should get: "Filename [[test_site_name]]_dev_2016-08-18T23-16-20_UTC_code.tar.gz" | ||
And I should get: "Size 31.8MB" | ||
And I should get: "Date 2016-08-18 23:16:30" | ||
And I should get: "Expiry 2017-08-19 05:02:06" | ||
And I should get: "Initiator manual" | ||
And I should get: "----------- -----------------------------------------------------" | ||
|
||
@vcr backup-get-none.yml | ||
Scenario: Failing to find a matching backup | ||
When I run "terminus backup:info [[test_site_name]].test --element=database" | ||
Then I should get: | ||
""" | ||
No backups available. Create one with `terminus backup:create [[test_site_name]].test` | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
namespace Pantheon\Terminus\UnitTests\Commands\Backup; | ||
|
||
use Consolidation\OutputFormatters\StructuredData\PropertyList; | ||
use Pantheon\Terminus\Commands\Backup\InfoCommand; | ||
|
||
/** | ||
* Class InfoCommandTest | ||
* Testing class for Pantheon\Terminus\Commands\Backup\InfoCommand | ||
* @package Pantheon\Terminus\UnitTests\Commands\Backup | ||
*/ | ||
class InfoCommandTest extends BackupCommandTest | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $expected_data; | ||
|
||
/** | ||
* Sets up the fixture, for example, open a network connection. | ||
* This method is called before a test is executed. | ||
*/ | ||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$sample_data = [ | ||
'file' => 'file name', | ||
'size' => 'file size', | ||
'date' => 459880805, | ||
'expiry' => 3615640805, | ||
'initiator' => 'backup initiator', | ||
]; | ||
$url = 'https://url.to/backup.tgz'; | ||
$this->expected_data = array_merge($sample_data, compact('url')); | ||
|
||
$this->backup->method('serialize')->willReturn($sample_data); | ||
$this->backup->method('getUrl')->willReturn($url); | ||
|
||
$this->command = new InfoCommand($this->sites); | ||
$this->command->setLogger($this->logger); | ||
$this->command->setSites($this->sites); | ||
} | ||
|
||
/** | ||
* Tests the backup:info command with file | ||
*/ | ||
public function testInfoBackupWithFile() | ||
{ | ||
$test_filename = 'test.tar.gz'; | ||
|
||
$this->backups->expects($this->once()) | ||
->method('getBackupByFileName') | ||
->with($test_filename) | ||
->willReturn($this->backup); | ||
|
||
$output = $this->command->info('mysite.dev', ['file' => $test_filename,]); | ||
$this->assertInstanceOf(PropertyList::class, $output); | ||
$this->assertEquals($this->expected_data, $output->getArrayCopy()); | ||
} | ||
|
||
/** | ||
* Tests the backup:info command with an element | ||
*/ | ||
public function testInfoBackupWithElement() | ||
{ | ||
$this->backups->expects($this->once()) | ||
->method('getFinishedBackups') | ||
->with('database') | ||
->willReturn([$this->backup,]); | ||
|
||
$output = $this->command->info('mysite.dev', ['element' => 'db',]); | ||
$this->assertInstanceOf(PropertyList::class, $output); | ||
$this->assertEquals($this->expected_data, $output->getArrayCopy()); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I personally like this, I believe US english prefers 'expiration'. But I'm 1/10 on this because expiry is shorter and way classier because it is true uncorrupted queens english :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like it too, so let's ask @kimby77 to weigh in. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no opinion :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whatever you guys think is best here!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✋