Skip to content

Commit

Permalink
rewrite FederationTrait.php to FederationService.php
Browse files Browse the repository at this point in the history
  • Loading branch information
temaotl committed Jul 25, 2024
1 parent 7eeb5b4 commit 9dd81a9
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 24 deletions.
8 changes: 4 additions & 4 deletions app/Console/Commands/DumpFromGit.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
use App\Models\Entity;
use App\Models\Membership;
use App\Models\User;
use App\Services\FederationService;
use App\Traits\DumpFromGit\CreateCategoriesAndGroupsTrait;
use App\Traits\DumpFromGit\CreateEntitiesTrait;
use App\Traits\DumpFromGit\CreateFederationTrait;
use App\Traits\DumpFromGit\EntitiesHelp\FixEntityTrait;
use App\Traits\DumpFromGit\EntitiesHelp\UpdateEntity;
use App\Traits\EdugainTrait;
use App\Traits\FederationTrait;
use App\Traits\GitTrait;
use App\Traits\ValidatorTrait;
use Exception;
Expand All @@ -22,7 +22,7 @@ class DumpFromGit extends Command
{
use CreateCategoriesAndGroupsTrait,CreateEntitiesTrait,CreateFederationTrait;
use EdugainTrait;
use FederationTrait,FixEntityTrait,UpdateEntity;
use FixEntityTrait,UpdateEntity;
use GitTrait, ValidatorTrait;

/**
Expand All @@ -41,7 +41,7 @@ class DumpFromGit extends Command

private function createMetadataFiles(): void
{
$this->updateFederationFolders();
FederationService::createFoldersToAllFederation();
$membership = Membership::select('entity_id', 'federation_id')->whereApproved(1)->get();
foreach ($membership as $member) {
EntityFacade::saveMetadataToFederationFolder($member->entity_id, $member->federation_id);
Expand All @@ -67,7 +67,7 @@ public function handle()
$this->createCategoriesAndGroups();
$this->updateGroupsAndCategories();
$this->updateEntitiesXml();
$this->updateFederationFolders();
FederationService::createFoldersToAllFederation();
$this->fixEntities();
$this->createMetadataFiles();
$this->makeEdu2Edugain();
Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/EntityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,8 @@ function () use ($entity) {
Notification::sendNow($new_operators, new YourEntityRightsChanged($entity, 'added'));
NotificationService::sendOperatorNotification($old_operators, new EntityOperatorsChanged($entity, $new_operators, 'added'));

/* Notification::send($old_operators, new EntityOperatorsChanged($entity, $new_operators, 'added'));
Notification::send($admins, new EntityOperatorsChanged($entity, $new_operators, 'added'));*/
/* Notification::send($old_operators, new EntityOperatorsChanged($entity, $new_operators, 'added'));
Notification::send($admins, new EntityOperatorsChanged($entity, $new_operators, 'added'));*/

return redirect()
->route('entities.show', $entity)
Expand All @@ -416,8 +416,8 @@ function () use ($entity) {
$admins = User::activeAdmins()->select('id', 'email')->get();
Notification::sendNow($old_operators, new YourEntityRightsChanged($entity, 'deleted'));
NotificationService::sendOperatorNotification($old_operators, new EntityOperatorsChanged($entity, $old_operators, 'deleted'));
/* Notification::send($new_operators, new EntityOperatorsChanged($entity, $old_operators, 'deleted'));
Notification::send($admins, new EntityOperatorsChanged($entity, $old_operators, 'deleted'));*/
/* Notification::send($new_operators, new EntityOperatorsChanged($entity, $old_operators, 'deleted'));
Notification::send($admins, new EntityOperatorsChanged($entity, $old_operators, 'deleted'));*/

return redirect()
->route('entities.show', $entity)
Expand Down
6 changes: 2 additions & 4 deletions app/Listeners/CreateFederationFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
namespace App\Listeners;

use App\Events\FederationApprove;
use App\Traits\FederationTrait;
use App\Services\FederationService;
use Illuminate\Support\Facades\Storage;

class CreateFederationFolder
{
use FederationTrait;

/**
* Create the event listener.
*/
Expand All @@ -28,7 +26,7 @@ public function handle(FederationApprove $event): void
$federation = $event->federation;
if ($federation->approved) {
if (! Storage::disk($diskName)->exists($federation->name)) {
$this->createFederationFolder($federation->name);
FederationService::createFederationFolder($federation->name);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<?php

namespace App\Traits;
namespace App\Services;

use App\Models\Federation;
use Illuminate\Support\Facades\Storage;

trait FederationTrait
class FederationService
{
public function createFederationFolder(string $name): void
public static function createFederationFolder(string $name): void
{

Storage::disk(config('storageCfg.name'))->makeDirectory($name);
}

public function updateFederationFolders(): void
public static function createFoldersToAllFederation(): void
{
$federations = Federation::all();

foreach ($federations as $fed) {
if (! Storage::disk(config('storageCfg.name'))->exists($fed['xml_id'])) {
$this->createFederationFolder($fed['xml_id']);
self::createFederationFolder($fed['xml_id']);
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions app/Traits/EdugainTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

trait EdugainTrait
{
use FederationTrait;

public function makeEdu2Edugain()
{
$folderName = config('storageCfg.edu2edugain');
Expand Down
7 changes: 2 additions & 5 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
use App\Models\Federation;
use App\Models\Group;
use App\Models\User;
use App\Traits\FederationTrait;
use App\Services\FederationService;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Storage;

class DatabaseSeeder extends Seeder
{
use FederationTrait;

/**
* Seed the application's database.
*
Expand All @@ -34,8 +32,7 @@ public function run()
User::factory()->create(['active' => true]);
User::factory(96)->create();

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

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

0 comments on commit 9dd81a9

Please sign in to comment.