Skip to content

Commit fcaf254

Browse files
authored
Merge branch 'main' into new/polls
2 parents d363e4b + 35b0f96 commit fcaf254

27 files changed

Lines changed: 188 additions & 221 deletions

‎config/packages/framework.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ framework:
4242
http_client:
4343
default_options:
4444
headers:
45-
'User-Agent': 'Mbin/1.10.0 (+https://%kbin_domain%/agent)'
45+
'User-Agent': 'Mbin/1.10.1 (+https://%kbin_domain%/agent)'
4646

4747
#esi: true
4848
#fragments: true

‎config/packages/security.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ security:
2424
security: true
2525
stateless: true
2626
oauth2: true
27+
user_checker: App\Security\UserChecker
2728
image_resolver:
2829
pattern: ^/media/cache/resolve
2930
security: false

‎migrations/Version20260526175316.php‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,13 @@ public function down(Schema $schema): void
4141
public function postUp(Schema $schema): void
4242
{
4343
$this->connection->transactional(function (): void {
44-
$sqlTpl = 'UPDATE $e SET last_boosted_at = greatest((SELECT $e_vote.created_at FROM $e_vote WHERE $e_vote.$fk = $e.id ORDER BY $e_vote.created_at DESC LIMIT 1), created_at);';
44+
$sqlTpl = 'UPDATE $e SET last_boosted_at = greatest((SELECT $e_vote.created_at FROM $e_vote WHERE $e_vote.$fk = $e.id AND choice = 1 ORDER BY $e_vote.created_at DESC LIMIT 1), created_at);';
4545
$this->connection->executeStatement(str_replace('$e', 'entry', str_replace('$fk', 'entry_id', $sqlTpl)));
46-
$this->connection->executeStatement(str_replace('$e', 'entry_comment', str_replace('$fk', 'comment_id', $sqlTpl)));
4746
$this->connection->executeStatement(str_replace('$e', 'post', str_replace('$fk', 'post_id', $sqlTpl)));
4847
$this->connection->executeStatement(str_replace('$e', 'post_comment', str_replace('$fk', 'comment_id', $sqlTpl)));
48+
49+
// set last_boosted_at of entry_comment to its created_at time to speed up migrations; not may comments are boosted anyway
50+
$this->connection->executeStatement('UPDATE entry_comment SET last_boosted_at = created_at;');
4951
});
5052
}
5153
}

