Skip to content

Commit

Permalink
add edu2edugain folder and update dump
Browse files Browse the repository at this point in the history
  • Loading branch information
temaotl committed May 31, 2024
1 parent 28d3b6d commit b07be35
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
5 changes: 5 additions & 0 deletions app/Console/Commands/DumpFromGit.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Traits\DumpFromGit\CreateFederationTrait;
use App\Traits\DumpFromGit\EntitiesHelp\FixEntityTrait;
use App\Traits\DumpFromGit\EntitiesHelp\UpdateEntity;
use App\Traits\EdugainTrait;
use App\Traits\EntityFolderTrait;
use App\Traits\FederationTrait;
use App\Traits\GitTrait;
Expand All @@ -23,6 +24,7 @@ class DumpFromGit extends Command
use GitTrait, ValidatorTrait,EntityFolderTrait;
use CreateFederationTrait,CreateEntitiesTrait,CreateCategoriesAndGroupsTrait;
use UpdateEntity,FederationTrait,FixEntityTrait;
use EdugainTrait;

/**
* The name and signature of the console command.
Expand Down Expand Up @@ -59,5 +61,8 @@ public function handle()
$this->updateFederationFolders();
$this->fixEntities();
$this->createAllMetadataFiles();
$this->makeEdu2Edugain();


}
}
22 changes: 17 additions & 5 deletions app/Services/EntityService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@

class EntityService
{
public function SaveEntityMetadataToFile($entity_id,$federation_id)
public function saveMetadataToFederationFolder($entity_id,$federation_id)
{
$entity = Entity::find($entity_id);
$federation = Federation::find($federation_id);

if(!$entity || !$federation){
return;
if(!$federation){
throw new \Exception("Federation $federation_id not found");
}
$this->saveEntityMetadataToFolder($entity_id,$federation->name);
}


public function saveEntityMetadataToFolder($entity_id,$folderName)
{
$entity = Entity::find($entity_id);
if(!$entity){
throw new \Exception("Entity not found with id $entity_id");
}
$folderName = $federation->name;
$fileName = $entity->file;
if(!Storage::disk('metadata')->exists($folderName))
{
Expand All @@ -23,5 +31,9 @@ public function SaveEntityMetadataToFile($entity_id,$federation_id)
$filePath = $folderName . '/' . $fileName;
$content = $entity->xml_file;
Storage::disk('metadata')->put($filePath, $content);


}


}
27 changes: 27 additions & 0 deletions app/Traits/EdugainTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
namespace App\Traits;
use App\Facades\EntityFacade;
use App\Models\Entity;

trait EdugainTrait{

use FederationTrait;

public function makeEdu2Edugain()
{
$folderName = 'edu2edugain';
$eduFed = Entity::where('edugain',1 )->get();

foreach ($eduFed as $edu) {
EntityFacade::saveEntityMetadataToFolder($edu->id, $folderName);

}



}




}
2 changes: 1 addition & 1 deletion app/Traits/EntityFolderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function createAllMetadataFiles() : void
$this->updateFederationFolders();
$membership = Membership::select('entity_id','federation_id')->whereApproved(1)->get();
foreach ($membership as $member) {
EntityFacade::SaveEntityMetadataToFile($member->entity_id, $member->federation_id);
EntityFacade::saveMetadataToFederationFolder($member->entity_id, $member->federation_id);
}


Expand Down

0 comments on commit b07be35

Please sign in to comment.