Skip to content

Commit

Permalink
rewrite metadata storage name to config file
Browse files Browse the repository at this point in the history
  • Loading branch information
temaotl committed Jul 8, 2024
1 parent 61553ca commit fa6a79e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
3 changes: 2 additions & 1 deletion app/Listeners/CreateFederationFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ public function __construct()
*/
public function handle(FederationApprove $event): void
{
$diskName = config('storageCfg.name');

$federation = $event->federation;
if ($federation->approved) {
if (! Storage::disk('metadata')->exists($federation->name)) {
if (! Storage::disk($diskName)->exists($federation->name)) {
$this->createFederationFolder($federation->name);
}
}
Expand Down
9 changes: 6 additions & 3 deletions app/Services/EntityService.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,20 @@ public function saveMetadataToFederationFolder($entity_id, $federation_id): void
*/
public function saveEntityMetadataToFolder($entity_id, $folderName): void
{
$diskName = config('storageCfg.name');


$entity = Entity::find($entity_id);
if (! $entity) {
throw new Exception("Entity not found with id $entity_id");
}
$fileName = $entity->file;
if (! Storage::disk('metadata')->exists($folderName)) {
Storage::disk('metadata')->makeDirectory($folderName);
if (! Storage::disk($diskName)->exists($folderName)) {
Storage::disk($diskName)->makeDirectory($folderName);
}
$filePath = $folderName.'/'.$fileName;
$content = $entity->xml_file;
Storage::disk('metadata')->put($filePath, $content);
Storage::disk($diskName)->put($filePath, $content);

}
}
8 changes: 6 additions & 2 deletions app/Traits/FederationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@

trait FederationTrait
{



public function createFederationFolder(string $name): void
{
Storage::disk('metadata')->makeDirectory($name);

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

public function updateFederationFolders(): void
{
$federations = Federation::select('name')->get();

foreach ($federations as $fed) {
if (! Storage::disk('metadata')->exists($fed['name'])) {
if (! Storage::disk(config('storageCfg.name'))->exists($fed['name'])) {
$this->createFederationFolder($fed['name']);
}
}
Expand Down
4 changes: 4 additions & 0 deletions config/storageCfg.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
return [
'name' => 'metadata',
];

0 comments on commit fa6a79e

Please sign in to comment.