Unverified Commit 82df2730 authored by Jonas Rittershofer's avatar Jonas Rittershofer
Browse files

Move Form Deletion to Mapper


Signed-off-by: default avatarJonas Rittershofer <jotoeri@users.noreply.github.com>
parent 600ce239
......@@ -430,10 +430,7 @@ class ApiController extends OCSController {
throw new OCSForbiddenException();
}
// Delete Submissions(incl. Answers), Questions(incl. Options) and Form.
$this->submissionMapper->deleteByForm($id);
$this->questionMapper->deleteByForm($id);
$this->formMapper->delete($form);
$this->formMapper->deleteForm($form);
return new DataResponse($id);
}
......
......@@ -31,14 +31,23 @@ use OCP\IDBConnection;
use OCP\AppFramework\Db\QBMapper;
class FormMapper extends QBMapper {
/** @var QuestionMapper */
private $questionMapper;
/** @var SubmissionMapper */
private $submissionMapper;
/**
* FormMapper constructor.
*
* @param IDBConnection $db
*/
public function __construct(IDBConnection $db) {
public function __construct(QuestionMapper $questionMapper,
SubmissionMapper $submissionMapper,
IDBConnection $db) {
parent::__construct($db, 'forms_v2_forms', Form::class);
$this->questionMapper = $questionMapper;
$this->submissionMapper = $submissionMapper;
}
/**
......@@ -107,4 +116,15 @@ class FormMapper extends QBMapper {
return $this->findEntities($qb);
}
/**
* Delete a Form including connected Questions and Submissions
* @param Form $form The form instance to delete
*/
public function deleteForm(Form $form): void {
// Delete Submissions(incl. Answers), Questions(incl. Options) and Form.
$this->submissionMapper->deleteByForm($form->getId());
$this->questionMapper->deleteByForm($form->getId());
$this->delete($form);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment