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 / Staging / Tasks / FileAdjustmentTask.php
wp-staging / Staging / Tasks Last commit date
StagingSite 1 day ago StagingSiteCreate 1 day ago StagingSiteDelete 1 day ago StagingSiteReset 1 day ago StagingSiteUpdate 1 day ago DataAdjustmentTask.php 1 day ago DatabaseAdjustmentTask.php 1 day ago FileAdjustmentTask.php 1 day ago FileCopierTask.php 1 day ago StagingTask.php 1 day ago
FileAdjustmentTask.php
97 lines
1 <?php
2
3 namespace WPStaging\Staging\Tasks;
4
5 use WPStaging\Framework\Exceptions\WPStagingException;
6 use WPStaging\Framework\Filesystem\Filesystem;
7 use WPStaging\Framework\Queue\SeekableQueueInterface;
8 use WPStaging\Framework\Job\Dto\StepsDto;
9 use WPStaging\Framework\SiteInfo;
10 use WPStaging\Framework\Utils\Cache\Cache;
11 use WPStaging\Framework\Utils\Urls;
12 use WPStaging\Vendor\Psr\Log\LoggerInterface;
13
14 abstract class FileAdjustmentTask extends DataAdjustmentTask
15 {
16
17
18
19 protected $filesystem;
20
21
22
23
24 protected $siteInfo;
25
26
27
28
29
30
31
32
33
34
35 public function __construct(LoggerInterface $logger, Cache $cache, StepsDto $stepsDto, SeekableQueueInterface $taskQueue, Urls $urls, Filesystem $filesystem, SiteInfo $siteInfo)
36 {
37 parent::__construct($logger, $cache, $stepsDto, $taskQueue, $urls);
38 $this->filesystem = $filesystem;
39 $this->siteInfo = $siteInfo;
40 }
41
42
43
44
45
46 protected function getDefineRegex(string $string): string
47 {
48 return "/define\s*\(\s*['\"]" . $string . "['\"]\s*,\s*(.*)\s*\);/";
49 }
50
51
52
53
54
55
56 protected function readFile(string $file): string
57 {
58 $path = trailingslashit($this->jobDataDto->getStagingSitePath()) . $file;
59 if (($content = file_get_contents($path)) === false) {
60 throw new WPStagingException("Error - can't read " . $file);
61 }
62
63 return $content;
64 }
65
66
67
68
69
70
71
72 protected function writeFile(string $file, string $content)
73 {
74 $path = trailingslashit($this->jobDataDto->getStagingSitePath()) . $file;
75 if ($this->filesystem->create($path, $content) === false) {
76 throw new WPStagingException("Error - can't write to " . $file . ".");
77 }
78 }
79
80
81
82
83 protected function readWpConfig(): string
84 {
85 return $this->readFile('wp-config.php');
86 }
87
88
89
90
91
92 protected function writeWpConfig(string $content)
93 {
94 $this->writeFile('wp-config.php', $content);
95 }
96 }
97