1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package File manager |
5
|
|
|
* @author Iurii Makukh <[email protected]> |
6
|
|
|
* @copyright Copyright (c) 2017, Iurii Makukh <[email protected]> |
7
|
|
|
* @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL-3.0+ |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace gplcart\modules\file_manager\handlers\commands; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Contains methods for "move" command |
14
|
|
|
*/ |
15
|
|
|
class Move extends Command |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Whether the command is allowed for the file |
20
|
|
|
* @param \SplFileInfo $file |
21
|
|
|
* @return bool |
22
|
|
|
*/ |
23
|
|
|
public function allowed($file) |
24
|
|
|
{ |
25
|
|
|
return in_array($file->getType(), array('file', 'dir')) && !$this->isInitialPath($file); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Returns an array of data used to display the command |
30
|
|
|
* @return array |
31
|
|
|
*/ |
32
|
|
|
public function view() |
33
|
|
|
{ |
34
|
|
|
return array('file_manager|commands/move' => array('path' => $this->getRelativePath())); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Moves submitted files to another destination |
39
|
|
|
* @param \gplcart\core\Controller $controller |
40
|
|
|
* @return array |
41
|
|
|
*/ |
42
|
|
|
public function submit($controller) |
43
|
|
|
{ |
44
|
|
|
set_time_limit(0); |
45
|
|
|
|
46
|
|
|
$submitted = $controller->getSubmitted(); |
47
|
|
|
|
48
|
|
|
$destination = null; |
49
|
|
|
$errors = $success = 0; |
50
|
|
|
foreach ($submitted['files'] as $index => $file) { |
51
|
|
|
|
52
|
|
|
if (empty($submitted['destinations'][$index])) { |
53
|
|
|
$errors++; |
54
|
|
|
continue; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$destination = $submitted['destinations'][$index]; |
58
|
|
|
|
59
|
|
|
/* @var $file \SplFileInfo */ |
60
|
|
|
if ($this->move($file->getRealPath(), $submitted['destinations'][$index])) { |
61
|
|
|
$success++; |
62
|
|
|
} else { |
63
|
|
|
$errors++; |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$query = array( |
68
|
|
|
'cmd' => 'list', |
69
|
|
|
'path' => isset($destination) ? dirname($this->getRelativeFilePath($destination)) : '' |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
$vars = array('@num_errors' => $errors, '@num_success' => $success); |
73
|
|
|
|
74
|
|
|
return array( |
75
|
|
|
'redirect' => $controller->url('', $query), |
76
|
|
|
'severity' => empty($errors) ? 'success' : 'warning', |
77
|
|
|
'message' => $this->translation->text('Moved @num_success file(s), errors: @num_errors', $vars) |
78
|
|
|
); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
} |
82
|
|
|
|