/
storage.php
124 lines (112 loc) · 4.05 KB
/
storage.php
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
namespace Concrete\Controller\Dialog\File\Bulk;
use Concrete\Controller\Backend\UserInterface as BackendInterfaceController;
use Concrete\Core\File\EditResponse;
use Concrete\Core\File\File;
use Concrete\Core\File\Set\Set;
use Concrete\Core\File\StorageLocation\StorageLocationFactory;
use Concrete\Core\Foundation\Queue\QueueService;
use Concrete\Core\Http\ResponseFactoryInterface;
use Concrete\Core\View\View;
use Permissions;
use Exception;
use stdClass;
class Storage extends BackendInterfaceController
{
public $helpers = array('form');
protected $viewPath = '/dialogs/file/bulk/storage';
protected $files = array();
protected $canEdit = false;
public function on_start()
{
parent::on_start();
$this->populateFiles();
}
protected function canAccess()
{
return $this->canEdit;
}
protected function populateFiles()
{
if (is_array($_REQUEST['fID'])) {
foreach ($_REQUEST['fID'] as $fID) {
$f = File::getByID($fID);
if (is_object($f)) {
$this->files[] = $f;
}
}
}
if (count($this->files) > 0) {
$this->canEdit = true;
foreach ($this->files as $f) {
$fp = new Permissions($f);
if (!$fp->canAdmin()) {
$this->canEdit = false;
}
}
} else {
$this->canEdit = false;
}
return $this->canEdit;
}
public function view()
{
$locations = $this->app->make(StorageLocationFactory::class)->fetchList();
$this->set('files', $this->files);
$this->set('locations', $locations);
}
public function submit()
{
$json = new \Concrete\Core\Application\EditResponse();
$err = $this->app->make('error');
if ($this->validateAction()) {
$post = $this->request->request->all();
$fsl = $this->app->make(StorageLocationFactory::class)->fetchByID($post['fslID']);
if (!is_object($fsl)) {
$err->add(t('Please select valid file storage location.'));
}
}
$json->setError($err);
return $json->outputJSON();
}
public function doChangeStorageLocation()
{
if ($this->validateAction()) {
$post = $this->request->request->all();
$fsl = $this->app->make(StorageLocationFactory::class)->fetchByID($post['fslID']);
if (is_object($fsl)) {
$fIDs = $post['fID'];
$q = $this->app->make(QueueService::class)->get('change_files_storage_location');
if ($this->request->request->get('process')) {
$obj = new stdClass();
$messages = $q->receive(5);
foreach ($messages as $key => $msg) {
$fID = $msg->body;
if ($fID !== false) {
$file = File::getByID($fID);
if (is_object($file)) {
$fp = new Permissions($file);
if ($fp->canEditFilePermissions()) {
$file->setFileStorageLocation($fsl);
}
}
}
$q->deleteMessage($msg);
}
$obj->totalItems = $q->count();
$obj->files = $fIDs;
if ($q->count() == 0) {
$q->deleteQueue();
}
return $this->app->make(ResponseFactoryInterface::class)->json($obj);
} elseif ($q->count() == 0) {
foreach ($fIDs as $fID) {
$q->send($fID);
}
}
$totalItems = $q->count();
View::element('progress_bar', ['totalItems' => $totalItems, 'totalItemsSummary' => t2('%d file', '%d files', $totalItems)]);
}
}
}
}