PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 4.9.2
WP STAGING – WordPress Backup, Restore, Migration & Clone v4.9.2
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 week ago StagingSiteCreate 2 weeks ago StagingSiteDelete 10 months ago StagingSiteReset 2 weeks ago StagingSiteUpdate 2 weeks ago DataAdjustmentTask.php 11 months ago DatabaseAdjustmentTask.php 2 weeks ago FileAdjustmentTask.php 11 months ago FileCopierTask.php 2 weeks ago StagingTask.php 1 year 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 * @var Filesystem
18 */
19 protected $filesystem;
20
21 /**
22 * @var SiteInfo
23 */
24 protected $siteInfo;
25
26 /**
27 * @param LoggerInterface $logger
28 * @param Cache $cache
29 * @param StepsDto $stepsDto
30 * @param SeekableQueueInterface $taskQueue
31 * @param Urls $urls
32 * @param Filesystem $filesystem
33 * @param SiteInfo $siteInfo
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 * @param string $string
44 * @return string
45 */
46 protected function getDefineRegex(string $string): string
47 {
48 return "/define\s*\(\s*['\"]" . $string . "['\"]\s*,\s*(.*)\s*\);/";
49 }
50
51 /**
52 * @param string $file
53 * @return string
54 * @throws WPStagingException
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 * @param string $file
68 * @param string $content
69 * @return void
70 * @throws WPStagingException
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 * @return string
82 */
83 protected function readWpConfig(): string
84 {
85 return $this->readFile('wp-config.php');
86 }
87
88 /**
89 * @param string $content
90 * @return void
91 */
92 protected function writeWpConfig(string $content)
93 {
94 $this->writeFile('wp-config.php', $content);
95 }
96 }
97