first commit

This commit is contained in:
Noor E Ilahi
2026-01-09 12:54:53 +05:30
commit 7ccf44f7da
1070 changed files with 113036 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Jobs;
use App\Models\TimeInterval;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\DB;
class AssignAppsToTimeInterval implements ShouldQueue, ShouldBeUnique
{
use Dispatchable, InteractsWithQueue, Queueable;
public int $uniqueFor = 60;
public function __construct(protected TimeInterval $interval)
{
}
public function uniqueId(): string
{
return $this->interval->id;
}
public function handle(): void
{
DB::table('tracked_applications')
->whereNull('time_interval_id')
->where('user_id', $this->interval->user_id)
->where('created_at', '>', $this->interval->start_at->setTimezone(config('app.timezone')))
->where('created_at', '<', $this->interval->end_at->setTimezone(config('app.timezone')))
->update(['time_interval_id' => $this->interval->id]);
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Jobs;
use App\Models\TrackedApplication;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
class ClearExpiredApps implements ShouldQueue, ShouldBeUnique
{
use Dispatchable, InteractsWithQueue, Queueable;
public int $uniqueFor = 3600;
public function handle(): void
{
TrackedApplication::where(
'created_at',
'<=',
now()->subDay()->toIso8601String()
)->withoutGlobalScopes()->each(fn (TrackedApplication $el) => $el->delete());
}
}

View File

@@ -0,0 +1,75 @@
<?php
namespace App\Jobs;
use App\Contracts\AppReport;
use App\Models\User;
use App\Notifications\ReportGenerated;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
use Maatwebsite\Excel\Excel;
use Storage;
use Throwable;
class GenerateAndSendReport implements ShouldQueue, ShouldBeUnique
{
use Dispatchable, InteractsWithQueue, Queueable;
public int $uniqueFor = 60;
private string $dir;
private const STORAGE_DRIVE = 'public';
public function getPublicPath(): string
{
return Storage::drive(self::STORAGE_DRIVE)->url($this->getReportPath());
}
/**
* @throws Throwable
*/
public function __construct(
private AppReport $report,
private User $user,
private ?string $type,
) {
$this->dir = Str::uuid();
throw_unless($type, ValidationException::withMessages(['Wrong accept mime type']));
}
/**
* @throws Throwable
*/
public function handle(): void
{
Storage::drive(self::STORAGE_DRIVE)->makeDirectory("reports/$this->dir");
$fileName = $this->getReportPath();
$this->report->store($fileName, self::STORAGE_DRIVE, $this->type === 'pdf' ? Excel::MPDF : Str::ucfirst($this->type));
$this->user->notify((new ReportGenerated($fileName, self::STORAGE_DRIVE)));
$dir = $this->dir;
// dispatch(
// static fn() => Storage::drive(self::STORAGE_DRIVE)->deleteDirectory("reports/$dir")
// )->delay(now()->addHour());
}
public function uniqueId(): string
{
return "{$this->user->id}_{$this->report->getReportId()}_$this->type";
}
private function getReportPath(): string
{
return "/reports/$this->dir/{$this->report->getLocalizedReportName()}.$this->type";
}
}

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Jobs;
use App\Contracts\ScreenshotService;
use App\Models\TimeInterval;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class GenerateScreenshotThumbnail implements ShouldQueue, ShouldBeUnique
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public int $uniqueFor = 3600;
public function __construct(private readonly TimeInterval|int $interval)
{
}
public function handle(ScreenshotService $screenshotService): void
{
$screenshotService->createThumbnail($this->interval);
}
public function uniqueId(): string
{
return optional($this->interval)->id ?: $this->interval;
}
}

View File

@@ -0,0 +1,58 @@
<?php
namespace App\Jobs;
use App\Http\Middleware\RegisterModulesEvents;
use App\Models\Task;
use App\Models\TaskHistory;
use App\Models\User;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Carbon;
class SaveTaskEditHistory implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
private Carbon $timestamp;
private array $changes;
private array $original;
public function __construct(protected Task $task, protected User $author, array $changes = null, array $original = null)
{
$this->timestamp = now();
$this->changes = $changes ?: $task->getChanges();
$this->original = $original ?: $task->getOriginal();
}
public function handle(): void
{
foreach ($this->changes as $key => $value) {
if (in_array($key, ['relative_position', 'created_at', 'updated_at', 'deleted_at'])) {
continue;
}
$new_value = $value;
$old_value = $this->original[$key];
// because we need to save a string, not id
if ($key === 'project_phase_id') {
$new_value = $this->task->phase?->name;
$old_value = $this->original['_old_phase_name'];
}
$activity = TaskHistory::create([
'task_id' => $this->task->id,
'user_id' => $this->author->id,
'field' => $key,
'new_value' => $new_value,
'old_value' => $old_value,
]);
$activity->updateQuietly(['created_at' => $this->timestamp]);
// broadcast activity
RegisterModulesEvents::broadcastEvent('tasks_activities', 'create', $activity->load('user'));
}
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace App\Jobs;
use App\Contracts\AttachmentService;
use App\Models\Attachment;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Log;
class VerifyAttachmentHash implements ShouldQueue, ShouldBeUnique
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Delete the job if its models no longer exist.
*
* @var bool
*/
public bool $deleteWhenMissingModels = true;
/**
* Create a new job instance.
*/
public function __construct(public Attachment $attachment)
{
//
}
/**
* Execute the job.
*/
public function handle(AttachmentService $service): void
{
$service->verifyHash($this->attachment);
}
/**
* The unique ID of the job.
*/
public function uniqueId(): string
{
return $this->attachment->id;
}
public function failed(\Throwable $exception = null): void
{
Log::error('Job VerifyAttachmentHash Failed', [
'attachment_id' => $this->attachment->id,
'exception' => $exception
]);
}
}