Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sg_news
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TYPO3
sg_news
Commits
a097c288
Commit
a097c288
authored
2 years ago
by
Dominik Beyer
Browse files
Options
Downloads
Patches
Plain Diff
[TASK] Overrite number of likes per news entry
parent
687abd41
No related branches found
No related tags found
1 merge request
!47
[TASK] Overrite number of likes per news entry
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Classes/Domain/Repository/NewsRepository.php
+23
-0
23 additions, 0 deletions
Classes/Domain/Repository/NewsRepository.php
Classes/Domain/Service/NewsService.php
+9
-0
9 additions, 0 deletions
Classes/Domain/Service/NewsService.php
with
32 additions
and
0 deletions
Classes/Domain/Repository/NewsRepository.php
+
23
−
0
View file @
a097c288
...
@@ -629,6 +629,29 @@ class NewsRepository extends AbstractRepository {
...
@@ -629,6 +629,29 @@ class NewsRepository extends AbstractRepository {
return
$query
->
execute
();
return
$query
->
execute
();
}
}
/**
* Sums up the number of likes per news entry for all existing translations.
*
* @param int $uid
* @return int The like count
* @throws \Doctrine\DBAL\DBALException
* @throws \Doctrine\DBAL\Driver\Exception
*/
public
function
sumLikes
(
int
$uid
):
int
{
$connection
=
$this
->
getConnection
();
$qb
=
$connection
->
createQueryBuilder
();
$constraints
=
[];
$constraints
[]
=
$qb
->
expr
()
->
eq
(
'uid'
,
$qb
->
createNamedParameter
(
$uid
,
Connection
::
PARAM_INT
));
$constraints
[]
=
$qb
->
expr
()
->
eq
(
'l10n_source'
,
$qb
->
createNamedParameter
(
$uid
,
Connection
::
PARAM_INT
));
$qb
->
addSelectLiteral
(
$qb
->
expr
()
->
sum
(
'tx_sgnews_likes'
,
'sum_likes'
))
->
from
(
'pages'
,
'pages'
)
->
where
(
$qb
->
expr
()
->
or
(
...
$constraints
));
return
$qb
->
execute
()
->
fetchOne
();
}
protected
function
getConnection
():
Connection
{
protected
function
getConnection
():
Connection
{
return
GeneralUtility
::
makeInstance
(
ConnectionPool
::
class
)
return
GeneralUtility
::
makeInstance
(
ConnectionPool
::
class
)
->
getConnectionForTable
(
'pages'
);
->
getConnectionForTable
(
'pages'
);
...
...
This diff is collapsed.
Click to expand it.
Classes/Domain/Service/NewsService.php
+
9
−
0
View file @
a097c288
...
@@ -28,6 +28,7 @@ namespace SGalinski\SgNews\Domain\Service;
...
@@ -28,6 +28,7 @@ namespace SGalinski\SgNews\Domain\Service;
use
SGalinski\SgNews\Domain\Model\Category
;
use
SGalinski\SgNews\Domain\Model\Category
;
use
SGalinski\SgNews\Domain\Model\News
;
use
SGalinski\SgNews\Domain\Model\News
;
use
SGalinski\SgNews\Domain\Repository\NewsRepository
;
use
TYPO3\CMS\Core\Resource\FileRepository
;
use
TYPO3\CMS\Core\Resource\FileRepository
;
use
TYPO3\CMS\Core\SingletonInterface
;
use
TYPO3\CMS\Core\SingletonInterface
;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
...
@@ -49,6 +50,8 @@ class NewsService implements SingletonInterface {
...
@@ -49,6 +50,8 @@ class NewsService implements SingletonInterface {
* @param Category $category
* @param Category $category
* @return array
* @return array
* @throws \InvalidArgumentException
* @throws \InvalidArgumentException
* @throws \Doctrine\DBAL\DBALException
* @throws \Doctrine\DBAL\Driver\Exception
*/
*/
public
function
getMetaDataForNews
(
News
$news
,
Category
$category
):
array
{
public
function
getMetaDataForNews
(
News
$news
,
Category
$category
):
array
{
$newsId
=
$news
->
getUid
();
$newsId
=
$news
->
getUid
();
...
@@ -72,6 +75,12 @@ class NewsService implements SingletonInterface {
...
@@ -72,6 +75,12 @@ class NewsService implements SingletonInterface {
];
];
}
}
// Overwrite the number of likes with the one from the default news entry and add possible likes from translated
// entries to fix broken data in older instances.
$newsRepository
=
GeneralUtility
::
makeInstance
(
NewsRepository
::
class
);
$totalLikes
=
$newsRepository
->
sumLikes
(
$newsId
);
$news
->
setLikes
(
$totalLikes
);
$newsRecord
=
array_merge
(
$newsRecord
=
array_merge
(
[
[
'category'
=>
$category
,
'category'
=>
$category
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment