Skip to content

Commit

Permalink
Merge pull request #1231 from pantheon-systems/fix/sites_list_notice
Browse files Browse the repository at this point in the history
Fixes sites list
  • Loading branch information
TeslaDethray authored Sep 24, 2016
2 parents a30fe6e + 8806faa commit 6e72c1a
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 93 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ All notable changes to this project starting with the 0.6.0 release will be docu
### Fixed
- Fixed apply upstream updates. (#1233)
- Fixed `site upstream-info`. (#1224)
- Fixed the notices emitting from `sites list`. (#1231)
- Fixed the memberships column in `sites list` to accurately reflect when your user is a both a team and organizational member of a site. (#1231)

## [0.13.1] - 2016-09-19
### Changed
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
}
},
"scripts": {
"cs": "phpcs --standard=PSR2 --extensions=php --severity=1 -n tests/* bin/terminus.php src/* php/*",
"cbf": "phpcbf --standard=PSR2 -n src",
"cs": "phpcs --standard=PSR2 --severity=1 -n tests/* bin/terminus.php src/* php/*",
"cbf": "phpcbf --standard=PSR2 -n tests/* bin/terminus.php src/* php/*",
"docs": "php utils/make-docs.php",
"phpunit": "TERMINUS_TEST_MODE=1 SHELL_INTERACTIVE=true phpunit --colors=always -c tests/config/phpunit-10.xml.dist --debug",
"behat": "TERMINUS_TEST_MODE=1 SHELL_INTERACTIVE=true behat --colors -c=tests/config/behat_10.yml --suite=default",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 19 additions & 14 deletions php/Terminus/Collections/Sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ public function createForMigration($params = [])
/**
* Fetches model data from API and instantiates its model instances
*
* @param array $arg_options params to pass to url request
* @param array $arg_options Options to change the requests made. Elements as follow:
* string org_id UUID of the organization to retrieve sites for
* boolean team_only True to only retrieve team sites
* @return Sites
*/
public function fetch(array $arg_options = [])
Expand All @@ -82,32 +84,35 @@ public function fetch(array $arg_options = [])
'org_id' => null,
'team_only' => false,
];
$options = array_merge($default_options, $arg_options);
$options = array_merge($default_options, $arg_options);

$sites = [];
if (is_null($options['org_id'])) {
$sites = $this->user->getSites();
$sites[] = $this->user->getSites();
}
if (!$options['team_only']) {
$memberships = $this->user->org_memberships->fetch()->all();
if (!is_null($org_id = $options['org_id']) && ($org_id != 'all')) {
$memberships = [$memberships[$org_id],];
}
foreach ($memberships as $membership) {
if ($membership->get('role') != 'unprivileged') {
$sites = array_merge($sites, $membership->organization->getSites());
$sites[] = $membership->organization->getSites();
}
}
}

foreach ($sites as $site) {
if (!isset($this->models[$site->id])) {
$site->collection = $this;
$this->models[$site->id] = $site;
} else {
$this->models[$site->id]->memberships[] = array_merge(
$this->models[$site->id]->memberships,
$site->memberships
);
$merged_sites = [];
foreach ($sites as $site_group) {
foreach ($site_group as $site) {
if (!isset($merged_sites[$site->id])) {
$merged_sites[$site->id] = $site;
} else {
$merged_sites[$site->id]->memberships[] = $site->memberships[0];
}
}
}
$this->models = $merged_sites;

return $this;
}

Expand Down
68 changes: 34 additions & 34 deletions php/Terminus/Commands/SitesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ public function index($args, $assoc_args)
}
$sites = $this->sites->all();

if (count($sites) == 0) {
$this->log()->warning('You have no sites.');
if (empty($sites)) {
$this->log()->info('You have no sites.');
}

$rows = [];
Expand All @@ -208,7 +208,7 @@ public function index($args, $assoc_args)
if (property_exists($membership, 'user')) {
$memberships[] = "{$membership->user->id}: Team";
} elseif (property_exists($membership, 'organization')) {
$profile = $membership->organization->get('profile');
$profile = $membership->organization->get('profile');
$memberships[] = "{$membership->organization->id}: {$profile->name}";
}
}
Expand All @@ -218,11 +218,8 @@ public function index($args, $assoc_args)
'service_level' => $site->get('service_level'),
'framework' => $site->get('framework'),
'owner' => $site->get('owner'),
'created' => date(
Config::get('date_format'),
$site->get('created')
),
'memberships' => implode(', ', $memberships),
'created' => date(Config::get('date_format'), $site->get('created')),
'memberships' => implode(', ', $memberships),
];
if (!is_null($site->get('frozen'))) {
$rows[$site->id]['frozen'] = true;
Expand Down Expand Up @@ -356,36 +353,36 @@ public function massUpdate($args, $assoc_args)
)
);
if (!$report) {
$confirmed = $this->input()->confirm(
array(
'message' => 'Apply upstream updates to %s ( run update.php:%s, xoption:%s )',
'context' => array(
$site->get('name'),
var_export($updatedb, 1),
var_export($xoption, 1)
),
'exit' => false,
)
);
$confirmed = $this->input()->confirm(
array(
'message' => 'Apply upstream updates to %s ( run update.php:%s, xoption:%s )',
'context' => array(
$site->get('name'),
var_export($updatedb, 1),
var_export($xoption, 1)
),
'exit' => false,
)
);
if (!$confirmed) {
continue; // User says No, go back to start.
continue; // User says No, go back to start.
}
// Back up the site so it may be restored should something go awry
$this->log()->info('Backing up {site}.', $context);
$backup = $env->backups->create(['element' => 'all',]);
// Only continue if the backup was successful.
// Back up the site so it may be restored should something go awry
$this->log()->info('Backing up {site}.', $context);
$backup = $env->backups->create(['element' => 'all',]);
// Only continue if the backup was successful.
if ($backup) {
$this->log()->info('Backup of {site} created.', $context);
$this->log()->info('Updating {site}.', $context);
$response = $env->applyUpstreamUpdates($updatedb, $xoption);
$data[$site->get('name')]['status'] = 'Updated';
$this->log()->info('{site} is updated.', $context);
$this->log()->info('Backup of {site} created.', $context);
$this->log()->info('Updating {site}.', $context);
$response = $env->applyUpstreamUpdates($updatedb, $xoption);
$data[$site->get('name')]['status'] = 'Updated';
$this->log()->info('{site} is updated.', $context);
} else {
$data[$site->get('name')]['status'] = 'Backup failed';
$this->failure(
'There was a problem backing up {site}. Update aborted.',
$context
);
$data[$site->get('name')]['status'] = 'Backup failed';
$this->failure(
'There was a problem backing up {site}. Update aborted.',
$context
);
}
}
} else {
Expand All @@ -407,6 +404,7 @@ public function massUpdate($args, $assoc_args)
}

/**
<<<<<<< 6069ee197b85b18c4fb73d9756dd70e7da825cd0
* Filters an array of sites by whether the user is an organizational member
*
* @param Site[] $sites An array of sites to filter by
Expand Down Expand Up @@ -495,6 +493,8 @@ function ($site) {
}

/**
=======
>>>>>>> Fixed sites list memberships so that information is correctly rendered when a user is both an organizational and a team member.
* A helper function for getting/prompting for the site create options.
*
* @param array $assoc_args Arguments from command
Expand Down
6 changes: 2 additions & 4 deletions php/Terminus/Models/OrganizationSiteMembership.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ public function __construct($attributes = null, array $options = [])
{
parent::__construct($attributes, $options);
$this->organization = $options['collection']->organization;
$this->site = new Site(
$attributes->site,
['id' => $attributes->site->id, 'memberships' => [$this,],]
);
$this->site = new Site($attributes->site);
$this->site->memberships = [$this,];
}

/**
Expand Down
6 changes: 2 additions & 4 deletions php/Terminus/Models/OrganizationUserMembership.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ class OrganizationUserMembership extends TerminusModel
public function __construct($attributes = null, array $options = [])
{
parent::__construct($attributes, $options);
$this->user = new User(
$attributes->user,
['id' => $attributes->user->id, 'memberships' => [$this,],]
);
$this->user = new User($attributes->user);
$this->user->memberships = [$this,];
$this->organization = $options['collection']->organization;
}

Expand Down
8 changes: 4 additions & 4 deletions php/Terminus/Models/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ public function __construct($attributes = null, array $options = [])
$this->url = "sites/{$this->id}?site_state=true";

$params = ['site' => $this,];
$this->authorizations = new SiteAuthorizations($params);
$this->environments = new Environments($params);
$this->org_memberships = new SiteOrganizationMemberships($params);
$this->authorizations = new SiteAuthorizations($params);
$this->environments = new Environments($params);
$this->org_memberships = new SiteOrganizationMemberships($params);
$this->user_memberships = new SiteUserMemberships($params);
$this->workflows = new Workflows($params);
$this->workflows = new Workflows($params);

if (isset($attributes->upstream)) {
$this->upstream = new Upstream($attributes->upstream, $params);
Expand Down
6 changes: 2 additions & 4 deletions php/Terminus/Models/SiteOrganizationMembership.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ public function __construct($attributes = null, array $options = [])
{
parent::__construct($attributes, $options);
$this->site = $options['collection']->site;
$this->organization = new Organization(
$attributes->organization,
['id' => $attributes->organization->id, 'memberships' => [$this,],]
);
$this->organization = new Organization($attributes->organization);
$this->organization->memberships = [$this,];
}

/**
Expand Down
6 changes: 2 additions & 4 deletions php/Terminus/Models/SiteUserMembership.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ public function __construct($attributes = null, array $options = [])
{
parent::__construct($attributes, $options);
$this->site = $options['collection']->site;
$this->user = new User(
$attributes->user,
['id' => $attributes->user->id, 'memberships' => [$this,],]
);
$this->user = new User($attributes->user);
$this->user->memberships = [$this,];
}

/**
Expand Down
6 changes: 2 additions & 4 deletions php/Terminus/Models/UserOrganizationMembership.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ public function __construct($attributes = null, array $options = [])
{
parent::__construct($attributes, $options);
$this->user = $options['collection']->user;
$this->organization = new Organization(
$attributes->organization,
['id' => $attributes->organization->id, 'memberships' => [$this,],]
);
$this->organization = new Organization($attributes->organization);
$this->organization->memberships = [$this,];
}
}
6 changes: 2 additions & 4 deletions php/Terminus/Models/UserSiteMembership.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ class UserSiteMembership extends TerminusModel
public function __construct($attributes = null, array $options = [])
{
parent::__construct($attributes, $options);
$this->site = new Site(
$attributes->site,
['id' => $attributes->site->id, 'memberships' => [$this,],]
);
$this->site = new Site($attributes->site);
$this->site->memberships = [$this,];
$this->user = $options['collection']->user;
}
}
Loading

0 comments on commit 6e72c1a

Please sign in to comment.