/
replace.php
102 lines (90 loc) · 2.53 KB
/
replace.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
<?php
namespace Concrete\Controller\Dialog\File;
use Concrete\Core\Entity\File\File;
use Concrete\Core\Permission\Checker;
use Doctrine\ORM\EntityManagerInterface;
class Replace extends Import
{
/**
* The file being replaced (false: not yet initialized; null: not found; File otherwise).
*
* @var \Concrete\Core\Entity\File\File|null|false
*/
private $replacingFile = false;
/**
* {@inheritdoc}
*
* @see \Concrete\Controller\Dialog\File\Import::setViewSets()
*/
protected function setViewSets()
{
parent::setViewSets();
$this->set('replacingFile', $this->getReplacingFile());
}
/**
* Get the file being replaced.
*
* @return \Concrete\Core\Entity\File\File|null null if not found, a File instance otherwise
*/
protected function getReplacingFile()
{
if ($this->replacingFile === false) {
$replacingFile = null;
$fID = $this->request->request->get('fID', $this->request->query->get('fID'));
if ($fID && is_scalar($fID)) {
$fID = (int) $fID;
if ($fID !== 0) {
$replacingFile = $this->app->make(EntityManagerInterface::class)->find(File::class, $fID);
}
}
$this->setReplacingFile($replacingFile);
}
return $this->replacingFile;
}
/**
* Set the file being replaced.
*
* @param \Concrete\Core\Entity\File\File|null $value null if not found, a File instance otherwise
*
* @return $this
*/
protected function setReplacingFile(File $value = null)
{
if ($value !== $this->replacingFile) {
$this->replacingFile = $value;
}
return $this;
}
/**
* {@inheritdoc}
*
* @see \Concrete\Controller\Dialog\File\Import::getCurrentFolder()
*/
protected function getCurrentFolder()
{
return null;
}
/**
* {@inheritdoc}
*
* @see \Concrete\Controller\Dialog\File\Import::getOriginalPage()
*/
protected function getOriginalPage()
{
return null;
}
/**
* {@inheritdoc}
*
* @see \Concrete\Controller\Dialog\File\Import::canAccess()
*/
protected function canAccess()
{
$replacingFile = $this->getReplacingFile();
if ($replacingFile === null) {
return false;
}
$replacingFilePermissions = new Checker($replacingFile);
return $replacingFilePermissions->canEditFileContents();
}
}