Skip to content

Commit

Permalink
make better seeder run pint and fix FolderAddEntity
Browse files Browse the repository at this point in the history
  • Loading branch information
temaotl committed Jul 17, 2024
1 parent 7c08067 commit ff6062a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 27 deletions.
10 changes: 4 additions & 6 deletions app/Jobs/FolderAddEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,10 @@ public function handle(): void

if ($this->entity->wasChanged('deleted_at') && is_null($this->entity->deleted_at)) {
NotificationService::sendEntityNotification($this->entity, EntityStateChanged::class);
} else
{
if($this->entity->wasChanged('approved') && $this->entity->approved == 1) {
NotificationService::sendEntityNotification($this->entity,);
}
else {
} else {
if ($this->entity->wasChanged('approved') && $this->entity->approved == 1) {
NotificationService::sendEntityNotification($this->entity, EntityStateChanged::class);
} else {
NotificationService::sendEntityNotification($this->entity, EntityUpdated::class);
}
}
Expand Down
5 changes: 0 additions & 5 deletions app/Listeners/SendUpdatedEntityToSaveJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
use App\Jobs\EduGainAddEntity;
use App\Jobs\EduGainDeleteEntity;
use App\Jobs\FolderAddEntity;
use App\Notifications\EntityAddedToHfd;
use App\Notifications\EntityAddedToRs;
use App\Notifications\EntityDeletedFromHfd;
use App\Notifications\EntityDeletedFromRs;
use App\Notifications\EntityUpdated;
use App\Services\NotificationService;

class SendUpdatedEntityToSaveJob
Expand Down
39 changes: 23 additions & 16 deletions app/Services/NotificationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class NotificationService
{
public static function sendEntityNotification(Entity $entity, $notification): void
{
if ($notification == null) {
return;
}

$admins = User::activeAdmins()->select('id', 'email')->get();

$operators = $entity->operators->pluck('id')->toArray();
Expand All @@ -29,39 +33,42 @@ public static function sendEntityNotification(Entity $entity, $notification): vo

private static function sendRsNotification(Entity $entity): bool
{
if($entity->wasChanged('rs')) {
if ($entity->wasChanged('rs')) {

if($entity->rs == 1) {
self::sendEntityNotification($entity,EntityAddedToRs::class);
if ($entity->rs == 1) {
self::sendEntityNotification($entity, EntityAddedToRs::class);
} else {
self::sendEntityNotification($entity,EntityDeletedFromRs::class);
self::sendEntityNotification($entity, EntityDeletedFromRs::class);
}

return true;
}

return false;
}
private static function sendHfDNotification(Entity $entity): bool

private static function sendHfDNotification(Entity $entity): bool
{
if ($entity->wasChanged('hfd')) {

if($entity->hfd) {
self::sendEntityNotification($entity,EntityAddedToHfd::class);
} else {
self::sendEntityNotification($entity,EntityDeletedFromHfd::class);
}
return true;
if ($entity->hfd) {
self::sendEntityNotification($entity, EntityAddedToHfd::class);
} else {
self::sendEntityNotification($entity, EntityDeletedFromHfd::class);
}

return true;
}

return false;
}


public static function sendUpdateNotification(Entity $entity): void
public static function sendUpdateNotification(Entity $entity): void
{

if( !self::sendRsNotification($entity) && !self::sendHfDNotification($entity)){
self::sendEntityNotification($entity,EntityUpdated::class);
if (! self::sendRsNotification($entity) && ! self::sendHfDNotification($entity)) {
self::sendEntityNotification($entity, EntityUpdated::class);
}

}

}
14 changes: 14 additions & 0 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,36 @@
use App\Models\Federation;
use App\Models\Group;
use App\Models\User;
use App\Traits\FederationTrait;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Storage;

class DatabaseSeeder extends Seeder
{
use FederationTrait;

/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
$diskName = config('storageCfg.name');

if (Storage::disk($diskName)->exists('')) {
Storage::disk($diskName)->deleteDirectory('');
}

User::factory()->create(['active' => true, 'admin' => true]);
User::factory()->create(['active' => true, 'admin' => true]);
User::factory()->create(['active' => false, 'admin' => true]);
User::factory()->create(['active' => true]);
User::factory(96)->create();

$edu2edugain = config('storageCfg.edu2edugain');
$this->createFederationFolder($edu2edugain);

/* Federation::factory(20)->create();
Entity::factory(100)->create();*/
/* Category::factory(20)->create();
Expand Down

0 comments on commit ff6062a

Please sign in to comment.