Skip to content

Commit

Permalink
Merge pull request #45 from dreamfactorysoftware/fix-hardcoded-event_…
Browse files Browse the repository at this point in the history
…script

Wrap hardcoded event_script parts in respective if statement
  • Loading branch information
yaroslavmo authored Jul 18, 2019
2 parents fc9e8ae + a57b94d commit f25c94f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
6 changes: 5 additions & 1 deletion src/Components/Package/Exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,18 @@ 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 */
if (class_exists(\DreamFactory\Core\Limit\ServiceProvider::class)) {
$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);

Expand Down
24 changes: 13 additions & 11 deletions src/Components/Package/Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('Upgrade to a paid license 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);
Expand All @@ -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 {
Expand All @@ -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;
Expand Down

0 comments on commit f25c94f

Please sign in to comment.