77 * Date: 12-06-2015
88 * All code (c) Beech Applications B.V. all rights reserved
99 */
10+
1011use BeechIt \NewsImporter \Domain \Model \ExtractedItem ;
1112use BeechIt \NewsImporter \Domain \Model \ImportSource ;
13+ use BeechIt \NewsImporter \Exception \NewsItemNotFoundException ;
1214use GeorgRinger \News \Domain \Service \NewsImportService ;
1315use TYPO3 \CMS \Backend \Utility \BackendUtility ;
16+ use TYPO3 \CMS \Core \Database \ConnectionPool ;
17+ use TYPO3 \CMS \Core \Database \Query \Restriction \DeletedRestriction ;
18+ use TYPO3 \CMS \Core \Html \RteHtmlParser ;
1419use TYPO3 \CMS \Core \Resource \DuplicationBehavior ;
1520use TYPO3 \CMS \Core \Resource \ResourceFactory ;
1621use TYPO3 \CMS \Core \SingletonInterface ;
@@ -25,7 +30,8 @@ class ImportService implements SingletonInterface
2530 /**
2631 * @var NewsImportService
2732 */
28- protected $ newsImportService ;
33+ protected NewsImportService $ newsImportService ;
34+
2935 public function __construct (NewsImportService $ newsImportService )
3036 {
3137 $ this ->newsImportService = $ newsImportService ;
@@ -37,7 +43,7 @@ public function __construct(NewsImportService $newsImportService)
3743 * @param ImportSource $importSource
3844 * @param ExtractedItem $item
3945 */
40- public function importItem (ImportSource $ importSource , ExtractedItem $ item )
46+ public function importItem (ImportSource $ importSource , ExtractedItem $ item ): void
4147 {
4248 $ data = $ item ->toArray ();
4349 $ data ['pid ' ] = $ importSource ->getStoragePid ();
@@ -62,15 +68,57 @@ public function importItem(ImportSource $importSource, ExtractedItem $item)
6268 * @param string $guid
6369 * @return bool
6470 */
65- public function alreadyImported ($ pid , $ guid )
71+ public function alreadyImported (int $ pid , string $ guid ): bool
6672 {
67- $ guid = $ this ->getDatabaseConnection ()->fullQuoteStr ($ guid , 'tx_news_domain_model_news ' );
68- $ record = $ this ->getDatabaseConnection ()->exec_SELECTgetSingleRow (
69- 'uid ' ,
70- 'tx_news_domain_model_news ' ,
71- 'deleted=0 AND pid= ' . (int )$ pid . ' AND import_source = \'ext:news_importer \' AND import_id= ' . $ guid
72- );
73- return $ record ? $ record ['uid ' ] : false ;
73+ $ newsItemImported = false ;
74+ try {
75+ $ this ->getNewsItemUid ($ pid , $ guid );
76+ $ newsItemImported = true ;
77+ } catch (NewsItemNotFoundException $ e ) {
78+ }
79+ return $ newsItemImported ;
80+ }
81+
82+ /**
83+ * @param int $pid
84+ * @param string $guid
85+ * @return int
86+ * @throws NewsItemNotFoundException
87+ */
88+ public function getNewsItemUid (int $ pid , string $ guid ): int
89+ {
90+ $ queryBuilder = GeneralUtility::makeInstance (ConnectionPool::class)->getQueryBuilderForTable ('tx_news_domain_model_news ' );
91+ $ queryBuilder
92+ ->getRestrictions ()
93+ ->removeAll ()
94+ ->add (GeneralUtility::makeInstance (DeletedRestriction::class));
95+ $ firstRecord = $ queryBuilder ->select ('uid ' )
96+ ->from ('tx_news_domain_model_news ' )
97+ ->where (
98+ $ queryBuilder ->expr ()->eq (
99+ 'pid ' ,
100+ $ queryBuilder ->createNamedParameter ($ pid , \PDO ::PARAM_INT )
101+ )
102+ )
103+ ->andWhere (
104+ $ queryBuilder ->expr ()->eq (
105+ 'import_source ' ,
106+ $ queryBuilder ->createNamedParameter ('ext:news_importer ' , \PDO ::PARAM_STR )
107+ )
108+ )
109+ ->andWhere (
110+ $ queryBuilder ->expr ()->eq (
111+ 'import_id ' ,
112+ $ queryBuilder ->createNamedParameter ($ guid , \PDO ::PARAM_STR )
113+ )
114+ )
115+ ->execute ()
116+ ->fetchAssociative ();
117+
118+ if ($ firstRecord === false ) {
119+ throw new NewsItemNotFoundException ($ guid );
120+ }
121+ return $ firstRecord ['uid ' ];
74122 }
75123
76124 /**
@@ -83,7 +131,7 @@ public function alreadyImported($pid, $guid)
83131 * @param array $searchFields
84132 * @return bool
85133 */
86- public function matchFilter (ExtractedItem $ item , $ filterWords , array $ searchFields = ['title ' , 'bodytext ' ])
134+ public function matchFilter (ExtractedItem $ item , $ filterWords , array $ searchFields = ['title ' , 'bodytext ' ]): bool
87135 {
88136 if (empty ($ searchFields )) {
89137 return true ;
@@ -105,8 +153,9 @@ public function matchFilter(ExtractedItem $item, $filterWords, array $searchFiel
105153 *
106154 * @param string $text
107155 * @param int $pid
156+ * @return mixed
108157 */
109- protected function cleanBodyText ($ text , $ pid )
158+ protected function cleanBodyText (string $ text , int $ pid )
110159 {
111160 static $ rteHtmlParsers ;
112161
@@ -115,17 +164,14 @@ protected function cleanBodyText($text, $pid)
115164 $ rteHtmlParsers = [];
116165 }
117166 /** @var $htmlParser \TYPO3\CMS\Core\Html\RteHtmlParser */
118- $ rteHtmlParsers [$ pid ] = GeneralUtility::makeInstance ('TYPO3 \\CMS \\Core \\Html \\RteHtmlParser ' );
119- $ rteHtmlParsers [$ pid ]->init ('tx_news_domain_model_news:bodytext ' , $ pid );
167+ $ rteHtmlParsers [$ pid ] = GeneralUtility::makeInstance (RteHtmlParser::class);
120168 }
121169
122170 // Perform transformation
123171 $ tsConfig = BackendUtility::getPagesTSconfig ($ pid );
124- return $ rteHtmlParsers [$ pid ]->RTE_transform (
172+ return $ rteHtmlParsers [$ pid ]->transformTextForPersistence (
125173 trim ($ text ),
126- ['rte_transform ' => ['parameters ' => ['flag=rte_disabled ' , 'mode=ts_css ' ]]],
127- 'db ' ,
128- $ tsConfig ['RTE. ' ]['default. ' ]
174+ $ tsConfig ['RTE. ' ]['default. ' ]['proc. ' ] ?? []
129175 );
130176 }
131177
@@ -188,12 +234,4 @@ protected function processMedia(array $data, ImportSource $importSource)
188234 }
189235 return $ media ;
190236 }
191-
192- /**
193- * @return \TYPO3\CMS\Core\Database\DatabaseConnection
194- */
195- protected function getDatabaseConnection ()
196- {
197- return $ GLOBALS ['TYPO3_DB ' ];
198- }
199237}
0 commit comments