[COMPONENTS][Posting] Fixed issue where an embed attachment would violate Note's conversation_id not null constraint

Conversation was only assigned after storing Note's attachments
This commit is contained in:
Eliseu Amaro 2022-02-19 18:08:05 +00:00 committed by Diogo Peralta Cordeiro
parent ecfd6b5ad2
commit a71c16d654
Signed by: diogo
GPG Key ID: 18D2D35001FBFAB0
1 changed files with 49 additions and 48 deletions

View File

@ -28,8 +28,6 @@ use App\Core\DB\DB;
use App\Core\Event;
use App\Core\Form;
use App\Core\GSFile;
use App\Entity\NoteType;
use Component\Notification\Entity\Attention;
use function App\Core\I18n\_m;
use App\Core\Modules\Component;
use App\Core\Router\Router;
@ -37,6 +35,7 @@ use App\Core\VisibilityScope;
use App\Entity\Activity;
use App\Entity\Actor;
use App\Entity\Note;
use App\Entity\NoteType;
use App\Util\Common;
use App\Util\Exception\BugFoundException;
use App\Util\Exception\ClientException;
@ -50,6 +49,7 @@ use Component\Attachment\Entity\ActorToAttachment;
use Component\Attachment\Entity\AttachmentToNote;
use Component\Conversation\Conversation;
use Component\Language\Entity\Language;
use Component\Notification\Entity\Attention;
use Functional as F;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
@ -211,8 +211,8 @@ class Posting extends Component
}
/**
* @throws DuplicateFoundException
* @throws ClientException
* @throws DuplicateFoundException
* @throws ServerException
*/
public static function storeLocalPage(
@ -244,7 +244,7 @@ class Posting extends Component
process_note_content_extra_args: $process_note_content_extra_args,
flush_and_notify: false,
rendered: $rendered,
source: $source
source: $source,
);
$note->setType(NoteType::PAGE);
$note->setTitle($title);
@ -276,10 +276,12 @@ class Posting extends Component
* @param bool $flush_and_notify True if the newly created Note activity should be passed on as a Notification
* @param null|string $rendered The Note's content post RenderNoteContent event, which sanitizes and processes the raw content sent
* @param string $source The source of this Note
* @return array [Activity, Note, int[]] Activity, Note, Attention Ids
*
* @throws ClientException
* @throws DuplicateFoundException
* @throws ServerException
*
* @return array [Activity, Note, int[]] Activity, Note, Attention Ids
*/
public static function storeLocalNote(
Actor $actor,
@ -297,7 +299,7 @@ class Posting extends Component
string $source = 'web',
): array {
$scope ??= VisibilityScope::EVERYWHERE; // TODO: If site is private, default to LOCAL
$reply_to_id = is_null($reply_to) ? null : (is_int($reply_to) ? $reply_to : $reply_to->getId());
$reply_to_id = \is_null($reply_to) ? null : (\is_int($reply_to) ? $reply_to : $reply_to->getId());
$mentions = [];
if (\is_null($rendered) && !empty($content)) {
Event::handle('RenderNoteContent', [$content, $content_type, &$rendered, $actor, $locale, &$mentions]);
@ -328,6 +330,7 @@ class Posting extends Component
}
DB::persist($note);
Conversation::assignLocalConversation($note, $reply_to_id);
// Need file and note ids for the next step
$note->setUrl(Router::url('note_view', ['id' => $note->getId()], Router::ABSOLUTE_URL));
@ -345,8 +348,6 @@ class Posting extends Component
}
}
Conversation::assignLocalConversation($note, $reply_to_id);
$activity = Activity::create([
'actor_id' => $actor->getId(),
'verb' => 'create',