← All changes
|
includes/Core/Integration/ZohoDesk/FilesApiHelper.php
+17
-0
3.1.1
→
3.3.1
View file →
| @@ -47,8 +47,9 @@ | ||
| 47 | 47 | * @return mixed $uploadedFiles ID's of uploaded file in Zoho Desk |
| 48 | 48 | */ |
| 49 | 49 | public function uploadFiles($files, $ticketId, $dataCenter) |
| 50 | 50 | { |
| 51 | + $files = self::normalizeFileNames($files); | |
| 51 | 52 | $uploadFileEndpoint = "https://desk.zoho.{$dataCenter}/api/v1/tickets/{$ticketId}/attachments"; |
| 52 | 53 | $payload = ''; |
| 53 | 54 | if (is_array($files)) { |
| 54 | 55 | foreach ($files as $fileIndex => $fileName) { |
| @@ -79,6 +80,22 @@ | ||
| 79 | 80 | |
| 80 | 81 | $uploadResponse = HttpHelper::post($uploadFileEndpoint, $payload, $this->_defaultHeader); |
| 81 | 82 | |
| 82 | 83 | return $uploadResponse; |
| 84 | + } | |
| 85 | + | |
| 86 | + /** | |
| 87 | + * Field values may arrive as public file URLs (see IntegrationHandler::handleFileUrl), | |
| 88 | + * so reduce each to the stored file name before resolving against the entry directory. | |
| 89 | + * | |
| 90 | + * @param mixed $files file name(s) or URL(s) | |
| 91 | + * | |
| 92 | + * @return mixed | |
| 93 | + */ | |
| 94 | + private static function normalizeFileNames($files) | |
| 95 | + { | |
| 96 | + if (is_array($files)) { | |
| 97 | + return array_map([__CLASS__, 'normalizeFileNames'], $files); | |
| 98 | + } | |
| 99 | + return is_string($files) ? basename(wp_parse_url($files, PHP_URL_PATH) ?: $files) : $files; | |
| 83 | 100 | } |
| 84 | 101 | } |