‎src/Controller/Tag/TagOverviewController.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ public function __construct(
2323

2424
public function __invoke(string $name, Request $request): Response
2525
{
26+
$user = $this->getUser();
2627
$activity = $this->tagRepository->findOverall(
2728
$this->getPageNb($request),
28-
$this->tagManager->transliterate(strtolower($name))
29+
$this->tagManager->transliterate(strtolower($name)),
30+
$user
2931
);
3032

3133
$params = [

‎src/Form/Type/MagazineAutocompleteType.php‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public function configureOptions(OptionsResolver $resolver): void
2828
'choice_label' => 'name',
2929
'placeholder' => 'select_magazine',
3030
'filter_query' => function (QueryBuilder $qb, string $query) {
31-
if ($currentUser = $this->security->getUser()) {
31+
$currentUser = $this->security->getUser();
32+
if ($currentUser) {
3233
$qb
3334
->andWhere(
3435
\sprintf(
@@ -39,15 +40,17 @@ public function configureOptions(OptionsResolver $resolver): void
3940
->setParameter('user', $currentUser);
4041
}
4142

43+
if (!$currentUser || (!$currentUser->isAdmin() && !$currentUser->isModerator())) {
44+
$qb->andWhere('entity.visibility = :visibility')
45+
->setParameter('visibility', VisibilityInterface::VISIBILITY_VISIBLE);
46+
}
47+
4248
if (!$query) {
4349
return;
4450
}
4551

4652
$qb->andWhere('entity.name LIKE :filter OR entity.title LIKE :filter')
47-
->andWhere('entity.visibility = :visibility')
48-
->setParameter('filter', '%'.$query.'%')
49-
->setParameter('visibility', VisibilityInterface::VISIBILITY_VISIBLE)
50-
;
53+
->setParameter('filter', '%'.$query.'%');
5154
},
5255
]);
5356
}

‎src/Repository/ContentRepository.php‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ public function findByCriteriaCursored(Criteria $criteria, mixed $currentCursor,
102102
private function getQueryAndParameters(Criteria $criteria, bool $addCursor): array
103103
{
104104
$includeEntries = Criteria::CONTENT_COMBINED === $criteria->content || Criteria::CONTENT_THREADS === $criteria->content;
105-
$includeEntryComments = Criteria::CONTENT_COMBINED === $criteria->content && $criteria->includeBoosts;
106-
$includePostComments = (Criteria::CONTENT_COMBINED === $criteria->content || Criteria::CONTENT_MICROBLOG === $criteria->content) && $criteria->includeBoosts;
105+
$includeEntryComments = $criteria->subscribed && Criteria::CONTENT_COMBINED === $criteria->content && $criteria->includeBoosts;
106+
$includePostComments = $criteria->subscribed && (Criteria::CONTENT_COMBINED === $criteria->content || Criteria::CONTENT_MICROBLOG === $criteria->content) && $criteria->includeBoosts;
107107

108108
$parameters = [
109109
'visible' => VisibilityInterface::VISIBILITY_VISIBLE,
@@ -523,7 +523,6 @@ private function getQueryAndParameters(Criteria $criteria, bool $addCursor): arr
523523
INNER JOIN \"user\" u ON c.user_id = u.id
524524
$outerWhere
525525
$orderBy";
526-
$this->logger->warning('##dbg '.$sql);
527526

528527
if (!str_contains($sql, ':loggedInUser')) {
529528
$parameters = array_filter($parameters, fn ($key) => 'loggedInUser' !== $key, mode: ARRAY_FILTER_USE_KEY);

‎src/Repository/TagRepository.php‎

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use App\Entity\Contracts\VisibilityInterface;
88
use App\Entity\Hashtag;
9+
use App\Entity\User;
910
use App\Pagination\NativeQueryAdapter;
1011
use App\Pagination\Transformation\ContentPopulationTransformer;
1112
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
@@ -34,7 +35,7 @@ public function __construct(
3435
parent::__construct($registry, Hashtag::class);
3536
}
3637

37-
public function findOverall(int $page, string $tag): PagerfantaInterface
38+
public function findOverall(int $page, string $tag, ?User $user): PagerfantaInterface
3839
{
3940
$hashtag = $this->findBy(['tag' => $tag]);
4041
$countAll = $this->tagLinkRepository->createQueryBuilder('link')
@@ -48,26 +49,34 @@ public function findOverall(int $page, string $tag): PagerfantaInterface
4849
$sql = "SELECT e.id, e.created_at, 'entry' AS type FROM entry e
4950
INNER JOIN hashtag_link l ON e.id = l.entry_id
5051
INNER JOIN hashtag h ON l.hashtag_id = h.id AND h.tag = :tag
51-
WHERE visibility = :visibility
52+
INNER JOIN magazine m ON e.magazine_id = m.id
53+
WHERE :visibilityBypass = TRUE OR (e.visibility = :visibility AND m.visibility = :visibility)
5254
UNION ALL
5355
SELECT ec.id, ec.created_at, 'entry_comment' AS type FROM entry_comment ec
5456
INNER JOIN hashtag_link l ON ec.id = l.entry_comment_id
5557
INNER JOIN hashtag h ON l.hashtag_id = h.id AND h.tag = :tag
56-
WHERE visibility = :visibility
58+
INNER JOIN magazine m ON ec.magazine_id = m.id
59+
WHERE :visibilityBypass = TRUE OR (ec.visibility = :visibility AND m.visibility = :visibility)
5760
UNION ALL
5861
SELECT p.id, p.created_at, 'post' AS type FROM post p
5962
INNER JOIN hashtag_link l ON p.id = l.post_id
6063
INNER JOIN hashtag h ON l.hashtag_id = h.id AND h.tag = :tag
61-
WHERE visibility = :visibility
64+
INNER JOIN magazine m ON p.magazine_id = m.id
65+
WHERE :visibilityBypass = TRUE OR (p.visibility = :visibility AND m.visibility = :visibility)
6266
UNION ALL
63-
SELECT pc.id, created_at, 'post_comment' AS type FROM post_comment pc
67+
SELECT pc.id, pc.created_at, 'post_comment' AS type FROM post_comment pc
6468
INNER JOIN hashtag_link l ON pc.id = l.post_comment_id
65-
INNER JOIN hashtag h ON l.hashtag_id = h.id AND h.tag = :tag WHERE visibility = :visibility
69+
INNER JOIN hashtag h ON l.hashtag_id = h.id AND h.tag = :tag
70+
INNER JOIN magazine m ON pc.magazine_id = m.id
71+
WHERE :visibilityBypass = TRUE OR (pc.visibility = :visibility AND m.visibility = :visibility)
6672
ORDER BY created_at DESC";
6773

74+
$visibilityBypass = null !== $user && ($user->isAdmin() || $user->isModerator());
75+
6876
$adapter = new NativeQueryAdapter($conn, $sql, [
6977
'tag' => $tag,
7078
'visibility' => VisibilityInterface::VISIBILITY_VISIBLE,
79+
'visibilityBypass' => $visibilityBypass,
7180
], $countAll, $this->populationTransformer);
7281

7382
$pagerfanta = new Pagerfanta($adapter);

‎src/Service/ProjectInfoService.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class ProjectInfoService
1111
{
1212
// If updating version, please also update http client UA in [/config/packages/framework.yaml]
13-
private const VERSION = '1.10.0'; // TODO: Retrieve the version from git tags or getenv()?
13+
private const VERSION = '1.10.1'; // TODO: Retrieve the version from git tags or getenv()?
1414
private const NAME = 'mbin';
1515
private const CANONICAL_NAME = 'Mbin';
1616
private const REPOSITORY_URL = 'https://github.com/MbinOrg/mbin';

‎src/Utils/SqlHelpers.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ public static function getSqlType(mixed $value): string|int
106106
return Types::DATETIMETZ_MUTABLE;
107107
} elseif (\is_int($value)) {
108108
return Types::INTEGER;
109+
} elseif (\is_bool($value)) {
110+
return Types::BOOLEAN;
109111
}
110112

111113
return Types::STRING;

‎tests/FactoryTrait.php‎

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -611,26 +611,43 @@ public function getKibbyFlippedImageDto(): ImageDto
611611
return $this->getKibbyImageVariantDto('_flipped');
612612
}
613613

614-
private function getKibbyImageVariantDto(string $suffix): ImageDto
614+
public function getKibbyImageUpload(): UploadedFile
615615
{
616-
$imageRepository = $this->imageRepository;
617-
$imageFactory = $this->imageFactory;
616+
return $this->getKibbyImageVariantUpload('');
617+
}
618618

619-
if (!file_exists(\dirname($this->kibbyPath).'/copy')) {
620-
if (!mkdir(\dirname($this->kibbyPath).'/copy')) {
619+
public function getKibbyFlippedImageUpload(): UploadedFile
620+
{
621+
return $this->getKibbyImageVariantUpload('_flipped');
622+
}
623+
624+
private function getKibbyImageVariantUpload(string $suffix): UploadedFile
625+
{
626+
if (!file_exists($this->imageUploadTmpDir)) {
627+
if (!mkdir($this->imageUploadTmpDir)) {
621628
throw new \Exception('The copy dir could not be created');
622629
}
623630
}
624631

625632
// Uploading a file appears to delete the file at the given path, so make a copy before upload
626-
$tmpPath = \dirname($this->kibbyPath).'/copy/'.bin2hex(random_bytes(32)).'.png';
633+
$tmpPath = $this->imageUploadTmpDir.bin2hex(random_bytes(32)).'.png';
627634
$srcPath = \dirname($this->kibbyPath).'/'.basename($this->kibbyPath, '.png').$suffix.'.png';
628635
if (!file_exists($srcPath)) {
629636
throw new \Exception('For some reason the kibby image got deleted');
630637
}
631638
copy($srcPath, $tmpPath);
639+
640+
return new UploadedFile($tmpPath, 'kibby_emoji.png', 'image/png');
641+
}
642+
643+
private function getKibbyImageVariantDto(string $suffix): ImageDto
644+
{
645+
$imageRepository = $this->imageRepository;
646+
$imageFactory = $this->imageFactory;
647+
648+
$imgUpload = $this->getKibbyImageVariantUpload($suffix);
632649
/** @var Image $image */
633-
$image = $imageRepository->findOrCreateFromUpload(new UploadedFile($tmpPath, 'kibby_emoji.png', 'image/png'));
650+
$image = $imageRepository->findOrCreateFromUpload($imgUpload);
634651
self::assertNotNull($image);
635652
$image->altText = 'kibby';
636653
$this->entityManager->persist($image);

0 commit comments

Comments
 (0)