PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.11.0
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.11.0
4.11.0 4.10.0 4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Framework / Filesystem / WpUploadsFolderSymlinker.php
wp-staging / Framework / Filesystem Last commit date
Filters 1 day ago Scanning 1 day ago AbstractFileObject.php 1 day ago AbstractFilesystemScanner.php 1 day ago DebugLogReader.php 1 day ago DirectoryListing.php 1 day ago DirectorySize.php 1 day ago DiskWriteCheck.php 1 day ago FileObject.php 1 day ago Filesystem.php 1 day ago FilesystemExceptions.php 5 years ago FilesystemScanner.php 1 day ago FilesystemScannerDto.php 1 day ago FilterableDirectoryIterator.php 1 day ago LegacyFileRulesTrait.php 1 day ago LogCleanup.php 1 day ago LogFiles.php 1 day ago MissingFileException.php 3 years ago OPcache.php 1 day ago PartIdentifier.php 1 day ago PathChecker.php 1 day ago PathIdentifier.php 1 day ago Permissions.php 1 day ago WpUploadsFolderSymlinker.php 1 day ago
WpUploadsFolderSymlinker.php
139 lines
1 <?php
2
3 namespace WPStaging\Framework\Filesystem;
4
5 use WPStaging\Backend\Modules\Jobs\Exceptions\FatalException;
6 use WPStaging\Framework\Utils\WpDefaultDirectories;
7
8
9
10
11
12
13 class WpUploadsFolderSymlinker
14 {
15
16
17
18 protected $stagingWpPath;
19
20
21
22
23 protected $stagingUploadPath;
24
25
26
27
28 protected $wpDirectories;
29
30
31
32
33 protected $error;
34
35 public function __construct(WpDefaultDirectories $wpDirectories)
36 {
37 $this->wpDirectories = $wpDirectories;
38 }
39
40
41
42
43
44 public function setStagingPath(string $stagingWpPath)
45 {
46 $this->stagingWpPath = trailingslashit($stagingWpPath);
47 $this->stagingUploadPath = rtrim($this->stagingWpPath . $this->wpDirectories->getRelativeUploadPath(), '/');
48 }
49
50
51
52
53
54 public function setStagingSiteUploadPath(string $stagingUploadPath)
55 {
56 $this->stagingUploadPath = rtrim($stagingUploadPath, '/');
57 }
58
59
60
61
62 public function trySymlink()
63 {
64 if (is_link($this->stagingUploadPath)) {
65 $this->error = __("Link already exists", 'wp-staging');
66 return false;
67 }
68
69 if (file_exists($this->stagingUploadPath)) {
70 $this->error = __("Path exists at link path", 'wp-staging');
71 return false;
72 }
73
74 $uploadPath = rtrim($this->wpDirectories->getUploadsPath(), '/\\');
75
76 (new Filesystem())->mkdir(dirname($this->stagingUploadPath));
77
78
79 if ((stripos(PHP_OS, 'WIN') === 0) && $this->isExecEnabled()) {
80 return $this->linkWithExec($uploadPath, $this->stagingUploadPath);
81 }
82
83 return $this->link($uploadPath, $this->stagingUploadPath);
84 }
85
86
87
88
89 public function getError()
90 {
91 return $this->error;
92 }
93
94
95
96
97
98
99
100
101 private function linkWithExec($source, $destination)
102 {
103 try {
104 exec('mklink /D "' . $destination . '" "' . $source . '"');
105 return true;
106 } catch (FatalException $ex) {
107 $this->error = sprintf(__("Can not symlink %s. Error: ", 'wp-staging'), $destination, $ex->getMessage());
108 return false;
109 }
110 }
111
112
113
114
115
116
117
118
119 private function link($source, $destination)
120 {
121 try {
122 return symlink($source, $destination);
123 } catch (FatalException $ex) {
124 $this->error = sprintf(__("Can not symlink %s. Error: ", 'wp-staging'), $destination, $ex->getMessage());
125 return false;
126 }
127 }
128
129 private function isExecEnabled()
130 {
131 if (!function_exists('exec')) {
132 return false;
133 }
134
135 $disabled = explode(',', ini_get('disable_functions'));
136 return !in_array('exec', $disabled);
137 }
138 }
139