From 1a79a55a3346e495356336d28960c0d35d5fd16a Mon Sep 17 00:00:00 2001 From: Artem Otliaguzov Date: Sat, 13 Jul 2024 16:08:00 +0200 Subject: [PATCH] add run script to EduGain jobs --- app/Jobs/EduGainAddEntity.php | 2 +- app/Jobs/EduGainDeleteEntity.php | 2 +- app/Jobs/EduGainRunMdaScript.php | 61 ++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 app/Jobs/EduGainRunMdaScript.php diff --git a/app/Jobs/EduGainAddEntity.php b/app/Jobs/EduGainAddEntity.php index cf29019..1818f65 100644 --- a/app/Jobs/EduGainAddEntity.php +++ b/app/Jobs/EduGainAddEntity.php @@ -54,8 +54,8 @@ public function handle(): void EntityFacade::saveEntityMetadataToFolder($this->entity->id,$folderName); //TODO write custom function to run special MDA script (ask about this) + EduGainRunMdaScript::dispatch($lock->owner()); - // RunMdaScript::dispatch($federation, $lock->owner()); } catch (Exception $e) { Log::error($e->getMessage()); } finally { diff --git a/app/Jobs/EduGainDeleteEntity.php b/app/Jobs/EduGainDeleteEntity.php index 866148a..6152ea5 100644 --- a/app/Jobs/EduGainDeleteEntity.php +++ b/app/Jobs/EduGainDeleteEntity.php @@ -57,7 +57,7 @@ public function handle(): void //TODO write custom function to run special MDA script (ask about this) - // RunMdaScript::dispatch($federation, $lock->owner()); + EduGainRunMdaScript::dispatch($lock->owner()); } catch (Exception $e) { Log::error($e->getMessage()); } finally { diff --git a/app/Jobs/EduGainRunMdaScript.php b/app/Jobs/EduGainRunMdaScript.php new file mode 100644 index 0000000..b7e9514 --- /dev/null +++ b/app/Jobs/EduGainRunMdaScript.php @@ -0,0 +1,61 @@ +owner = $owner; + } + + /** + * Execute the job. + */ + public function handle(): void + { + $diskName = config('storageCfg.name'); + $folderName = config('storageCfg.edu2edugain'); + + $pathToDirectory = Storage::disk($diskName)->path($folderName); + $lockKey = 'directory-'.md5($pathToDirectory).'-lock'; + $scriptPath = config('storageCfg.mdaScript'); + $realScriptPath = realpath($scriptPath); + + try { + $file = escapeshellarg($folderName).'.xml'; + $pipeline = 'main'; + $command = 'sh '.escapeshellarg($realScriptPath).' '.$file.' '.$pipeline; + + $res = shell_exec($command); + dump($res); + + } catch (Exception $e) { + Log::error($e->getMessage()); + } finally { + Cache::restoreLock($lockKey, $this->owner)->release(); + + } + + + + + } +}