1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the puli/manager package. |
5
|
|
|
* |
6
|
|
|
* (c) Bernhard Schussek <[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 Puli\Manager\Installer; |
13
|
|
|
|
14
|
|
|
use Puli\Manager\Api\Installation\InstallationParams; |
15
|
|
|
use Puli\Manager\Api\Installer\ResourceInstaller; |
16
|
|
|
use Puli\Repository\Api\Resource\FilesystemResource; |
17
|
|
|
use Puli\Repository\Api\Resource\PuliResource; |
18
|
|
|
use Puli\Repository\FilesystemRepository; |
19
|
|
|
use Webmozart\PathUtil\Path; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Installs resources via a local filesystem copy. |
23
|
|
|
* |
24
|
|
|
* @since 1.0 |
25
|
|
|
* |
26
|
|
|
* @author Bernhard Schussek <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
class CopyInstaller implements ResourceInstaller |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* @var bool |
32
|
|
|
*/ |
33
|
|
|
protected $symlinks = false; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
*/ |
38
|
|
|
public function validateParams(InstallationParams $params) |
39
|
|
|
{ |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
7 |
|
public function installResource(PuliResource $resource, InstallationParams $params) |
46
|
|
|
{ |
47
|
7 |
|
$documentRoot = Path::makeAbsolute($params->getDocumentRoot(), $params->getRootDirectory()); |
48
|
|
|
|
49
|
7 |
|
if (!file_exists($documentRoot)) { |
50
|
7 |
|
mkdir($documentRoot, 0777, true); |
51
|
|
|
} |
52
|
|
|
|
53
|
7 |
|
$serverPath = $params->getServerPathForResource($resource); |
54
|
7 |
|
$parameterValues = $params->getParameterValues(); |
55
|
7 |
|
$relative = !isset($parameterValues['relative']) || $parameterValues['relative']; |
56
|
7 |
|
$filesystemRepo = new FilesystemRepository($documentRoot, $this->symlinks, $relative); |
57
|
|
|
|
58
|
7 |
|
if ('/' === $serverPath) { |
59
|
4 |
|
foreach ($resource->listChildren() as $child) { |
60
|
4 |
|
$name = $child->getName(); |
61
|
|
|
|
62
|
|
|
// If the resource is not attached, the name is empty |
63
|
4 |
|
if (!$name && $child instanceof FilesystemResource) { |
64
|
4 |
|
$name = Path::getFilename($child->getFilesystemPath()); |
65
|
|
|
} |
66
|
|
|
|
67
|
4 |
|
if ($name) { |
68
|
4 |
|
$filesystemRepo->remove($serverPath.'/'.$name); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
} else { |
72
|
3 |
|
$filesystemRepo->remove($serverPath); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
// Don't attach the original resource to the repository we just created |
76
|
7 |
|
$filesystemRepo->add($serverPath, clone $resource); |
77
|
7 |
|
} |
78
|
|
|
} |
79
|
|
|
|