PluginProbe
The Innovative Form Builder – IvyForms / 1.4.1
The Innovative Form Builder – IvyForms v1.4.1
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / backend / src / Services / Entry / Managers / EntryDeletionManager.php

EntryDeletionManager.php in The Innovative Form Builder – IvyForms 1.4.1, at backend/src/Services/Entry/Managers/EntryDeletionManager.php

90 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\Services\Entry\Managers;
4
5 use IvyForms\Common\Exceptions\InvalidArgumentException;
6 use IvyForms\Repository\Entry\EntryRepositoryInterface;
7 use IvyForms\Repository\EntryField\EntryFieldRepositoryInterface;
8 use IvyForms\Services\Translations\BackendStrings;
9
10 /**
11 * Handles bulk entry deletion operations across forms.
12 */
13 class EntryDeletionManager
14 {
15 private EntryRepositoryInterface $entryRepository;
16 private EntryFieldRepositoryInterface $entryFieldRepository;
17
18 public function __construct(
19 EntryRepositoryInterface $entryRepository,
20 EntryFieldRepositoryInterface $entryFieldRepository
21 ) {
22 $this->entryRepository = $entryRepository;
23 $this->entryFieldRepository = $entryFieldRepository;
24 }
25
26 /**
27 * Delete an entry by its ID.
28 *
29 * @param int $id
30 * @return int
31 */
32 public function deleteEntry(int $id): int
33 {
34 return $this->entryRepository->delete($id);
35 }
36
37 /**
38 * Delete multiple entries by their IDs in bulk.
39 *
40 * @param int[] $ids
41 * @return int Number of deleted entries
42 */
43 public function deleteEntriesByIds(array $ids): int
44 {
45 if (empty($ids)) {
46 return 0;
47 }
48 return $this->entryRepository->deleteMany($ids);
49 }
50
51 /**
52 * Delete all entry fields for multiple entry IDs in bulk.
53 *
54 * @param int[] $entryIds
55 * @return int Number of deleted entry fields
56 */
57 public function deleteEntryFieldsByEntryIds(array $entryIds): int
58 {
59 if (empty($entryIds)) {
60 return 0;
61 }
62 $allFields = $this->entryFieldRepository->findIdsByEntryIds($entryIds);
63 if (empty($allFields)) {
64 return 0;
65 }
66 return $this->entryFieldRepository->deleteMany($allFields);
67 }
68
69 /**
70 * Delete all entries for multiple form IDs in bulk.
71 *
72 * @param int[] $formIds
73 * @return int Number of deleted entries
74 * @throws InvalidArgumentException
75 */
76 public function deleteEntriesByFormIds(array $formIds): int
77 {
78 if (empty($formIds)) {
79 throw new InvalidArgumentException(
80 BackendStrings::getExceptionStrings()['no_form_ids_provided']
81 );
82 }
83
84 // Delete entry fields by form IDs using a subquery
85 $this->entryFieldRepository->deleteByFormIds($formIds);
86 // Delete entries by formId
87 return $this->entryRepository->deleteManyByForeignKeyValues($formIds);
88 }
89 }
90