Commit a300c4ba authored by Thomas Löffler's avatar Thomas Löffler

Use a new function to remove duplicated code

parent 95355fef
Pipeline #7104 passed with stages
in 5 minutes and 33 seconds
......@@ -523,14 +523,12 @@ class ExtensionController extends \T3o\TerFe2\Controller\AbstractController
public function likeAction(\T3o\TerFe2\Domain\Model\Extension $extension)
{
$liked = false;
if ($GLOBALS['TSFE'] && $GLOBALS['TSFE']->loginUser) {
$currentUser = $this->ownerRepository->findByUid((int)$GLOBALS['TSFE']->fe_user->user['uid']);
if ($currentUser instanceof \T3o\TerFe2\Domain\Model\FrontendUser) {
$currentUser->addLikedExtension($extension);
$this->ownerRepository->update($currentUser);
$this->extensionRepository->update($extension);
$liked = true;
}
$currentUser = $this->getLoggedInUser();
if ($currentUser instanceof \T3o\TerFe2\Domain\Model\FrontendUser) {
$currentUser->addLikedExtension($extension);
$this->ownerRepository->update($currentUser);
$this->extensionRepository->update($extension);
$liked = true;
}
return json_encode($liked);
......@@ -539,14 +537,12 @@ class ExtensionController extends \T3o\TerFe2\Controller\AbstractController
public function disLikeAction(\T3o\TerFe2\Domain\Model\Extension $extension)
{
$disliked = false;
if ($GLOBALS['TSFE'] && $GLOBALS['TSFE']->loginUser) {
$currentUser = $this->ownerRepository->findByUid((int)$GLOBALS['TSFE']->fe_user->user['uid']);
if ($currentUser instanceof \T3o\TerFe2\Domain\Model\FrontendUser) {
$currentUser->removeLikedExtension($extension);
$this->ownerRepository->update($currentUser);
$this->extensionRepository->update($extension);
$disliked = true;
}
$currentUser = $this->getLoggedInUser();
if ($currentUser instanceof \T3o\TerFe2\Domain\Model\FrontendUser) {
$currentUser->removeLikedExtension($extension);
$this->ownerRepository->update($currentUser);
$this->extensionRepository->update($extension);
$disliked = true;
}
return json_encode($disliked);
......@@ -555,14 +551,12 @@ class ExtensionController extends \T3o\TerFe2\Controller\AbstractController
public function activateNotificationAction(\T3o\TerFe2\Domain\Model\Extension $extension): string
{
$notified = false;
if ($GLOBALS['TSFE'] && $GLOBALS['TSFE']->loginUser) {
$currentUser = $this->ownerRepository->findByUid((int)$GLOBALS['TSFE']->fe_user->user['uid']);
if ($currentUser instanceof \T3o\TerFe2\Domain\Model\FrontendUser) {
$currentUser->addNotifiedExtension($extension);
$this->ownerRepository->update($currentUser);
$this->extensionRepository->update($extension);
$notified = true;
}
$currentUser = $this->getLoggedInUser();
if ($currentUser instanceof \T3o\TerFe2\Domain\Model\FrontendUser) {
$currentUser->addNotifiedExtension($extension);
$this->ownerRepository->update($currentUser);
$this->extensionRepository->update($extension);
$notified = true;
}
return json_encode($notified);
......@@ -571,14 +565,12 @@ class ExtensionController extends \T3o\TerFe2\Controller\AbstractController
public function deactivateNotificationAction(\T3o\TerFe2\Domain\Model\Extension $extension): string
{
$unnotified = false;
if ($GLOBALS['TSFE'] && $GLOBALS['TSFE']->loginUser) {
$currentUser = $this->ownerRepository->findByUid((int)$GLOBALS['TSFE']->fe_user->user['uid']);
if ($currentUser instanceof \T3o\TerFe2\Domain\Model\FrontendUser) {
$currentUser->removeNotifiedExtension($extension);
$this->ownerRepository->update($currentUser);
$this->extensionRepository->update($extension);
$unnotified = true;
}
$currentUser = $this->getLoggedInUser();
if ($currentUser instanceof \T3o\TerFe2\Domain\Model\FrontendUser) {
$currentUser->removeNotifiedExtension($extension);
$this->ownerRepository->update($currentUser);
$this->extensionRepository->update($extension);
$unnotified = true;
}
return json_encode($unnotified);
......@@ -607,6 +599,18 @@ class ExtensionController extends \T3o\TerFe2\Controller\AbstractController
return !empty($isAllowedToUploadKey);
}
/**
* @return \T3o\TerFe2\Domain\Model\FrontendUser|null
*/
protected function getLoggedInUser(): ?\T3o\TerFe2\Domain\Model\FrontendUser
{
if ($GLOBALS['TSFE'] && $GLOBALS['TSFE']->fe_user && $GLOBALS['TSFE']->fe_user->user) {
return $this->ownerRepository->findByUid((int)$GLOBALS['TSFE']->fe_user->user['uid']);
}
return null;
}
/**
* Check if an version does not exist for extension
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment