| | |
| | | namespace JVBase\managers; |
| | | |
| | | use JVBase\base\Site; |
| | | use JVBase\inc\managers\ErrorHelper; |
| | | use JVBase\Instance; |
| | | use Exception; |
| | | use Imagick; |
| | |
| | | */ |
| | | class UploadManager |
| | | { |
| | | use Instance; |
| | | use Instance, ErrorHelper; |
| | | protected array $allowedTypes = [ |
| | | // Images |
| | | 'image/jpeg' => 'image', |
| | |
| | | 'stored_at' => current_time('mysql') |
| | | ]; |
| | | } catch (Exception $e) { |
| | | Errors::getInstance()->log('UploadManager','Failed to store uploaded file: ' . print_r($e->getMessage(), true)); |
| | | $this->logError('Failed to store uploaded file', 'secureUploadedFile', ['error' => $e->getMessage()]); |
| | | return []; |
| | | } |
| | | } |
| | |
| | | }; |
| | | |
| | | } catch (Exception $e) { |
| | | Errors::getInstance()->log( |
| | | '[UploadManager]:processUpload', |
| | | $e->getMessage(), |
| | | ['temp_path' => $temp_path, 'context' => $context] |
| | | ); |
| | | $this->logError($e->getMessage(), 'processUpload'); |
| | | |
| | | return new WP_Error('upload_failed', $e->getMessage()); |
| | | } |
| | |
| | | ); |
| | | |
| | | } catch (Exception $e) { |
| | | Errors::getInstance()->log('Uploader', 'Image conversion failed: ' . print_r($e->getMessage(), true)); |
| | | $this->logError($e->getMessage(), 'processImage'); |
| | | // Fallback to original |
| | | $ext = pathinfo($original_path, PATHINFO_EXTENSION); |
| | | $final_path = "{$full_dir}/{$filename}.{$ext}"; |
| | |
| | | try { |
| | | $attachment_id = $this->createAttachment($final_path, $filename, $context, $post_id); |
| | | } catch (Exception $e) { |
| | | Errors::getInstance()->log('Uploader', 'Attachment creation failed: '.print_r($e->getMessage(), true)); |
| | | $this->logError($e->getMessage(), 'processVideo'); |
| | | return ['success' => false]; |
| | | } |
| | | |
| | |
| | | try { |
| | | $attachment_id = $this->createAttachment($final_path, $filename, $context, $post_id); |
| | | } catch (Exception $e) { |
| | | Errors::getInstance()->log('Uploader','Conversion failed: '.print_r($e->getMessage(), true)); |
| | | $this->logError($e->getMessage(), 'processDocument'); |
| | | return ['success' => false]; |
| | | } |
| | | |