Skip to content

Commit

Permalink
run pint
Browse files Browse the repository at this point in the history
  • Loading branch information
temaotl committed Jul 13, 2024
1 parent 1a79a55 commit dd1446f
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 79 deletions.
38 changes: 19 additions & 19 deletions app/Http/Controllers/EntityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -474,15 +474,15 @@ function () use ($entity) {
$color = $entity->rs ? 'green' : 'red';

// TODO notification
/* if ($entity->rs) {
GitAddToRs::dispatch($entity, Auth::user());
Notification::send($entity->operators, new EntityAddedToRs($entity));
Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityAddedToRs($entity));
} else {
GitDeleteFromRs::dispatch($entity, Auth::user());
Notification::send($entity->operators, new EntityDeletedFromRs($entity));
Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityDeletedFromRs($entity));
}*/
/* if ($entity->rs) {
GitAddToRs::dispatch($entity, Auth::user());
Notification::send($entity->operators, new EntityAddedToRs($entity));
Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityAddedToRs($entity));
} else {
GitDeleteFromRs::dispatch($entity, Auth::user());
Notification::send($entity->operators, new EntityDeletedFromRs($entity));
Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityDeletedFromRs($entity));
}*/

return redirect()
->back()
Expand Down Expand Up @@ -543,16 +543,16 @@ function () use ($entity, $category) {
$color = $entity->hfd ? 'red' : 'green';

//TODO change HfD status
/* if ($entity->hfd) {
GitAddToHfd::dispatch($entity, Auth::user());
Notification::send($entity->operators, new EntityAddedToHfd($entity));
Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityAddedToHfd($entity));
} else {
GitDeleteFromHfd::dispatch($entity, Auth::user());
Mail::to(config('mail.ra.address'))->send(new NewIdentityProvider($entity));
Notification::send($entity->operators, new EntityDeletedFromHfd($entity));
Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityDeletedFromHfd($entity));
}*/
/* if ($entity->hfd) {
GitAddToHfd::dispatch($entity, Auth::user());
Notification::send($entity->operators, new EntityAddedToHfd($entity));
Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityAddedToHfd($entity));
} else {
GitDeleteFromHfd::dispatch($entity, Auth::user());
Mail::to(config('mail.ra.address'))->send(new NewIdentityProvider($entity));
Notification::send($entity->operators, new EntityDeletedFromHfd($entity));
Notification::send(User::activeAdmins()->select('id', 'email')->get(), new EntityDeletedFromHfd($entity));
}*/

return redirect()
->route('entities.show', $entity)
Expand Down
10 changes: 3 additions & 7 deletions app/Jobs/EduGainAddEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

use App\Facades\EntityFacade;
use App\Models\Entity;
use App\Notifications\EntityStateChanged;
use App\Notifications\EntityUpdated;
use App\Services\NotificationService;
use App\Traits\HandlesJobsFailuresTrait;
use Exception;
use Illuminate\Bus\Queueable;
Expand All @@ -22,6 +19,7 @@ class EduGainAddEntity implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
use HandlesJobsFailuresTrait;

public Entity $entity;

/**
Expand All @@ -41,7 +39,7 @@ public function handle(): void
$folderName = config('storageCfg.edu2edugain');
try {
if (! Storage::disk($diskName)->exists($folderName)) {
throw new Exception("No $folderName in $diskName");
throw new Exception("No $folderName in $diskName");
}
} catch (Exception $e) {
$this->fail($e);
Expand All @@ -51,7 +49,7 @@ public function handle(): void
$lock = Cache::lock($lockKey, 61);
try {
$lock->block(61);
EntityFacade::saveEntityMetadataToFolder($this->entity->id,$folderName);
EntityFacade::saveEntityMetadataToFolder($this->entity->id, $folderName);

//TODO write custom function to run special MDA script (ask about this)
EduGainRunMdaScript::dispatch($lock->owner());
Expand All @@ -64,7 +62,5 @@ public function handle(): void
}
}



}
}
4 changes: 2 additions & 2 deletions app/Jobs/EduGainDeleteEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function handle(): void
$folderName = config('storageCfg.edu2edugain');
try {
if (! Storage::disk($diskName)->exists($folderName)) {
throw new Exception("No $folderName in $diskName");
throw new Exception("No $folderName in $diskName");
}
} catch (Exception $e) {
$this->fail($e);
Expand All @@ -53,7 +53,7 @@ public function handle(): void
$lock = Cache::lock($lockKey, 61);
try {
$lock->block(61);
EntityFacade::deleteEntityMetadataFromFolder($this->entity->file,$folderName);
EntityFacade::deleteEntityMetadataFromFolder($this->entity->file, $folderName);

//TODO write custom function to run special MDA script (ask about this)

Expand Down
3 changes: 0 additions & 3 deletions app/Jobs/EduGainRunMdaScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,5 @@ public function handle(): void

}




}
}
11 changes: 2 additions & 9 deletions app/Jobs/FolderAddEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
namespace App\Jobs;

use App\Facades\EntityFacade;
use App\Mail\ExceptionOccured;
use App\Models\Entity;
use App\Models\Federation;
use App\Models\Membership;
use App\Notifications\EntityStateChanged;
use App\Notifications\EntityUpdated;
use App\Services\EntityService;
use App\Services\NotificationService;
use App\Traits\HandlesJobsFailuresTrait;
use Illuminate\Bus\Queueable;
Expand All @@ -20,10 +18,8 @@
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Storage;
use Mockery\Exception;
use Throwable;

class FolderAddEntity implements ShouldQueue
{
Expand All @@ -34,7 +30,6 @@ class FolderAddEntity implements ShouldQueue
*/
use HandlesJobsFailuresTrait;


public Entity $entity;

/**
Expand Down Expand Up @@ -71,11 +66,10 @@ public function handle(): void
$lock->block(61);
EntityFacade::saveMetadataToFederationFolder($this->entity->id, $fedId->federation_id);


if ($this->entity->wasRecentlyCreated) {
NotificationService::sendEntityNotification($this->entity,EntityUpdated::class);
NotificationService::sendEntityNotification($this->entity, EntityUpdated::class);
} elseif ($this->entity->wasChanged('deleted_at') && is_null($this->entity->deleted_at)) {
NotificationService::sendEntityNotification($this->entity,EntityStateChanged::class);
NotificationService::sendEntityNotification($this->entity, EntityStateChanged::class);
}

RunMdaScript::dispatch($federation, $lock->owner());
Expand All @@ -99,5 +93,4 @@ public function middleware(): array
{
return [(new WithoutOverlapping($this->entity->id))->dontRelease()];
}

}
6 changes: 2 additions & 4 deletions app/Jobs/FolderDeleteEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use App\Models\Entity;
use App\Notifications\EntityDeletedFromHfd;
use App\Notifications\EntityStateChanged;
use App\Services\EntityService;
use App\Services\NotificationService;
use App\Traits\HandlesJobsFailuresTrait;
use Illuminate\Bus\Queueable;
Expand Down Expand Up @@ -58,12 +57,11 @@ public function handle(): void
$lock->block(61);
EntityFacade::deleteEntityMetadataFromFolder($entity->file, $federation->xml_id);

NotificationService::sendEntityNotification($entity,EntityStateChanged::class);
NotificationService::sendEntityNotification($entity, EntityStateChanged::class);
if ($entity->hfd) {
NotificationService::sendEntityNotification($entity,EntityDeletedFromHfd::class);
NotificationService::sendEntityNotification($entity, EntityDeletedFromHfd::class);
}


RunMdaScript::dispatch($federation, $lock->owner());
} catch (Exception $e) {
Log::error($e->getMessage());
Expand Down
5 changes: 2 additions & 3 deletions app/Jobs/RunMdaScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public function handle(): void
$filterArray = explode(', ', $this->federation->filters);
$scriptPath = config('storageCfg.mdaScript');


$realScriptPath = realpath($scriptPath);

try {
Expand Down Expand Up @@ -77,11 +76,11 @@ public function middleware(): array
{
$diskName = config('storageCfg.name');
$pathToDirectory = Storage::disk($diskName)->path($this->federation->name);
$lockKey = 'directory-' . md5($pathToDirectory) . '-lock';
$lockKey = 'directory-'.md5($pathToDirectory).'-lock';

return [
new RateLimited('mda-run-limit'),
(new WithoutOverlapping($lockKey))->dontRelease()
(new WithoutOverlapping($lockKey))->dontRelease(),
];

}
Expand Down
2 changes: 1 addition & 1 deletion app/Listeners/SendCreatedEntityToSaveJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function handle(CreateEntity $event): void
if ($event->entity->approved == 1) {
FolderAddEntity::dispatch($event->entity);

if($event->entity->edugain == 1){
if ($event->entity->edugain == 1) {
EduGainAddEntity::dispatch($event->entity);
}

Expand Down
4 changes: 1 addition & 3 deletions app/Listeners/SendDeletedEntityToDeleteJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use App\Jobs\EduGainDeleteEntity;
use App\Jobs\FolderDeleteEntity;


class SendDeletedEntityToDeleteJob
{
/**
Expand All @@ -24,10 +23,9 @@ public function handle(DeleteEntity $event): void
{
FolderDeleteEntity::dispatch($event->entity);

if($event->entity->edugain == 1){
if ($event->entity->edugain == 1) {
EduGainDeleteEntity::dispatch($event->entity);
}


}
}
18 changes: 5 additions & 13 deletions app/Listeners/SendUpdatedEntityToSaveJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
use App\Jobs\EduGainAddEntity;
use App\Jobs\EduGainDeleteEntity;
use App\Jobs\FolderAddEntity;
use App\Models\User;
use App\Notifications\EntityUpdated;
use App\Services\NotificationService;
use Illuminate\Support\Facades\Notification;

class SendUpdatedEntityToSaveJob
{
Expand All @@ -31,24 +29,18 @@ public function handle(UpdateEntity $event): void

if ($entity->wasChanged('xml_file') ||
($entity->wasChanged('approved') && $entity->approved == 1)
)
{
) {
FolderAddEntity::dispatch($event->entity);
} elseif ($entity->approved == 1 && ! $entity->wasChanged('edugain')) {
NotificationService::sendEntityNotification($entity, EntityUpdated::class);
}
elseif ($entity->approved == 1 && !$entity->wasChanged('edugain'))
{
NotificationService::sendEntityNotification($entity,EntityUpdated::class);
}
if($entity->wasChanged('edugain'))
{
if($entity->edugain == 1) {
if ($entity->wasChanged('edugain')) {
if ($entity->edugain == 1) {
EduGainAddEntity::dispatch($entity);
} else {
EduGainDeleteEntity::dispatch($entity);
}
}



}
}
14 changes: 7 additions & 7 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public function boot()
// Mail::alwaysTo('[email protected]');
Model::preventLazyLoading();
}
//TODO comment this for testing part
/* RateLimiter::for('mda-run-limit', function (RunMdaScript $job) {
$diskName = config('storageCfg.name');
$pathToDirectory = Storage::disk($diskName)->path($job->federation->name);
$lockKey = 'directory-'.md5($pathToDirectory).'-lock';
return Limit::perMinute(1)->by($lockKey);
});*/
//TODO comment this for testing part
/* RateLimiter::for('mda-run-limit', function (RunMdaScript $job) {
$diskName = config('storageCfg.name');
$pathToDirectory = Storage::disk($diskName)->path($job->federation->name);
$lockKey = 'directory-'.md5($pathToDirectory).'-lock';
return Limit::perMinute(1)->by($lockKey);
});*/

}
}
13 changes: 7 additions & 6 deletions app/Services/NotificationService.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
<?php

