Backup
2 years ago
FileList
2 years ago
Restore
2 years ago
Backup.php
2 years ago
BackupSpeedIndex.php
2 years ago
Cancel.php
3 years ago
Delete.php
3 years ago
Edit.php
2 years ago
FileInfo.php
3 years ago
FileList.php
2 years ago
Listing.php
2 years ago
Parts.php
3 years ago
PrepareJob.php
2 years ago
Restore.php
2 years ago
ScheduleList.php
2 years ago
Status.php
3 years ago
Upload.php
2 years ago
FileInfo.php
56 lines
| 1 | <?php |
| 2 | |
| 3 | // TODO PHP7.x; declare(strict_type=1); |
| 4 | // TODO PHP7.x; type hints & return types |
| 5 | |
| 6 | namespace WPStaging\Backup\Ajax; |
| 7 | |
| 8 | use WPStaging\Framework\Component\AbstractTemplateComponent; |
| 9 | use WPStaging\Framework\TemplateEngine\TemplateEngine; |
| 10 | use WPStaging\Backup\Entity\BackupMetadata; |
| 11 | use WPStaging\Backup\Service\BackupsFinder; |
| 12 | |
| 13 | class FileInfo extends AbstractTemplateComponent |
| 14 | { |
| 15 | /** @var BackupsFinder */ |
| 16 | private $backupsFinder; |
| 17 | |
| 18 | public function __construct(TemplateEngine $templateEngine, BackupsFinder $backupsFinder) |
| 19 | { |
| 20 | parent::__construct($templateEngine); |
| 21 | $this->backupsFinder = $backupsFinder; |
| 22 | } |
| 23 | |
| 24 | public function render() |
| 25 | { |
| 26 | if (!$this->canRenderAjax()) { |
| 27 | return; |
| 28 | } |
| 29 | |
| 30 | $filePath = isset($_POST['filePath']) ? sanitize_text_field($_POST['filePath']) : ''; |
| 31 | // Make sure path is inside Backups Directory |
| 32 | $backupDir = wp_normalize_path($this->backupsFinder->getBackupsDirectory()); |
| 33 | $file = $backupDir . str_replace($backupDir, '', wp_normalize_path(untrailingslashit($filePath))); |
| 34 | |
| 35 | try { |
| 36 | $info = (new BackupMetadata())->hydrateByFilePath($file); |
| 37 | } catch (\Exception $e) { |
| 38 | wp_send_json([ |
| 39 | 'error' => true, |
| 40 | 'message' => $e->getMessage(), |
| 41 | ]); |
| 42 | } |
| 43 | |
| 44 | $viewData = [ |
| 45 | 'info' => $info |
| 46 | ]; |
| 47 | |
| 48 | $result = $this->templateEngine->render( |
| 49 | 'Backend/views/backup/modal/confirm-restore.php', |
| 50 | $viewData |
| 51 | ); |
| 52 | |
| 53 | wp_send_json($result); |
| 54 | } |
| 55 | } |
| 56 |