Ajax
1 month ago
BackgroundProcessing
1 year ago
Dto
1 week ago
Entity
1 week ago
Exceptions
1 year ago
FileHeader
1 month ago
Interfaces
6 months ago
Job
1 month ago
Request
1 year ago
Service
1 week ago
Storage
1 month ago
Task
1 week ago
Traits
10 months ago
Utils
3 months ago
AfterRestore.php
5 months ago
BackupDeleter.php
2 months ago
BackupDownload.php
8 months ago
BackupFileIndex.php
1 year ago
BackupGlitchReason.php
1 year ago
BackupHeader.php
1 month ago
BackupRepairer.php
6 months ago
BackupRetentionHandler.php
1 month ago
BackupScheduler.php
1 week ago
BackupServiceProvider.php
1 month ago
BackupValidator.php
6 months ago
FileHeader.php
1 week ago
FileHeaderAttribute.php
2 years ago
WithBackupIdentifier.php
1 year ago
AfterRestore.php
67 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Backup; |
| 4 | |
| 5 | use WPStaging\Backup\Service\Database\DatabaseImporter; |
| 6 | use WPStaging\Framework\Database\TableService; |
| 7 | use WPStaging\Framework\Facades\Hooks; |
| 8 | use WPStaging\Framework\Security\AccessToken; |
| 9 | use WPStaging\Framework\ThirdParty\NinjaForms; |
| 10 | |
| 11 | class AfterRestore |
| 12 | { |
| 13 | /** @var string */ |
| 14 | const FILTER_BACKUP_IMPORT_DATABASE_DROP_OLD_TABLES_AFTER_RESTORE = 'wpstg.backup.import.database.dropOldTablesAfterRestore'; |
| 15 | |
| 16 | /** |
| 17 | * @var TableService |
| 18 | */ |
| 19 | protected $tableService; |
| 20 | |
| 21 | /** |
| 22 | * @var AccessToken |
| 23 | */ |
| 24 | protected $accessToken; |
| 25 | |
| 26 | /** |
| 27 | * @var NinjaForms |
| 28 | */ |
| 29 | protected $ninjaForms; |
| 30 | |
| 31 | /** |
| 32 | * @param TableService $tableService |
| 33 | * @param AccessToken $accessToken |
| 34 | * @param NinjaForms $ninjaForms |
| 35 | */ |
| 36 | public function __construct(TableService $tableService, AccessToken $accessToken, NinjaForms $ninjaForms) |
| 37 | { |
| 38 | $this->tableService = $tableService; |
| 39 | $this->accessToken = $accessToken; |
| 40 | $this->ninjaForms = $ninjaForms; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * @action wp_login |
| 45 | * @see \WPStaging\Backup\BackupServiceProvider::addHooks |
| 46 | */ |
| 47 | public function loginAfterRestore() |
| 48 | { |
| 49 | // Early bail: Not a login after a successful restore |
| 50 | if (get_option('wpstg.restore.justRestored') !== 'yes') { |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | // Disable WordPress automatic background updates on this request. |
| 55 | add_filter('automatic_updater_disabled', '__return_false'); |
| 56 | |
| 57 | if (Hooks::applyFilters(self::FILTER_BACKUP_IMPORT_DATABASE_DROP_OLD_TABLES_AFTER_RESTORE, true)) { |
| 58 | $this->tableService->deleteTablesStartWith(DatabaseImporter::TMP_DATABASE_PREFIX_TO_DROP, [], true); |
| 59 | } |
| 60 | |
| 61 | $this->ninjaForms->mayBeDisableMaintenanceMode(); |
| 62 | $this->accessToken->generateNewToken(); |
| 63 | delete_option('wpstg.restore.justRestored'); |
| 64 | delete_option('wpstg.restore.justRestored.metadata'); |
| 65 | } |
| 66 | } |
| 67 |