-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
correctly use restful syntax, refs #718
- Loading branch information
Showing
6 changed files
with
296 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
namespace Opencast\Routes\Config; | ||
|
||
use Psr\Http\Message\ResponseInterface as Response; | ||
use Psr\Http\Message\ServerRequestInterface as Request; | ||
use Opencast\OpencastTrait; | ||
use Opencast\OpencastController; | ||
use Opencast\Errors\AuthorizationFailedException; | ||
use Opencast\Models\Config; | ||
use Opencast\Models\Endpoints; | ||
use Opencast\Models\SeminarEpisodes; | ||
use Opencast\Models\LTI\LtiHelper; | ||
|
||
use Opencast\Models\I18N as _; | ||
|
||
class ConfigAdd extends OpencastController | ||
{ | ||
use OpencastTrait; | ||
|
||
public function __invoke(Request $request, Response $response, $args) | ||
{ | ||
\SimpleOrMap::expireTableScheme(); | ||
|
||
$json = $this->getRequestData($request); | ||
|
||
$config_checked = false; | ||
$duplicate_url = false; | ||
|
||
// check, if a config with the same data already exists: | ||
$config = reset(Config::findBySql('service_url = ?', [$json['config']['service_url']])); | ||
|
||
// POST request - create config | ||
if ($config) { | ||
$duplicate_url = true; | ||
} else { | ||
$config = new Config; | ||
} | ||
|
||
// Throw error if the url is already used | ||
if ($duplicate_url) { | ||
return $this->createResponse([ | ||
'message'=> [ | ||
'type' => 'error', | ||
'text' => sprintf( | ||
_('Eine Konfiguration mit der angegebenen URL ist bereits vorhanden: "%s"'), | ||
$json['config']['service_url'] | ||
) | ||
], | ||
], $response); | ||
} | ||
|
||
// check settings and store them to the database | ||
$config->updateSettings($json['config']); | ||
|
||
// check configuration and load endpoints | ||
$message = $config->updateEndpoints($this->container); | ||
|
||
$ret_config = $config->toArray(); | ||
$ret_config = array_merge($ret_config, $ret_config['settings']); | ||
unset($ret_config['settings']); | ||
|
||
if ($config_checked) { | ||
$lti = LtiHelper::getLaunchData($config->id); | ||
|
||
return $this->createResponse([ | ||
'config' => $ret_config, | ||
'message'=> $message, | ||
'lti' => $lti | ||
], $response); | ||
} | ||
|
||
return $this->createResponse([ | ||
'config' => $ret_config, | ||
'message'=> $message, | ||
], $response); | ||
} | ||
} |
Oops, something went wrong.