diff --git a/app/Platform/Mail/Http/Admin/MailConfigurationController.php b/app/Platform/Mail/Http/Admin/MailConfigurationController.php deleted file mode 100755 index 364d11ac..00000000 --- a/app/Platform/Mail/Http/Admin/MailConfigurationController.php +++ /dev/null @@ -1,94 +0,0 @@ -authorize('manage email config'); - - $setting = Setting::getSetting('profile_complete'); - - $this->mailConfigurationService->saveGlobalConfig($request->validated()); - - if ($setting !== 'COMPLETED') { - Setting::setSetting('profile_complete', 4); - } - - return response()->json([ - 'success' => 'mail_variables_save_successfully', - ]); - } - - /** - * Return the mail environment variables - * - * - * @throws AuthorizationException - */ - public function getMailEnvironment(): JsonResponse - { - $this->authorize('manage email config'); - - return response()->json($this->mailConfigurationService->getGlobalConfig()); - } - - /** - * Return the available mail drivers - * - * - * @throws AuthorizationException - */ - public function getMailDrivers(): JsonResponse - { - $this->authorize('manage email config'); - - return response()->json($this->mailConfigurationService->getAvailableDrivers()); - } - - /** - * Test the email configuration - * - * - * - * @throws AuthorizationException - * @throws ValidationException - */ - public function testEmailConfig(Request $request): JsonResponse - { - $this->authorize('manage email config'); - - $this->validate($request, [ - 'to' => 'required|email', - 'subject' => 'required', - 'message' => 'required', - ]); - - Mail::to($request->to)->send(new TestMail($request->subject, $request->message)); - - return response()->json([ - 'success' => true, - ]); - } -} diff --git a/app/Platform/Mail/Http/Requests/MailEnvironmentRequest.php b/app/Platform/Mail/Http/Requests/MailEnvironmentRequest.php deleted file mode 100644 index 0ad9f67d..00000000 --- a/app/Platform/Mail/Http/Requests/MailEnvironmentRequest.php +++ /dev/null @@ -1,27 +0,0 @@ -validationRules( - $this->string('mail_driver')->toString() - ); - } -} diff --git a/app/Platform/Mail/Mailables/TestMail.php b/app/Platform/Mail/Mailables/TestMail.php deleted file mode 100644 index a9b87f60..00000000 --- a/app/Platform/Mail/Mailables/TestMail.php +++ /dev/null @@ -1,38 +0,0 @@ -subject = $subject; - $this->message = $message; - } - - /** - * Build the message. - * - * @return $this - */ - public function build() - { - return $this->subject($this->subject)->markdown('emails.test')->with([ - 'my_message' => $this->message, - ]); - } -} diff --git a/app/Platform/Mail/Models/EmailLog.php b/app/Platform/Mail/Models/EmailLog.php deleted file mode 100644 index 4dc113e7..00000000 --- a/app/Platform/Mail/Models/EmailLog.php +++ /dev/null @@ -1,49 +0,0 @@ -morphTo(); - } - - /** - * Check if the email log's public link has expired based on the owning - * company's link expiry settings (link_expiry_days and automatically_expire_public_links). - */ - public function isExpired(): bool - { - $mailable = $this->mailable; - - // A token whose target document no longer resolves is treated as - // expired/invalid rather than throwing. - if (! $mailable) { - return true; - } - - $linkExpiryDays = (int) CompanySetting::getSetting('link_expiry_days', $mailable->company_id); - $checkExpiryLinks = CompanySetting::getSetting('automatically_expire_public_links', $mailable->company_id); - - $expiryDate = $this->created_at->addDays($linkExpiryDays); - - if ($checkExpiryLinks == 'YES' && Carbon::now()->format('Y-m-d') > $expiryDate->format('Y-m-d')) { - return true; - } - - return false; - } -} diff --git a/app/Platform/Pdf/Concerns/GeneratesPdf.php b/app/Platform/Pdf/Concerns/GeneratesPdf.php deleted file mode 100644 index f488d5e9..00000000 --- a/app/Platform/Pdf/Concerns/GeneratesPdf.php +++ /dev/null @@ -1,204 +0,0 @@ -getGeneratedPDF($collection_name); - if ($pdf && file_exists($pdf['path'])) { - return response()->make(file_get_contents($pdf['path']), 200, [ - 'Content-Type' => 'application/pdf', - 'Content-Disposition' => 'inline; filename="'.$pdf['file_name'].'"', - ]); - } - - $locale = CompanySetting::getSetting('language', $this->company_id); - - App::setLocale($locale); - app(FontService::class)->ensureFontsForLocale($locale); - - $pdf = $this->getPDFData(); - - // ->output(), not ->stream(): stream() already returns a Response, and - // nesting one inside response()->make() stringifies it, prepending the - // whole "HTTP/1.0 200 OK" preamble to the file. Readers scan the first - // kilobyte for %PDF so it looked fine, but the bytes were malformed and - // anything that validates them (PDF/A, extraction tooling) would balk. - return response()->make($pdf->output(), 200, [ - 'Content-Type' => 'application/pdf', - 'Content-Disposition' => 'inline; filename="'.$this[$collection_name.'_number'].'.pdf"', - ]); - } - - public function getGeneratedPDF($collection_name) - { - try { - $media = $this->getMedia($collection_name)->first(); - - if ($media) { - $file_disk = FileDisk::find($media->custom_properties['file_disk_id']); - - if (! $file_disk) { - return false; - } - - $file_disk->setConfig(); - - $path = null; - - if ($file_disk->driver == 'local') { - $path = $media->getPath(); - } else { - $path = $media->getTemporaryUrl(Carbon::now()->addMinutes(5)); - } - - return collect([ - 'path' => $path, - 'file_name' => $media->file_name, - ]); - } - } catch (\Exception $e) { - return false; - } - - return false; - } - - public function generatePDF($collection_name, $file_name, $deleteExistingFile = false) - { - $save_pdf_to_disk = Setting::getSetting('save_pdf_to_disk') ?? 'NO'; - - if ($save_pdf_to_disk == 'NO') { - return 0; - } - - $locale = CompanySetting::getSetting('language', $this->company_id); - - App::setLocale($locale); - app(FontService::class)->ensureFontsForLocale($locale); - - $pdf = $this->getPDFData(); - - \Storage::disk('local')->put('temp/'.$collection_name.'/'.$this->id.'/temp.pdf', $pdf->output()); - - if ($deleteExistingFile) { - $this->clearMediaCollection($this->id); - } - - $file_disk = FileDisk::whereSetAsDefault(true)->first(); - - if ($file_disk) { - $file_disk->setConfig(); - } - - $media = \Storage::disk('local')->path('temp/'.$collection_name.'/'.$this->id.'/temp.pdf'); - - try { - $this->addMedia($media) - ->withCustomProperties(['file_disk_id' => $file_disk->id]) - ->usingFileName($file_name.'.pdf') - ->toMediaCollection($collection_name, config('filesystems.default')); - - \Storage::disk('local')->deleteDirectory('temp/'.$collection_name.'/'.$this->id); - - return true; - } catch (\Exception $e) { - return $e->getMessage(); - } - } - - public function getFieldsArray() - { - $customer = $this->customer; - $shippingAddress = $customer->shippingAddress ?? new Address; - $billingAddress = $customer->billingAddress ?? new Address; - $companyAddress = $this->company->address ?? new Address; - - $fields = [ - '{SHIPPING_ADDRESS_NAME}' => $shippingAddress->name, - '{SHIPPING_COUNTRY}' => $shippingAddress->country_name, - '{SHIPPING_STATE}' => $shippingAddress->state, - '{SHIPPING_CITY}' => $shippingAddress->city, - '{SHIPPING_ADDRESS_STREET_1}' => $shippingAddress->address_street_1, - '{SHIPPING_ADDRESS_STREET_2}' => $shippingAddress->address_street_2, - '{SHIPPING_PHONE}' => $shippingAddress->phone, - '{SHIPPING_ZIP_CODE}' => $shippingAddress->zip, - '{BILLING_ADDRESS_NAME}' => $billingAddress->name, - '{BILLING_COUNTRY}' => $billingAddress->country_name, - '{BILLING_STATE}' => $billingAddress->state, - '{BILLING_CITY}' => $billingAddress->city, - '{BILLING_ADDRESS_STREET_1}' => $billingAddress->address_street_1, - '{BILLING_ADDRESS_STREET_2}' => $billingAddress->address_street_2, - '{BILLING_PHONE}' => $billingAddress->phone, - '{BILLING_ZIP_CODE}' => $billingAddress->zip, - '{COMPANY_NAME}' => $this->company->name, - '{COMPANY_COUNTRY}' => $companyAddress->country_name, - '{COMPANY_STATE}' => $companyAddress->state, - '{COMPANY_CITY}' => $companyAddress->city, - '{COMPANY_ADDRESS_STREET_1}' => $companyAddress->address_street_1, - '{COMPANY_ADDRESS_STREET_2}' => $companyAddress->address_street_2, - '{COMPANY_PHONE}' => $companyAddress->phone, - '{COMPANY_ZIP_CODE}' => $companyAddress->zip, - '{COMPANY_VAT}' => $this->company->vat_id, - '{COMPANY_TAX}' => $this->company->tax_id, - '{CONTACT_DISPLAY_NAME}' => $customer->name, - '{PRIMARY_CONTACT_NAME}' => $customer->contact_name, - '{CONTACT_EMAIL}' => $customer->email, - '{CONTACT_PHONE}' => $customer->phone, - '{CONTACT_WEBSITE}' => $customer->website, - '{CONTACT_TAX_ID}' => __('pdf_tax_id').': '.$customer->tax_id, - ]; - - $customFields = $this->fields; - $customerCustomFields = $this->customer->fields; - - foreach ($customFields as $customField) { - $fields['{'.$customField->customField->slug.'}'] = $customField->defaultAnswer; - } - - foreach ($customerCustomFields as $customField) { - $fields['{'.$customField->customField->slug.'}'] = $customField->defaultAnswer; - } - - foreach ($fields as $key => $field) { - // Cast: an address line, custom field or tax id that was never filled - // in arrives as null, and passing null here is deprecated in PHP 8.4 - // and an error in 9. Every PDF render was emitting these. - $fields[$key] = htmlspecialchars((string) $field, ENT_QUOTES, 'UTF-8'); - } - - return $fields; - } - - public function getFormattedString($format) - { - $values = array_merge($this->getFieldsArray(), $this->getExtraFields()); - - $str = nl2br(strtr((string) $format, $values)); - - $str = preg_replace('/{(.*?)}/', '', $str); - - $str = preg_replace("/<[^\/>]*>([\s]?)*<\/[^>]*>/", '', $str); - - $str = str_replace('

', '', $str); - - $str = str_replace('

', '
', $str); - - // Sanitize the assembled HTML to strip any SSRF vectors that may have - // entered through user-supplied address fields, customer names, or - // custom field values. Notes also pass through this method, so they - // get the same treatment without needing a separate wrapper. - return PdfHtmlSanitizer::sanitize($str); - } -} diff --git a/app/Platform/Pdf/Http/Middleware/PdfMiddleware.php b/app/Platform/Pdf/Http/Middleware/PdfMiddleware.php deleted file mode 100644 index e93df6c8..00000000 --- a/app/Platform/Pdf/Http/Middleware/PdfMiddleware.php +++ /dev/null @@ -1,27 +0,0 @@ -check() || Auth::guard('sanctum')->check() || Auth::guard('customer')->check()) { - return $next($request); - } - - return redirect('/login'); - } -} diff --git a/app/Platform/Storage/Http/BackupsController.php b/app/Platform/Storage/Http/BackupsController.php deleted file mode 100644 index 2a294783..00000000 --- a/app/Platform/Storage/Http/BackupsController.php +++ /dev/null @@ -1,117 +0,0 @@ -authorize('manage backups'); - - try { - $destination = $this->backupService->getDestination($request->file_disk_id); - - $backups = $destination - ->backups() - ->map(function (Backup $backup) { - return [ - 'path' => $backup->path(), - 'created_at' => $backup->date()->format('Y-m-d H:i:s'), - 'size' => Format::humanReadableSize($backup->sizeInBytes()), - ]; - }) - ->toArray(); - - return response()->json([ - 'backups' => $backups, - ]); - } catch (\Exception $e) { - return response()->json([ - 'backups' => [], - 'error' => 'invalid_disk_credentials', - 'error_message' => $e->getMessage(), - ]); - } - } - - public function store(Request $request): JsonResponse - { - $this->authorize('manage backups'); - - $data = $request->all(); - - dispatch(new CreateBackupJob($data))->onQueue(config('backup.queue.name')); - - return response()->json(['success' => true]); - } - - public function destroy($disk, Request $request): JsonResponse - { - $this->authorize('manage backups'); - - $validated = $request->validate([ - 'path' => ['required', new PathToZip], - ]); - - $destination = $this->backupService->getDestination($request->file_disk_id); - - $destination - ->backups() - ->first(function (Backup $backup) use ($validated) { - return $backup->path() === $validated['path']; - }) - ->delete(); - - return response()->json(['success' => true]); - } - - public function download(Request $request): Response|StreamedResponse - { - $this->authorize('manage backups'); - - $validated = $request->validate([ - 'path' => ['required', new PathToZip], - ]); - - $destination = $this->backupService->getDestination($request->file_disk_id); - - $backup = $destination->backups()->first(function (Backup $backup) use ($validated) { - return $backup->path() === $validated['path']; - }); - - if (! $backup) { - return response('Backup not found', 422); - } - - $fileName = pathinfo($backup->path(), PATHINFO_BASENAME); - - return response()->stream(function () use ($backup) { - $stream = $backup->stream(); - fpassthru($stream); - if (is_resource($stream)) { - fclose($stream); - } - }, 200, [ - 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', - 'Content-Type' => 'application/zip', - 'Content-Length' => $backup->sizeInBytes(), - 'Content-Disposition' => 'attachment; filename="'.$fileName.'"', - 'Pragma' => 'public', - ]); - } -} diff --git a/app/Platform/Storage/Http/DiskController.php b/app/Platform/Storage/Http/DiskController.php deleted file mode 100644 index 2fe44d63..00000000 --- a/app/Platform/Storage/Http/DiskController.php +++ /dev/null @@ -1,268 +0,0 @@ -authorize('manage file disk'); - - $limit = $request->has('limit') ? $request->limit : 5; - $disks = FileDisk::applyFilters($request->all()) - ->latest() - ->paginateData($limit); - - return FileDiskResource::collection($disks); - } - - /** - * @return JsonResponse - * - * @throws AuthorizationException - * @throws AuthorizationException - */ - public function store(DiskEnvironmentRequest $request): JsonResponse|FileDiskResource - { - $this->authorize('manage file disk'); - - if (! $this->fileDiskService->validateCredentials($request->credentials, $request->driver)) { - return respondJson('invalid_credentials', 'Invalid Credentials.'); - } - - $disk = $this->fileDiskService->create($request); - - return new FileDiskResource($disk); - } - - /** - * @throws AuthorizationException - */ - public function update(FileDisk $disk, Request $request): JsonResponse|FileDiskResource - { - $this->authorize('manage file disk'); - - $credentials = $request->credentials; - $driver = $request->driver; - - if ($credentials && $driver && $disk->type !== 'SYSTEM') { - if (! $this->fileDiskService->validateCredentials($credentials, $driver)) { - return respondJson('invalid_credentials', 'Invalid Credentials.'); - } - - $this->fileDiskService->update($disk, $request); - } elseif ($request->set_as_default) { - $this->fileDiskService->setAsDefault($disk); - } - - return new FileDiskResource($disk); - } - - /** - * @param Request $request - * - * @throws AuthorizationException - * @throws AuthorizationException - */ - public function show($disk): JsonResponse - { - - $this->authorize('manage file disk'); - - $diskData = []; - switch ($disk) { - case 'local': - // Path is relative to storage/app/. - // e.g., "backups" resolves to storage/app/backups/ at runtime. - $diskData = [ - 'root' => '', - ]; - - break; - - case 's3': - $diskData = [ - 'key' => '', - 'secret' => '', - 'region' => '', - 'bucket' => '', - 'root' => '', - ]; - - break; - - case 's3compat': - $diskData = [ - 'endpoint' => '', - 'key' => '', - 'secret' => '', - 'region' => '', - 'bucket' => '', - 'root' => '', - ]; - - case 'doSpaces': - $diskData = [ - 'key' => '', - 'secret' => '', - 'region' => '', - 'bucket' => '', - 'endpoint' => '', - 'root' => '', - ]; - - break; - - case 'dropbox': - $diskData = [ - 'token' => '', - 'key' => '', - 'secret' => '', - 'app' => '', - 'root' => '', - ]; - - break; - } - - $data = array_merge($diskData); - - return response()->json($data); - } - - /** - * Remove the specified resource from storage. - * - * @param FileDisk $taxType - * - * @throws AuthorizationException - * @throws AuthorizationException - */ - public function destroy(FileDisk $disk): JsonResponse - { - $this->authorize('manage file disk'); - - if ($disk->type === 'SYSTEM') { - return respondJson('not_allowed', 'System disks cannot be deleted.'); - } - - if ($disk->setAsDefault()) { - return respondJson('not_allowed', 'The default disk cannot be deleted.'); - } - - $prefix = env('DYNAMIC_DISK_PREFIX', 'temp_'); - $diskName = $prefix.$disk->driver; - $mediaCount = DB::table('media') - ->where('disk', $diskName) - ->orWhere('disk', $disk->driver) - ->count(); - - if ($mediaCount > 0) { - return respondJson('disk_has_files', 'Cannot delete this disk — it contains '.$mediaCount.' file(s). Migrate files first.'); - } - - $disk->delete(); - - return response()->json([ - 'success' => true, - ]); - } - - /** - * @throws AuthorizationException - * @throws AuthorizationException - */ - public function getDiskDrivers(): JsonResponse - { - $this->authorize('manage file disk'); - - $drivers = [ - [ - 'name' => 'Local', - 'value' => 'local', - ], - [ - 'name' => 'Amazon S3', - 'value' => 's3', - ], - [ - 'name' => 'S3 Compatible Storage', - 'value' => 's3compat', - ], - [ - 'name' => 'Digital Ocean Spaces', - 'value' => 'doSpaces', - ], - [ - 'name' => 'Dropbox', - 'value' => 'dropbox', - ], - ]; - - $defaultDisk = FileDisk::where('set_as_default', true)->first(); - - return response()->json([ - 'drivers' => $drivers, - 'default' => $defaultDisk?->driver ?? 'local', - ]); - } - - public function getDiskPurposes(): JsonResponse - { - $this->authorize('manage file disk'); - - $defaultDisk = FileDisk::where('set_as_default', true)->first(); - $defaultId = $defaultDisk?->id; - - return response()->json([ - 'media_disk_id' => Setting::getSetting('media_disk_id') ?? $defaultId, - 'pdf_disk_id' => Setting::getSetting('pdf_disk_id') ?? $defaultId, - 'backup_disk_id' => Setting::getSetting('backup_disk_id') ?? $defaultId, - ]); - } - - public function updateDiskPurposes(Request $request): JsonResponse - { - $this->authorize('manage file disk'); - - $request->validate([ - 'media_disk_id' => 'nullable|exists:file_disks,id', - 'pdf_disk_id' => 'nullable|exists:file_disks,id', - 'backup_disk_id' => 'nullable|exists:file_disks,id', - ]); - - if ($request->has('media_disk_id')) { - Setting::setSetting('media_disk_id', $request->media_disk_id); - } - - if ($request->has('pdf_disk_id')) { - Setting::setSetting('pdf_disk_id', $request->pdf_disk_id); - } - - if ($request->has('backup_disk_id')) { - Setting::setSetting('backup_disk_id', $request->backup_disk_id); - } - - return response()->json(['success' => true]); - } -} diff --git a/app/Platform/Storage/Http/Middleware/ConfigMiddleware.php b/app/Platform/Storage/Http/Middleware/ConfigMiddleware.php deleted file mode 100644 index 5ab68dd3..00000000 --- a/app/Platform/Storage/Http/Middleware/ConfigMiddleware.php +++ /dev/null @@ -1,34 +0,0 @@ -has('file_disk_id')) { - $file_disk = FileDisk::find($request->file_disk_id); - - if ($file_disk) { - $file_disk->setConfig(); - } - } - // The default file disk is applied during application bootstrap. - } - - return $next($request); - } -} diff --git a/app/Platform/Storage/Http/Requests/DiskEnvironmentRequest.php b/app/Platform/Storage/Http/Requests/DiskEnvironmentRequest.php deleted file mode 100644 index f6a916b3..00000000 --- a/app/Platform/Storage/Http/Requests/DiskEnvironmentRequest.php +++ /dev/null @@ -1,127 +0,0 @@ -get('driver')) { - case 's3': - $rules = [ - 'credentials.key' => [ - 'required', - 'string', - ], - 'credentials.secret' => [ - 'required', - 'string', - ], - 'credentials.region' => [ - 'required', - 'string', - ], - 'credentials.bucket' => [ - 'required', - 'string', - ], - 'credentials.endpoint' => [ - 'nullable', - 'string', - 'url', - new PublicHttpUrl, - ], - 'credentials.root' => [ - 'required', - 'string', - ], - ]; - - break; - - case 'doSpaces': - $rules = [ - 'credentials.key' => [ - 'required', - 'string', - ], - 'credentials.secret' => [ - 'required', - 'string', - ], - 'credentials.region' => [ - 'required', - 'string', - ], - 'credentials.bucket' => [ - 'required', - 'string', - ], - 'credentials.endpoint' => [ - 'required', - 'string', - 'url', - new PublicHttpUrl, - ], - 'credentials.root' => [ - 'required', - 'string', - ], - ]; - - break; - - case 'dropbox': - $rules = [ - 'credentials.token' => [ - 'required', - 'string', - ], - 'credentials.key' => [ - 'required', - 'string', - ], - 'credentials.secret' => [ - 'required', - 'string', - ], - 'credentials.app' => [ - 'required', - 'string', - ], - 'credentials.root' => [ - 'required', - 'string', - ], - ]; - - break; - } - - $defaultRules = [ - 'name' => [ - 'required', - ], - 'driver' => [ - 'required', - ], - ]; - - return array_merge($rules, $defaultRules); - } -} diff --git a/app/Platform/Storage/Http/Resources/FileDiskCollection.php b/app/Platform/Storage/Http/Resources/FileDiskCollection.php deleted file mode 100644 index c99a861d..00000000 --- a/app/Platform/Storage/Http/Resources/FileDiskCollection.php +++ /dev/null @@ -1,19 +0,0 @@ - $this->id, - 'name' => $this->name, - 'type' => $this->type, - 'driver' => $this->driver, - 'set_as_default' => $this->set_as_default, - 'credentials' => $this->credentials, - 'company_id' => $this->company_id, - ]; - } -} diff --git a/app/Platform/Storage/Jobs/CreateBackupJob.php b/app/Platform/Storage/Jobs/CreateBackupJob.php deleted file mode 100644 index a2871939..00000000 --- a/app/Platform/Storage/Jobs/CreateBackupJob.php +++ /dev/null @@ -1,59 +0,0 @@ -data = $data; - } - - /** - * Execute the job. - */ - public function handle(): void - { - $config = BackupConfigurationFactory::make($this->data); - $backupJob = BackupJobFactory::createFromConfig($config); - if (! defined('SIGINT')) { - $backupJob->disableSignals(); - } - - if ($this->data['option'] === 'only-db') { - $backupJob->dontBackupFilesystem(); - } - - if ($this->data['option'] === 'only-files') { - $backupJob->dontBackupDatabases(); - } - - if (! empty($this->data['option'])) { - $prefix = str_replace('_', '-', $this->data['option']).'-'; - - $backupJob->setFilename($prefix.date('Y-m-d-H-i-s').'.zip'); - } - - $backupJob->run(); - } -} diff --git a/app/Platform/Storage/Models/FileDisk.php b/app/Platform/Storage/Models/FileDisk.php deleted file mode 100644 index 0b449884..00000000 --- a/app/Platform/Storage/Models/FileDisk.php +++ /dev/null @@ -1,158 +0,0 @@ - 'boolean', - ]; - } - - public function setCredentialsAttribute(mixed $value): void - { - $this->attributes['credentials'] = json_encode($value); - } - - /** - * Decode credentials, handling double-encoded JSON from legacy data. - */ - public function getDecodedCredentials(): Collection - { - $decoded = json_decode($this->credentials, true); - - // Handle double-encoded JSON (string inside string) - if (is_string($decoded)) { - $decoded = json_decode($decoded, true); - } - - return collect($decoded ?? []); - } - - public function scopeWhereOrder($query, $orderByField, $orderBy) - { - SafeOrderBy::apply($query, $orderByField, $orderBy); - } - - public function scopeFileDisksBetween($query, $start, $end) - { - return $query->whereBetween( - 'file_disks.created_at', - [$start->format('Y-m-d'), $end->format('Y-m-d')] - ); - } - - public function scopeWhereSearch($query, $search) - { - foreach (explode(' ', $search) as $term) { - $query->where('name', 'LIKE', '%'.$term.'%') - ->orWhere('driver', 'LIKE', '%'.$term.'%'); - } - } - - public function scopePaginateData($query, $limit) - { - if ($limit == 'all') { - return $query->get(); - } - - return $query->paginate($limit); - } - - public function scopeApplyFilters($query, array $filters) - { - $filters = collect($filters); - if ($filters->get('search')) { - $query->whereSearch($filters->get('search')); - } - - if ($filters->get('from_date') && $filters->get('to_date')) { - $start = Carbon::createFromFormat('Y-m-d', $filters->get('from_date')); - $end = Carbon::createFromFormat('Y-m-d', $filters->get('to_date')); - $query->fileDisksBetween($start, $end); - } - - if ($filters->get('orderByField') || $filters->get('orderBy')) { - $field = $filters->get('orderByField') ? $filters->get('orderByField') : 'sequence_number'; - $orderBy = $filters->get('orderBy') ? $filters->get('orderBy') : 'asc'; - $query->whereOrder($field, $orderBy); - } - } - - /** - * Apply this disk's credentials to the filesystem configuration at runtime. - * - * @deprecated Use FileDiskService::registerDisk() instead — setConfig() mutates filesystems.default. - */ - public function setConfig(): void - { - $service = app(FileDiskService::class); - $diskName = $service->registerDisk($this); - config(['filesystems.default' => $diskName]); - } - - /** - * Determine whether this disk is configured as the default storage disk. - */ - public function setAsDefault(): bool - { - return $this->set_as_default; - } - - /** - * Register a dynamic filesystem disk in the runtime configuration using the given credentials. - * - * @deprecated Use FileDisk::find($id)->registerDisk() instead. - */ - public static function setFilesystem(Collection $credentials, string $driver): void - { - $prefix = env('DYNAMIC_DISK_PREFIX', 'temp_'); - - config(['filesystems.default' => $prefix.$driver]); - - $disks = config('filesystems.disks.'.$driver); - - foreach ($disks as $key => $value) { - if ($credentials->has($key)) { - $disks[$key] = $credentials[$key]; - } - } - - if ($driver === 'local' && isset($disks['root']) && ! str_starts_with($disks['root'], '/')) { - $disks['root'] = storage_path('app/'.$disks['root']); - } - - config(['filesystems.disks.'.$prefix.$driver => $disks]); - } - - public function isSystem(): bool - { - return $this->type === self::DISK_TYPE_SYSTEM; - } - - public function isRemote(): bool - { - return $this->type === self::DISK_TYPE_REMOTE; - } -} diff --git a/app/Platform/Storage/Rules/BackupDisk.php b/app/Platform/Storage/Rules/BackupDisk.php deleted file mode 100644 index 3d95c480..00000000 --- a/app/Platform/Storage/Rules/BackupDisk.php +++ /dev/null @@ -1,31 +0,0 @@ -