| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Codappix\SearchCore\Domain\Index; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * Copyright (C) 2016  Daniel Siepmann <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * This program is free software; you can redistribute it and/or | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * modify it under the terms of the GNU General Public License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * as published by the Free Software Foundation; either version 2 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * of the License, or (at your option) any later version. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * This program is distributed in the hope that it will be useful, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * GNU General Public License for more details. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * You should have received a copy of the GNU General Public License | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * along with this program; if not, write to the Free Software | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * 02110-1301, USA. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | use Codappix\SearchCore\Configuration\ConfigurationContainerInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | use Codappix\SearchCore\Connection\ConnectionInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | use Codappix\SearchCore\Domain\Index\TcaIndexer\TcaTableServiceInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  * Will index the given table using configuration from TCA. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | class TcaIndexer extends AbstractIndexer | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * @var TcaTableServiceInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     protected $tcaTableService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      * @param TcaTableServiceInterface $tcaTableService | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * @param ConnectionInterface $connection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * @param ConfigurationContainerInterface $configuration | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 54 |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         TcaTableServiceInterface $tcaTableService, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         ConnectionInterface $connection, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |         ConfigurationContainerInterface $configuration | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 | 54 |  |         parent::__construct($connection, $configuration); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 54 |  |         $this->tcaTableService = $tcaTableService; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 54 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * @param integer $offset | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * @param integer $limit | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * @return array|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 26 |  |     protected function getRecords(int $offset, int $limit) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 26 |  |         $records = $this->tcaTableService->getRecords($offset, $limit); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 26 |  |         if ($records === []) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 | 26 |  |             return null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 | 26 |  |         $this->tcaTableService->filterRecordsByRootLineBlacklist($records); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 26 |  |         foreach ($records as &$record) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 26 |  |             $this->tcaTableService->prepareRecord($record); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 26 |  |         return $records; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      * @param integer $identifier | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      * @throws NoRecordFoundException If record could not be found. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 4 |  |     protected function getRecord(int $identifier): array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 | 4 |  |         $record = $this->tcaTableService->getRecord($identifier); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 4 |  |         if ($record === []) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 2 |  |             throw new NoRecordFoundException( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 | 2 |  |                 'Record could not be fetched from database: "' . $identifier . '". Perhaps record is not active.', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 2 |  |                 1484225364 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 | 2 |  |         $this->tcaTableService->prepareRecord($record); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 | 2 |  |         return $record; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 | 28 |  |     protected function getDocumentName(): string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 | 28 |  |         return $this->tcaTableService->getTableName(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      * @param string $identifier | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |      * @return string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 102 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 103 | 28 |  |     public function getDocumentIdentifier($identifier): string | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 105 | 28 |  |         return $this->getDocumentName() . '-' . $identifier; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 107 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 108 |  |  |  |