← All changes
|
backend/src/Controllers/Notification/DuplicateNotificationController.php
+8
-8
0.1.2
→
1.5
View file →
| @@ -1,13 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace IvyForms\Controllers\Notification; |
| 4 | 4 | |
| 5 | -// phpcs:disable PSR1.Files.SideEffects | |
| 6 | -if (!defined('ABSPATH')) { | |
| 7 | - exit; // Exit if accessed directly | |
| 8 | -} | |
| 9 | - | |
| 10 | 5 | use IvyForms\Common\Exceptions\ForbiddenException; |
| 11 | 6 | use IvyForms\Common\Exceptions\InvalidArgumentException; |
| 12 | 7 | use IvyForms\Common\Exceptions\NotFoundException; |
| 13 | 8 | use IvyForms\Common\Exceptions\QueryExecutionException; |
| @@ -15,8 +10,9 @@ | ||
| 15 | 10 | use IvyForms\Common\Sanitizer\Sanitizer; |
| 16 | 11 | use IvyForms\Controllers\Controller; |
| 17 | 12 | use IvyForms\Factory\Notification\NotificationFactory; |
| 18 | 13 | use IvyForms\Services\Notification\NotificationService; |
| 14 | +use IvyForms\Services\Translations\BackendStrings; | |
| 19 | 15 | use WP_REST_Request; |
| 20 | 16 | use WP_REST_Response; |
| 21 | 17 | |
| 22 | 18 | /** |
| @@ -50,9 +46,11 @@ | ||
| 50 | 46 | Sanitizer::verifyNonce($data->get_header('X-WP-Nonce')); |
| 51 | 47 | // Validate request data |
| 52 | 48 | $notificationId = Sanitizer::sanitizeId($data->get_param('id')); |
| 53 | 49 | if (empty($notificationId)) { |
| 54 | - throw new InvalidArgumentException('Notification ID is required.'); | |
| 50 | + throw new InvalidArgumentException( | |
| 51 | + BackendStrings::getExceptionStrings()['notification_id_required'] | |
| 52 | + ); | |
| 55 | 53 | } |
| 56 | 54 | |
| 57 | 55 | // Retrieve the original notification |
| 58 | 56 | $originalNotification = $this->notificationService->getNotificationById($notificationId); |
| @@ -65,9 +63,11 @@ | ||
| 65 | 63 | |
| 66 | 64 | // Save the new notification to the database |
| 67 | 65 | $newNotificationId = $this->notificationService->createNotification($newNotification); |
| 68 | 66 | if (!$newNotificationId) { |
| 69 | - throw new QueryExecutionException('Failed to duplicate notification.'); | |
| 67 | + throw new QueryExecutionException( | |
| 68 | + BackendStrings::getSettingsFormBuilderStrings()['failed_to_duplicate_notification' . '.'] | |
| 69 | + ); | |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | // Set the new notification ID |
| 73 | 73 | $newNotification->setId($newNotificationId); |
| @@ -72,9 +72,9 @@ | ||
| 72 | 72 | // Set the new notification ID |
| 73 | 73 | $newNotification->setId($newNotificationId); |
| 74 | 74 | |
| 75 | 75 | return new WP_REST_Response([ |
| 76 | - 'message' => 'OK', | |
| 76 | + 'message' => BackendStrings::getCommonStrings()['ok'], | |
| 77 | 77 | 'data' => $newNotification->toArray() |
| 78 | 78 | ], 200); |
| 79 | 79 | } |
| 80 | 80 | } |