Database
1 week ago
AbstractStagingSetup.php
1 week ago
DirectoryScanner.php
1 week ago
FileCopier.php
1 week ago
LegacyOptionsCache.php
1 week ago
StagingEngine.php
1 week ago
StagingSetup.php
1 week ago
TableScanner.php
1 week ago
LegacyOptionsCache.php
65 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Staging\Service; |
| 4 | |
| 5 | use stdClass; |
| 6 | use WPStaging\Backend\Modules\Jobs\Job; |
| 7 | use WPStaging\Core\WPStaging; |
| 8 | use WPStaging\Framework\Utils\Cache\Cache; |
| 9 | use WPStaging\Staging\Sites; |
| 10 | |
| 11 | /** |
| 12 | * Prepares the legacy staging options cache for unified setup screens. |
| 13 | */ |
| 14 | class LegacyOptionsCache |
| 15 | { |
| 16 | public function prepare(string $mainJob, string $cloneId = '') |
| 17 | { |
| 18 | if (WPStaging::make(StagingEngine::class)->getEngine() !== StagingEngine::ENGINE_LEGACY) { |
| 19 | return; |
| 20 | } |
| 21 | |
| 22 | $cloneOptionCache = WPStaging::make(Cache::class); |
| 23 | $cloneOptionCache->setLifetime(-1); |
| 24 | $cloneOptionCache->setPath(WPStaging::getContentDir()); |
| 25 | $cloneOptionCache->setFileName(Job::CLONE_OPTIONS_KEY); |
| 26 | |
| 27 | $filesIndexCache = WPStaging::make(Cache::class); |
| 28 | $filesIndexCache->setLifetime(-1); |
| 29 | $filesIndexCache->setPath(WPStaging::getContentDir()); |
| 30 | $filesIndexCache->setFileName(Job::FILES_INDEX_KEY); |
| 31 | $filesIndexCache->delete(); |
| 32 | |
| 33 | $existingClones = get_option(Sites::STAGING_SITES_OPTION, []); |
| 34 | $existingClones = is_array($existingClones) ? $existingClones : []; |
| 35 | $currentCloneId = isset($existingClones[$cloneId]) ? $cloneId : null; |
| 36 | |
| 37 | $options = new stdClass(); |
| 38 | $options->root = str_replace(["\\", '/'], DIRECTORY_SEPARATOR, ABSPATH); |
| 39 | $options->current = $currentCloneId; |
| 40 | $options->clone = $cloneId; |
| 41 | $options->currentClone = $currentCloneId !== null ? $existingClones[$cloneId] : null; |
| 42 | $options->existingClones = $existingClones; |
| 43 | |
| 44 | $options->clonedTables = []; |
| 45 | |
| 46 | $options->totalFiles = 0; |
| 47 | $options->totalFileSize = 0; |
| 48 | $options->copiedFiles = 0; |
| 49 | |
| 50 | $options->includedDirectories = []; |
| 51 | $options->includedExtraDirectories = []; |
| 52 | $options->excludedDirectories = []; |
| 53 | $options->extraDirectories = []; |
| 54 | $options->scannedDirectories = []; |
| 55 | |
| 56 | $options->currentJob = $mainJob === Job::PUSH ? '' : 'PreserveDataFirstStep'; |
| 57 | $options->currentStep = 0; |
| 58 | $options->totalSteps = 0; |
| 59 | $options->mainJob = $mainJob; |
| 60 | $options->stagingEngine = StagingEngine::ENGINE_LEGACY; |
| 61 | |
| 62 | $cloneOptionCache->save($options); |
| 63 | } |
| 64 | } |
| 65 |