forked from pantheon-systems/terminus
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switching from service levels to plans (pantheon-systems#1901)
- Loading branch information
1 parent
498d3c8
commit 7773fc7
Showing
29 changed files
with
1,346 additions
and
38 deletions.
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,36 @@ | ||
<?php | ||
|
||
namespace Pantheon\Terminus\Collections; | ||
|
||
use Pantheon\Terminus\Models\Plan; | ||
|
||
/** | ||
* Class Plans | ||
* @package Pantheon\Terminus\Collections | ||
*/ | ||
class Plans extends SiteOwnedCollection | ||
{ | ||
public static $pretty_name = 'plans'; | ||
/** | ||
* @var string | ||
*/ | ||
protected $collected_class = Plan::class; | ||
/** | ||
* @var string | ||
*/ | ||
protected $url = 'sites/{site_id}/plans'; | ||
|
||
/** | ||
* Sets the site's plan to the plan indicated. | ||
* | ||
* @param Plan $plan Plan to be set. | ||
* @return Workflow | ||
*/ | ||
public function set(Plan $plan) | ||
{ | ||
return $this->getSite()->getWorkflows()->create( | ||
'change_site_service_level', | ||
['params' => ['sku' => $plan->getSku(),],] | ||
); | ||
} | ||
} |
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,47 @@ | ||
<?php | ||
|
||
namespace Pantheon\Terminus\Commands\Plan; | ||
|
||
use Consolidation\OutputFormatters\StructuredData\PropertyList; | ||
use Pantheon\Terminus\Commands\Site\SiteCommand; | ||
|
||
/** | ||
* Class InfoCommand | ||
* @package Pantheon\Terminus\Commands\Plan | ||
*/ | ||
class InfoCommand extends SiteCommand | ||
{ | ||
/** | ||
* Displays information about a site's plan. | ||
* | ||
* @authorize | ||
* | ||
* @command plan:info | ||
* | ||
* @field-labels | ||
* id: ID | ||
* sku: SKU | ||
* name: Name | ||
* billing_cycle: Billing Cycle | ||
* price: Price | ||
* monthly_price: Monthly Price | ||
* automated_backups: Automated Backups | ||
* cache_server: Cache Server | ||
* custom_upstreams: Custom Upstreams | ||
* multidev: Multidev Environments | ||
* new_relic: New Relic | ||
* rackspace_ssl: Rackspace SSL | ||
* secure_runtime_access: Secure Runtime Access | ||
* storage: Storage (GB) | ||
* support_plan: Support Plan | ||
* @return PropertyList | ||
* | ||
* @param string $site The name or UUID of a site to retrieve current plan information on | ||
* | ||
* @usage <site> Displays <site>'s current plan information. | ||
*/ | ||
public function info($site) | ||
{ | ||
return new PropertyList($this->sites->get($site)->getPlan()->fetch()->serialize()); | ||
} | ||
} |
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 @@ | ||
<?php | ||
|
||
namespace Pantheon\Terminus\Commands\Plan; | ||
|
||
use Consolidation\OutputFormatters\StructuredData\RowsOfFields; | ||
use Pantheon\Terminus\Commands\Site\SiteCommand; | ||
|
||
/** | ||
* Class ListCommand | ||
* @package Pantheon\Terminus\Commands\Plan | ||
*/ | ||
class ListCommand extends SiteCommand | ||
{ | ||
/** | ||
* Displays the list of available site plans. | ||
* | ||
* @authorize | ||
* | ||
* @command plan:list | ||
* @aliases plans | ||
* | ||
* @field-labels | ||
* sku: SKU | ||
* name: Name | ||
* billing_cycle: Billing Cycle | ||
* price: Price | ||
* monthly_price: Monthly Price | ||
* @return RowsOfFields | ||
* | ||
* @param string $site_id The name or UUID of a site to view the available plans for | ||
* | ||
* @usage <site_id> Displays a list of plans available to <site>. | ||
*/ | ||
public function listPlans($site_id) | ||
{ | ||
return new RowsOfFields($this->getSite($site_id)->getPlans()->serialize()); | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
|
||
namespace Pantheon\Terminus\Commands\Plan; | ||
|
||
use Pantheon\Terminus\Commands\TerminusCommand; | ||
use Pantheon\Terminus\Site\SiteAwareInterface; | ||
use Pantheon\Terminus\Site\SiteAwareTrait; | ||
|
||
/** | ||
* Class SetCommand | ||
* @package Pantheon\Terminus\Commands\Plan | ||
*/ | ||
class SetCommand extends TerminusCommand implements SiteAwareInterface | ||
{ | ||
use SiteAwareTrait; | ||
|
||
/** | ||
* Changes a site's plan. | ||
* | ||
* @authorize | ||
* | ||
* @command plan:set | ||
* | ||
* @param string $site_id Site name | ||
* @param string $plan_id The SKU or UUID of the plan to set | ||
* | ||
* @usage <site> <plan> Updates <site>'s plan to <plan>. | ||
*/ | ||
public function set($site_id, $plan_id) | ||
{ | ||
$site = $this->getSite($site_id); | ||
$plans = $site->getPlans(); | ||
$workflow = $plans->set($plans->get($plan_id)); | ||
$this->log()->notice('Setting plan of "{site_id}" to "{plan_id}".', compact('site_id', 'plan_id')); | ||
while (!$workflow->checkProgress()) { | ||
// @TODO: Add Symfony progress bar to indicate that something is happening. | ||
} | ||
$this->log()->notice($workflow->getMessage()); | ||
} | ||
} |
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
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,126 @@ | ||
<?php | ||
|
||
namespace Pantheon\Terminus\Models; | ||
|
||
use Pantheon\Terminus\Friends\SiteInterface; | ||
use Pantheon\Terminus\Friends\SiteTrait; | ||
use Robo\Common\ConfigAwareTrait; | ||
use Robo\Contract\ConfigAwareInterface; | ||
|
||
/** | ||
* Class Plan | ||
* @package Pantheon\Terminus\Models | ||
*/ | ||
class Plan extends TerminusModel implements ConfigAwareInterface, SiteInterface | ||
{ | ||
use ConfigAwareTrait; | ||
use SiteTrait; | ||
|
||
public static $pretty_name = 'plan'; | ||
/** | ||
* @var string | ||
*/ | ||
protected $url = 'sites/{site_id}/plan'; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function __construct($attributes = null, array $options = []) | ||
{ | ||
if (property_exists($attributes, 'attributes')) { | ||
$attributes = (object)$attributes->attributes; | ||
} | ||
parent::__construct($attributes, $options); | ||
} | ||
|
||
/** | ||
* @return float|int | ||
*/ | ||
public function getMonthlyPrice() | ||
{ | ||
$price = (integer)$this->get('price'); | ||
if ($this->isAnnual()) { | ||
return $price/12; | ||
} | ||
return $price; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
$name = $this->get('name'); | ||
return !is_null($name) ? $name : $this->get('plan_name'); | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getReferences() | ||
{ | ||
return [$this->id, $this->getSku(),]; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getSku() | ||
{ | ||
$sku = $this->get('sku'); | ||
return !is_null($sku) ? $sku : $this->get('plan_sku'); | ||
} | ||
|
||
/** | ||
* @return boolean | ||
*/ | ||
public function isAnnual() | ||
{ | ||
return $this->get('billing_cycle') === 'annual'; | ||
} | ||
|
||
/** | ||
* @return boolean | ||
*/ | ||
public function isFree() | ||
{ | ||
return strpos($this->getSku(), 'plan-free') === 0; | ||
} | ||
|
||
/** | ||
* @return boolean | ||
*/ | ||
public function isMonthly() | ||
{ | ||
return $this->get('billing_cycle') === 'monthly'; | ||
} | ||
|
||
/** | ||
* @return null|string | ||
*/ | ||
public function formatPrice($price) | ||
{ | ||
if (!$this->isFree() && ($price === 0)) { | ||
return null; | ||
} | ||
return sprintf($this->getConfig()->get('monetary_format'), ($price / 100)); | ||
} | ||
|
||
|
||
/** | ||
* Formats plan object into an associative array for output | ||
* | ||
* @return array Associative array of data for output | ||
*/ | ||
public function serialize() | ||
{ | ||
return [ | ||
'billing_cycle' => $this->get('billing_cycle'), | ||
'id' => $this->id, | ||
'monthly_price' => $this->formatPrice($this->getMonthlyPrice()), | ||
'name' => $this->getName(), | ||
'price' => $this->formatPrice($this->get('price')), | ||
'sku' => $this->getSku(), | ||
]; | ||
} | ||
} |
Oops, something went wrong.