blob: aeed24af0fd57bd1cace392bde32d11816e26980 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
<?php
/**
* @author stev leibelt <artodeto@bazzline.net>
* @since 2014-08-12
*/
/**
* Class Command_User_Delete
*/
class Command_User_Delete extends Command_User_AbstractCommand
{
/**
* @var int
*/
private $inputId;
/**
* @throws Exception
*/
public function execute()
{
reset($this->users);
$lines = $this->file->read();
$content = array();
foreach ($lines as $line) {
if ($line == '$users[0][\'channels\'] = array(0);') {
$content[] = $line;
$content[] = '';
break;
} else {
$content[] = $line;
}
}
unset($this->users[0]);
if (empty($this->users)) {
throw new Exception(
'nothing to delete'
);
} else {
unset($this->users[$this->inputId]);
$idToUser = array_values($this->users);
if (!empty($idToUser)) {
foreach ($idToUser as $id => $user) {
++$id; //we have to increase by one since we have to prevent overwriting the "0" user
$content[] = '// updated - ' . date('Y-m-d H:i:s');
$content[] = '$users[' . $id . '] = array();';
$content[] = '$users[' . $id . '][\'userRole\'] = ' . $this->roles[$user['userRole']] . ';';
$content[] = '$users[' . $id . '][\'userName\'] = \'' . $user['userName'] . '\';';
$content[] = '$users[' . $id . '][\'password\'] = \'' . $user['password'] . '\';';
$content[] = '$users[' . $id . '][\'channels\'] = array(' . implode(',', $user['channels']) . ');';
}
}
$this->file->write($content);
}
}
/**
* @return array
*/
public function getUsage()
{
$users = $this->users;
unset($users[0]);
return array(
'userid=<id>',
' available users: ' . implode(',', array_keys($users))
);
}
/**
* @throws Exception
*/
public function verify()
{
if ($this->input->getNumberOfArguments() !== 1) {
throw new Exception(
'invalid number of arguments provided'
);
}
$validIds = array_keys($this->users);
$userId = $this->input->getParameterValue('user_id');
if (!isset($validIds[$userId])) {
throw new Exception(
'invalid id "' . $userId . '" provided'
);
}
if ($userId === 0) {
throw new Exception(
'you are not allowed to delete id "' . $userId . '"'
);
}
$this->inputId = $userId;
}
}
|