| @@ -5,8 +5,17 @@ | ||
| 5 | 5 | use Exception; |
| 6 | 6 | use FluentForm\App\Modules\Payments\PaymentHelper; |
| 7 | 7 | use FluentForm\Framework\Support\Arr; |
| 8 | 8 | |
| 9 | +/** | |
| 10 | + * Legacy duplicate of the Submission model (deprecated code). | |
| 11 | + * | |
| 12 | + * @deprecated Dead pair with EntryMeta: they reference only each other (a circular | |
| 13 | + * relation that is never invoked) plus Form. No external code in free or | |
| 14 | + * Pro uses either class, and remove() has no callers. The live "Entry" | |
| 15 | + * API is \FluentForm\App\Api\Entry; submissions go through Submission. | |
| 16 | + * TODO: delete Entry AND EntryMeta together; remove() kept fail-closed meanwhile. | |
| 17 | + */ | |
| 9 | 18 | class Entry extends Model |
| 10 | 19 | { |
| 11 | 20 | /** |
| 12 | 21 | * The table associated with the model. |
| @@ -174,10 +183,25 @@ | ||
| 174 | 183 | { |
| 175 | 184 | $this->where('id', $id)->update($data); |
| 176 | 185 | } |
| 177 | 186 | |
| 178 | - public static function remove($entryIds) | |
| 187 | + public static function remove($entryIds, $formId = null) | |
| 179 | 188 | { |
| 189 | + // Fail-closed scope guard: $formId scopes every delete to its owning form; | |
| 190 | + // a missing scope throws rather than ever deleting unscoped. | |
| 191 | + if (empty($formId)) { | |
| 192 | + throw new \InvalidArgumentException('Entry::remove() requires a form id to scope the deletion.'); | |
| 193 | + } | |
| 194 | + | |
| 195 | + $entryIds = static::where('form_id', $formId) | |
| 196 | + ->whereIn('id', (array) $entryIds) | |
| 197 | + ->pluck('id') | |
| 198 | + ->all(); | |
| 199 | + | |
| 200 | + if (!$entryIds) { | |
| 201 | + return; | |
| 202 | + } | |
| 203 | + | |
| 180 | 204 | static::whereIn('id', $entryIds)->delete(); |
| 181 | 205 | |
| 182 | 206 | EntryMeta::whereIn('response_id', $entryIds)->delete(); |
| 183 | 207 | |