Skip to content

Commit

Permalink
Entity feature (#25)
Browse files Browse the repository at this point in the history
* add xml_file field to update case in store

* fix test and commit Bus:chain

* start with job

* rewrite update to transaction

* use pint for code style

* make save job

* make update (no tested)

* rewrite metadata storage name to config file

* change saving attribute from name to xml_id

* make Cache lock on job

* make run script function

* rewrite to Locks Across Processes

* mke mda paths  with env

* make RateLimited for RunMdaScript job

* Add pint to laravel workflow

---------

Co-authored-by: Artem Otliaguzov <[email protected]>
  • Loading branch information
JanOppolzer and temaotl authored Jul 9, 2024
1 parent 6473425 commit cd9bf9d
Show file tree
Hide file tree
Showing 88 changed files with 1,073 additions and 868 deletions.
5 changes: 4 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ VITE_PUSHER_PORT="${PUSHER_PORT}"
VITE_PUSHER_SCHEME="${PUSHER_SCHEME}"
VITE_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

MDA_CONFIG_FOLDER=/opt/mda-distribution-0.10.0/config
MDA_SCRIPT=/opt/mda-distribution-0.10.0/mda.sh

GIT_REMOTE=[email protected]:repository
GIT_REMOTE_BRANCH=main
GIT_LOCAL=/home/user/metaman/storage/git
Expand All @@ -86,4 +89,4 @@ LDAP_PORT=636
LDAP_BASE_DN="ou=Organizations,dc=example,dc=org"
LDAP_BASE_DN_EDUIDCZORGANIZATIONS="ou=Organizations,o=saml,dc=example,dc=org"
LDAP_SSL=true
LDAP_TLS=false
LDAP_TLS=false
2 changes: 2 additions & 0 deletions .github/workflows/laravel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ jobs:
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Run pint
run: vendor/bin/pint --test
- name: Generate key
run: php artisan key:generate
- name: Run translations check
Expand Down
19 changes: 8 additions & 11 deletions app/Console/Commands/DumpFromGit.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Console\Commands;


use App\Facades\EntityFacade;
use App\Models\Membership;
use App\Models\User;
Expand All @@ -14,17 +13,16 @@
use App\Traits\EdugainTrait;
use App\Traits\FederationTrait;
use App\Traits\GitTrait;
use App\Traits\ValidatorTrait;
use Exception;
use Illuminate\Console\Command;
use App\Traits\ValidatorTrait;


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

/**
* The name and signature of the console command.
Expand All @@ -43,23 +41,23 @@ class DumpFromGit extends Command
private function createMetadataFiles(): void
{
$this->updateFederationFolders();
$membership = Membership::select('entity_id','federation_id')->whereApproved(1)->get();
$membership = Membership::select('entity_id', 'federation_id')->whereApproved(1)->get();
foreach ($membership as $member) {
EntityFacade::saveMetadataToFederationFolder($member->entity_id, $member->federation_id);
}
}


/**
* Execute the console command.
*
* @throws Exception no amin
*/
public function handle()
{
$firstAdminId = User::where('admin', 1)->first()->id;
if(empty($firstAdminId))
if (empty($firstAdminId)) {
throw new Exception('firstAdminId is null');

}

$this->initializeGit();
$this->createFederations();
Expand All @@ -72,6 +70,5 @@ public function handle()
$this->createMetadataFiles();
$this->makeEdu2Edugain();


}
}
65 changes: 40 additions & 25 deletions app/Console/Commands/ValidateMetaConsole.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace App\Console\Commands;

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

class ValidateMetaConsole extends Command
Expand All @@ -23,71 +25,84 @@ class ValidateMetaConsole extends Command
*/
protected $description = 'Command description';


use ValidatorTrait,FixEntityTrait;
use FixEntityTrait,ValidatorTrait;

/**
* Execute the console command.
*/

private function doc()
{
foreach (Entity::select()->get() as $entity)
{
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 = json_decode($this->validateMetadata($ent->xml_file, true), true);
$res['ent_id'] = $ent->id;
$errorArray = $res['errorArray'];


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

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

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

$curr = 345;

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


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


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

}
}
}

private function runMDA(Federation $federation)
{
$filterArray = explode(', ', $federation->filters);

$scriptPath = config('storageCfg.mdaScript');
$command = 'sh '.config('storageCfg.mdaScript');

$realScriptPath = realpath($scriptPath);

if ($realScriptPath === false) {
throw new Exception('file not exist'.$scriptPath);
}

foreach ($filterArray as $filter) {
$file = escapeshellarg($filter).'.xml';
$pipeline = 'main';
$command = 'sh '.escapeshellarg($realScriptPath).' '.$file.' '.$pipeline;

$res = shell_exec($command);
dump($res);
}
}

public function handle()
{
$federation = Federation::where('id', 1)->first();
$this->runMDA($federation);

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

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

}
}
1 change: 0 additions & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class Kernel extends ConsoleKernel
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
protected function schedule(Schedule $schedule)
Expand Down
23 changes: 23 additions & 0 deletions app/Events/CreateEntity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Events;

use App\Models\Entity;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class CreateEntity
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public Entity $entity;

/**
* Create a new event instance.
*/
public function __construct(Entity $entity)
{
$this->entity = $entity;
}
}
7 changes: 1 addition & 6 deletions app/Events/FederationApprove.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
namespace App\Events;

use App\Models\Federation;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

Expand All @@ -20,9 +16,8 @@ class FederationApprove
/**
* Create a new event instance.
*/
public function __construct(Federation $federation)
public function __construct(Federation $federation)
{
$this->federation = $federation;
}

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

namespace App\Events;

use App\Models\Entity;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class UpdateEntity
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public Entity $entity;

/**
* Create a new event instance.
*/
public function __construct(Entity $entity)
{
$this->entity = $entity;
}
}
4 changes: 0 additions & 4 deletions app/Http/Controllers/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public function store(StoreCategory $request)
/**
* Display the specified resource.
*
* @param \App\Models\Category $category
* @return \Illuminate\Http\Response
*/
public function show(Category $category)
Expand All @@ -92,7 +91,6 @@ public function show(Category $category)
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\Category $category
* @return \Illuminate\Http\Response
*/
public function edit(Category $category)
Expand All @@ -108,7 +106,6 @@ public function edit(Category $category)
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Models\Category $category
* @return \Illuminate\Http\Response
*/
public function update(UpdateCategory $request, Category $category)
Expand All @@ -134,7 +131,6 @@ public function update(UpdateCategory $request, Category $category)
/**
* Remove the specified resource from storage.
*
* @param \App\Models\Category $category
* @return \Illuminate\Http\Response
*/
public function destroy(Category $category)
Expand Down
Loading

0 comments on commit cd9bf9d

Please sign in to comment.