[PLUGINS][Repeat] Delete note repeat rather than the original Note. Don't fetch when we want a simple count

This commit is contained in:
Hugo Sales 2021-09-05 17:56:03 +01:00
parent be27a10244
commit 61d95265a9
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
1 changed files with 5 additions and 11 deletions

View File

@ -25,7 +25,6 @@ use App\Core\Form;
use App\Core\Modules\NoteHandlerPlugin; use App\Core\Modules\NoteHandlerPlugin;
use App\Entity\Note; use App\Entity\Note;
use App\Util\Common; use App\Util\Common;
use App\Util\Exception\NotFoundException;
use App\Util\Exception\RedirectException; use App\Util\Exception\RedirectException;
use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\Form\Extension\Core\Type\SubmitType;
@ -36,6 +35,7 @@ class Repeat extends NoteHandlerPlugin
/** /**
* HTML rendering event that adds the repeat form as a note * HTML rendering event that adds the repeat form as a note
* action, if a user is logged in * action, if a user is logged in
*
* @throws RedirectException * @throws RedirectException
*/ */
public function onAddNoteActions(Request $request, Note $note, array &$actions) public function onAddNoteActions(Request $request, Note $note, array &$actions)
@ -44,13 +44,8 @@ class Repeat extends NoteHandlerPlugin
return Event::next; return Event::next;
} }
$opts = ['gsactor_id' => $user->getId(), 'repeat_of' => $note->getId()]; $opts = ['gsactor_id' => $user->getId(), 'repeat_of' => $note->getId()];
try { $is_set = DB::count('note', $opts) == 1;
$is_set = DB::findOneBy('note', $opts) != null;
} catch (NotFoundException $e) {
// Not found
$is_set = false;
}
$form_repeat = Form::create([ $form_repeat = Form::create([
['submit_repeat', SubmitType::class, ['submit_repeat', SubmitType::class,
[ [
@ -67,7 +62,6 @@ class Repeat extends NoteHandlerPlugin
// Handle form // Handle form
$ret = self::noteActionHandle( $ret = self::noteActionHandle(
$request, $form_repeat, $note, "repeat-{$note->getId()}", function ($note, $data, $user) use ($opts) { $request, $form_repeat, $note, "repeat-{$note->getId()}", function ($note, $data, $user) use ($opts) {
if ($data["repeat-{$note->getId()}"] === '0') { if ($data["repeat-{$note->getId()}"] === '0') {
DB::persist(Note::create([ DB::persist(Note::create([
'gsactor_id' => $user->getId(), 'gsactor_id' => $user->getId(),
@ -76,7 +70,7 @@ class Repeat extends NoteHandlerPlugin
'is_local' => true, 'is_local' => true,
])); ]));
} else { } else {
DB::remove($note); DB::remove(DB::findOneBy('note', ['gsactor_id' => $user->getId(), 'repeat_of' => $note->getId()]));
} }
DB::flush(); DB::flush();
@ -84,7 +78,7 @@ class Repeat extends NoteHandlerPlugin
throw new RedirectException(); throw new RedirectException();
return Event::stop; return Event::stop;
}); });
if ($ret !== null) { if ($ret !== null) {
return $ret; return $ret;