[Posting] Rename file to attachment and cache result of actor tag query
This commit is contained in:
parent
5579f4fa5d
commit
c053e8da8e
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
// {{{ License
|
// {{{ License
|
||||||
|
|
||||||
// This file is part of GNU social - https://www.gnu.org/software/social
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
||||||
//
|
//
|
||||||
// GNU social is free software: you can redistribute it and/or modify
|
// GNU social is free software: you can redistribute it and/or modify
|
||||||
@ -15,17 +16,19 @@
|
|||||||
//
|
//
|
||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
// }}}
|
// }}}
|
||||||
|
|
||||||
namespace Component\Posting;
|
namespace Component\Posting;
|
||||||
|
|
||||||
|
use App\Core\Cache;
|
||||||
use App\Core\DB\DB;
|
use App\Core\DB\DB;
|
||||||
use App\Core\Event;
|
use App\Core\Event;
|
||||||
use App\Core\Form;
|
use App\Core\Form;
|
||||||
use function App\Core\I18n\_m;
|
use function App\Core\I18n\_m;
|
||||||
use App\Core\Modules\Module;
|
use App\Core\Modules\Module;
|
||||||
use App\Core\Security;
|
use App\Core\Security;
|
||||||
use App\Entity\FileToNote;
|
use App\Entity\AttachmentToNote;
|
||||||
use App\Entity\Note;
|
use App\Entity\Note;
|
||||||
use App\Util\Common;
|
use App\Util\Common;
|
||||||
use App\Util\Exceptiion\InvalidFormException;
|
use App\Util\Exceptiion\InvalidFormException;
|
||||||
@ -50,7 +53,10 @@ class Posting extends Module
|
|||||||
|
|
||||||
$actor_id = $user->getId();
|
$actor_id = $user->getId();
|
||||||
$to_tags = [];
|
$to_tags = [];
|
||||||
foreach (DB::dql('select c.tag from App\Entity\GSActorCircle c where c.tagger = :tagger', ['tagger' => $actor_id]) as $t) {
|
$tags = Cache::get("actor-tags-{$actor_id}", function () use ($actor_id) {
|
||||||
|
return DB::dql('select c.tag from App\Entity\GSActorCircle c where c.tagger = :tagger', ['tagger' => $actor_id]);
|
||||||
|
});
|
||||||
|
foreach ($tags as $t) {
|
||||||
$t = $t['tag'];
|
$t = $t['tag'];
|
||||||
$to_tags[$t] = $t;
|
$to_tags[$t] = $t;
|
||||||
}
|
}
|
||||||
@ -97,20 +103,22 @@ class Posting extends Module
|
|||||||
'reply_to' => $reply_to,
|
'reply_to' => $reply_to,
|
||||||
'repeat_of' => $repeat_of,
|
'repeat_of' => $repeat_of,
|
||||||
]);
|
]);
|
||||||
$files = [];
|
$processed_attachments = [];
|
||||||
foreach ($attachments as $f) {
|
foreach ($attachments as $f) {
|
||||||
$nf = Media::validateAndStoreFile($f, Common::config('attachments', 'dir'),
|
$na = Media::validateAndStoreAttachment(
|
||||||
Security::sanitize($title = $f->getClientOriginalName()),
|
$f, Common::config('attachments', 'dir'),
|
||||||
$is_local = true, $actor_id);
|
Security::sanitize($title = $f->getClientOriginalName()),
|
||||||
$files[] = $nf;
|
$is_local = true, $actor_id
|
||||||
DB::persist($nf);
|
);
|
||||||
|
$processed_attachments[] = $na;
|
||||||
|
DB::persist($na);
|
||||||
}
|
}
|
||||||
DB::persist($note);
|
DB::persist($note);
|
||||||
// Need file and note ids for the next step
|
// Need file and note ids for the next step
|
||||||
DB::flush();
|
DB::flush();
|
||||||
if ($attachments != []) {
|
if ($processed_attachments != []) {
|
||||||
foreach ($files as $f) {
|
foreach ($processed_attachments as $a) {
|
||||||
DB::persist(FileToNote::create(['file_id' => $f->getId(), 'note_id' => $note->getId()]));
|
DB::persist(AttachmentToNote::create(['attachment_id' => $a->getId(), 'note_id' => $note->getId()]));
|
||||||
}
|
}
|
||||||
DB::flush();
|
DB::flush();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user