2021-03-15 02:30:51 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2020-06-11 13:30:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Circles - Bring cloud-users closer together.
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later. See the COPYING file.
|
|
|
|
*
|
|
|
|
* @author Maxence Lange <maxence@artificial-owl.com>
|
2021-03-15 02:30:51 +01:00
|
|
|
* @copyright 2021
|
2020-06-11 13:30:38 +02:00
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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 Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
namespace OCA\Circles\Command;
|
|
|
|
|
2021-03-15 02:30:51 +01:00
|
|
|
|
2021-03-17 13:48:41 +01:00
|
|
|
use daita\MySmallPhpTools\Exceptions\InvalidItemException;
|
2021-03-13 23:32:10 +01:00
|
|
|
use daita\MySmallPhpTools\Exceptions\ItemNotFoundException;
|
2021-03-22 13:52:56 +01:00
|
|
|
use daita\MySmallPhpTools\Traits\Nextcloud\nc22\TNC22Deserialize;
|
2020-06-11 13:30:38 +02:00
|
|
|
use daita\MySmallPhpTools\Traits\TArrayTools;
|
2021-03-15 02:30:51 +01:00
|
|
|
use daita\MySmallPhpTools\Traits\TStringTools;
|
2020-08-05 16:10:14 +02:00
|
|
|
use Exception;
|
2020-06-11 13:30:38 +02:00
|
|
|
use OC\Core\Command\Base;
|
2021-03-15 02:30:51 +01:00
|
|
|
use OCA\Circles\AppInfo\Application;
|
|
|
|
use OCA\Circles\Db\CoreQueryBuilder;
|
|
|
|
use OCA\Circles\Exceptions\CircleNotFoundException;
|
|
|
|
use OCA\Circles\Model\Circle;
|
2021-03-21 13:30:48 +01:00
|
|
|
use OCA\Circles\Model\FederatedUser;
|
2021-03-15 02:30:51 +01:00
|
|
|
use OCA\Circles\Model\Member;
|
2020-06-11 13:30:38 +02:00
|
|
|
use OCA\Circles\Service\ConfigService;
|
2021-03-13 23:32:10 +01:00
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
2020-06-11 13:30:38 +02:00
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
2020-08-05 16:10:14 +02:00
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
2020-06-11 13:30:38 +02:00
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2021-03-13 23:32:10 +01:00
|
|
|
use Symfony\Component\Process\Process;
|
2020-06-11 13:30:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2020-12-29 00:54:44 +01:00
|
|
|
* Class CirclesTest
|
2020-06-11 13:30:38 +02:00
|
|
|
*
|
|
|
|
* @package OCA\Circles\Command
|
|
|
|
*/
|
|
|
|
class CirclesTest extends Base {
|
|
|
|
|
|
|
|
|
|
|
|
use TArrayTools;
|
2021-03-15 02:30:51 +01:00
|
|
|
use TStringTools;
|
2021-03-22 13:52:56 +01:00
|
|
|
use TNC22Deserialize;
|
2021-03-15 02:30:51 +01:00
|
|
|
|
2020-06-11 13:30:38 +02:00
|
|
|
|
2021-03-15 02:30:51 +01:00
|
|
|
static $INSTANCES = [
|
|
|
|
'global-scale-1',
|
|
|
|
'global-scale-2',
|
|
|
|
'global-scale-3',
|
|
|
|
'passive',
|
|
|
|
'external',
|
|
|
|
'trusted'
|
|
|
|
];
|
|
|
|
|
|
|
|
|
2021-03-23 00:23:38 +01:00
|
|
|
static $TEST_CIRCLES = [
|
|
|
|
'test_001'
|
|
|
|
];
|
|
|
|
|
|
|
|
|
2021-03-15 02:30:51 +01:00
|
|
|
/** @var CoreQueryBuilder */
|
|
|
|
private $coreQueryBuilder;
|
2020-06-11 13:30:38 +02:00
|
|
|
|
|
|
|
/** @var ConfigService */
|
|
|
|
private $configService;
|
|
|
|
|
2020-08-05 16:10:14 +02:00
|
|
|
|
2021-03-16 14:31:04 +01:00
|
|
|
/** @var InputInterface */
|
|
|
|
private $input;
|
|
|
|
|
2021-03-15 02:30:51 +01:00
|
|
|
/** @var OutputInterface */
|
|
|
|
private $output;
|
|
|
|
|
2021-03-13 23:32:10 +01:00
|
|
|
/** @var array */
|
|
|
|
private $config = [];
|
|
|
|
|
2021-03-15 02:30:51 +01:00
|
|
|
/** @var string */
|
|
|
|
private $local = '';
|
|
|
|
|
|
|
|
/** @var bool */
|
|
|
|
private $pOn = false;
|
|
|
|
|
2021-03-13 23:32:10 +01:00
|
|
|
/** @var array */
|
2021-03-15 02:30:51 +01:00
|
|
|
private $circles = [];
|
2020-08-07 04:56:45 +02:00
|
|
|
|
2021-03-15 02:30:51 +01:00
|
|
|
/** @var array */
|
2021-03-21 13:30:48 +01:00
|
|
|
private $federatedUsers = [];
|
2020-08-07 04:56:45 +02:00
|
|
|
|
2021-03-23 00:23:38 +01:00
|
|
|
|
2020-06-11 13:30:38 +02:00
|
|
|
/**
|
2020-12-29 00:54:44 +01:00
|
|
|
* CirclesTest constructor.
|
2020-06-11 13:30:38 +02:00
|
|
|
*
|
2021-03-15 02:30:51 +01:00
|
|
|
* @param CoreQueryBuilder $coreQueryBuilder
|
2020-06-11 13:30:38 +02:00
|
|
|
* @param ConfigService $configService
|
|
|
|
*/
|
2021-03-15 02:30:51 +01:00
|
|
|
public function __construct(CoreQueryBuilder $coreQueryBuilder, ConfigService $configService) {
|
2020-06-11 13:30:38 +02:00
|
|
|
parent::__construct();
|
|
|
|
|
2021-03-15 02:30:51 +01:00
|
|
|
$this->coreQueryBuilder = $coreQueryBuilder;
|
2020-06-11 13:30:38 +02:00
|
|
|
$this->configService = $configService;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-15 02:30:51 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2020-06-11 13:30:38 +02:00
|
|
|
protected function configure() {
|
|
|
|
parent::configure();
|
|
|
|
$this->setName('circles:test')
|
2020-08-05 16:10:14 +02:00
|
|
|
->setDescription('testing some features')
|
2021-03-13 23:32:10 +01:00
|
|
|
->addArgument('deprecated', InputArgument::OPTIONAL, '')
|
|
|
|
->addOption(
|
2021-03-16 14:31:04 +01:00
|
|
|
'are-you-aware-this-will-delete-all-my-data', '', InputOption::VALUE_REQUIRED,
|
2021-03-13 23:32:10 +01:00
|
|
|
'Well, are you ?', ''
|
2021-03-16 14:31:04 +01:00
|
|
|
)
|
2021-03-21 13:30:48 +01:00
|
|
|
->addOption('skip-init', '', InputOption::VALUE_NONE, 'Bypass Initialisation')
|
2021-04-23 12:09:06 +02:00
|
|
|
->addOption('skip-setup', '', InputOption::VALUE_NONE, 'Bypass Circles Setup')
|
|
|
|
->addOption('only-setup', '', InputOption::VALUE_NONE, 'Stop after Circles Setup, pre-Sync');
|
2020-06-11 13:30:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param InputInterface $input
|
|
|
|
* @param OutputInterface $output
|
|
|
|
*
|
|
|
|
* @return int
|
2021-03-21 13:30:48 +01:00
|
|
|
* @throws Exception
|
2020-06-11 13:30:38 +02:00
|
|
|
*/
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int {
|
2021-03-16 14:31:04 +01:00
|
|
|
$this->input = $input;
|
2021-03-15 02:30:51 +01:00
|
|
|
$this->output = $output;
|
2021-03-16 14:31:04 +01:00
|
|
|
|
|
|
|
if ($input->getOption('are-you-aware-this-will-delete-all-my-data') === 'yes-i-am') {
|
2021-03-15 02:30:51 +01:00
|
|
|
try {
|
|
|
|
$this->testCirclesApp();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
if ($this->pOn) {
|
2021-03-21 13:30:48 +01:00
|
|
|
$message = ($e->getMessage() !== '') ? $e->getMessage() : get_class($e);
|
|
|
|
$this->output->writeln('<error>' . $message . '</error>');
|
2021-03-15 02:30:51 +01:00
|
|
|
} else {
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
2020-12-02 17:53:22 +01:00
|
|
|
|
2020-11-16 20:21:34 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2020-08-05 16:10:14 +02:00
|
|
|
|
2021-03-13 23:32:10 +01:00
|
|
|
$output->writeln('');
|
|
|
|
$output->writeln(
|
|
|
|
'<error>Since Nextcloud 22, this command have changed, please read the message below:</error>'
|
|
|
|
);
|
|
|
|
$output->writeln('<error>This new command is to test the integrity of the Circles App.</error>');
|
|
|
|
$output->writeln(
|
|
|
|
'<error>Running this command will REMOVE all your current configuration and all your current Circles.</error>'
|
|
|
|
);
|
|
|
|
$output->writeln('<error>There is a huge probability that you do not want to do that.</error>');
|
|
|
|
$output->writeln('');
|
|
|
|
$output->writeln(
|
|
|
|
'<error>The old testing command you might looking for have moved to "./occ circles:check"</error>'
|
|
|
|
);
|
|
|
|
$output->writeln('');
|
2020-08-05 16:10:14 +02:00
|
|
|
|
2021-03-13 23:32:10 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2020-08-05 16:10:14 +02:00
|
|
|
|
2020-06-11 13:30:38 +02:00
|
|
|
|
2021-03-13 23:32:10 +01:00
|
|
|
/**
|
2021-03-21 13:30:48 +01:00
|
|
|
* @throws CircleNotFoundException
|
|
|
|
* @throws InvalidItemException
|
2021-03-13 23:32:10 +01:00
|
|
|
* @throws ItemNotFoundException
|
|
|
|
*/
|
|
|
|
private function testCirclesApp() {
|
2021-03-16 14:31:04 +01:00
|
|
|
$this->t('Bootup');
|
2021-03-13 23:32:10 +01:00
|
|
|
$this->loadConfiguration();
|
2021-03-16 14:31:04 +01:00
|
|
|
|
2021-03-21 13:30:48 +01:00
|
|
|
if (!$this->input->getOption('skip-setup')) {
|
|
|
|
if (!$this->input->getOption('skip-init')) {
|
2021-04-20 14:59:19 +02:00
|
|
|
$this->t('Initialisation Nextcloud');
|
2021-03-21 13:30:48 +01:00
|
|
|
$this->initEnvironment();
|
|
|
|
}
|
2021-04-20 14:59:19 +02:00
|
|
|
|
|
|
|
$this->t('Initialisation Circles App');
|
2021-03-16 14:31:04 +01:00
|
|
|
$this->reloadCirclesApp();
|
2021-03-17 13:48:41 +01:00
|
|
|
$this->configureCirclesApp();
|
2021-03-16 14:31:04 +01:00
|
|
|
$this->confirmVersion();
|
|
|
|
$this->confirmEmptyCircles();
|
2021-04-23 12:09:06 +02:00
|
|
|
|
|
|
|
if ($this->input->getOption('only-setup')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-16 14:31:04 +01:00
|
|
|
$this->syncCircles();
|
2021-03-21 13:30:48 +01:00
|
|
|
|
|
|
|
$this->t('Fresh installation status');
|
|
|
|
$this->statusFreshInstances();
|
|
|
|
$this->createRemoteLink();
|
2021-03-16 14:31:04 +01:00
|
|
|
}
|
2020-11-16 20:21:34 +01:00
|
|
|
|
2021-03-21 13:30:48 +01:00
|
|
|
$this->t('Building Local Database');
|
|
|
|
$this->buildingLocalDatabase();
|
|
|
|
|
|
|
|
$this->t('Testing Basic Circle Creation');
|
2021-03-23 00:23:38 +01:00
|
|
|
$this->circleCreation001();
|
2021-03-21 13:30:48 +01:00
|
|
|
|
|
|
|
$this->t('Adding local users and moderators');
|
2021-03-23 00:23:38 +01:00
|
|
|
$this->addLocalMemberByUserId();
|
2021-04-20 14:59:19 +02:00
|
|
|
// $this->addLocalMemberBySingleId();
|
|
|
|
// $this->addLocalMemberUsingMember();
|
|
|
|
// $this->levelLocalMemberToModerator();
|
|
|
|
// $this->addRemoteMemberUsingModerator();
|
|
|
|
// $this->addRemoteMemberUsingRemoteMember();
|
|
|
|
// $this->levelRemoteMemberToAdmin();
|
|
|
|
// $this->addRemoteMemberUsingRemoteAdmin();
|
|
|
|
//
|
2020-06-11 13:30:38 +02:00
|
|
|
}
|
|
|
|
|
2020-08-07 04:56:45 +02:00
|
|
|
|
|
|
|
/**
|
2021-03-15 02:30:51 +01:00
|
|
|
* @throws ItemNotFoundException
|
|
|
|
*/
|
|
|
|
private function loadConfiguration() {
|
|
|
|
$this->p('Loading configuration');
|
|
|
|
$configuration = file_get_contents(__DIR__ . '/../../testConfiguration.json');
|
|
|
|
$this->config = json_decode($configuration, true);
|
|
|
|
$this->r(true, 'testConfiguration.json');
|
|
|
|
|
|
|
|
$this->p('Checking configuration');
|
|
|
|
foreach (self::$INSTANCES as $instance) {
|
|
|
|
$cloudId = $this->getConfig($instance, 'config.frontal_cloud_id');
|
|
|
|
if ($this->configService->isLocalInstance($cloudId)) {
|
|
|
|
$this->local = $instance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->r();
|
|
|
|
|
|
|
|
$this->p('Checking local');
|
|
|
|
if ($this->local === '') {
|
|
|
|
throw new ItemNotFoundException('local not defined');
|
|
|
|
}
|
|
|
|
$this->r(true, $this->local);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws ItemNotFoundException
|
|
|
|
*/
|
|
|
|
private function initEnvironment() {
|
2021-04-20 14:59:19 +02:00
|
|
|
$this->p('Disabling Password Policy App:');
|
|
|
|
foreach ($this->getInstances() as $instanceId) {
|
|
|
|
$this->occ($instanceId, 'app:disable password_policy', false, false);
|
|
|
|
$this->pm($instanceId);
|
|
|
|
}
|
|
|
|
$this->r();
|
|
|
|
|
2021-03-16 14:31:04 +01:00
|
|
|
foreach ($this->getInstances() as $instance) {
|
|
|
|
$this->p('Creating users on ' . $instance);
|
|
|
|
foreach ($this->getConfigArray($instance, 'users') as $userId) {
|
|
|
|
$this->pm($userId);
|
2021-04-20 14:59:19 +02:00
|
|
|
$this->occ(
|
|
|
|
$instance, 'user:add --password-from-env ' . $userId, false, false,
|
|
|
|
['OC_PASS' => 'testtest']
|
|
|
|
);
|
2021-03-16 14:31:04 +01:00
|
|
|
}
|
|
|
|
$this->r();
|
|
|
|
|
|
|
|
foreach ($this->getConfigArray($instance, 'groups') as $groupId => $users) {
|
|
|
|
$this->p('Creating group <info>' . $groupId . '</info> on <info>' . $instance . '</info>');
|
|
|
|
$this->occ($instance, 'group:add ' . $groupId, false, false);
|
|
|
|
foreach ($users as $userId) {
|
|
|
|
$this->pm($userId);
|
|
|
|
$this->occ($instance, 'group:adduser ' . $groupId . ' ' . $userId, true, false);
|
|
|
|
}
|
|
|
|
$this->r();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws ItemNotFoundException
|
|
|
|
*/
|
|
|
|
private function reloadCirclesApp() {
|
|
|
|
$this->p('Reload Circles App');
|
2021-03-15 02:30:51 +01:00
|
|
|
foreach ($this->getInstances(false) as $instance) {
|
|
|
|
$this->pm($instance);
|
|
|
|
$this->occ($instance, 'circles:clean --uninstall', false, false);
|
|
|
|
$this->occ($instance, 'app:enable circles', true, false);
|
|
|
|
}
|
|
|
|
$this->r();
|
|
|
|
|
2021-03-16 14:31:04 +01:00
|
|
|
$this->p('Empty Circles database on local');
|
2021-03-15 02:30:51 +01:00
|
|
|
$this->coreQueryBuilder->cleanDatabase();
|
|
|
|
$this->r();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-17 13:48:41 +01:00
|
|
|
/**
|
|
|
|
* @throws ItemNotFoundException
|
|
|
|
*/
|
|
|
|
private function configureCirclesApp() {
|
|
|
|
$this->p('Configure Circles App');
|
|
|
|
foreach ($this->getInstances(true) as $instance) {
|
|
|
|
$this->pm($instance);
|
|
|
|
foreach ($this->getConfigArray($instance, 'config') as $k => $v) {
|
|
|
|
$this->occ($instance, 'config:app:set --value ' . $v . ' circles ' . $k, true, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->r();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-15 02:30:51 +01:00
|
|
|
/**
|
|
|
|
* @throws ItemNotFoundException
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
private function confirmVersion() {
|
|
|
|
$version = $this->configService->getAppValue('installed_version');
|
|
|
|
$this->p('Confirming version <info>' . $version . '</info>');
|
|
|
|
foreach ($this->getInstances(false) as $instance) {
|
|
|
|
$this->pm($instance);
|
|
|
|
$capabilities = $this->occ($instance, 'circles:check --capabilities');
|
|
|
|
$v = $this->get('version', $capabilities);
|
|
|
|
if ($v !== $version) {
|
|
|
|
throw new Exception($v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->r();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws ItemNotFoundException
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
private function confirmEmptyCircles() {
|
|
|
|
$this->p('Confirming empty database');
|
|
|
|
foreach ($this->getInstances() as $instance) {
|
|
|
|
$this->pm($instance);
|
|
|
|
$result = $this->occ($instance, 'circles:manage:list --all');
|
|
|
|
if (!is_array($result) || !empty($result)) {
|
|
|
|
throw new Exception('no');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->r();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws ItemNotFoundException
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
private function syncCircles() {
|
|
|
|
$this->p('Running Circles Sync');
|
|
|
|
foreach ($this->getInstances() as $instance) {
|
|
|
|
$this->pm($instance);
|
|
|
|
$this->occ($instance, 'circles:sync');
|
|
|
|
}
|
|
|
|
$this->r();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-17 13:48:41 +01:00
|
|
|
/**
|
|
|
|
* @throws CircleNotFoundException
|
|
|
|
* @throws InvalidItemException
|
2021-03-21 13:30:48 +01:00
|
|
|
* @throws ItemNotFoundException
|
2021-03-17 13:48:41 +01:00
|
|
|
*/
|
2021-03-15 02:30:51 +01:00
|
|
|
private function statusFreshInstances() {
|
|
|
|
foreach ($this->getInstances() as $instanceId) {
|
|
|
|
$this->p('Circles on ' . $instanceId);
|
|
|
|
$result = $this->occ($instanceId, 'circles:manage:list --all');
|
2021-03-16 14:31:04 +01:00
|
|
|
$expectedSize = sizeof($this->getConfigArray($instanceId, 'groups'))
|
|
|
|
+ sizeof($this->getConfigArray($instanceId, 'users'))
|
|
|
|
+ 1;
|
|
|
|
$this->r((sizeof($result) === $expectedSize), sizeof($result) . ' circles');
|
2021-03-15 02:30:51 +01:00
|
|
|
|
2021-03-21 13:30:48 +01:00
|
|
|
$membersList = $groupsList = [];
|
2021-03-15 02:30:51 +01:00
|
|
|
foreach ($result as $item) {
|
2021-03-21 13:30:48 +01:00
|
|
|
/** @var Circle $circle */
|
|
|
|
$circle = $this->deserialize($item, Circle::class);
|
|
|
|
|
2021-03-15 02:30:51 +01:00
|
|
|
if ($circle->isConfig(Circle::CFG_SINGLE)) {
|
2021-03-21 13:30:48 +01:00
|
|
|
$membersList[] = $circle;
|
2021-03-15 02:30:51 +01:00
|
|
|
}
|
|
|
|
|
2021-03-16 13:32:35 +01:00
|
|
|
if ($circle->getSource() === Member::TYPE_GROUP) {
|
2021-03-21 13:30:48 +01:00
|
|
|
$groupsList[] = $circle;
|
2021-03-15 02:30:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$instance = $this->getConfig($instanceId, 'config.frontal_cloud_id');
|
2021-03-17 13:48:41 +01:00
|
|
|
|
2021-03-15 02:30:51 +01:00
|
|
|
foreach ($this->getConfigArray($instanceId, 'users') as $userId) {
|
2021-03-17 13:48:41 +01:00
|
|
|
$this->p('Checking Single Circle for <comment>' . $userId . '@' . $instance . '</comment>');
|
2021-03-21 13:30:48 +01:00
|
|
|
$circle = $this->getSingleCircleForMember($membersList, $userId, $instance);
|
2021-03-17 13:48:41 +01:00
|
|
|
|
|
|
|
$compareToOwnerBasedOn = new Circle();
|
|
|
|
$compareToOwnerBasedOn->setConfig(Circle::CFG_SINGLE)
|
|
|
|
->setName('user:' . $userId . ':{CIRCLEID}')
|
2021-04-20 14:59:19 +02:00
|
|
|
->setDisplayName($userId);
|
2021-03-15 02:30:51 +01:00
|
|
|
|
|
|
|
$compareToOwner = new Member();
|
|
|
|
$compareToOwner->setUserId($userId)
|
|
|
|
->setUserType(Member::TYPE_USER)
|
|
|
|
->setInstance($instance)
|
|
|
|
->setDisplayName($userId)
|
|
|
|
->setId('{CIRCLEID}')
|
|
|
|
->setCircleId('{CIRCLEID}')
|
|
|
|
->setSingleId('{CIRCLEID}')
|
|
|
|
->setStatus(Member::STATUS_MEMBER)
|
2021-03-17 13:48:41 +01:00
|
|
|
->setLevel(Member::LEVEL_OWNER)
|
|
|
|
->setBasedOn($compareToOwnerBasedOn);
|
|
|
|
|
2021-03-15 02:30:51 +01:00
|
|
|
$compareTo = new Circle();
|
|
|
|
$compareTo->setOwner($compareToOwner)
|
2021-03-17 13:48:41 +01:00
|
|
|
->setConfig(Circle::CFG_SINGLE)
|
2021-03-16 13:32:35 +01:00
|
|
|
->setName('user:' . $userId . ':{CIRCLEID}')
|
2021-04-20 14:59:19 +02:00
|
|
|
->setDisplayName($userId);
|
2021-03-15 02:30:51 +01:00
|
|
|
|
|
|
|
$this->confirmCircleData($circle, $compareTo);
|
2021-04-20 14:59:19 +02:00
|
|
|
$this->r(true, $circle->getSingleId());
|
2021-03-15 02:30:51 +01:00
|
|
|
}
|
|
|
|
|
2021-03-17 13:48:41 +01:00
|
|
|
$this->p('Checking Single Circle for <comment>Circles App</comment>');
|
2021-03-21 13:30:48 +01:00
|
|
|
$circle = $this->getSingleCircleForMember($membersList, 'circles', $instance);
|
2021-03-17 13:48:41 +01:00
|
|
|
|
|
|
|
$compareToOwnerBasedOn = new Circle();
|
|
|
|
$compareToOwnerBasedOn->setConfig(Circle::CFG_SINGLE | Circle::CFG_ROOT)
|
|
|
|
->setName('app:circles:{CIRCLEID}')
|
2021-04-20 14:59:19 +02:00
|
|
|
->setDisplayName('circles');
|
2021-03-17 13:48:41 +01:00
|
|
|
|
2021-03-15 02:30:51 +01:00
|
|
|
$compareToOwner = new Member();
|
|
|
|
$compareToOwner->setUserId(Application::APP_ID)
|
|
|
|
->setUserType(Member::TYPE_APP)
|
|
|
|
->setInstance($instance)
|
|
|
|
->setDisplayName(Application::APP_ID)
|
|
|
|
->setId('{CIRCLEID}')
|
|
|
|
->setCircleId('{CIRCLEID}')
|
|
|
|
->setSingleId('{CIRCLEID}')
|
|
|
|
->setStatus(Member::STATUS_MEMBER)
|
2021-03-21 13:30:48 +01:00
|
|
|
->setLevel(Member::LEVEL_OWNER)
|
2021-03-17 13:48:41 +01:00
|
|
|
->setBasedOn($compareToOwnerBasedOn);
|
2021-03-15 02:30:51 +01:00
|
|
|
|
|
|
|
$compareTo = new Circle();
|
|
|
|
$compareTo->setOwner($compareToOwner)
|
2021-03-16 13:32:35 +01:00
|
|
|
->setConfig(Circle::CFG_SINGLE | Circle::CFG_ROOT)
|
2021-03-15 02:30:51 +01:00
|
|
|
->setName('app:circles:{CIRCLEID}')
|
2021-04-20 14:59:19 +02:00
|
|
|
->setDisplayName('circles');
|
2021-03-15 02:30:51 +01:00
|
|
|
|
|
|
|
$this->confirmCircleData($circle, $compareTo);
|
2021-04-20 14:59:19 +02:00
|
|
|
$this->r(true, $circle->getSingleId());
|
2021-03-15 02:30:51 +01:00
|
|
|
|
2021-03-17 13:48:41 +01:00
|
|
|
foreach ($this->getConfigArray($instanceId, 'groups') as $groupId => $members) {
|
|
|
|
$this->p('Checking Circle for <comment>' . $groupId . '@' . $instance . '</comment>');
|
2021-03-23 00:23:38 +01:00
|
|
|
$circle = $this->getCircleFromList($groupsList, 'group:' . $groupId);
|
2021-03-17 13:48:41 +01:00
|
|
|
|
2021-03-21 13:30:48 +01:00
|
|
|
$appCircle = $this->getSingleCircleForMember($membersList, 'circles', $instance);
|
2021-03-17 13:48:41 +01:00
|
|
|
$appOwner = $appCircle->getOwner();
|
|
|
|
|
|
|
|
$compareToOwnerBasedOn = new Circle();
|
|
|
|
$compareToOwnerBasedOn->setConfig(Circle::CFG_SINGLE | Circle::CFG_ROOT)
|
|
|
|
->setName($appCircle->getName())
|
|
|
|
->setDisplayName($appCircle->getDisplayName());
|
|
|
|
|
|
|
|
$compareToOwner = new Member();
|
|
|
|
$compareToOwner->setUserId($appOwner->getUserId())
|
|
|
|
->setUserType($appOwner->getUserType())
|
|
|
|
->setInstance($appOwner->getInstance())
|
|
|
|
->setDisplayName($appOwner->getDisplayName())
|
|
|
|
->setCircleId('{CIRCLEID}')
|
|
|
|
->setSingleId($appOwner->getSingleId())
|
|
|
|
->setStatus($appOwner->getStatus())
|
|
|
|
->setLevel($appOwner->getLevel())
|
|
|
|
->setBasedOn($compareToOwnerBasedOn);
|
|
|
|
|
|
|
|
$compareTo = new Circle();
|
|
|
|
$compareTo->setOwner($compareToOwner)
|
|
|
|
->setConfig(Circle::CFG_SYSTEM | Circle::CFG_NO_OWNER | Circle::CFG_HIDDEN)
|
|
|
|
->setName('group:' . $groupId)
|
|
|
|
->setDisplayName($groupId);
|
|
|
|
|
|
|
|
$this->confirmCircleData($circle, $compareTo);
|
2021-04-20 14:59:19 +02:00
|
|
|
$this->r(true, $circle->getSingleId());
|
2021-03-17 13:48:41 +01:00
|
|
|
}
|
2021-03-15 02:30:51 +01:00
|
|
|
|
|
|
|
$this->output->writeln('');
|
|
|
|
}
|
2021-03-17 13:48:41 +01:00
|
|
|
}
|
2021-03-15 02:30:51 +01:00
|
|
|
|
2021-03-17 13:48:41 +01:00
|
|
|
|
2021-03-21 13:30:48 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2021-03-17 13:48:41 +01:00
|
|
|
private function createRemoteLink() {
|
|
|
|
foreach ($this->getInstances() as $instanceId) {
|
|
|
|
$this->p('Init remote link from ' . $instanceId);
|
|
|
|
$links = $this->getConfigArray($instanceId, 'remote');
|
|
|
|
foreach ($links as $link => $type) {
|
|
|
|
$remote = $this->getConfig($link, 'config.frontal_cloud_id');
|
|
|
|
$this->pm($remote . '(' . $type . ')');
|
|
|
|
$this->occ($instanceId, 'circles:remote ' . $remote . ' --type ' . $type . ' --yes');
|
|
|
|
}
|
|
|
|
$this->r();
|
|
|
|
}
|
2021-03-15 02:30:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-03-21 13:30:48 +01:00
|
|
|
* @throws InvalidItemException
|
|
|
|
* @throws ItemNotFoundException
|
2020-08-07 04:56:45 +02:00
|
|
|
*/
|
2021-03-21 13:30:48 +01:00
|
|
|
private function buildingLocalDatabase() {
|
|
|
|
$this->circles = $this->federatedUsers = [];
|
|
|
|
foreach ($this->getInstances() as $instanceId) {
|
|
|
|
$this->p('Retrieving Circles from ' . $instanceId);
|
|
|
|
$circles = $this->occ($instanceId, 'circles:manage:list --all');
|
|
|
|
foreach ($circles as $item) {
|
|
|
|
/** @var Circle $circle */
|
|
|
|
$circle = $this->deserialize($item, Circle::class);
|
|
|
|
if ($circle->isConfig(Circle::CFG_SINGLE)) {
|
|
|
|
$pos = strrpos($circle->getName(), ':');
|
|
|
|
if (!$pos) {
|
|
|
|
throw new InvalidItemException('could not parse circle.name');
|
|
|
|
}
|
|
|
|
|
|
|
|
$owner = new FederatedUser();
|
|
|
|
$owner->importFromIFederatedUser($circle->getOwner());
|
|
|
|
$this->federatedUsers[$instanceId][$owner->getUserId()] = $owner;
|
|
|
|
$this->circles[$instanceId][substr($circle->getName(), 0, $pos)] = $circle;
|
|
|
|
} else {
|
|
|
|
$this->circles[$instanceId][$circle->getName()] = $circle;
|
|
|
|
}
|
2021-03-15 02:30:51 +01:00
|
|
|
}
|
2021-03-21 13:30:48 +01:00
|
|
|
$this->r();
|
2021-03-15 02:30:51 +01:00
|
|
|
}
|
|
|
|
}
|
2020-12-29 00:54:44 +01:00
|
|
|
|
2020-08-07 04:56:45 +02:00
|
|
|
|
2021-03-17 13:48:41 +01:00
|
|
|
/**
|
2021-03-21 13:30:48 +01:00
|
|
|
* @throws InvalidItemException
|
|
|
|
* @throws ItemNotFoundException
|
2021-03-17 13:48:41 +01:00
|
|
|
*/
|
2021-03-23 00:23:38 +01:00
|
|
|
private function circleCreation001() {
|
2021-03-21 13:30:48 +01:00
|
|
|
$this->p('Creating basic circle');
|
|
|
|
|
|
|
|
$localInstanceId = 'global-scale-1';
|
2021-03-23 00:23:38 +01:00
|
|
|
$name = self::$TEST_CIRCLES[0];
|
|
|
|
$owner = $this->getInstanceUsers($localInstanceId)[1];
|
2021-04-23 12:09:06 +02:00
|
|
|
$dataCreatedCircle001 =
|
|
|
|
$this->occ($localInstanceId, 'circles:manage:create --type user ' . $owner . ' ' . $name);
|
2021-03-23 00:23:38 +01:00
|
|
|
/** @var Circle $createdCircle */
|
|
|
|
$createdCircle = $this->deserialize($dataCreatedCircle001, Circle::class);
|
|
|
|
$this->circles[$localInstanceId][$createdCircle->getName()] = $createdCircle;
|
2021-04-20 14:59:19 +02:00
|
|
|
$this->r(true, $createdCircle->getSingleId());;
|
2021-03-21 13:30:48 +01:00
|
|
|
|
|
|
|
$this->p('Comparing data returned at creation');
|
2021-04-20 14:59:19 +02:00
|
|
|
if ($createdCircle->getSingleId() === '' || $createdCircle->getOwner()->getId() === '') {
|
2021-03-21 13:30:48 +01:00
|
|
|
throw new InvalidItemException('empty id or owner.member_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
$knownOwner = new Member();
|
|
|
|
$knownOwner->importFromIFederatedUser($this->federatedUsers[$localInstanceId][$owner]);
|
2021-04-20 14:59:19 +02:00
|
|
|
$knownOwner->setCircleId($createdCircle->getSingleId());
|
2021-03-21 13:30:48 +01:00
|
|
|
$knownOwner->setLevel(Member::LEVEL_OWNER);
|
|
|
|
$knownOwner->setStatus(Member::STATUS_MEMBER);
|
2021-03-23 00:23:38 +01:00
|
|
|
$knownOwner->setId($createdCircle->getOwner()->getId());
|
2021-03-21 13:30:48 +01:00
|
|
|
|
|
|
|
$compareTo = new Circle();
|
|
|
|
$compareTo->setOwner($knownOwner)
|
2021-04-20 14:59:19 +02:00
|
|
|
->setSingleId($createdCircle->getSingleId())
|
2021-03-21 13:30:48 +01:00
|
|
|
->setInitiator($knownOwner)
|
|
|
|
->setConfig(Circle::CFG_CIRCLE)
|
|
|
|
->setName($name)
|
|
|
|
->setDisplayName($name);
|
2021-04-20 14:59:19 +02:00
|
|
|
echo json_encode($createdCircle, JSON_PRETTY_PRINT);
|
2021-03-23 00:23:38 +01:00
|
|
|
$this->confirmCircleData($createdCircle, $compareTo, 'circle', true);
|
2021-03-21 13:30:48 +01:00
|
|
|
$this->r();
|
|
|
|
|
|
|
|
|
|
|
|
$this->p('Comparing local stored data');
|
2021-04-20 14:59:19 +02:00
|
|
|
$dataCircle = $this->occ($localInstanceId, 'circle:manage:details ' . $createdCircle->getSingleId());
|
2021-03-21 13:30:48 +01:00
|
|
|
|
|
|
|
/** @var Circle $tmpCircle */
|
|
|
|
$tmpCircle = $this->deserialize($dataCircle, Circle::class);
|
2021-03-23 00:23:38 +01:00
|
|
|
$this->confirmCircleData($tmpCircle, $createdCircle);
|
2021-04-20 14:59:19 +02:00
|
|
|
$this->r(true, $tmpCircle->getSingleId());
|
2021-03-21 13:30:48 +01:00
|
|
|
|
|
|
|
$links = $this->getConfigArray('global-scale-1', 'remote');
|
|
|
|
foreach ($this->getInstances(false) as $instanceId) {
|
|
|
|
$this->p('Comparing data stored on ' . $instanceId);
|
|
|
|
$dataCircle =
|
2021-04-20 14:59:19 +02:00
|
|
|
$this->occ($instanceId, 'circle:manage:details ' . $createdCircle->getSingleId(), false);
|
2021-03-21 13:30:48 +01:00
|
|
|
|
|
|
|
if ($instanceId === $localInstanceId || $links[$instanceId] === 'GlobalScale') {
|
|
|
|
/** @var Circle $tmpCircle */
|
|
|
|
$tmpCircle = $this->deserialize($dataCircle, Circle::class);
|
|
|
|
// we reset some data that should not be available on remote instance
|
2021-03-23 00:23:38 +01:00
|
|
|
$createdCircle->setInitiator(null)
|
|
|
|
->getOwner()->setBasedOn(null);
|
|
|
|
$this->confirmCircleData($tmpCircle, $createdCircle);
|
2021-04-20 14:59:19 +02:00
|
|
|
$this->r(true, $tmpCircle->getSingleId());
|
2021-03-21 13:30:48 +01:00
|
|
|
} else {
|
|
|
|
if (is_null($dataCircle)) {
|
|
|
|
$this->r(true, 'empty');
|
|
|
|
} else {
|
|
|
|
$this->r(false, 'should be empty');
|
|
|
|
}
|
2021-03-17 13:48:41 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-21 13:30:48 +01:00
|
|
|
}
|
2021-03-17 13:48:41 +01:00
|
|
|
|
2021-03-21 13:30:48 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws InvalidItemException
|
|
|
|
* @throws ItemNotFoundException
|
2021-03-23 00:23:38 +01:00
|
|
|
* @throws CircleNotFoundException
|
2021-03-21 13:30:48 +01:00
|
|
|
*/
|
2021-03-23 00:23:38 +01:00
|
|
|
private function addLocalMemberByUserId() {
|
|
|
|
$this->p('Adding local user as member, based on userId');
|
|
|
|
|
2021-04-20 14:59:19 +02:00
|
|
|
$instanceId = 'global-scale-1';
|
|
|
|
$circleName = self::$TEST_CIRCLES[0];
|
|
|
|
$member = $this->getInstanceUsers($instanceId)[2];
|
2021-03-23 00:23:38 +01:00
|
|
|
|
2021-04-20 14:59:19 +02:00
|
|
|
$addedMember = $this->processMemberAdd($instanceId, $circleName, $member, 'user');
|
|
|
|
$this->r(true, $addedMember->getId());;
|
2021-03-23 00:23:38 +01:00
|
|
|
|
2021-04-20 14:59:19 +02:00
|
|
|
// check test2
|
2021-03-23 00:23:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws CircleNotFoundException
|
|
|
|
* @throws InvalidItemException
|
|
|
|
* @throws ItemNotFoundException
|
|
|
|
*/
|
|
|
|
private function addLocalMemberBySingleId() {
|
|
|
|
$this->p('Adding local user as member, based on singleId');
|
|
|
|
|
|
|
|
$localInstanceId = 'global-scale-1';
|
|
|
|
$name = self::$TEST_CIRCLES[0];
|
|
|
|
$circle = $this->getCircleByName($localInstanceId, $name);
|
|
|
|
$userId = $this->getInstanceUsers($localInstanceId)[6];
|
|
|
|
$userCircle = $this->getCircleByName($localInstanceId, 'user:' . $userId);
|
|
|
|
$user = $userCircle->getOwner();
|
|
|
|
$dataAddedMember =
|
|
|
|
$this->occ(
|
2021-04-20 14:59:19 +02:00
|
|
|
$localInstanceId, 'circles:members:add ' . $circle->getSingleId() . ' ' . $user->getSingleId()
|
2021-03-23 00:23:38 +01:00
|
|
|
);
|
|
|
|
/** @var Member $addedMember */
|
|
|
|
$addedMember = $this->deserialize($dataAddedMember, Member::class);
|
|
|
|
$this->r(true, $addedMember->getId());;
|
|
|
|
|
|
|
|
// check test6
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private function addLocalMemberUsingMember() {
|
|
|
|
$this->p('Adding local member using local Member');
|
2021-04-20 14:59:19 +02:00
|
|
|
$localInstanceId = 'global-scale-1';
|
|
|
|
$initiator = $this->getInstanceUsers($localInstanceId)[6];
|
|
|
|
$member = $this->getInstanceUsers($localInstanceId)[6];
|
|
|
|
$circleName = self::$TEST_CIRCLES[0];
|
|
|
|
|
|
|
|
$circle = $this->getCircleByName($localInstanceId, $circleName);
|
|
|
|
$userId = $this->getInstanceUsers($localInstanceId)[6];
|
|
|
|
$userCircle = $this->getCircleByName($localInstanceId, 'user:' . $userId);
|
|
|
|
$user = $userCircle->getOwner();
|
|
|
|
$dataAddedMember =
|
|
|
|
$this->occ(
|
|
|
|
$localInstanceId, 'circles:members:add ' . $circle->getSingleId() . ' ' . $user->getSingleId()
|
|
|
|
);
|
|
|
|
/** @var Member $addedMember */
|
|
|
|
$addedMember = $this->deserialize($dataAddedMember, Member::class);
|
|
|
|
$this->r(true, $addedMember->getId());;
|
2021-03-23 00:23:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function levelLocalMemberToModerator() {
|
|
|
|
$this->p('Changing local level to Moderator');
|
|
|
|
}
|
|
|
|
|
|
|
|
private function addLocalMemberUsingModerator() {
|
|
|
|
$this->p('Adding local member using local Moderator');
|
|
|
|
}
|
|
|
|
|
|
|
|
private function levelLocalMemberToModeratorUsingModerator() {
|
|
|
|
// fail
|
|
|
|
$this->p('Changing local level to moderator using local Moderator');
|
|
|
|
}
|
|
|
|
|
|
|
|
private function addRemoteMemberUsingModerator() {
|
|
|
|
$this->p('Adding remote user using local Moderator');
|
|
|
|
}
|
|
|
|
|
|
|
|
private function addLocalMemberUsingRemoteMember() {
|
|
|
|
// fail
|
|
|
|
$this->p('Adding local user using remote Member');
|
|
|
|
}
|
|
|
|
|
|
|
|
private function addRemoteMemberUsingRemoteMember() {
|
|
|
|
// fail
|
|
|
|
$this->p('Adding remote user using remote Member');
|
|
|
|
}
|
|
|
|
|
|
|
|
private function levelRemoteMemberToAdmin() {
|
|
|
|
$this->p('Changing remote level to Admin');
|
|
|
|
}
|
|
|
|
|
|
|
|
private function addLocalMemberUsingRemoteAdmin() {
|
|
|
|
$this->p('Adding remote member using remote Admin');
|
2021-03-17 13:48:41 +01:00
|
|
|
}
|
2021-03-21 14:19:21 +01:00
|
|
|
|
2021-03-23 00:23:38 +01:00
|
|
|
private function addRemoteMemberUsingRemoteAdmin() {
|
|
|
|
$this->p('Adding remote member using remote Admin');
|
|
|
|
}
|
|
|
|
|
|
|
|
private function levelRemoteMemberToModeratorUsingRemoteAdmin() {
|
|
|
|
}
|
|
|
|
|
|
|
|
private function levelRemoteMemberToAdminUsingRemoteAdmin() {
|
|
|
|
// fail
|
|
|
|
}
|
|
|
|
|
|
|
|
private function verifyMemberList001() {
|
|
|
|
}
|
|
|
|
|
|
|
|
private function removeLocalMemberUsingRemoteMember() {
|
2021-04-20 14:59:19 +02:00
|
|
|
// fail
|
2021-03-23 00:23:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private function removeLocalMemberUsingRemoteAdmin() {
|
|
|
|
}
|
|
|
|
|
2021-04-20 14:59:19 +02:00
|
|
|
|
2021-03-23 00:23:38 +01:00
|
|
|
private function removeRemoteMemberUsingRemoteMember() {
|
|
|
|
// fail
|
|
|
|
}
|
|
|
|
|
|
|
|
private function removeRemoteMemberUsingRemoteAdmin() {
|
|
|
|
}
|
2021-03-17 13:48:41 +01:00
|
|
|
|
2021-03-15 02:30:51 +01:00
|
|
|
/**
|
|
|
|
* @param Circle $circle
|
|
|
|
* @param Circle $compareTo
|
2021-03-21 13:30:48 +01:00
|
|
|
* @param string $prefix
|
|
|
|
* @param bool $versa
|
|
|
|
* @param array $params
|
2021-03-15 02:30:51 +01:00
|
|
|
*
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2021-03-21 13:30:48 +01:00
|
|
|
private function confirmCircleData(
|
|
|
|
Circle $circle,
|
|
|
|
Circle $compareTo,
|
|
|
|
string $prefix = 'circle',
|
|
|
|
bool $versa = false,
|
|
|
|
array $params = []
|
|
|
|
) {
|
|
|
|
|
|
|
|
if (empty($params)) {
|
|
|
|
$params = [
|
2021-04-20 14:59:19 +02:00
|
|
|
'CIRCLEID' => $circle->getSingleId()
|
2021-03-21 13:30:48 +01:00
|
|
|
];
|
2021-03-15 02:30:51 +01:00
|
|
|
}
|
2021-03-17 13:48:41 +01:00
|
|
|
|
2021-04-20 14:59:19 +02:00
|
|
|
$this->compare($compareTo->getSingleId(), $circle->getSingleId(), $prefix . '.id', $params);
|
2021-03-21 13:30:48 +01:00
|
|
|
$this->compare($compareTo->getName(), $circle->getName(), $prefix . '.name', $params);
|
|
|
|
$this->compare(
|
|
|
|
$compareTo->getDisplayName(), $circle->getDisplayName(), $prefix . '.displayName', $params
|
|
|
|
);
|
2021-03-23 00:23:38 +01:00
|
|
|
$this->compareInt($compareTo->getConfig(), $circle->getConfig(), $prefix . '.config', true);
|
|
|
|
$this->compareInt($compareTo->getSource(), $circle->getSource(), $prefix . '.source');
|
2021-03-21 13:30:48 +01:00
|
|
|
|
|
|
|
if ($compareTo->hasOwner()) {
|
|
|
|
$compareToOwner = $compareTo->getOwner();
|
|
|
|
if ($compareToOwner !== null) {
|
|
|
|
$owner = $circle->getOwner();
|
|
|
|
if ($owner === null) {
|
|
|
|
throw new Exception('empty owner');
|
2021-03-17 13:48:41 +01:00
|
|
|
}
|
2021-04-20 14:59:19 +02:00
|
|
|
if ($owner->getCircleId() !== $circle->getSingleId()) {
|
2021-03-21 13:30:48 +01:00
|
|
|
throw new Exception($prefix . '.owner.circleId is different than ' . $prefix . '.id');
|
2021-03-17 13:48:41 +01:00
|
|
|
}
|
2021-03-21 13:30:48 +01:00
|
|
|
$this->confirmMemberData($owner, $compareToOwner, 'owner', false, $params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ($compareTo->hasInitiator()) {
|
|
|
|
$compareToInitiator = $compareTo->getInitiator();
|
|
|
|
if ($compareToInitiator !== null) {
|
|
|
|
if (!$circle->hasInitiator()) {
|
|
|
|
throw new Exception('empty initiator');
|
2021-03-17 13:48:41 +01:00
|
|
|
}
|
2021-03-21 13:30:48 +01:00
|
|
|
$initiator = $circle->getInitiator();
|
2021-04-20 14:59:19 +02:00
|
|
|
if ($initiator->getCircleId() !== $circle->getSingleId()) {
|
2021-03-21 13:30:48 +01:00
|
|
|
throw new Exception($prefix . '.initiator.circleId is different than ' . $prefix . '.id');
|
2021-03-17 13:48:41 +01:00
|
|
|
}
|
2021-03-21 13:30:48 +01:00
|
|
|
$this->confirmMemberData($initiator, $compareToInitiator, 'owner', false, $params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($versa) {
|
|
|
|
$this->confirmCircleData($compareTo, $circle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Member $member
|
|
|
|
* @param Member $compareTo
|
|
|
|
* @param string $prefix
|
|
|
|
* @param bool $versa
|
|
|
|
* @param array $params
|
|
|
|
*
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
private function confirmMemberData(
|
|
|
|
Member $member,
|
|
|
|
Member $compareTo,
|
|
|
|
string $prefix = 'member',
|
|
|
|
bool $versa = false,
|
|
|
|
array $params = []
|
|
|
|
) {
|
|
|
|
$this->compare($compareTo->getId(), $member->getId(), $prefix . '.id', $params);
|
|
|
|
$this->compare($compareTo->getCircleId(), $member->getCircleId(), $prefix . '.circleId', $params);
|
|
|
|
$this->compare($compareTo->getSingleId(), $member->getSingleId(), $prefix . '.singleId', $params);
|
|
|
|
$this->compare($compareTo->getUserId(), $member->getUserId(), $prefix . '.userId', $params);
|
|
|
|
$this->compare(
|
|
|
|
$compareTo->getDisplayName(), $member->getDisplayName(), $prefix . '.displayName', $params
|
|
|
|
);
|
2021-03-23 00:23:38 +01:00
|
|
|
$this->compareInt($compareTo->getUserType(), $member->getUserType(), $prefix . '.userType');
|
2021-03-21 13:30:48 +01:00
|
|
|
$this->compare($compareTo->getInstance(), $member->getInstance(), $prefix . '.instance', $params);
|
2021-03-23 00:23:38 +01:00
|
|
|
$this->compareInt($compareTo->getLevel(), $member->getLevel(), $prefix . '.level', true);
|
2021-03-21 13:30:48 +01:00
|
|
|
$this->compare($compareTo->getStatus(), $member->getStatus(), $prefix . '.status', $params);
|
|
|
|
|
|
|
|
$compareToBasedOn = $compareTo->getBasedOn();
|
|
|
|
if ($compareToBasedOn !== null) {
|
|
|
|
$basedOn = $member->getBasedOn();
|
|
|
|
if ($basedOn === null) {
|
|
|
|
throw new Exception('empty ' . $prefix . '.basedOn');
|
2021-03-17 13:48:41 +01:00
|
|
|
}
|
2021-03-21 13:30:48 +01:00
|
|
|
$this->confirmCircleData($basedOn, $compareToBasedOn, $prefix . '.basedOn', false, $params);
|
2021-03-15 02:30:51 +01:00
|
|
|
}
|
|
|
|
|
2020-08-07 04:56:45 +02:00
|
|
|
}
|
|
|
|
|
2020-12-03 22:30:51 +01:00
|
|
|
|
2021-03-21 13:30:48 +01:00
|
|
|
/**
|
|
|
|
* @param string $expected
|
|
|
|
* @param string $compare
|
|
|
|
* @param string $def
|
|
|
|
* @param array $params
|
|
|
|
*
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
private function compare(string $expected, string $compare, string $def, array $params) {
|
|
|
|
if ($expected !== ''
|
|
|
|
&& $this->feedStringWithParams($expected, $params) !== $compare) {
|
|
|
|
throw new Exception($def . ': ' . $compare . ' (' . $expected . ')');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $expected
|
|
|
|
* @param int $compare
|
|
|
|
* @param string $def
|
|
|
|
* @param array $params
|
|
|
|
* @param bool $force
|
|
|
|
*
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
2021-03-23 00:23:38 +01:00
|
|
|
private function compareInt(int $expected, int $compare, string $def, bool $force = false) {
|
2021-03-21 13:30:48 +01:00
|
|
|
if (($expected > 0 || ($force && $expected >= 0))
|
|
|
|
&& $expected !== $compare) {
|
|
|
|
throw new Exception('wrong ' . $def . ': ' . $compare . ' (' . $expected . ')');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-03 22:30:51 +01:00
|
|
|
/**
|
2021-03-15 02:30:51 +01:00
|
|
|
* @param bool $localIncluded
|
2021-03-13 23:32:10 +01:00
|
|
|
*
|
2021-03-15 02:30:51 +01:00
|
|
|
* @return array
|
2020-12-03 22:30:51 +01:00
|
|
|
*/
|
2021-03-15 02:30:51 +01:00
|
|
|
private function getInstances(bool $localIncluded = true): array {
|
|
|
|
$instances = self::$INSTANCES;
|
|
|
|
if (!$localIncluded) {
|
|
|
|
$instances = array_diff($instances, [$this->local]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $instances;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-21 13:30:48 +01:00
|
|
|
/**
|
|
|
|
* @param array $circles
|
|
|
|
* @param string $userId
|
|
|
|
* @param string $instance
|
|
|
|
*
|
|
|
|
* @return Circle
|
|
|
|
* @throws CircleNotFoundException
|
|
|
|
*/
|
|
|
|
private function getSingleCircleForMember(array $circles, string $userId, string $instance): Circle {
|
|
|
|
foreach ($circles as $circle) {
|
|
|
|
$owner = $circle->getOwner();
|
|
|
|
if ($owner->getUserId() === $userId && $owner->getInstance() === $instance) {
|
|
|
|
return $circle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new CircleNotFoundException('cannot find ' . $userId . ' in the list of Single Circle');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-23 00:23:38 +01:00
|
|
|
/**
|
|
|
|
* @param string $instanceId
|
|
|
|
* @param string $name
|
|
|
|
*
|
|
|
|
* @return Circle
|
|
|
|
* @throws CircleNotFoundException
|
|
|
|
*/
|
|
|
|
private function getCircleByName(string $instanceId, string $name): Circle {
|
|
|
|
if (array_key_exists($instanceId, $this->circles)
|
|
|
|
&& array_key_exists($name, $this->circles[$instanceId])) {
|
|
|
|
return $this->circles[$instanceId][$name];
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new CircleNotFoundException(
|
|
|
|
'cannot extract \'' . $name . '\' from the list of generated Circles'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-21 13:30:48 +01:00
|
|
|
/**
|
|
|
|
* @param array $circles
|
|
|
|
* @param string $name
|
|
|
|
*
|
|
|
|
* @return Circle
|
|
|
|
* @throws CircleNotFoundException
|
|
|
|
*/
|
2021-03-23 00:23:38 +01:00
|
|
|
private function getCircleFromList(array $circles, string $name): Circle {
|
2021-03-21 13:30:48 +01:00
|
|
|
foreach ($circles as $circle) {
|
|
|
|
if ($circle->getName() === $name) {
|
|
|
|
return $circle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-23 00:23:38 +01:00
|
|
|
throw new CircleNotFoundException(
|
|
|
|
'cannot extract \'' . $name . '\' from the list of provided Circles'
|
|
|
|
);
|
2021-03-21 13:30:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-15 02:30:51 +01:00
|
|
|
/**
|
|
|
|
* @param string $instance
|
|
|
|
* @param string $key
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @throws ItemNotFoundException
|
|
|
|
*/
|
|
|
|
private function getConfig(string $instance, string $key): string {
|
|
|
|
$config = $this->getConfigInstance($instance);
|
|
|
|
|
|
|
|
return $this->get($key, $config);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $instance
|
|
|
|
* @param string $key
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @throws ItemNotFoundException
|
|
|
|
*/
|
|
|
|
private function getConfigArray(string $instance, string $key): array {
|
|
|
|
$config = $this->getConfigInstance($instance);
|
|
|
|
|
|
|
|
return $this->getArray($key, $config);
|
2021-03-13 23:32:10 +01:00
|
|
|
}
|
2020-12-03 22:30:51 +01:00
|
|
|
|
|
|
|
|
2021-03-13 23:32:10 +01:00
|
|
|
/**
|
|
|
|
* @param string $instance
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @throws ItemNotFoundException
|
|
|
|
*/
|
|
|
|
private function getConfigInstance(string $instance): array {
|
|
|
|
foreach ($this->getArray('instances', $this->config) as $item) {
|
|
|
|
if (strtolower($this->get('id', $item)) === strtolower($instance)) {
|
|
|
|
return $item;
|
|
|
|
}
|
2020-12-03 22:30:51 +01:00
|
|
|
}
|
|
|
|
|
2021-03-15 02:30:51 +01:00
|
|
|
throw new ItemNotFoundException($instance . ' not found');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-23 00:23:38 +01:00
|
|
|
/**
|
|
|
|
* @param $instanceId
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @throws ItemNotFoundException
|
|
|
|
*/
|
|
|
|
private function getInstanceUsers($instanceId): array {
|
|
|
|
return $this->getConfigArray($instanceId, 'users');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-15 02:30:51 +01:00
|
|
|
/**
|
|
|
|
* @param string $instance
|
|
|
|
* @param string $cmd
|
|
|
|
* @param bool $exceptionOnFail
|
|
|
|
* @param bool $jsonAsOutput
|
2021-04-20 14:59:19 +02:00
|
|
|
* @param array $env
|
2021-03-15 02:30:51 +01:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
* @throws ItemNotFoundException
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
private function occ(
|
|
|
|
string $instance,
|
|
|
|
string $cmd,
|
|
|
|
bool $exceptionOnFail = true,
|
2021-04-20 14:59:19 +02:00
|
|
|
bool $jsonAsOutput = true,
|
|
|
|
array $env = []
|
2021-03-15 02:30:51 +01:00
|
|
|
): ?array {
|
|
|
|
$configInstance = $this->getConfigInstance($instance);
|
|
|
|
$path = $this->get('path', $configInstance);
|
|
|
|
$occ = rtrim($path, '/') . '/occ';
|
|
|
|
|
|
|
|
$command = array_merge([$occ], explode(' ', $cmd));
|
|
|
|
if ($jsonAsOutput) {
|
|
|
|
$command = array_merge($command, ['--output=json']);
|
|
|
|
}
|
|
|
|
$process = new Process($command);
|
2021-04-20 14:59:19 +02:00
|
|
|
$process->run(null, $env);
|
2021-03-15 02:30:51 +01:00
|
|
|
|
|
|
|
if ($exceptionOnFail && !$process->isSuccessful()) {
|
|
|
|
throw new Exception(implode(' ', $command) . ' failed');
|
|
|
|
}
|
|
|
|
|
|
|
|
$output = json_decode($process->getOutput(), true);
|
|
|
|
if (!is_array($output)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $title
|
|
|
|
*/
|
|
|
|
private function t(string $title): void {
|
|
|
|
$this->output->writeln('');
|
|
|
|
$this->output->writeln('<comment>### ' . $title . '</comment>');
|
|
|
|
$this->output->writeln('');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $processing
|
|
|
|
*/
|
|
|
|
private function p(string $processing): void {
|
|
|
|
$this->pOn = true;
|
|
|
|
$this->output->write('- ' . $processing . ': ');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $more
|
|
|
|
*/
|
|
|
|
private function pm(string $more): void {
|
|
|
|
$this->output->write($more . ' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param bool $result
|
|
|
|
* @param string $info
|
|
|
|
*/
|
|
|
|
private function r(bool $result = true, string $info = ''): void {
|
|
|
|
$this->pOn = false;
|
|
|
|
if ($result) {
|
|
|
|
$this->output->writeln('<info>' . (($info !== '') ? $info : 'done') . '</info>');
|
|
|
|
} else {
|
2021-03-16 14:31:04 +01:00
|
|
|
$this->output->writeln('<error>' . (($info !== '') ? $info : 'done') . '</error>');
|
2021-03-15 02:30:51 +01:00
|
|
|
}
|
2020-12-03 22:30:51 +01:00
|
|
|
}
|
|
|
|
|
2021-04-20 14:59:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $instanceId
|
|
|
|
* @param string $circleName
|
|
|
|
* @param string $userId
|
|
|
|
* @param string $type
|
|
|
|
*
|
|
|
|
* @return Member
|
|
|
|
* @throws CircleNotFoundException
|
|
|
|
* @throws InvalidItemException
|
|
|
|
* @throws ItemNotFoundException
|
|
|
|
*/
|
|
|
|
private function processMemberAdd(string $instanceId, string $circleName, string $userId, string $type
|
|
|
|
): Member {
|
|
|
|
$circle = $this->getCircleByName($instanceId, $circleName);
|
|
|
|
$dataAddedMember =
|
|
|
|
$this->occ(
|
2021-04-23 12:09:06 +02:00
|
|
|
$instanceId,
|
|
|
|
'circles:members:add ' . $circle->getSingleId() . ' ' . $userId . ' --type ' . $type
|
2021-04-20 14:59:19 +02:00
|
|
|
);
|
|
|
|
/** @var Member $addedMember */
|
|
|
|
$addedMember = $this->deserialize($dataAddedMember, Member::class);
|
|
|
|
|
|
|
|
|
|
|
|
echo 'ADDEDMEMBER: ' . json_encode($addedMember, JSON_PRETTY_PRINT) . "\n";
|
|
|
|
|
|
|
|
$federatedUser = $this->federatedUsers[$instanceId][$userId];
|
|
|
|
echo 'FEDERATEDUER: ' . json_encode($federatedUser, JSON_PRETTY_PRINT) . "\n";
|
|
|
|
|
|
|
|
return $addedMember;
|
|
|
|
}
|
|
|
|
|
2020-06-11 13:30:38 +02:00
|
|
|
}
|
|
|
|
|