EventLogger.php
73 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Framework\Settings; |
| 4 | |
| 5 | use WPStaging\Framework\Traits\EventLoggerTrait; |
| 6 | use WPStaging\Framework\Utils\Sanitize; |
| 7 | |
| 8 | class EventLogger |
| 9 | { |
| 10 | use EventLoggerTrait; |
| 11 | |
| 12 | /** |
| 13 | * @var Sanitize |
| 14 | */ |
| 15 | private $sanitize; |
| 16 | |
| 17 | /** |
| 18 | * @var string |
| 19 | */ |
| 20 | private $process; |
| 21 | |
| 22 | /** |
| 23 | * @var array |
| 24 | */ |
| 25 | private $processPrefixes; |
| 26 | |
| 27 | /** |
| 28 | * @param Sanitize $sanitize |
| 29 | */ |
| 30 | public function __construct(Sanitize $sanitize) |
| 31 | { |
| 32 | $this->sanitize = $sanitize; |
| 33 | $this->processPrefixes = [ |
| 34 | 'backup' => $this->backupProcessPrefix, |
| 35 | 'restore' => $this->restoreProcessPrefix, |
| 36 | 'clone' => $this->cloneProcessPrefix, |
| 37 | 'push' => $this->pushProcessPrefix, |
| 38 | ]; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * @return void |
| 43 | */ |
| 44 | public function ajaxLogEventFailure() |
| 45 | { |
| 46 | $process = isset($_POST['process']) ? $this->sanitize->sanitizeString($_POST['process']) : ''; |
| 47 | if (empty($process)) { |
| 48 | wp_send_json_error(); |
| 49 | } |
| 50 | |
| 51 | $this->process = $this->getProcessPrefix($process); |
| 52 | if (empty($this->process)) { |
| 53 | wp_send_json_error(); |
| 54 | } |
| 55 | |
| 56 | $response = $this->updateFailedProcess($this->process); |
| 57 | if ($response) { |
| 58 | wp_send_json_success(); |
| 59 | } |
| 60 | |
| 61 | wp_send_json_error(); |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * @param string $processName |
| 66 | * @return string |
| 67 | */ |
| 68 | protected function getProcessPrefix(string $processName): string |
| 69 | { |
| 70 | return empty($this->processPrefixes[$processName]) ? '' : $this->processPrefixes[$processName]; |
| 71 | } |
| 72 | } |
| 73 |