Skip to content

Commit

Permalink
refactor lastUpdated for Submissions
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Hartmann <[email protected]>
  • Loading branch information
Chartman123 committed Sep 10, 2024
1 parent 6928e2e commit fae2372
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
16 changes: 0 additions & 16 deletions lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -993,8 +993,6 @@ public function deleteAllSubmissions(int $formId): DataResponse {
// Delete all submissions (incl. Answers)
$this->submissionMapper->deleteByForm($formId);

$this->formMapper->update($form);

return new DataResponse($formId);
}

Expand Down Expand Up @@ -1072,8 +1070,6 @@ public function newSubmission(int $formId, array $answers, string $shareHash = '
$this->storeAnswersForQuestion($form, $submission->getId(), $questions[$questionIndex], $answerArray);
}

$this->formMapper->update($form);

//Create Activity
$this->formsService->notifyNewSubmission($form, $submission);

Expand Down Expand Up @@ -1133,8 +1129,6 @@ public function deleteSubmission(int $formId, int $submissionId): DataResponse {
// Delete submission (incl. Answers)
$this->submissionMapper->deleteById($submissionId);

$this->formMapper->update($form);

return new DataResponse($submissionId);
}

Expand Down Expand Up @@ -2325,8 +2319,6 @@ public function insertSubmissionLegacy(int $formId, array $answers, string $shar
$this->storeAnswersForQuestion($form, $submission->getId(), $questions[$questionIndex], $answerArray);
}

$this->formMapper->update($form);

//Create Activity
$this->formsService->notifyNewSubmission($form, $submission);

Expand Down Expand Up @@ -2378,8 +2370,6 @@ public function deleteSubmissionLegacy(int $id): DataResponse {
// Delete submission (incl. Answers)
$this->submissionMapper->deleteById($id);

$this->formMapper->update($form);

return new DataResponse($id);
}

Expand Down Expand Up @@ -2415,8 +2405,6 @@ public function deleteAllSubmissionsLegacy(int $formId): DataResponse {
// Delete all submissions (incl. Answers)
$this->submissionMapper->deleteByForm($formId);

$this->formMapper->update($form);

return new DataResponse($formId);
}

Expand Down Expand Up @@ -2514,8 +2502,6 @@ public function unlinkFileLegacy(string $hash): DataResponse {

$this->formMapper->update($form);

$this->formMapper->update($form);

return new DataResponse($hash);
}

Expand Down Expand Up @@ -2559,8 +2545,6 @@ public function linkFileLegacy(string $hash, string $path, string $fileFormat):

$filePath = $this->formsService->getFilePath($form);

$this->formMapper->update($form);

return new DataResponse([
'fileId' => $file->getId(),
'fileFormat' => $fileFormat,
Expand Down
39 changes: 38 additions & 1 deletion lib/Db/SubmissionMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
namespace OCA\Forms\Db;

use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
Expand All @@ -42,11 +43,45 @@ class SubmissionMapper extends QBMapper {
*/
public function __construct(
IDBConnection $db,
private AnswerMapper $answerMapper
private AnswerMapper $answerMapper,
private FormMapper $formMapper
) {
parent::__construct($db, 'forms_v2_submissions', Submission::class);
}

/**
* @param Entity $entity
* @psalm-param Submission $entity
* @return Submission
* @throws \OCP\DB\Exception
*/
public function insert(Entity $entity): Submission {
$this->formMapper->update($this->formMapper->findById($entity->getFormId()));
return parent::insert($entity);
}

/**
* @param Entity $entity
* @psalm-param Submission $entity
* @return Submission
* @throws \OCP\DB\Exception
*/
public function update(Entity $entity): Submission {
$this->formMapper->update($this->formMapper->findById($entity->getFormId()));
return parent::update($entity);
}

/**
* @param Entity $entity
* @psalm-param Submission $entity
* @return Submission
* @throws \OCP\DB\Exception
*/
public function delete(Entity $entity): Submission {
$this->formMapper->update($this->formMapper->findById($entity->getFormId()));
return parent::delete($entity);
}

/**
* @param int $formId
* @throws DoesNotExistException if not found
Expand Down Expand Up @@ -178,5 +213,7 @@ public function deleteByForm(int $formId): void {
);

$qb->executeStatement();

$this->formMapper->update($this->formMapper->findById($formId));
}
}

0 comments on commit fae2372

Please sign in to comment.