From 5977dda81c9cf9e7655927f3e3e944a0c15df6cb Mon Sep 17 00:00:00 2001 From: Yaroslav Mokhurenko Date: Wed, 17 Jul 2019 16:18:49 +0300 Subject: [PATCH 1/2] Wrap hardcoded event_script parts in respective if statement --- src/Components/Package/Exporter.php | 6 +++++- src/Components/Package/Importer.php | 24 +++++++++++++----------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/Components/Package/Exporter.php b/src/Components/Package/Exporter.php index dcaf5713..80534d20 100644 --- a/src/Components/Package/Exporter.php +++ b/src/Components/Package/Exporter.php @@ -186,7 +186,6 @@ public function getManifestOnly($systemOnly = false, $fullTree = false) $this->data['system']['cors'] = $this->getAllResources('system', 'cors', ['fields' => 'id,path']); $this->data['system']['email_template'] = $this->getAllResources('system', 'email_template', ['fields' => 'id,name']); - $this->data['system']['event_script'] = $this->getAllResources('system', 'event_script', ['fields' => 'name']); $this->data['system']['lookup'] = $this->getAllResources('system', 'lookup', ['fields' => 'id,name']); /* Check for paid limits class */ @@ -194,6 +193,11 @@ public function getManifestOnly($systemOnly = false, $fullTree = false) $this->data['system']['limit'] = $this->getAllResources('system', 'limit', ['fields' => 'id,name']); } + /* Check for paid event_script class */ + if (class_exists(\DreamFactory\Core\Script\ServiceProvider::class)) { + $this->data['system']['event_script'] = $this->getAllResources('system', 'event_script', ['fields' => 'name']); + } + $manifest = $this->package->getManifestHeader(); $this->getAllowedSystemResources($manifest); diff --git a/src/Components/Package/Importer.php b/src/Components/Package/Importer.php index dc7e1e7d..c53e033c 100644 --- a/src/Components/Package/Importer.php +++ b/src/Components/Package/Importer.php @@ -767,14 +767,17 @@ protected function insertDbTableResources($service) */ protected function insertEventScripts() { - if (empty($data = $this->package->getResourceFromZip('system/event_script.json'))) { - // pre-2.3.0 version - $data = $this->package->getResourceFromZip('system/event.json'); - } - $scripts = $this->cleanDuplicates($data, 'system', 'event_script'); + try { - if (!empty($scripts)) { - try { + if (class_exists(\DreamFactory\Core\Script\ServiceProvider::class)) throw new ForbiddenException('You need Silver license to be able to import event_scripts.'); + + if (empty($data = $this->package->getResourceFromZip('system/event_script.json'))) { + // pre-2.3.0 version + $data = $this->package->getResourceFromZip('system/event.json'); + } + $scripts = $this->cleanDuplicates($data, 'system', 'event_script'); + + if (!empty($scripts)) { foreach ($scripts as $script) { $name = array_get($script, 'name'); $this->fixCommonFields($script); @@ -786,9 +789,9 @@ protected function insertEventScripts() throw ResponseFactory::createExceptionFromResponse($result); } } - return true; - } catch (\Exception $e) { + } + } catch (\Exception $e) { // if ($e->getCode() === HttpStatusCodes::HTTP_FORBIDDEN) { // $this->log('error', 'Failed to insert event_script. ' . $this->getErrorDetails($e)); // } else { @@ -797,8 +800,7 @@ protected function insertEventScripts() // $this->getErrorDetails($e) // ); // } - $this->throwExceptions($e, 'Failed to insert event_script'); - } + $this->throwExceptions($e, 'Failed to insert event_script'); } return false; From a57b94d0d8dca5b87fb40a0aa7ab317df50def97 Mon Sep 17 00:00:00 2001 From: Yaroslav Mokhurenko Date: Wed, 17 Jul 2019 17:18:16 +0300 Subject: [PATCH 2/2] Update exception text --- src/Components/Package/Importer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/Package/Importer.php b/src/Components/Package/Importer.php index c53e033c..335f334a 100644 --- a/src/Components/Package/Importer.php +++ b/src/Components/Package/Importer.php @@ -769,7 +769,7 @@ protected function insertEventScripts() { try { - if (class_exists(\DreamFactory\Core\Script\ServiceProvider::class)) throw new ForbiddenException('You need Silver license to be able to import event_scripts.'); + if (class_exists(\DreamFactory\Core\Script\ServiceProvider::class)) throw new ForbiddenException('Upgrade to a paid license to import event scripts.'); if (empty($data = $this->package->getResourceFromZip('system/event_script.json'))) { // pre-2.3.0 version