1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Magallanes package. |
5
|
|
|
* |
6
|
|
|
* (c) Andrés Montañez <[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 Mage\Task\BuiltIn\FS; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Process\Process; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* File System Task - Copy a File |
18
|
|
|
* |
19
|
|
|
* @author Marian Bäuerle |
20
|
|
|
*/ |
21
|
|
|
class ChangeModeTask extends AbstractFileTask |
22
|
|
|
{ |
23
|
48 |
|
public function getName(): string |
24
|
|
|
{ |
25
|
48 |
|
return 'fs/chmod'; |
26
|
|
|
} |
27
|
|
|
|
28
|
4 |
|
public function getDescription(): string |
29
|
|
|
{ |
30
|
|
|
try { |
31
|
4 |
|
return sprintf('[FS] Change mode of "%s" to "%s"', $this->getFile('file'), $this->options['mode']); |
32
|
1 |
|
} catch (\Exception $exception) { |
33
|
1 |
|
return '[FS] Chmod [missing parameters]'; |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
|
37
|
4 |
|
public function execute(): bool |
38
|
|
|
{ |
39
|
4 |
|
$file = $this->getFile('file'); |
40
|
3 |
|
$mode = $this->options['mode']; |
41
|
3 |
|
$flags = $this->options['flags']; |
42
|
|
|
|
43
|
3 |
|
$cmd = sprintf('chmod %s %s "%s"', $flags, $mode, $file); |
44
|
|
|
|
45
|
|
|
/** @var Process $process */ |
46
|
3 |
|
$process = $this->runtime->runCommand($cmd); |
47
|
|
|
|
48
|
3 |
|
return $process->isSuccessful(); |
49
|
|
|
} |
50
|
|
|
|
51
|
4 |
|
protected function getParameters(): array |
52
|
|
|
{ |
53
|
4 |
|
return ['file', 'mode', 'flags']; |
54
|
|
|
} |
55
|
|
|
|
56
|
4 |
|
public function getDefaults(): array |
57
|
|
|
{ |
58
|
4 |
|
return ['flags' => null]; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|