feat: upgrade filament to v4 and ensure 100% test coverage
- Upgrade Filament framework from v3 to v4 - Update all Filament resources and pages for v4 compatibility - Fix test suite to maintain 100% pass rate (321 tests passing) - Add visibility condition for ticket close action (only when not closed) - Update dependencies and build assets for new Filament version - Maintain backward compatibility while leveraging v4 improvements
This commit is contained in:
@@ -2,6 +2,10 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Ddeboer\Imap\ConnectionInterface;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\ColorPicker;
|
||||
use Carbon\Carbon;
|
||||
use Carbon\CarbonImmutable;
|
||||
@@ -48,7 +52,7 @@ class Email extends Model
|
||||
'timestamp' => 'datetime', // Cast timestamp to Carbon instance
|
||||
];
|
||||
|
||||
public static function connectMailBox($imap = null): \Ddeboer\Imap\ConnectionInterface
|
||||
public static function connectMailBox($imap = null): ConnectionInterface
|
||||
{
|
||||
if ($imap === null) {
|
||||
$imap = json_decode(config('app.settings.imap_settings'), true);
|
||||
@@ -69,7 +73,7 @@ class Email extends Model
|
||||
|
||||
try {
|
||||
$allowed = explode(',', 'doc,docx,xls,xlsx,ppt,pptx,xps,pdf,dxf,ai,psd,eps,ps,svg,ttf,zip,rar,tar,gzip,mp3,mpeg,wav,ogg,jpeg,jpg,png,gif,bmp,tif,webm,mpeg4,3gpp,mov,avi,mpegs,wmv,flx,txt');
|
||||
$connection = \App\Models\Email::connectMailBox();
|
||||
$connection = Email::connectMailBox();
|
||||
$mailbox = $connection->getMailbox('INBOX');
|
||||
$messages = $mailbox->getMessages();
|
||||
|
||||
@@ -79,7 +83,7 @@ class Email extends Model
|
||||
$sender = $message->getFrom();
|
||||
$date = $message->getDate();
|
||||
if (! $date) {
|
||||
$date = new \DateTime;
|
||||
$date = new DateTime;
|
||||
if ($message->getHeaders()->get('udate')) {
|
||||
$date->setTimestamp($message->getHeaders()->get('udate'));
|
||||
}
|
||||
@@ -146,8 +150,8 @@ class Email extends Model
|
||||
$directory.$attachment->getFilename(),
|
||||
$attachment->getDecodedContent()
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
\Illuminate\Support\Facades\Log::error($e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -204,7 +208,7 @@ class Email extends Model
|
||||
}
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
// \Log::error($e);
|
||||
}
|
||||
} else {
|
||||
@@ -241,7 +245,7 @@ class Email extends Model
|
||||
}
|
||||
}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
// \Log::error($e);
|
||||
}
|
||||
}
|
||||
@@ -250,8 +254,8 @@ class Email extends Model
|
||||
|
||||
$connection->expunge();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
\Illuminate\Support\Facades\Log::error($e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -364,20 +368,20 @@ class Email extends Model
|
||||
if (File::exists($dir)) {
|
||||
File::cleanDirectory($dir);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
\Illuminate\Support\Facades\Log::error($e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static function deleteBulkMailboxes()
|
||||
{
|
||||
$foldersToClean = ['INBOX', 'ZDUMP', 'Trash'];
|
||||
$cutoff = (new \DateTime)->modify('-3 hours');
|
||||
$cutoff = (new DateTime)->modify('-3 hours');
|
||||
$totalDeleted = 0;
|
||||
$maxToDelete = 100;
|
||||
|
||||
foreach ($foldersToClean as $folderName) {
|
||||
$connection = \App\Models\Email::connectMailBox();
|
||||
$connection = Email::connectMailBox();
|
||||
if ($totalDeleted >= $maxToDelete) {
|
||||
$connection->expunge();
|
||||
break;
|
||||
@@ -385,7 +389,7 @@ class Email extends Model
|
||||
|
||||
if ($connection->hasMailbox($folderName)) {
|
||||
$mailbox = $connection->getMailbox($folderName);
|
||||
$messages = $mailbox->getMessages(new Since(new \DateTime('today')));
|
||||
$messages = $mailbox->getMessages(new Since(new DateTime('today')));
|
||||
|
||||
foreach ($messages as $message) {
|
||||
if ($totalDeleted >= $maxToDelete) {
|
||||
@@ -446,12 +450,12 @@ class Email extends Model
|
||||
public static function cleanMailbox(): string
|
||||
{
|
||||
$foldersToClean = ['INBOX'];
|
||||
$cutoff = (new \DateTime)->modify('-6 hours');
|
||||
$cutoff = (new DateTime)->modify('-6 hours');
|
||||
$totalDeleted = 0;
|
||||
$maxToDelete = 100;
|
||||
|
||||
foreach ($foldersToClean as $folderName) {
|
||||
$connection = \App\Models\Email::connectMailBox();
|
||||
$connection = Email::connectMailBox();
|
||||
if ($totalDeleted >= $maxToDelete) {
|
||||
$connection->expunge();
|
||||
break;
|
||||
@@ -459,7 +463,7 @@ class Email extends Model
|
||||
|
||||
if ($connection->hasMailbox($folderName)) {
|
||||
$mailbox = $connection->getMailbox($folderName);
|
||||
$messages = $mailbox->getMessages(new Since(new \DateTime('today')));
|
||||
$messages = $mailbox->getMessages(new Since(new DateTime('today')));
|
||||
|
||||
foreach ($messages as $message) {
|
||||
if ($totalDeleted >= $maxToDelete) {
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\ColorPicker;
|
||||
use Carbon\Carbon;
|
||||
use Ddeboer\Imap\Search\Email\Cc;
|
||||
@@ -151,7 +154,7 @@ class Message extends Model
|
||||
$sender = $message->getFrom();
|
||||
$date = $message->getDate();
|
||||
if (! $date) {
|
||||
$date = new \DateTime;
|
||||
$date = new DateTime;
|
||||
if ($message->getHeaders()->get('udate')) {
|
||||
$date->setTimestamp($message->getHeaders()->get('udate'));
|
||||
}
|
||||
@@ -208,8 +211,8 @@ class Message extends Model
|
||||
$directory.$attachment->getFilename(),
|
||||
$attachment->getDecodedContent()
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
\Illuminate\Support\Facades\Log::error($e->getMessage());
|
||||
} catch (Exception $e) {
|
||||
Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
if ($attachment->getFilename() !== 'undefined') {
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Ddeboer\Imap\ConnectionInterface;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use Log;
|
||||
use App\ColorPicker;
|
||||
use Carbon\Carbon;
|
||||
use Ddeboer\Imap\Search\Email\Cc;
|
||||
@@ -15,7 +19,7 @@ use Illuminate\Support\Facades\Cookie;
|
||||
class Premium extends Model
|
||||
{
|
||||
use ColorPicker;
|
||||
public static function connectMailBox($imap = null): \Ddeboer\Imap\ConnectionInterface
|
||||
public static function connectMailBox($imap = null): ConnectionInterface
|
||||
{
|
||||
$imapDB = json_decode(config('app.settings.imap_settings'), true);
|
||||
$imap = [
|
||||
@@ -67,7 +71,7 @@ class Premium extends Model
|
||||
$sender = $message->getFrom();
|
||||
$date = $message->getDate();
|
||||
if (!$date) {
|
||||
$date = new \DateTime();
|
||||
$date = new DateTime();
|
||||
if ($message->getHeaders()->get('udate')) {
|
||||
$date->setTimestamp($message->getHeaders()->get('udate'));
|
||||
}
|
||||
@@ -126,7 +130,7 @@ class Premium extends Model
|
||||
$directory . $attachment->getFilename(),
|
||||
$attachment->getDecodedContent()
|
||||
);
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
\Illuminate\Support\Facades\Log::error($e->getMessage());
|
||||
}
|
||||
}
|
||||
@@ -527,8 +531,8 @@ class Premium extends Model
|
||||
$usageLog->emails_created_history = $history;
|
||||
$usageLog->save();
|
||||
}
|
||||
} catch (\Exception $exception) {
|
||||
\Log::error($exception->getMessage());
|
||||
} catch (Exception $exception) {
|
||||
Log::error($exception->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Exception;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -61,7 +62,7 @@ class Ticket extends Model
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Database\Factories\UserFactory;
|
||||
use Filament\Models\Contracts\FilamentUser;
|
||||
use Filament\Panel;
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
@@ -16,7 +17,7 @@ use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class User extends Authenticatable implements FilamentUser, MustVerifyEmail
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
/** @use HasFactory<UserFactory> */
|
||||
use Billable, HasApiTokens, HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Ddeboer\Imap\ConnectionInterface;
|
||||
use Ddeboer\Imap\Search\Email\To;
|
||||
use Ddeboer\Imap\Server;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -11,7 +12,7 @@ use function str_replace;
|
||||
|
||||
class ZEmail extends Model
|
||||
{
|
||||
public static function connectMailBox($imap = null): \Ddeboer\Imap\ConnectionInterface
|
||||
public static function connectMailBox($imap = null): ConnectionInterface
|
||||
{
|
||||
if ($imap === null) {
|
||||
$imap = json_decode(config('app.settings.imap_settings'), true);
|
||||
|
||||
Reference in New Issue
Block a user