|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the slack-cli package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Cas Leentfaar <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace CL\SlackCli\Command; |
|
13
|
|
|
|
|
14
|
|
|
use CL\Slack\Payload\GroupsCreateChildPayload; |
|
15
|
|
|
use CL\Slack\Payload\GroupsCreateChildPayloadResponse; |
|
16
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
17
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @author Cas Leentfaar <[email protected]> |
|
21
|
|
|
*/ |
|
22
|
|
|
class GroupsCreateChildCommand extends AbstractApiCommand |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* {@inheritDoc} |
|
26
|
|
|
*/ |
|
27
|
|
|
protected function configure() |
|
28
|
|
|
{ |
|
29
|
|
|
parent::configure(); |
|
30
|
|
|
|
|
31
|
|
|
$this->setName('groups:create-child'); |
|
32
|
|
|
$this->setDescription('This method creates a child group from an existing group (see `--help`)'); |
|
33
|
|
|
$this->addArgument('group-id', InputArgument::REQUIRED, 'The name of the channel to create (must not exist already)'); |
|
34
|
|
|
$this->setHelp(<<<EOT |
|
35
|
|
|
The <info>groups:create-child</info> command takes an existing private group and performs the following steps: |
|
36
|
|
|
|
|
37
|
|
|
- Renames the existing group (from "example" to "example-archived"). |
|
38
|
|
|
- Archives the existing group. |
|
39
|
|
|
- Creates a new group with the name of the existing group. |
|
40
|
|
|
- Adds all members of the existing group to the new group. |
|
41
|
|
|
|
|
42
|
|
|
This is useful when inviting a new member to an existing group while hiding all previous chat history from them. |
|
43
|
|
|
In this scenario you can run <info>groups.createChild</info> followed by <info>groups.invite</info>. |
|
44
|
|
|
|
|
45
|
|
|
The new group will have a special `parent_group` property pointing to the original archived group. |
|
46
|
|
|
This will only be returned for members of both groups, so will not be visible to any newly invited members. |
|
47
|
|
|
|
|
48
|
|
|
For more information about the related API method, check out the official documentation: |
|
49
|
|
|
<comment>https://api.slack.com/methods/groups.createChild</comment> |
|
50
|
|
|
EOT |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @return GroupsCreateChildPayload |
|
56
|
|
|
*/ |
|
57
|
|
|
protected function createPayload() |
|
58
|
|
|
{ |
|
59
|
|
|
$payload = new GroupsCreateChildPayload(); |
|
60
|
|
|
$payload->setGroupId($this->input->getArgument('group-id')); |
|
61
|
|
|
|
|
62
|
|
|
return $payload; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* {@inheritdoc} |
|
67
|
|
|
* |
|
68
|
|
|
* @param GroupsCreateChildPayloadResponse $payloadResponse |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function handleResponse($payloadResponse) |
|
71
|
|
|
{ |
|
72
|
|
|
if ($payloadResponse->isOk()) { |
|
73
|
|
|
$this->writeOk('Successfully created child group!'); |
|
74
|
|
|
if ($this->output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL) { |
|
75
|
|
|
$data = $this->serializeObjectToArray($payloadResponse->getGroup()); |
|
76
|
|
|
$this->renderKeyValueTable($data); |
|
77
|
|
|
} |
|
78
|
|
|
} else { |
|
79
|
|
|
$this->writeError(sprintf('Failed to create child group: %s', lcfirst($payloadResponse->getErrorExplanation()))); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|