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 |