Skip to content

Commit

Permalink
Merge PR #22
Browse files Browse the repository at this point in the history
  • Loading branch information
JanOppolzer committed May 13, 2024
1 parent aa39fa1 commit ae3df2e
Show file tree
Hide file tree
Showing 31 changed files with 1,593 additions and 365 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
/storage/*.key
/storage/debugbar
/storage/git
/storage/metadata
/tests/report
/vendor
/storage/logs
.env
.env.backup
.env.dusk.local
Expand All @@ -17,4 +19,4 @@ envoy
npm-debug.log
yarn-error.log
/docker/8.1/id_ed25519*
/docker/8.1/known_hosts
/docker/8.1/known_hosts
60 changes: 60 additions & 0 deletions app/Console/Commands/DumpFromGit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace App\Console\Commands;


use App\Facades\EntityFacade;
use App\Models\User;
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\EntityFolderTrait;
use App\Traits\FederationTrait;
use App\Traits\GitTrait;
use Illuminate\Console\Command;
use App\Traits\ValidatorTrait;
use Illuminate\Support\Facades\Artisan;


class DumpFromGit extends Command
{
use GitTrait, ValidatorTrait,EntityFolderTrait;
use CreateFederationTrait,CreateEntitiesTrait,CreateCategoriesAndGroupsTrait;
use UpdateEntity,FederationTrait,FixEntityTrait;

/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:dump-from-git';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';




/**
* Execute the console command.
*/
public function handle()
{
$firstAdminId = User::where('admin', 1)->first()->id;
$this->initializeGit();
$this->createFederations();
$this->createEntities($firstAdminId);
$this->createCategoriesAndGroups();
$this->updateGroupsAndCategories();
$this->updateEntitiesXml();
$this->updateFederationFolders();
$this->fixEntities();
$this->createAllMetadataFiles();
}
}
93 changes: 93 additions & 0 deletions app/Console/Commands/ValidateMetaConsole.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace App\Console\Commands;

use App\Models\Entity;
use App\Traits\DumpFromGit\EntitiesHelp\FixEntityTrait;
use App\Traits\ValidatorTrait;
use Illuminate\Console\Command;

class ValidateMetaConsole extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:val';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';


use ValidatorTrait,FixEntityTrait;

/**
* Execute the console command.
*/

private function doc()
{
foreach (Entity::select()->get() as $entity)
{
$ent = Entity::where('id', $entity->id)->select()->first();


// $res = json_decode($this->validateMetadata($ent->metadata),true);
$res = json_decode($this->validateMetadata($ent->xml_file,true),true);
$res['ent_id'] = $ent->id;
$errorArray = $res['errorArray'];


if($res['code']==1)
{
dump($res);
}
else
{
dump($res['ent_id']);
}
}
}

private function meta()
{
foreach (Entity::select()->get() as $entity)
{

$ent = Entity::where('id', $entity->id)->select()->first();

$curr = 345;

if($ent->id < $curr)
continue;
if($ent->id > $curr)
break;


$res = json_decode($this->validateMetadata($ent->metadata),true);
$res['ent_id'] = $ent->id;


dump($res);
if( $res['code']==1)
{

}
}
}


public function handle()
{

// $this->fixEntities();
$this->doc();


}
}
13 changes: 13 additions & 0 deletions app/Facades/EntityFacade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Facades;

use Illuminate\Support\Facades\Facade;

class EntityFacade extends Facade
{
protected static function getFacadeAccessor()
{
return 'entity';
}
}
42 changes: 42 additions & 0 deletions app/Jobs/SaveMetadataToFolders.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace App\Jobs;

use App\Facades\EntityFacade;
use App\Models\Entity;
use App\Models\Federation;
use App\Traits\FederationTrait;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;

class SaveMetadataToFolders implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* Create a new job instance.
*/

protected int $entity_id;
protected int $federation_id;

public function __construct($entity_id, $federation_id)
{
$this->entity_id = $entity_id;
$this->federation_id = $federation_id;
}

/**
* Execute the job.
*/
public function handle(): void
{
EntityFacade::SaveEntityMetadataToFile($this->entity_id,$this->federation_id);

}
}
1 change: 1 addition & 0 deletions app/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Category extends Model
'name',
'description',
'tagfile',
'xml_value'
];

public function entities()
Expand Down
1 change: 1 addition & 0 deletions app/Models/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Entity extends Model
'type',
'entityid',
'file',
'xml_file',
'name_en',
'name_cs',
'description_en',
Expand Down
3 changes: 2 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Providers;

use App\Services\EntityService;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\ServiceProvider;
Expand All @@ -15,7 +16,7 @@ class AppServiceProvider extends ServiceProvider
*/
public function register()
{
//

}

/**
Expand Down
27 changes: 27 additions & 0 deletions app/Providers/EntityFacadeServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Providers;

use App\Services\EntityService;
use Illuminate\Support\ServiceProvider;

class EntityFacadeServiceProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
$this->app->singleton('entity', function ($app) {
return new EntityService();
});
}

/**
* Bootstrap services.
*/
public function boot(): void
{
//
}
}
27 changes: 27 additions & 0 deletions app/Services/EntityService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
namespace App\Services;
use App\Models\Entity;
use App\Models\Federation;
use Illuminate\Support\Facades\Storage;

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

if(!$entity || !$federation){
return;
}
$folderName = $federation->name;
$fileName = $entity->file;
if(!Storage::disk('metadata')->exists($folderName))
{
Storage::disk('metadata')->makeDirectory($folderName);
}
$filePath = $folderName . '/' . $fileName . 'xml';
$content = $entity->xml_file;
Storage::disk('metadata')->put($filePath, $content);
}
}
Loading

0 comments on commit ae3df2e

Please sign in to comment.