namespace App\Services;

use App\Models\Entity;
use App\Models\User;
use Illuminate\Support\Facades\Notification;


class NotificationService{

public static function sendEntityNotification(Entity $entity,$notification){
class NotificationService
{
public static function sendEntityNotification(Entity $entity, $notification)
{
$admins = User::activeAdmins()->select('id', 'email')->get();

$operators = $entity->operators->pluck('id')->toArray();

$filteredAdmins = $admins->filter(function ($admin) use ($operators) {
return !in_array($admin->id, $operators);
return ! in_array($admin->id, $operators);
});

Notification::sendNow($entity->operators, new $notification($entity));
Notification::sendNow($filteredAdmins, new $notification($entity));
}

}
4 changes: 3 additions & 1 deletion app/Traits/HandlesJobsFailuresTrait.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

namespace App\Traits;

use App\Mail\ExceptionOccured;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use App\Mail\ExceptionOccured;
use Throwable;

trait HandlesJobsFailuresTrait
Expand Down
2 changes: 1 addition & 1 deletion config/storageCfg.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
'name' => 'metadata',
'mdaConfigFolder' => env('MDA_CONFIG_FOLDER'),
'mdaScript' => env('MDA_SCRIPT'),
'edu2edugain' =>env('EDU_TO_EDUGAIN_FOLDER'),
'edu2edugain' => env('EDU_TO_EDUGAIN_FOLDER'),
];

0 comments on commit dd1446f

Please sign in to comment.