Skip to content
Snippets Groups Projects
Commit 6f50eb6f authored by Matthias Adrowski's avatar Matthias Adrowski
Browse files

Merge branch 'feature_Upgrade-to-TYPO3-11' into 'master'

Feature upgrade to typo3 11

See merge request !38
parents 9ac5a6bc 4a30b13d
No related branches found
Tags 9.0.15
1 merge request!38Feature upgrade to typo3 11
Showing
with 430 additions and 291 deletions
......@@ -29,6 +29,7 @@ namespace SGalinski\SgNews\Command;
use SGalinski\SgNews\Domain\Model\News;
use SGalinski\SgNews\Domain\Repository\FileReferenceRepository;
use SGalinski\SgNews\Domain\Repository\NewsRepository;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
......@@ -41,7 +42,6 @@ use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\FileInterface;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use Symfony\Component\Console\Command\Command;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Persistence\Exception\IllegalObjectTypeException;
use TYPO3\CMS\Extbase\Persistence\Exception\UnknownObjectException;
......@@ -77,12 +77,15 @@ class MigrateNewsCommandController extends Command {
->addArgument('categoryPid', InputArgument::REQUIRED, 'The page id of the category page')
->addArgument('year', InputArgument::OPTIONAL, 'Only news from that year will be migrated', 2015)
->addArgument(
'languageMapAsJson', InputArgument::OPTIONAL,
'languageMapAsJson',
InputArgument::OPTIONAL,
'A json, mapping language ids (old => new). this is needed if the sys_language_uids have changed',
'{"3":1,"1":0,"2":2,"0":3}'
)
->addArgument(
'categoryMapAsJson', InputArgument::OPTIONAL, 'A json, mapping sys_category ids (old => new).',
'categoryMapAsJson',
InputArgument::OPTIONAL,
'A json, mapping sys_category ids (old => new).',
'{"2":17,"3":16,"4":15,"5":14,"6":14,"7":15,"8":16,"9":17}'
)
->addArgument('pId', InputArgument::OPTIONAL, 'Only news from that pid will be migrated', 52);
......@@ -93,7 +96,7 @@ class MigrateNewsCommandController extends Command {
*
* @param InputInterface $input
* @param OutputInterface $output
* @return void
* @return int
* @throws \JsonException
*/
public function execute(InputInterface $input, OutputInterface $output) {
......@@ -121,7 +124,7 @@ class MigrateNewsCommandController extends Command {
->where(
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($pId, Connection::PARAM_INT))
)
->execute()->fetchAll();
->execute()->fetchAllAssociative();
$localDataHandler = GeneralUtility::makeInstance(DataHandler::class);
Bootstrap::initializeBackendAuthentication();
$localCommandMap = [
......@@ -163,20 +166,26 @@ class MigrateNewsCommandController extends Command {
$newsPage->setLastUpdated($date);
$this->setMatchingTag($row);
/** @var File $image */
/** @var File $file */
$file = $this->getMatchingFile($row);
if ($file instanceof File) {
$teaserImage1 = $fileReferenceRepository->addFileReferenceFromFile(
$file, $this->newsPagesMap[$row['uid']],
$this->newsPagesMap[$row['uid']], 'pages', 'tx_sgnews_teaser1_image'
$file,
$this->newsPagesMap[$row['uid']],
$this->newsPagesMap[$row['uid']],
'pages',
'tx_sgnews_teaser1_image'
);
if ($teaserImage1) {
$newsPage->addTeaser1Image($teaserImage1);
$teaserImage2 = $fileReferenceRepository->addFileReferenceFromFile(
$file, $this->newsPagesMap[$row['uid']],
$this->newsPagesMap[$row['uid']], 'pages', 'tx_sgnews_teaser2_image'
$file,
$this->newsPagesMap[$row['uid']],
$this->newsPagesMap[$row['uid']],
'pages',
'tx_sgnews_teaser2_image'
);
$newsPage->addTeaser2Image($teaserImage2);
}
......@@ -194,12 +203,15 @@ class MigrateNewsCommandController extends Command {
->where(
$queryBuilder->expr()->andX(
$queryBuilder->expr()->eq(
'pid', $queryBuilder->createNamedParameter($newPageId, Connection::PARAM_INT)
'pid',
$queryBuilder->createNamedParameter($newPageId, Connection::PARAM_INT)
),
$queryBuilder->expr()->eq(
'sys_language_uid', $queryBuilder->createNamedParameter(
$this->languageMap[(int) $row['sys_language_uid']], \PDO::PARAM_INT
)
'sys_language_uid',
$queryBuilder->createNamedParameter(
$this->languageMap[(int) $row['sys_language_uid']],
\PDO::PARAM_INT
)
)
)
)
......@@ -210,6 +222,7 @@ class MigrateNewsCommandController extends Command {
$this->updateTranslation($row);
}
}
return Command::SUCCESS;
}
/**
......@@ -230,15 +243,17 @@ class MigrateNewsCommandController extends Command {
->where(
$queryBuilder->expr()->andX(
$queryBuilder->expr()->eq(
'tablenames', $queryBuilder->createNamedParameter('tx_news_domain_model_news')
'tablenames',
$queryBuilder->createNamedParameter('tx_news_domain_model_news')
),
$queryBuilder->expr()->eq('fieldname', $queryBuilder->createNamedParameter('fal_media')),
$queryBuilder->expr()->eq(
'uid_foreign', $queryBuilder->createNamedParameter($row['uid'], Connection::PARAM_INT)
'uid_foreign',
$queryBuilder->createNamedParameter($row['uid'], Connection::PARAM_INT)
)
)
)
->execute()->fetch();
->execute()->fetchAssociative();
if (!$fileReferenceResult) {
return NULL;
}
......@@ -251,10 +266,11 @@ class MigrateNewsCommandController extends Command {
->from('sys_file_news_migration')
->where(
$queryBuilder->expr()->eq(
'uid', $queryBuilder->createNamedParameter($fileReferenceResult['uid_local'], Connection::PARAM_INT)
'uid',
$queryBuilder->createNamedParameter($fileReferenceResult['uid_local'], Connection::PARAM_INT)
)
)
->execute()->fetch();
->execute()->fetchAssociative();
if (!$fileResult) {
return NULL;
}
......@@ -283,10 +299,11 @@ class MigrateNewsCommandController extends Command {
->from('sys_category_record_mm_news_migration')
->where(
$queryBuilder->expr()->eq(
'uid_foreign', $queryBuilder->createNamedParameter($row['uid'], Connection::PARAM_INT)
'uid_foreign',
$queryBuilder->createNamedParameter($row['uid'], Connection::PARAM_INT)
)
)
->execute()->fetchAll();
->execute()->fetchAllAssociative();
foreach ($mmRows as $mmRow) {
$values = [
'uid_local' => $this->categoryMap[(int) $mmRow['uid_local']],
......@@ -322,7 +339,8 @@ class MigrateNewsCommandController extends Command {
if ((int) $this->languageMap[(int) $row['sys_language_uid'] === 0]) {
$queryBuilder->where(
$queryBuilder->expr()->eq(
'uid', $queryBuilder->createNamedParameter($originalContentElement[0], Connection::PARAM_INT)
'uid',
$queryBuilder->createNamedParameter($originalContentElement[0], Connection::PARAM_INT)
)
);
} else {
......@@ -338,9 +356,11 @@ class MigrateNewsCommandController extends Command {
if (isset($this->languageMap[(int) $row['sys_language_uid']])) {
$queryBuilder->andWhere(
$queryBuilder->expr()->eq(
'sys_language_uid', $queryBuilder->createNamedParameter(
$this->languageMap[(int) $row['sys_language_uid']], Connection::PARAM_INT
)
'sys_language_uid',
$queryBuilder->createNamedParameter(
$this->languageMap[(int) $row['sys_language_uid']],
Connection::PARAM_INT
)
)
);
} else {
......@@ -362,10 +382,11 @@ class MigrateNewsCommandController extends Command {
->from('pages')
->where(
$queryBuilder->expr()->eq(
'uid', $queryBuilder->createNamedParameter($parentId, Connection::PARAM_INT)
'uid',
$queryBuilder->createNamedParameter($parentId, Connection::PARAM_INT)
)
)
->execute()->fetch();
->execute()->fetchAssociative();
if ($result) {
$queryBuilder->where(
$queryBuilder->expr()->eq(
......@@ -390,7 +411,8 @@ class MigrateNewsCommandController extends Command {
$queryBuilder->update('pages')
->where(
$queryBuilder->expr()->eq(
'uid', $queryBuilder->createNamedParameter($parentId, Connection::PARAM_INT)
'uid',
$queryBuilder->createNamedParameter($parentId, Connection::PARAM_INT)
)
)
->set('title', $newTitle, TRUE)
......@@ -402,7 +424,8 @@ class MigrateNewsCommandController extends Command {
$queryBuilder->update('pages')
->where(
$queryBuilder->expr()->eq(
'l10n_parent', $queryBuilder->createNamedParameter($parentId, Connection::PARAM_INT)
'l10n_parent',
$queryBuilder->createNamedParameter($parentId, Connection::PARAM_INT)
)
);
......@@ -412,9 +435,11 @@ class MigrateNewsCommandController extends Command {
) {
$queryBuilder->andWhere(
$queryBuilder->expr()->eq(
'sys_language_uid', $queryBuilder->createNamedParameter(
$this->languageMap[(int) $row['sys_language_uid']], Connection::PARAM_INT
)
'sys_language_uid',
$queryBuilder->createNamedParameter(
$this->languageMap[(int) $row['sys_language_uid']],
Connection::PARAM_INT
)
)
);
} else {
......
......@@ -57,7 +57,7 @@ abstract class AbstractController extends ActionController {
* @throws \RuntimeException
*/
public function errorAction() {
throw new RuntimeException(parent::errorAction());
throw new RuntimeException($this->getFlattenedValidationErrorMessage());
}
/**
......@@ -75,4 +75,15 @@ abstract class AbstractController extends ActionController {
}
return $offset;
}
/**
* Build Typo3 11 Response
* @param string|NULL $html
* @return \Psr\Http\Message\ResponseInterface
*/
protected function htmlResponse(string $html = NULL): \Psr\Http\Message\ResponseInterface {
return $this->responseFactory->createResponse()
->withHeader('Content-Type', 'text/html; charset=utf-8')
->withBody($this->streamFactory->createStream($html ?? $this->view->render()));
}
}
......@@ -36,7 +36,6 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
* @package SGalinski\SgNews\Controller\Ajax
*/
class LikeController extends AbstractAjaxController {
/**
* This action increases the tx_sgnews_likes field of a given page ($newsPid) by one
*
......@@ -57,9 +56,9 @@ class LikeController extends AbstractAjaxController {
)
->execute();
} catch (\Exception $exception) {
$this->returnData(['success' => false]);
$this->returnData(['success' => FALSE]);
}
$this->returnData(['success' => true]);
$this->returnData(['success' => TRUE]);
}
}
......@@ -26,14 +26,17 @@ namespace SGalinski\SgNews\Controller;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use SGalinski\SgNews\Paginator\QueryBuilderPaginator;
use SGalinski\SgNews\Utility\BackendNewsUtility;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\Components\DocHeaderComponent;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Pagination\SimplePagination;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
......@@ -43,7 +46,6 @@ use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
* News Controller
*/
class BackendController extends ActionController {
/**
* The uid of the current page
*
......@@ -79,6 +81,12 @@ class BackendController extends ActionController {
*/
private $docHeaderComponent;
/**
* @var ?ModuleTemplate
*/
protected $moduleTemplate = NULL;
/**
* Initializes the view before invoking an action method.
*
......@@ -100,7 +108,11 @@ class BackendController extends ActionController {
$backendUser = $GLOBALS['BE_USER'];
$this->pageInfo = BackendUtility::readPageAccess($this->pageUid, $backendUser->getPagePermsClause(1));
if ($this->pageInfo) {
$this->docHeaderComponent = GeneralUtility::makeInstance(DocHeaderComponent::class);
if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) {
$this->docHeaderComponent = GeneralUtility::makeInstance(DocHeaderComponent::class);
} else {
$this->getDocHeaderComponent();
}
if ($this->pageUid) {
$this->rootPageUid = BackendNewsUtility::getRootUidByPageUid($this->pageUid);
}
......@@ -114,7 +126,8 @@ class BackendController extends ActionController {
}
$this->language = $backendUser->getModuleData(
'tools_beuser/index.php/web_SgNewsNews_language', 'ses'
'tools_beuser/index.php/web_SgNewsNews_language',
'ses'
) ?: 0;
$languageOptions = BackendNewsUtility::getAvailableLanguages($this->pageUid);
$currentLanguageInfo = $languageOptions[$this->language] ?? NULL;
......@@ -131,16 +144,15 @@ class BackendController extends ActionController {
}
/**
* @param array $filters
* @throws \InvalidArgumentException
* @throws \UnexpectedValueException
* @param array|null $filters
* @return \Psr\Http\Message\ResponseInterface|null
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public function indexAction(array $filters = NULL) {
public function indexAction(array $filters = NULL): ?\Psr\Http\Message\ResponseInterface {
$showNewsList = FALSE;
if (
($this->pageUid && $this->pageUid === $this->rootPageUid) ||
(int) $this->pageInfo['doktype'] === BackendNewsUtility::CATEGORY_DOKTYPE
(isset($this->pageInfo['doktype']) && (int) $this->pageInfo['doktype'] === BackendNewsUtility::CATEGORY_DOKTYPE)
) {
/** @var BackendUserAuthentication $backendUser */
$backendUser = $GLOBALS['BE_USER'];
......@@ -157,7 +169,13 @@ class BackendController extends ActionController {
$filters['categories'] = [$this->pageUid];
}
$tags = BackendNewsUtility::getTagsForPage($this->pageUid, $this->language);
$news = BackendNewsUtility::getNewsByFilters($this->rootPageUid, $filters, $this->language);
[$news, $newsQueryBuilder] = BackendNewsUtility::getNewsByFilters($this->rootPageUid, $filters, $this->language);
$paginator = new QueryBuilderPaginator($newsQueryBuilder);
$pagination = new SimplePagination($paginator);
$this->view->assign('paginator', $paginator);
$this->view->assign('pagination', $pagination);
$this->view->assign('tags', $tags);
$this->view->assign('news', $news);
......@@ -168,6 +186,14 @@ class BackendController extends ActionController {
$this->view->assign('alternativePageOptions', $alternativePageOptions);
}
$this->view->assign('showNewsList', $showNewsList);
if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) {
$this->view->assign('V11', FALSE);
return NULL;
} else {
$this->view->assign('V11', TRUE);
return $this->createBackendResponse();
}
}
/**
......@@ -226,7 +252,8 @@ class BackendController extends ActionController {
->setTitle($language['title'])
->setHref(
$uriBuilder->buildUriFromRoute(
'web_SgNewsNews', ['id' => $this->pageUid, 'SET' => ['language' => $key]]
'web_SgNewsNews',
['id' => $this->pageUid, 'SET' => ['language' => $key]]
)
);
if ((int) $this->language === (int) $key) {
......@@ -236,4 +263,39 @@ class BackendController extends ActionController {
}
$this->docHeaderComponent->getMenuRegistry()->addMenu($languageMenu);
}
/**
* Use the ModuleTemplateResponse to create a response object for the backend
*
* @return \Psr\Http\Message\ResponseInterface
*/
protected function createBackendResponse(): \Psr\Http\Message\ResponseInterface {
$this->getModuleTemplate();
$this->moduleTemplate->setContent($this->view->render());
return $this->htmlResponse($this->moduleTemplate->renderContent());
}
/**
* Since we cannot use constructer Injection, we do have to get one Dynamicly. If we want to use
* our ModuleTemplate, call GetModuleTemplate before, which will init one if there is none for some reason
*/
protected function getModuleTemplate() {
if ($this->moduleTemplate === NULL) {
$moduleTemplateFactory = GeneralUtility::makeInstance(
\TYPO3\CMS\Backend\Template\ModuleTemplateFactory::class
);
$this->moduleTemplate = $moduleTemplateFactory->create($this->request);
}
}
/**
* Other Helper function, which gets us just the DocHeaderComponent
*/
protected function getDocHeaderComponent() {
if ($this->moduleTemplate === NULL) {
$this->getModuleTemplate();
}
$this->docHeaderComponent = $this->moduleTemplate->getDocHeaderComponent();
}
}
......@@ -64,36 +64,64 @@ class LatestController extends AbstractController {
*
* @param array $newsMetaData
* @param int $offset
* @return void
* @return null|\Psr\Http\Message\ResponseInterface
* @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
* @throws \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException
*/
public function indexAction(array $newsMetaData = [], $offset = 0) {
$limit = ((int) $this->settings['limit']);
public function indexAction(array $newsMetaData = [], $offset = 0): ?\Psr\Http\Message\ResponseInterface {
$limit = 0;
if (isset($this->settings['limit'])) {
$limit = ((int) $this->settings['limit']);
}
$limit = ($limit < 1 ? 1 : $limit);
$configurationService = GeneralUtility::makeInstance(ConfigurationService::class);
$sortBy = $configurationService->getConfiguration('sortBy', $this->settings);
$categoryUids = GeneralUtility::intExplode(',', $this->settings['categories'], TRUE);
$tagUids = GeneralUtility::intExplode(',', $this->settings['tags'], TRUE);
$categoryUids = [];
$tagUids = [];
if (isset($this->settings['categories'])) {
$categoryUids = GeneralUtility::intExplode(',', $this->settings['categories'], TRUE);
}
if (isset($this->settings['tags'])) {
$tagUids = GeneralUtility::intExplode(',', $this->settings['tags'], TRUE);
}
if ((int) $GLOBALS['TSFE']->page['doktype'] === 117 && !count($categoryUids)) {
$categoryUids = [$GLOBALS['TSFE']->id];
}
$startTime = (int) $this->settings['starttime'];
$endTime = (int) $this->settings['endtime'];
$startTime = 0;
$endTime = 0;
if (isset($this->settings['starttime'])) {
$startTime = (int) $this->settings['starttime'];
}
if (isset($this->settings['endtime'])) {
$endTime = (int) $this->settings['endtime'];
}
$latestNewsEntries = $this->newsRepository->findLastUpdatedOrHighlightedNewsByCategories(
$limit, FALSE, $categoryUids, $offset, TRUE, $sortBy, $tagUids, $startTime, $endTime
$limit,
FALSE,
$categoryUids,
$offset,
TRUE,
$sortBy,
$tagUids,
$startTime,
$endTime
);
$categories = [];
$category = NULL;
foreach ($latestNewsEntries as $latestNewsEntry) {
/** @var News $latestNewsEntry */
/** @var Category $category */
$categoryUid = $latestNewsEntry->getPid();
$category = $categories[$categoryUid];
if (isset($categories[$categoryUid])) {
$category = $categories[$categoryUid];
}
if (!$category) {
$category = $this->categoryRepository->findByUid($categoryUid);
if (!$category) {
......@@ -110,12 +138,18 @@ class LatestController extends AbstractController {
}
$this->view->assign('newsMetaData', $newsMetaData);
if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) {
return NULL;
} else {
return $this->htmlResponse();
}
}
/**
* @param CategoryRepository $categoryRepository
*/
public function injectCategoryRepository(CategoryRepository $categoryRepository
public function injectCategoryRepository(
CategoryRepository $categoryRepository
) {
$this->categoryRepository = $categoryRepository;
}
......
......@@ -33,8 +33,8 @@ use SGalinski\SgNews\Domain\Repository\TagRepository;
use SGalinski\SgNews\Domain\Service\NewsService;
use SGalinski\SgNews\Service\ConfigurationService;
use SGalinski\SgNews\Service\HeaderMetaDataService;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Http\ImmediateResponseException;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Controller\ErrorController;
use TYPO3\CMS\Frontend\Page\PageAccessFailureReasons;
......@@ -66,7 +66,8 @@ class ListByCategoryController extends AbstractController {
/**
* @param CategoryRepository $categoryRepository
*/
public function injectCategoryRepository(CategoryRepository $categoryRepository
public function injectCategoryRepository(
CategoryRepository $categoryRepository
) {
$this->categoryRepository = $categoryRepository;
}
......@@ -98,7 +99,9 @@ class ListByCategoryController extends AbstractController {
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentNameException
*/
public function initializeIndexAction() {
$currentPageBrowserPage = (int) GeneralUtility::_GP('tx_sgnews_pagebrowser')['currentPage'];
$currentPageBrowserPage = GeneralUtility::_GP('tx_sgnews_pagebrowser')
? (int) GeneralUtility::_GP('tx_sgnews_pagebrowser')['currentPage']
: 0;
if ($currentPageBrowserPage > 0) {
$this->request->setArgument('currentPageBrowserPage', $currentPageBrowserPage);
}
......@@ -109,17 +112,23 @@ class ListByCategoryController extends AbstractController {
*
* @param array $newsMetaData
* @param int $currentPageBrowserPage
* @return void
* @return null|\Psr\Http\Message\ResponseInterface
* @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
* @throws \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException
* @throws ImmediateResponseException
* @throws \TYPO3\CMS\Core\Error\Http\PageNotFoundException
*/
public function indexAction(array $newsMetaData = [], int $currentPageBrowserPage = 0) {
public function indexAction(array $newsMetaData = [], int $currentPageBrowserPage = 0): ?\Psr\Http\Message\ResponseInterface {
$filterByCategories = FALSE;
$categoryUids = GeneralUtility::intExplode(',', $this->settings['categories']);
$tagUids = GeneralUtility::intExplode(',', $this->settings['tags'], TRUE);
$categoryUids = [];
$tagUids = [];
if (isset($this->settings['categories'])) {
$categoryUids = GeneralUtility::intExplode(',', $this->settings['categories'], TRUE);
}
if (isset($this->settings['tags'])) {
$tagUids = GeneralUtility::intExplode(',', $this->settings['tags'], TRUE);
}
HeaderMetaDataService::addPageNumberToCanonical($currentPageBrowserPage);
......@@ -150,8 +159,14 @@ class ListByCategoryController extends AbstractController {
}
}
$startTime = (int) $this->settings['starttime'];
$endTime = (int) $this->settings['endtime'];
$startTime = 0;
$endTime = 0;
if (isset($this->settings['starttime'])) {
$startTime = (int) $this->settings['starttime'];
}
if (isset($this->settings['endtime'])) {
$endTime = (int) $this->settings['endtime'];
}
$newsPerPage = (int) $this->settings['newsLimitPerPage'];
$newsCount = $this->newsRepository->newsCountByCategories($categoryUids, $tagUids, $startTime, $endTime);
......@@ -175,29 +190,30 @@ class ListByCategoryController extends AbstractController {
$sortDirection = $configurationService->getConfiguration('sortDirection', $this->settings);
$news = $this->newsRepository->findAllSortedNewsByCategories(
$categoryUids, $newsPerPage, $offset, $sortBy, $tagUids, $startTime, $endTime, $sortDirection
$categoryUids,
$newsPerPage,
$offset,
$sortBy,
$tagUids,
$startTime,
$endTime,
$sortDirection
)->toArray();
foreach ($news as $newsEntry) {
/** @var News $newsEntry */
$data = $this->newsService->getMetaDataForNews($newsEntry, $categories[$newsEntry->getPid()]);
$newsMetaData[] = $data;
if (!$headerSet) {
if (!version_compare(ExtensionManagementUtility::getExtensionVersion('sg_seo'), '5.0.0', '>=')) {
if ($data['image']) {
HeaderMetaDataService::addOgImageToHeader($data['image']);
$headerSet = TRUE;
} elseif ($data['teaserImage']) {
HeaderMetaDataService::addOgImageToHeader($data['teaserImage']);
$headerSet = TRUE;
}
}
}
}
$this->view->assign('numberOfPages', $numberOfPages);
$this->view->assign('newsMetaData', $newsMetaData);
$this->view->assign('categories', $categories);
if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) {
return NULL;
} else {
return $this->htmlResponse();
}
}
}
......@@ -57,18 +57,22 @@ class NewsByAuthorController extends AbstractController {
* Renders the news author list.
*
* @param int $authorId
* @return void
* @return null|\Psr\Http\Message\ResponseInterface
* @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
* @throws \TYPO3\CMS\Core\Package\Exception
*/
public function listAction($authorId = 0): void {
public function listAction($authorId = 0): ?\Psr\Http\Message\ResponseInterface {
if ($authorId) {
$newsAuthorsIds[] = $authorId;
} else {
$newsAuthorsIds = GeneralUtility::intExplode(',', $this->settings['newsAuthors']);
if (\count($newsAuthorsIds) <= 0) {
return;
if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) {
return NULL;
} else {
return $this->htmlResponse();
}
}
}
......@@ -81,33 +85,34 @@ class NewsByAuthorController extends AbstractController {
continue;
}
if (version_compare(ExtensionManagementUtility::getExtensionVersion('sg_seo'), '5.0.0', '>=')) {
$headTagService = GeneralUtility::makeInstance(
HeadTagService::class,
TRUE,
$author->getName(),
$author->getDescription(),
'&tx_sgnews_newsbyauthor[authorId]=' . $author->getUid()
);
$headTagService->execute();
} else {
$GLOBALS['TSFE']->page['titlebyextension'] = $author->getName();
$GLOBALS['TSFE']->page['description'] = \strip_tags(\substr($author->getDescription(), 0, 200));
$GLOBALS['TSFE']->page['extensionArgumentsForCanonicalAndHrefLang'] =
'&tx_sgnews_newsbyauthor[authorId]=' . $author->getUid();
}
$headTagService = GeneralUtility::makeInstance(
HeadTagService::class,
TRUE,
$author->getName(),
$author->getDescription(),
'&tx_sgnews_newsbyauthor[authorId]=' . $author->getUid()
);
$headTagService->execute();
$authors[] = $author;
}
if (\count($authors) <= 0) {
return;
if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) {
return NULL;
} else {
return $this->htmlResponse();
}
}
$newsRepository = $this->objectManager->get(NewsRepository::class);
$news = $newsRepository->findAllByNewsAuthor($newsAuthorsIds);
if (\count($news) <= 0) {
return;
if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) {
return NULL;
} else {
return $this->htmlResponse();
}
}
$categories = $newsMetaData = [];
......@@ -137,5 +142,11 @@ class NewsByAuthorController extends AbstractController {
$this->view->assign('newsMetaData', $newsMetaData);
$this->view->assign('authors', $authors);
if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) {
return NULL;
} else {
return $this->htmlResponse();
}
}
}
......@@ -43,16 +43,24 @@ class NewsFeedController extends AbstractController {
/**
* Renders the news feed
*
* @return void
* @return null|\Psr\Http\Message\ResponseInterface
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public function indexAction() {
public function indexAction(): ?\Psr\Http\Message\ResponseInterface {
$categories = GeneralUtility::intExplode(',', $this->settings['showCategories'], TRUE);
$tags = GeneralUtility::intExplode(',', $this->settings['showTags'], TRUE);
$startTime = (int) $this->settings['starttime'];
$endTime = (int) $this->settings['endtime'];
$news = $this->newsRepository->findLastUpdatedOrHighlightedNewsByCategories(
10, FALSE, $categories, 0, FALSE, 'date', $tags, $startTime, $endTime
10,
FALSE,
$categories,
0,
FALSE,
'date',
$tags,
$startTime,
$endTime
);
$newsCategories = [];
......@@ -74,6 +82,12 @@ class NewsFeedController extends AbstractController {
$this->view->assign('news', $news);
$this->view->assign('newsCategories', $newsCategories);
if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) {
return NULL;
} else {
return $this->htmlResponse();
}
}
/**
......
......@@ -70,7 +70,8 @@ class OverviewController extends AbstractController {
/**
* @param CategoryRepository $categoryRepository
*/
public function injectCategoryRepository(CategoryRepository $categoryRepository
public function injectCategoryRepository(
CategoryRepository $categoryRepository
) {
$this->categoryRepository = $categoryRepository;
}
......@@ -102,7 +103,7 @@ class OverviewController extends AbstractController {
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentNameException
*/
public function initializeOverviewAction() {
$currentPageBrowserPage = (int) GeneralUtility::_GP('tx_sgnews_pagebrowser')['currentPage'];
$currentPageBrowserPage = (int) (GeneralUtility::_GP('tx_sgnews_pagebrowser')['currentPage'] ?? 0);
if ($currentPageBrowserPage > 0) {
$this->request->setArgument('currentPageBrowserPage', $currentPageBrowserPage);
}
......@@ -119,34 +120,45 @@ class OverviewController extends AbstractController {
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
* @throws \TYPO3\CMS\Extbase\Configuration\Exception\InvalidConfigurationTypeException
*/
public function overviewAction(array $newsFilter = [], int $currentPageBrowserPage = 0) {
public function overviewAction(array $newsFilter = [], int $currentPageBrowserPage = 0): ?\Psr\Http\Message\ResponseInterface {
if ((int) $this->settings['groupBy'] === 0 && (bool) $this->settings['enableFilter'] === FALSE) {
$this->forward('overviewWithoutCategories', NULL, NULL, $this->request->getArguments());
if (version_compare(
\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(),
'11.0.0',
'<'
)) {
$this->forward('overviewWithoutCategories', NULL, NULL, $this->request->getArguments());
} else {
return (new \TYPO3\CMS\Extbase\Http\ForwardResponse(
'overviewWithoutCategories'
))
->withArguments($this->request->getArguments());
}
}
// Setup settings
$startTime = (int) $this->settings['starttime'];
$endTime = (int) $this->settings['endtime'];
$newsLimit = (int) $this->settings['newsLimit'];
$startTime = (int) ($this->settings['starttime'] ?? 0);
$endTime = (int) ($this->settings['endtime'] ?? 0);
$newsLimit = (int) ($this->settings['newsLimit'] ?? 0);
$offset = $this->calculatePaginationOffset($currentPageBrowserPage, $newsLimit);
$configurationService = GeneralUtility::makeInstance(ConfigurationService::class);
$sortBy = $configurationService->getConfiguration('sortBy', $this->settings);
$sortDirection = $configurationService->getConfiguration('sortDirection', $this->settings);
$this->tagRepository->setDefaultOrderings(['sorting' => QueryInterface::ORDER_ASCENDING]);
$this->categoryRepository->setDefaultOrderings(['sorting' => QueryInterface::ORDER_ASCENDING]);
$useAllFilters = (bool) $this->settings['enableFilter'];
$isCategoryFiltered = $useAllFilters || (int) $this->settings['groupBy'] === 1;
$isTagFiltered = $useAllFilters || (int) $this->settings['groupBy'] === 2;
$useAllFilters = (bool) ($this->settings['enableFilter'] ?? FALSE);
$isCategoryFiltered = $useAllFilters || $this->settings['groupBy'] === 1 ? 1 : 0;
$isTagFiltered = $useAllFilters || $this->settings['groupBy'] === 2 ? 1 : 0;
HeaderMetaDataService::addPageNumberToCanonical($currentPageBrowserPage);
// Get tag pid
$tagPid = (int) $this->settings['tagPid'];
$tagPid = (int) ($this->settings['tagPid'] ?? 0);
if (!$tagPid) {
$tagPid = $GLOBALS['TSFE']->id;
}
if ($this->settings['onlyNewsWithinThisPageSection']) {
if ($this->settings['onlyNewsWithinThisPageSection'] ?? FALSE) {
$categories = $this->categoryRepository->findCategoriesInRootLine($GLOBALS['TSFE']->id);
$tags = $this->tagRepository->findTagsInRootLine($tagPid);
} else {
......@@ -155,7 +167,7 @@ class OverviewController extends AbstractController {
}
// Apply category restrictions
$categoryRestrictions = GeneralUtility::intExplode(',', $this->settings['categoryRestrictions'], TRUE);
$categoryRestrictions = GeneralUtility::intExplode(',', $this->settings['categoryRestrictions'] ?? '', TRUE);
if (!$isCategoryFiltered) {
$categoryRestrictions = [];
}
......@@ -181,7 +193,7 @@ class OverviewController extends AbstractController {
}
// Apply tag restrictions
$tagRestrictions = GeneralUtility::intExplode(',', $this->settings['tagRestrictions'], TRUE);
$tagRestrictions = GeneralUtility::intExplode(',', $this->settings['tagRestrictions'] ?? '', TRUE);
if (!$isTagFiltered) {
$tagRestrictions = [];
}
......@@ -195,7 +207,7 @@ class OverviewController extends AbstractController {
// Get category ids or use the one in the filter
$categoryIds = [];
if ($newsFilter['category']) {
if ($newsFilter['category'] ?? FALSE) {
$categoryIds = [(int) $newsFilter['category']];
} elseif ($isCategoryFiltered) {
foreach ($categories as $category) {
......@@ -207,7 +219,7 @@ class OverviewController extends AbstractController {
// Get tag ids or use the one in the filter
$tagIds = [];
if ($newsFilter['tag']) {
if ($newsFilter['tag'] ?? FALSE) {
$tagIds = [(int) $newsFilter['tag']];
} elseif ($isTagFiltered) {
foreach ($tags as $tag) {
......@@ -219,7 +231,14 @@ class OverviewController extends AbstractController {
// Get all news by category and tag ids
$news = $this->newsRepository->findAllSortedNewsByCategories(
$categoryIds, $newsLimit, $offset, $sortBy, $tagIds, $startTime, $endTime, $sortDirection
$categoryIds,
$newsLimit,
$offset,
$sortBy,
$tagIds,
$startTime,
$endTime,
$sortDirection
);
// Process news result query based on filters
......@@ -229,8 +248,8 @@ class OverviewController extends AbstractController {
foreach ($news as $newsEntry) {
/** @var News $newsEntry */
$newsCategory = $this->categoryRepository->findOriginalLanguageById(
$newsEntry->getPid()
) ?? $this->categoryRepository->findByUid($newsEntry->getPid());
$newsEntry->getPid()
) ?? $this->categoryRepository->findByUid($newsEntry->getPid());
$newsCategoryId = $newsCategory->getUid();
$newsMetaData = $this->newsService->getMetaDataForNews($newsEntry, $newsCategory);
......@@ -292,8 +311,8 @@ class OverviewController extends AbstractController {
}
// remember selection of the filter values, if any
$selectedTag = $this->tagRepository->findByUid((int) $newsFilter['tag']);
$selectedCategory = $this->categoryRepository->findByUid((int) $newsFilter['category']);
$selectedTag = $this->tagRepository->findByUid((int) ($newsFilter['tag'] ?? 0));
$selectedCategory = $this->categoryRepository->findByUid((int) ($newsFilter['category'] ?? 0));
$this->view->assign('selectedCategory', $selectedCategory);
$this->view->assign('selectedTag', $selectedTag);
$this->view->assign('tags', $tags);
......@@ -303,7 +322,7 @@ class OverviewController extends AbstractController {
$this->view->assign('allNews', $allNews);
$this->setupGridColumns();
switch ($this->settings['groupBy']) {
switch ($this->settings['groupBy'] ?? '') {
case 1:
$this->view->assign('groupBy', 'category');
$this->view->assign('categoryTabs', TRUE);
......@@ -315,6 +334,12 @@ class OverviewController extends AbstractController {
default:
$this->view->assign('groupBy', 'none');
}
if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) {
return NULL;
} else {
return $this->htmlResponse();
}
}
/**
......@@ -334,10 +359,13 @@ class OverviewController extends AbstractController {
switch ($columnAmount) {
case 4:
$columnClasses .= 'col-lg-3 ';
// no break
case 3:
$columnClasses .= 'col-md-4 ';
// no break
case 2:
$columnClasses .= 'col-sm-6 ';
// no break
default:
$columnClasses .= 'col-xs-12';
}
......@@ -353,13 +381,21 @@ class OverviewController extends AbstractController {
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
protected function highlightBestFitNews(array $categoryIds = NULL, array $tagIds = NULL) {
$startTime = (int) $this->settings['starttime'];
$endTime = (int) $this->settings['endtime'];
$startTime = (int) ($this->settings['starttime'] ?? 0);
$endTime = (int) ($this->settings['endtime'] ?? 0);
/** @var News $highlightedNews */
$highlightedNews = $this->newsRepository
->findLastUpdatedOrHighlightedNewsByCategories(
1, FALSE, $categoryIds, 0, FALSE, $this->settings['sortBy'], $tagIds, $startTime, $endTime
1,
FALSE,
$categoryIds,
0,
FALSE,
$this->settings['sortBy'],
$tagIds,
$startTime,
$endTime
)->getFirst();
if (!$highlightedNews) {
return;
......@@ -371,14 +407,6 @@ class OverviewController extends AbstractController {
if ($category) {
$highlightedNewsMetaData = $this->newsService->getMetaDataForNews($highlightedNews, $category);
}
if (!version_compare(ExtensionManagementUtility::getExtensionVersion('sg_seo'), '5.0.0', '>=')) {
if ($highlightedNewsMetaData['image']) {
HeaderMetaDataService::addOgImageToHeader($highlightedNewsMetaData['image']);
} elseif ($highlightedNewsMetaData['teaserImage']) {
HeaderMetaDataService::addOgImageToHeader($highlightedNewsMetaData['teaserImage']);
}
}
}
/**
......@@ -406,7 +434,9 @@ class OverviewController extends AbstractController {
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
protected function overviewWithoutCategoriesAction(
array $newsMetaData = [], array $newsFilter = NULL, int $currentPageBrowserPage = 0
array $newsMetaData = [],
array $newsFilter = NULL,
int $currentPageBrowserPage = 0
) {
// remember selection of the filter values, if any
$selectedTag = $this->tagRepository->findByUid((int) $newsFilter['tag']);
......@@ -484,7 +514,14 @@ class OverviewController extends AbstractController {
}
$news = $this->newsRepository->findAllSortedNewsByCategories(
$categoryIds, $newsPerPage, $offset, $sortBy, $tagIds, $startTime, $endTime, $sortDirection
$categoryIds,
$newsPerPage,
$offset,
$sortBy,
$tagIds,
$startTime,
$endTime,
$sortDirection
);
foreach ($news as $newsEntry) {
/** @var News $newsEntry */
......
......@@ -68,44 +68,41 @@ class SingleViewController extends AbstractController {
/**
* Renders the news single view
*
* @return void
* @return null|\Psr\Http\Message\ResponseInterface
* @throws \InvalidArgumentException
*/
public function singleViewAction() {
/** @var News $news */
public function singleViewAction(): ?\Psr\Http\Message\ResponseInterface {
$currentId = (int) $GLOBALS['TSFE']->id;
/** @var News $news */
$news = $this->newsRepository->findByUid($currentId);
if (!$news) {
return;
if (version_compare(
\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(),
'11.0.0',
'<'
)) {
return NULL;
} else {
return $this->htmlResponse();
}
}
/** @var Category $newsCategory */
$newsCategory = $this->categoryRepository->findByUid($news->getPid());
if (!$newsCategory) {
return;
if (version_compare(
\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(),
'11.0.0',
'<'
)) {
return NULL;
} else {
return $this->htmlResponse();
}
}
// $similarNewsMetaData = [];
// $similarNews = $this->newsRepository->findRandomNews(3, $news);
// foreach ($similarNews as $similarNewsEntry) {
// /** @var News $similarNewsEntry */
// /** @var Category $category */
// $category = $this->categoryRepository->findByUid($similarNewsEntry->getPid());
// if (!$category) {
// continue;
// }
//
// $similarNewsMetaData[] = $this->getMetaDataForNews($similarNewsEntry, $category);
// }
$newsMetaData = $this->newsService->getMetaDataForNews($news, $newsCategory);
if (!version_compare(ExtensionManagementUtility::getExtensionVersion('sg_seo'), '5.0.0', '>=')) {
if ($newsMetaData['image']) {
HeaderMetaDataService::addOgImageToHeader($newsMetaData['image']);
} elseif ($newsMetaData['teaserImage']) {
HeaderMetaDataService::addOgImageToHeader($newsMetaData['teaserImage']);
}
}
$previousNews = $this->newsRepository->findPreviousNewsEntryFromCurrentNews($news, $this->settings['sortBy'])
->getFirst();
......@@ -121,12 +118,18 @@ class SingleViewController extends AbstractController {
'newsAuthor' => $news->getNewsAuthor(),
]
);
if (version_compare(\TYPO3\CMS\Core\Utility\VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '<')) {
return NULL;
} else {
return $this->htmlResponse();
}
}
/**
* @param CategoryRepository $categoryRepository
*/
public function injectCategoryRepository(CategoryRepository $categoryRepository
public function injectCategoryRepository(
CategoryRepository $categoryRepository
) {
$this->categoryRepository = $categoryRepository;
}
......
......@@ -30,5 +30,4 @@ namespace SGalinski\SgNews\Domain\Model;
* FileReference
*/
class FileReference extends \TYPO3\CMS\Extbase\Domain\Model\FileReference {
}
......@@ -31,7 +31,6 @@ use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
* Tag
*/
class Tag extends AbstractEntity {
/**
* @var string
*/
......
......@@ -27,6 +27,7 @@ namespace SGalinski\SgNews\Domain\Repository;
***************************************************************/
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Http\ApplicationType;
use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
use TYPO3\CMS\Extbase\Persistence\QueryInterface;
use TYPO3\CMS\Extbase\Persistence\Repository;
......@@ -43,44 +44,17 @@ abstract class AbstractRepository extends Repository {
* @return void
*/
public function initializeObject() {
/** @var $querySettings Typo3QuerySettings */
/** @var Typo3QuerySettings $querySettings */
$querySettings = $this->objectManager->get(Typo3QuerySettings::class);
$querySettings->setRespectStoragePage(FALSE);
if (TYPO3_MODE === 'BE') {
// in Migration wizard it was possible tha $GLOBALS['TYPO3_REQUEST'] was not set
// this should not be the case in any other case
if (!isset($GLOBALS['TYPO3_REQUEST']) || ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isBackend()) {
$querySettings->setIgnoreEnableFields(TRUE);
}
$this->setDefaultQuerySettings($querySettings);
}
/**
* Method creates a statement string of the enableFields for the given database table.
*
* @param string $table
* @param string $alias
* @param bool $ignoreEnableFields
* @return string
* @throws \InvalidArgumentException
*/
protected function getEnableFieldsStatement($table, $alias = '', $ignoreEnableFields = FALSE): string {
if (TYPO3_MODE === 'FE' && $GLOBALS['TSFE'] instanceof TypoScriptFrontendController) {
/** @var PageRepository $pageRepository */
$pageRepository = $GLOBALS['TSFE']->sys_page;
$statement = $pageRepository->enableFields($table);
} else {
$statement = BackendUtility::deleteClause($table);
if (!$ignoreEnableFields) {
$statement .= BackendUtility::BEenableFields($table);
}
}
if ($alias !== '') {
$statement = str_replace($table, $alias, $statement);
}
return $statement;
}
/**
* This count returns the right amount of results, in contrast to $query->execute()->count(), which does not respect
* the language- nor the workspace overlay.
......@@ -90,6 +64,6 @@ abstract class AbstractRepository extends Repository {
* @return int
*/
public function getCount(QueryInterface $query) {
return \count($query->execute(true));
return \count($query->execute(TRUE));
}
}
......@@ -32,5 +32,4 @@ use SGalinski\SgNews\Domain\Repository\AbstractRepository;
* Repository for the Author model.
*/
class AuthorRepository extends AbstractRepository {
}
......@@ -37,7 +37,6 @@ use TYPO3\CMS\Extbase\Persistence\QueryInterface;
* Category Repository
*/
class CategoryRepository extends AbstractRepository {
/**
* @var array
*/
......@@ -61,7 +60,7 @@ class CategoryRepository extends AbstractRepository {
$queryBuilder->expr()->eq('translation.uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT))
)
->setMaxResults(1)
->execute()->fetch();
->execute()->fetchAssociative();
if ($row && (int) $row['uid'] !== 0) {
return current($dataMapper->map($this->objectType, [$row]));
}
......
......@@ -26,16 +26,15 @@ namespace SGalinski\SgNews\Domain\Repository;
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use SGalinski\SgNews\Domain\Model\FileReference;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* FileReference Repository
*/
class FileReferenceRepository extends AbstractRepository {
/**
* Method creates a file reference entry in the database. This step is necessary because the
* extbase can not handle the default TCA for FAL records. Without this method the FAL records will miss
......@@ -71,7 +70,7 @@ class FileReferenceRepository extends AbstractRepository {
* extbase can not handle the default TCA for FAL records. Without this method the FAL records will miss
* the uid_foreign, field name and table names.
*
* @param $fileId
* @param int $fileId
* @param array $reference
* @param string $tablename
* @param string $fieldname
......
......@@ -86,8 +86,14 @@ class NewsRepository extends AbstractRepository {
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public function findAllSortedNewsByCategories(
array $categoryIds = NULL, $limit = 0, $offset = 0, $sortBy = 'date', array $tagIds = NULL,
$startTime = 0, $endTime = 0, $sortDirection = 'DESC'
array $categoryIds = NULL,
$limit = 0,
$offset = 0,
$sortBy = 'date',
array $tagIds = NULL,
$startTime = 0,
$endTime = 0,
$sortDirection = 'DESC'
): QueryResultInterface {
$query = $this->createQuery();
......@@ -171,7 +177,10 @@ class NewsRepository extends AbstractRepository {
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public function newsCountByCategories(
array $categoryIds = NULL, array $tagIds = NULL, $startTime = 0, $endTime = 0
array $categoryIds = NULL,
array $tagIds = NULL,
$startTime = 0,
$endTime = 0
): int {
$query = $this->createQuery();
......@@ -231,13 +240,26 @@ class NewsRepository extends AbstractRepository {
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public function findLastUpdatedOrHighlightedNewsByCategories(
$limit = 1, $onlyHighlighted = FALSE, array $categoryIds = NULL,
$offset = 0, $hideNeverHighlightedNews = FALSE, $sortBy = 'date', array $tagIds = NULL,
$startTime = 0, $endTime = 0
$limit = 1,
$onlyHighlighted = FALSE,
array $categoryIds = NULL,
$offset = 0,
$hideNeverHighlightedNews = FALSE,
$sortBy = 'date',
array $tagIds = NULL,
$startTime = 0,
$endTime = 0
): QueryResultInterface {
return $this->getQueryForLastUpdatedOrHighlightedNewsByCategories(
$limit, $onlyHighlighted, $categoryIds, $offset, $hideNeverHighlightedNews, $sortBy, $tagIds,
$startTime, $endTime
$limit,
$onlyHighlighted,
$categoryIds,
$offset,
$hideNeverHighlightedNews,
$sortBy,
$tagIds,
$startTime,
$endTime
)->execute();
}
......@@ -257,9 +279,15 @@ class NewsRepository extends AbstractRepository {
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
protected function getQueryForLastUpdatedOrHighlightedNewsByCategories(
$limit = 1, $onlyHighlighted = FALSE, array $categoryIds = NULL,
$offset = 0, $hideNeverHighlightedNews = FALSE, $sortBy = 'date', array $tagIds = NULL,
$startTime = 0, $endTime = 0
$limit = 1,
$onlyHighlighted = FALSE,
array $categoryIds = NULL,
$offset = 0,
$hideNeverHighlightedNews = FALSE,
$sortBy = 'date',
array $tagIds = NULL,
$startTime = 0,
$endTime = 0
): QueryInterface {
$query = $this->createQuery();
$constraints = NULL;
......@@ -498,7 +526,7 @@ class NewsRepository extends AbstractRepository {
*/
public function findByUidIgnoreEnableFields($uid) {
$query = $this->createQuery();
/** @var $querySettings \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings */
/** @var \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings $querySettings */
$querySettings = $query->getQuerySettings();
$querySettings->setIgnoreEnableFields(TRUE);
$querySettings->setRespectStoragePage(FALSE);
......@@ -553,9 +581,9 @@ class NewsRepository extends AbstractRepository {
// Here we fetch the lastUpdated of the $limit amount of news with older lastUpdated dates
$result = $qb->where(
$qb->expr()->eq('doktype', $qb->createNamedParameter(News::DOK_TYPE_NEWS, Connection::PARAM_INT)),
$qb->expr()->lte('lastUpdated', $news->getLastUpdated()->getTimestamp())
)->andWhere(...$constraints)
$qb->expr()->eq('doktype', $qb->createNamedParameter(News::DOK_TYPE_NEWS, Connection::PARAM_INT)),
$qb->expr()->lte('lastUpdated', $news->getLastUpdated()->getTimestamp())
)->andWhere(...$constraints)
->orderBy('lastUpdated', 'asc')
->execute();
$oldest = $result->fetchOne();
......
......@@ -28,10 +28,10 @@ namespace SGalinski\SgNews\Domain\Service;
use SGalinski\SgNews\Domain\Model\Category;
use SGalinski\SgNews\Domain\Model\News;
use TYPO3\CMS\Core\Resource\FileRepository;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Domain\Model\FileReference;
use TYPO3\CMS\Core\Resource\FileRepository;
/**
* This service takes care of meta data generation for the news objects
......
<?php
namespace SGalinski\SgNews\Hooks;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.de)
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use SGalinski\SgNews\Utility\BackendNewsUtility;
use TYPO3\CMS\Backend\Controller\EditDocumentController as CoreEditDocumentController;
use TYPO3\CMS\Backend\Utility\BackendUtility;
/**
* Backend edid form hook
*/
class EditDocumentController {
/**
* Sets the default value for the pages author field
* to the name of the logged-in user
*
* @param CoreEditDocumentController $controller
* @return void
*/
public function preInitAfter($controller) {
$tables = ['pages'];
if (
$GLOBALS['BE_USER']->user['realName'] !== ''
&& (isset($controller->editconf[$tables[0]]) || isset($controller->editconf[$tables[1]]))
) {
$doktype = 0;
$userName = $GLOBALS['BE_USER']->user['realName'];
$tableName = isset($controller->editconf[$tables[0]]) ? $tables[0] : $tables[1];
$command = reset($controller->editconf[$tableName]);
$pageUid = key($controller->editconf[$tableName]);
if ($command === 'edit') {
$pageRow = BackendUtility::getRecord($tableName, (int) $pageUid);
if ($pageRow && isset($pageRow['doktype'])) {
$doktype = (int) $pageRow['doktype'];
}
} elseif ($command === 'new' && isset($controller->overrideVals[$tableName]['doktype'])) {
$doktype = (int) $controller->overrideVals[$tableName]['doktype'];
}
if ($doktype === BackendNewsUtility::NEWS_DOKTYPE) {
$GLOBALS['BE_USER']->userTS['TCAdefaults.'][$tableName . '.']['author'] = $userName;
}
}
}
}
......@@ -37,17 +37,15 @@ use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
* Backend edid form hook
*/
class PageLayoutController {
/**
* Sets the default value for the pages author field
* to the name of the logged-in user
* Adds a Button to News-Pages which allows the user to switch to the News module
*
* @param array $parameters
* @param CorePageLayoutController $controller
* @return string
* @throws \InvalidArgumentException
*/
public function addNewsModuleLink(array $parameters = [], $controller): string {
public function addNewsModuleLink(array $parameters = [], CorePageLayoutController $controller = NULL): string {
$out = '';
$pageRow = BackendUtility::getRecord('pages', $controller->id);
$acceptedDoktypes = [BackendNewsUtility::NEWS_DOKTYPE, BackendNewsUtility::CATEGORY_DOKTYPE];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment