Skip to content
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

Team member sync #745

Merged
merged 5 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions modules/apigee_edge_teams/apigee_edge_teams.links.task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,8 @@ apigee_edge_teams.team_app.analytics:
title: 'Analytics'
base_route: entity.team_app.canonical
weight: -1

apigee_edge_teams.settings.team_member.sync:
route_name: apigee_edge_teams.settings.team_member.sync
title: 'Sync'
base_route: apigee_edge_teams.settings.team
24 changes: 24 additions & 0 deletions modules/apigee_edge_teams/apigee_edge_teams.routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,27 @@ apigee_edge_teams.settings.team_app.cache:
_title: 'Caching'
requirements:
_permission: 'administer team'

apigee_edge_teams.settings.team_member.sync:
path: '/admin/config/apigee-edge/app-settings/team-settings/sync'
defaults:
_form: '\Drupal\apigee_edge_teams\Form\TeamMemberSyncForm'
_title: 'Team Memeber Synchronization'
divya-intelli marked this conversation as resolved.
Show resolved Hide resolved
requirements:
_permission: 'administer team'

apigee_edge_teams.team_member.run:
path: '/admin/config/apigee-edge/app-settings/team-settings/sync/run'
defaults:
_controller: '\Drupal\apigee_edge_teams\Controller\TeamMemberSyncController::run'
requirements:
_permission: 'administer team'
_csrf_token: 'TRUE'

apigee_edge_teams.team_member.schedule:
path: '/admin/config/apigee-edge/app-settings/team-settings/sync/schedule'
defaults:
_controller: '\Drupal\apigee_edge_teams\Controller\TeamMemberSyncController::schedule'
requirements:
_permission: 'administer team'
_csrf_token: 'TRUE'
4 changes: 4 additions & 0 deletions modules/apigee_edge_teams/apigee_edge_teams.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,7 @@ services:
arguments: ['@entity_type.manager', '@logger.channel.apigee_edge_teams']
tags:
- { name: paramconverter }

apigee_edge_teams.cli:
class: Drupal\apigee_edge_teams\CliService
arguments: ['@apigee_edge.apigee_edge_mgmt_cli_service']
9 changes: 8 additions & 1 deletion modules/apigee_edge_teams/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,12 @@
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
"prefer-stable": true,
"extra": {
"drush": {
"services": {
"drush.services.yml": "^9"
}
}
}
}
6 changes: 6 additions & 0 deletions modules/apigee_edge_teams/drush.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
apigee_edge_teams.commands:
class: \Drupal\apigee_edge_teams\Commands\ApigeeEdgeCommands
arguments: ['@apigee_edge_teams.cli', '@apigee_edge.apigee_edge_mgmt_cli_service']
tags:
- { name: drush.command }
73 changes: 73 additions & 0 deletions modules/apigee_edge_teams/src/CliService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

/**
* Copyright 2022 Google Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 2 as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

namespace Drupal\apigee_edge_teams;

use Drupal\apigee_edge_teams\Controller\TeamMemberSyncController;
use Drupal\apigee_edge\Command\Util\ApigeeEdgeManagementCliServiceInterface;
use Symfony\Component\Console\Style\StyleInterface;

/**
* A CLI service which defines all the commands logic and delegates the methods.
*/
class CliService implements CliServiceInterface {

/**
* The service that makes calls to the Apigee API.
*
* @var \Drupal\apigee_edge\Command\Util\ApigeeEdgeManagementCliServiceInterface
*/
private $apigeeEdgeManagementCliService;

/**
* CliService constructor.
*
* @param \Drupal\apigee_edge\Command\Util\ApigeeEdgeManagementCliServiceInterface $apigeeEdgeManagementCliService
* The ApigeeEdgeManagementCliService to make calls to Apigee Edge.
*/
public function __construct(ApigeeEdgeManagementCliServiceInterface $apigeeEdgeManagementCliService) {
$this->apigeeEdgeManagementCliService = $apigeeEdgeManagementCliService;
}

/**
* {@inheritdoc}
*/
public function sync(StyleInterface $io, callable $t) {
$io->title($t('Team Member synchronization'));
$batch = TeamMemberSyncController::getBatch();
$last_message = '';

foreach ($batch['operations'] as $operation) {
$context = [
'finished' => 0,
];

while ($context['finished'] < 1) {
call_user_func_array($operation[0], array_merge($operation[1], [&$context]));
if (isset($context['message']) && $context['message'] !== $last_message) {
$io->text($t($context['message']));
}
$last_message = $context['message'];

gc_collect_cycles();
}
}
}

}
39 changes: 39 additions & 0 deletions modules/apigee_edge_teams/src/CliServiceInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/**
* Copyright 2022 Google Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 2 as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

namespace Drupal\apigee_edge_teams;

use Symfony\Component\Console\Style\StyleInterface;

/**
* Defines an interface for CLI service classes.
*/
interface CliServiceInterface {

/**
* Handle the sync interaction.
*
* @param \Symfony\Component\Console\Style\StyleInterface $io
* The IO interface of the CLI tool calling the method.
* @param callable $t
* The translation function akin to t().
*/
public function sync(StyleInterface $io, callable $t);

}
61 changes: 61 additions & 0 deletions modules/apigee_edge_teams/src/Commands/ApigeeEdgeCommands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/**
* Copyright 2022 Google Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License version 2 as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

namespace Drupal\apigee_edge_teams\Commands;

use Consolidation\AnnotatedCommand\CommandData;
use Drupal\apigee_edge_teams\CliServiceInterface;
use Drush\Commands\DrushCommands;

/**
* Drush 9 command file.
*/
class ApigeeEdgeCommands extends DrushCommands {

/**
* The interoperability cli service.
*
* @var \Drupal\apigee_edge_teams\CliServiceInterface
*/
protected $cliService;

/**
* ApigeeEdgeCommands constructor.
*
* @param \Drupal\apigee_edge_teams\CliServiceInterface $cli_service
* The CLI service which allows interoperability.
*/
public function __construct(CliServiceInterface $cli_service = NULL) {
parent::__construct();
$this->cliService = $cli_service;
}

/**
* Team Member synchronization.
*
* @command apigee-edge-teams:sync
*
* @usage drush apigee-edge-teams:sync
* Starts the team member synchronization.
*/
public function sync() {
$this->cliService->sync($this->io(), 'dt');
}

}
Loading