From 9573cab4cb65537aa4ea1aa9157add2cb400e6fc Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sat, 5 Sep 2020 21:28:53 +0000 Subject: [PATCH] [Posting] Fix form name and remove unused recycle route and controller --- components/Posting/Controller/Post.php | 42 +++----------------------- components/Posting/Posting.php | 7 +++-- 2 files changed, 8 insertions(+), 41 deletions(-) diff --git a/components/Posting/Controller/Post.php b/components/Posting/Controller/Post.php index bb877fa469..7bcd061f62 100644 --- a/components/Posting/Controller/Post.php +++ b/components/Posting/Controller/Post.php @@ -1,6 +1,7 @@ . + // }}} namespace Component\Posting\Controller; @@ -43,13 +45,13 @@ class Post throw new ClientException(_m('No such note')); } - $actor_id = Common::ensureLoggedIn()->getActor()->getId(); + $actor_id = Common::ensureLoggedIn()->getId(); $form = Form::create([ ['reply_to', HiddenType::class, ['data' => (int) $reply_to]], ['content', TextareaType::class, ['label' => ' ']], ['attachments', FileType::class, ['label' => ' ', 'multiple' => true, 'required' => false]], - ['save', SubmitType::class, ['label' => _m('Submit')]], + ['reply', SubmitType::class, ['label' => _m('Submit')]], ]); $form->handleRequest($request); @@ -70,42 +72,6 @@ class Post ]; } - public function recycle(Request $request, string $repeat_of) - { - $note = DB::find('note', ['id' => $repeat_of]); - $content_repeat = DB::dql('select n.content from App\Entity\Note n ' . - 'where n.reply_to = ' . $repeat_of - ); - - if ($note == null) { - throw new ClientException(_m('No such note')); - } - - $actor_id = Common::ensureLoggedIn()->getActor()->getId(); - - $form = Form::create([ - ['repeat_of', HiddenType::class, ['data' => (int) $repeat_of]], - ['save', SubmitType::class, ['label' => _m('Submit')]], - ]); - - $form->handleRequest($request); - - if ($form->isSubmitted()) { - $data = $form->getData(); - if ($form->isValid()) { - self::storeNote($actor_id, $data[$content_repeat], $data['attachments'], $is_local = true, $data['reply_to'], $data['repeat_of']); - } else { - // TODO display errors - } - } - - return [ - '_template' => 'note/reply.html.twig', - 'note' => $note, - 'reply' => $form->createView(), - ]; - } - public static function storeNote(int $actor_id, string $content, array $attachments, bool $is_local, ?int $reply_to = null, ?int $repeat_of = null) { $note = Note::create(['gsactor_id' => $actor_id, 'content' => $content, 'is_local' => $is_local, 'reply_to' => $reply_to, 'repeat_of' => $repeat_of]); diff --git a/components/Posting/Posting.php b/components/Posting/Posting.php index 9b958e837a..9b2cf4d6c8 100644 --- a/components/Posting/Posting.php +++ b/components/Posting/Posting.php @@ -25,6 +25,7 @@ use App\Core\Form; use function App\Core\I18n\_m; use App\Core\Module; use App\Util\Common; +use App\Util\Exception\RedirectException; use Component\Posting\Controller as C; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\FileType; @@ -36,16 +37,15 @@ class Posting extends Module public function onAddRoute($r) { $r->connect('note_reply', '/note/reply/{reply_to<\d*>}', [C\Post::class, 'reply']); - $r->connect('note_recycle', '/main/all', [C\Post::class, 'recycle']); } public function onStartTwigPopulateVars(array &$vars) { - if (Common::user() == null) { + if (($user = Common::user()) == null) { return; } - $actor_id = Common::actor()->getId(); + $actor_id = $user->getId(); $to_tags = []; foreach (DB::dql('select c.tag from App\Entity\GSActorCircle c where c.tagger = :tagger', ['tagger' => $actor_id]) as $t) { $t = $t['tag']; @@ -69,6 +69,7 @@ class Posting extends Module $data = $form->getData(); if ($form->isValid()) { C\Post::storeNote($actor_id, $data['content'], $data['attachments'], $is_local = true); + throw new RedirectException(); } else { // TODO Display error }