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
|
|
|
use Exception; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* File System Task - Move a File |
19
|
|
|
* |
20
|
|
|
* @author Andrés Montañez <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class MoveTask extends AbstractFileTask |
23
|
|
|
{ |
24
|
48 |
|
public function getName(): string |
25
|
|
|
{ |
26
|
48 |
|
return 'fs/move'; |
27
|
|
|
} |
28
|
|
|
|
29
|
4 |
|
public function getDescription(): string |
30
|
|
|
{ |
31
|
|
|
try { |
32
|
4 |
|
return sprintf('[FS] Move "%s" to "%s"', $this->getFile('from'), $this->getFile('to')); |
33
|
1 |
|
} catch (Exception $exception) { |
34
|
1 |
|
return '[FS] Move [missing parameters]'; |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
4 |
|
public function execute(): bool |
39
|
|
|
{ |
40
|
4 |
|
$moveFrom = $this->getFile('from'); |
41
|
3 |
|
$moveTo = $this->getFile('to'); |
42
|
3 |
|
$flags = $this->options['flags']; |
43
|
|
|
|
44
|
3 |
|
$cmd = sprintf('mv %s "%s" "%s"', $flags, $moveFrom, $moveTo); |
45
|
|
|
|
46
|
|
|
/** @var Process $process */ |
47
|
3 |
|
$process = $this->runtime->runCommand($cmd); |
48
|
|
|
|
49
|
3 |
|
return $process->isSuccessful(); |
50
|
|
|
} |
51
|
|
|
|
52
|
4 |
|
protected function getParameters(): array |
53
|
|
|
{ |
54
|
4 |
|
return ['from', 'to', 'flags']; |
55
|
|
|
} |
56
|
|
|
|
57
|
4 |
|
public function getDefaults(): array |
58
|
|
|
{ |
59
|
4 |
|
return ['flags' => null]; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|