Skip to content

Commit

Permalink
Use post for query run
Browse files Browse the repository at this point in the history
  • Loading branch information
driusan committed Dec 16, 2022
1 parent 0b5d507 commit a0d5de6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 26 deletions.
22 changes: 15 additions & 7 deletions modules/dataquery/php/queries.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class Queries extends \NDB_Page
*/
public function handle(ServerRequestInterface $request) : ResponseInterface
{
$user = $request->getAttribute('user');
$url = $request->getURI()->getPath();
$pieces = [];
$user = $request->getAttribute('user');
$url = $request->getURI()->getPath();
$pieces = [];
if (preg_match(
"/queries$/",
$url,
Expand All @@ -48,7 +48,7 @@ class Queries extends \NDB_Page
case 'GET':
return new \LORIS\Http\Response\JSON\OK(
[
'recent' => iterator_to_array(
'recent' => iterator_to_array(
$this->getRecentRuns($user),
false,
),
Expand Down Expand Up @@ -90,8 +90,13 @@ class Queries extends \NDB_Page
$pieces
) === 1
) {
$queryID = intval($pieces[1]);
return $this->runQuery($user, $queryID);
switch ($request->getMethod()) {
case 'POST':
$queryID = intval($pieces[1]);
return $this->runQuery($user, $queryID);
default:
return new \LORIS\Http\Response\JSON\MethodNotAllowed(['POST']);
}
}
if (preg_match(
"/queries\/([0-9]+)\/count$/",
Expand Down Expand Up @@ -294,7 +299,10 @@ class Queries extends \NDB_Page
'Unhandled PATCH action'
);
}
return new \LORIS\Http\Response\JSON\MethodNotAllowed(['GET'], 'Request must be GET');
return new \LORIS\Http\Response\JSON\MethodNotAllowed(
['GET'],
'Request must be GET'
);
}

/**
Expand Down
28 changes: 15 additions & 13 deletions modules/dataquery/php/query.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ class Query implements \LORIS\StudyEntities\AccessibleResource,
/**
* Construct a Query object
*
* @param \LORIS\LorisInstance $loris The LORIS Instance
* @param int $queryID The Query ID
* @param ?array $query The serialized form of
* the query
* @param ?string $name The query name
* @param ?array $sharedBy List of users who shared
* this query
* @param ?bool $starred True if this query is starred
* @param ?bool $shared True if this query is shared
* @param \LORIS\LorisInstance $loris The LORIS Instance
* @param int $queryID The Query ID
* @param ?array $query The serialized form of
* the query
* @param ?string $name The query name
* @param ?string $adminname The name used by an admin
* pinning the query
* @param ?array $sharedBy List of users who shared
* this query
* @param ?bool $starred True if this query is starred
*/
public function __construct(
protected \LORIS\LorisInstance $loris,
Expand Down Expand Up @@ -726,8 +727,9 @@ class Query implements \LORIS\StudyEntities\AccessibleResource,
public function jsonSerialize() : mixed
{
$factory = \NDB_Factory::singleton();
$result = [
'self' => $factory->settings()->getBaseURL() . '/dataquery/queries/' . $this->queryID,
$result = [
'self' => $factory->settings()->getBaseURL()
. '/dataquery/queries/' . $this->queryID,
'QueryID' => $this->queryID,
'Query' => $this->data,
];
Expand All @@ -736,14 +738,14 @@ class Query implements \LORIS\StudyEntities\AccessibleResource,
}
if ($this->adminname !== null && $this->adminname !== '') {
$result['AdminName'] = $this->adminname;
$result['Pinned'] = true;
$result['Pinned'] = true;
} else {
$result['Pinned'] = false;
}

if ($this->sharedBy !== null) {
$result['SharedBy'] = $this->sharedBy;
$result['Public'] = true;
$result['Public'] = true;
} else {
$result['Public'] = false;
}
Expand Down
13 changes: 7 additions & 6 deletions modules/dataquery/php/queryrun.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,13 @@ class QueryRun implements \LORIS\StudyEntities\AccessibleResource,
{
$factory = \NDB_Factory::singleton();
$baseURL = $factory->settings()->getBaseURL();
$result = [
'self' => $baseURL
. '/dataquery/queries/' . $this->query->queryID . '/run/' . $this->runID,
'Query' => $this->query->queryID,
'RunTime' => $this->runTime,
'QueryID' => $this->query->queryID,
$result = [
'self' => $baseURL
. '/dataquery/queries/' . $this->query->queryID
. '/run/' . $this->runID,
'Query' => $this->query->queryID,
'RunTime' => $this->runTime,
'QueryID' => $this->query->queryID,
'QueryRunID' => $this->runID,
];
return $result;
Expand Down

0 comments on commit a0d5de6

Please sign in to comment.