-
Notifications
You must be signed in to change notification settings - Fork 9
/
CopyFilesystemPublisher.php
executable file
·86 lines (64 loc) · 2.44 KB
/
CopyFilesystemPublisher.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
<?php
namespace Xi\Filelib\Publisher\Filesystem;
use Xi\Filelib\File\File;
use Xi\Filelib\Publisher\Publisher;
use Xi\Filelib\Plugin\VersionProvider\VersionProvider;
/**
* Publishes files in a filesystem by retrieving them from storage and creating a copy
*
* @author pekkis
*
*/
class CopyFilesystemPublisher extends AbstractFilesystemPublisher implements Publisher
{
public function publish(File $file)
{
$fl = $this->getFilelib();
$linker = $this->getLinkerForFile($file);
$link = $this->getPublicRoot() . '/' . $linker->getLink($file, true);
if(!is_file($link)) {
$path = dirname($link);
if(!is_dir($path)) {
mkdir($path, $this->getDirectoryPermission(), true);
}
$tmp = $this->getFilelib()->getStorage()->retrieve($file->getResource());
copy($tmp, $link);
chmod($link, $this->getFilePermission());
}
}
public function publishVersion(File $file, $version, VersionProvider $versionProvider)
{
$fl = $this->getFilelib();
$linker = $this->getLinkerForFile($file);
$link = $this->getPublicRoot() . '/' . $linker->getLinkVersion($file, $version, $versionProvider->getExtensionFor($version));
if(!is_file($link)) {
$path = dirname($link);
if(!is_dir($path)) {
mkdir($path, $this->getDirectoryPermission(), true);
}
if ($versionProvider->areSharedVersionsAllowed()) {
$tmp = $this->getFilelib()->getStorage()->retrieveVersion($file->getResource(), $version, null);
} else {
$tmp = $this->getFilelib()->getStorage()->retrieveVersion($file->getResource(), $version, $file);
}
copy($tmp, $link);
chmod($link, $this->getFilePermission());
}
}
public function unpublish(File $file)
{
$linker = $this->getLinkerForFile($file);
$link = $this->getPublicRoot() . '/' . $linker->getLink($file);
if(is_file($link)) {
unlink($link);
}
}
public function unpublishVersion(File $file, $version, VersionProvider $versionProvider)
{
$linker = $this->getLinkerForFile($file);
$link = $this->getPublicRoot() . '/' . $linker->getLinkVersion($file, $version, $versionProvider->getExtensionFor($version));
if(is_file($link)) {
unlink($link);
}
}
}