Passed
Push — master ( 18f4bc...05e0e0 )
by Timo
48:10 queued 27:51
created

ConnectionManager::getConnectionsBySite()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 12
cts 12
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 1
crap 2
1
<?php
2
namespace ApacheSolrForTypo3\Solr;
3
4
/***************************************************************
5
 *  Copyright notice
6
 *
7
 *  (c) 2010-2015 Ingo Renner <[email protected]>
8
 *  All rights reserved
9
 *
10
 *  This script is part of the TYPO3 project. The TYPO3 project is
11
 *  free software; you can redistribute it and/or modify
12
 *  it under the terms of the GNU General Public License as published by
13
 *  the Free Software Foundation; either version 2 of the License, or
14
 *  (at your option) any later version.
15
 *
16
 *  The GNU General Public License can be found at
17
 *  http://www.gnu.org/copyleft/gpl.html.
18
 *
19
 *  This script is distributed in the hope that it will be useful,
20
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 *  GNU General Public License for more details.
23
 *
24
 *  This copyright notice MUST APPEAR in all copies of the script!
25
 ***************************************************************/
26
27
use Psr\Http\Message\ResponseInterface;
28
use Psr\Http\Message\ServerRequestInterface;
29
use TYPO3\CMS\Backend\Routing\UriBuilder;
30
use TYPO3\CMS\Backend\Toolbar\ClearCacheActionsHookInterface;
31
use TYPO3\CMS\Backend\Utility\BackendUtility;
32
use TYPO3\CMS\Core\Imaging\Icon;
33
use TYPO3\CMS\Core\Imaging\IconFactory;
34
use TYPO3\CMS\Core\SingletonInterface;
35
use TYPO3\CMS\Core\Utility\GeneralUtility;
36
37
/**
38
 * A class to easily create a connection to a Solr server.
39
 *
40
 * Internally keeps track of already existing connections and makes sure that no
41
 * duplicate connections are created.
42
 *
43
 * @author Ingo Renner <[email protected]>
44
 */
45
class ConnectionManager implements SingletonInterface, ClearCacheActionsHookInterface
46
{
47
48
    /**
49
     * @var array
50
     */
51
    protected static $connections = array();
52
53
    /**
54
     * Gets a Solr connection.
55
     *
56
     * Instead of generating a new connection with each call, connections are
57
     * kept and checked whether the requested connection already exists. If a
58
     * connection already exists, it's reused.
59
     *
60
     * @param string $host Solr host (optional)
61
     * @param int $port Solr port (optional)
62
     * @param string $path Solr path (optional)
63
     * @param string $scheme Solr scheme, defaults to http, can be https (optional)
64
     * @return SolrService A solr connection.
65
     */
66 53
    public function getConnection(
67
        $host = '',
68
        $port = 8983,
69
        $path = '/solr/',
70
        $scheme = 'http'
71
    ) {
72 53
        $connection = null;
0 ignored issues
show
Unused Code introduced by
$connection is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
73
74 53
        if (empty($host)) {
75 1
            GeneralUtility::devLog(
76
                'ApacheSolrForTypo3\Solr\ConnectionManager::getConnection() called with empty
77
                host parameter. Using configuration from TSFE, might be
78
                inaccurate. Always provide a host or use the getConnectionBy*
79 1
                methods.',
80 1
                'solr',
81
                2
82 1
            );
83
84 1
            $configuration = Util::getSolrConfiguration();
85 1
            $solrConfiguration = $configuration->getValueByPathOrDefaultValue('plugin.tx_solr.solr.', array());
86 1
            $host = $solrConfiguration['host'];
87 1
            $port = $solrConfiguration['port'];
88 1
            $path = $solrConfiguration['path'];
89 1
            $scheme = $solrConfiguration['scheme'];
90 1
        }
91
92 53
        $connectionHash = md5($scheme . '://' . $host . $port . $path);
93
94 53
        if (!isset(self::$connections[$connectionHash])) {
95 53
            $connection = GeneralUtility::makeInstance(
96 53
                'ApacheSolrForTypo3\\Solr\\SolrService',
97 53
                $host,
98 53
                $port,
99 53
                $path,
100
                $scheme
101 53
            );
102
103 52
            self::$connections[$connectionHash] = $connection;
104 52
        }
105
106 52
        return self::$connections[$connectionHash];
107
    }
108
109
    /**
110
     * Gets a Solr configuration for a page ID.
111
     *
112
     * @param int $pageId A page ID.
113
     * @param int $language The language ID to get the connection for as the path may differ. Optional, defaults to 0.
114
     * @param string $mount Comma list of MountPoint parameters
115
     * @return array A solr configuration.
116
     * @throws NoSolrConnectionFoundException
117
     */
118 43
    public function getConfigurationByPageId(
119
        $pageId,
120
        $language = 0,
121
        $mount = ''
122
    ) {
123
        // find the root page
124 43
        $pageSelect = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
125 43
        $rootLine = $pageSelect->getRootLine($pageId, $mount);
126 43
        $siteRootPageId = $this->getSiteRootPageIdFromRootLine($rootLine);
127
128
        try {
129 43
            $solrConfiguration = $this->getConfigurationByRootPageId($siteRootPageId,
130 43
                $language);
131 43
        } catch (NoSolrConnectionFoundException $nscfe) {
132
            /* @var $noSolrConnectionException NoSolrConnectionFoundException */
133
            $noSolrConnectionException = GeneralUtility::makeInstance(
134
                'ApacheSolrForTypo3\\Solr\\NoSolrConnectionFoundException',
135
                $nscfe->getMessage() . ' Initial page used was [' . $pageId . ']',
136
                1275399922
137
            );
138
            $noSolrConnectionException->setPageId($pageId);
139
140
            throw $noSolrConnectionException;
141
        }
142
143 43
        return $solrConfiguration;
144
    }
145
146
    /**
147
     * Gets a Solr connection for a page ID.
148
     *
149
     * @param int $pageId A page ID.
150
     * @param int $language The language ID to get the connection for as the path may differ. Optional, defaults to 0.
151
     * @param string $mount Comma list of MountPoint parameters
152
     * @return SolrService A solr connection.
153
     * @throws NoSolrConnectionFoundException
154
     */
155 43
    public function getConnectionByPageId($pageId, $language = 0, $mount = '')
156
    {
157 43
        $solrConnection = null;
0 ignored issues
show
Unused Code introduced by
$solrConnection is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
158
159 43
        $solrServer = $this->getConfigurationByPageId($pageId, $language,
160 43
            $mount);
161 43
        $solrConnection = $this->getConnection(
162 43
            $solrServer['solrHost'],
163 43
            $solrServer['solrPort'],
164 43
            $solrServer['solrPath'],
165 43
            $solrServer['solrScheme']
166 43
        );
167
168 43
        return $solrConnection;
169
    }
170
171
    /**
172
     * Gets a Solr configuration for a root page ID.
173
     *
174
     * @param int $pageId A root page ID.
175
     * @param int $language The language ID to get the configuration for as the path may differ. Optional, defaults to 0.
176
     * @return array A solr configuration.
177
     * @throws NoSolrConnectionFoundException
178
     */
179 43
    public function getConfigurationByRootPageId($pageId, $language = 0)
180
    {
181 43
        $solrConfiguration = false;
0 ignored issues
show
Unused Code introduced by
$solrConfiguration is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
182 43
        $connectionKey = $pageId . '|' . $language;
183
184 43
        $registry = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Registry');
185 43
        $solrServers = $registry->get('tx_solr', 'servers');
186
187 43
        if (isset($solrServers[$connectionKey])) {
188 43
            $solrConfiguration = $solrServers[$connectionKey];
189 43
        } else {
190
            /* @var $noSolrConnectionException NoSolrConnectionFoundException */
191
            $noSolrConnectionException = GeneralUtility::makeInstance(
192
                'ApacheSolrForTypo3\\Solr\\NoSolrConnectionFoundException',
193
                'Could not find a Solr connection for root page ['
194
                . $pageId . '] and language [' . $language . '].',
195
                1275396474
196
            );
197
            $noSolrConnectionException->setRootPageId($pageId);
198
            $noSolrConnectionException->setLanguageId($language);
199
200
            throw $noSolrConnectionException;
201
        }
202
203 43
        return $solrConfiguration;
204
    }
205
206
    /**
207
     * Gets a Solr connection for a root page ID.
208
     *
209
     * @param int $pageId A root page ID.
210
     * @param int $language The language ID to get the connection for as the path may differ. Optional, defaults to 0.
211
     * @return SolrService A solr connection.
212
     * @throws NoSolrConnectionFoundException
213
     */
214 2
    public function getConnectionByRootPageId($pageId, $language = 0)
215
    {
216 2
        $solrConnection = null;
0 ignored issues
show
Unused Code introduced by
$solrConnection is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
217
218 2
        $solrServer = $this->getConfigurationByRootPageId($pageId, $language);
219 2
        $solrConnection = $this->getConnection(
220 2
            $solrServer['solrHost'],
221 2
            $solrServer['solrPort'],
222 2
            $solrServer['solrPath'],
223 2
            $solrServer['solrScheme']
224 2
        );
225
226 2
        return $solrConnection;
227
    }
228
229
    /**
230
     * Gets all connection configurations found.
231
     *
232
     * @return array An array of connection configurations.
233
     */
234 18
    public function getAllConfigurations()
235
    {
236 18
        $registry = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Registry');
237 18
        $solrConfigurations = $registry->get('tx_solr', 'servers', array());
238
239 18
        return $solrConfigurations;
240
    }
241
242
    /**
243
     * Gets all connections found.
244
     *
245
     * @return SolrService[] An array of initialized ApacheSolrForTypo3\Solr\SolrService connections
246
     */
247 3
    public function getAllConnections()
248
    {
249 3
        $connections = array();
250
251 3
        $solrServers = $this->getAllConfigurations();
252 3
        foreach ($solrServers as $solrServer) {
253 3
            $connections[] = $this->getConnection(
254 3
                $solrServer['solrHost'],
255 3
                $solrServer['solrPort'],
256 3
                $solrServer['solrPath'],
257 3
                $solrServer['solrScheme']
258 3
            );
259 3
        }
260
261 3
        return $connections;
262
    }
263
264
    /**
265
     * Gets all connection configurations for a given site.
266
     *
267
     * @param Site $site A TYPO3 site
268
     * @return array An array of Solr connection configurations for a site
269
     */
270 15
    public function getConfigurationsBySite(Site $site)
271
    {
272 15
        $solrConfigurations = array();
273
274 15
        $allConfigurations = $this->getAllConfigurations();
275 15
        foreach ($allConfigurations as $configuration) {
276 15
            if ($configuration['rootPageUid'] == $site->getRootPageId()) {
277 15
                $solrConfigurations[] = $configuration;
278 15
            }
279 15
        }
280
281 15
        return $solrConfigurations;
282
    }
283
284
    /**
285
     * Gets all connections configured for a given site.
286
     *
287
     * @param Site $site A TYPO3 site
288
     * @return SolrService[] An array of Solr connection objects (ApacheSolrForTypo3\Solr\SolrService)
289
     */
290 5
    public function getConnectionsBySite(Site $site)
291
    {
292 5
        $connections = array();
293
294 5
        $solrServers = $this->getConfigurationsBySite($site);
295 5
        foreach ($solrServers as $solrServer) {
296 5
            $connections[] = $this->getConnection(
297 5
                $solrServer['solrHost'],
298 5
                $solrServer['solrPort'],
299 5
                $solrServer['solrPath'],
300 5
                $solrServer['solrScheme']
301 5
            );
302 5
        }
303
304 5
        return $connections;
305
    }
306
307
    // updates
308
309
    /**
310
     * Adds a menu entry to the clear cache menu to detect Solr connections.
311
     *
312
     * @param array $cacheActions Array of CacheMenuItems
313
     * @param array $optionValues Array of AccessConfigurations-identifiers (typically  used by userTS with options.clearCache.identifier)
314
     */
315
    public function manipulateCacheActions(&$cacheActions, &$optionValues)
316
    {
317
        if ($GLOBALS['BE_USER']->isAdmin()) {
318
            $title = 'Initialize Solr connections';
319
            $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
320
321
            $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
322
            $cacheActions[] = array(
323
                'id' => 'clearSolrConnectionCache',
324
                'title' => $title,
325
                'href' =>  $uriBuilder->buildUriFromRoute('ajax_solr_updateConnections'),
326
                'icon' => $iconFactory->getIcon('extensions-solr-module-initsolrconnections', Icon::SIZE_SMALL)
327
            );
328
            $optionValues[] = 'clearSolrConnectionCache';
329
        }
330
    }
331
332
    /**
333
     * Updates the connections in the registry.
334
     *
335
     */
336
    public function updateConnections()
337
    {
338
        $solrConnections = $this->getConfiguredSolrConnections();
339
        $solrConnections = $this->filterDuplicateConnections($solrConnections);
340
341
        if (!empty($solrConnections)) {
342
            $registry = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Registry');
343
            $registry->set('tx_solr', 'servers', $solrConnections);
344
        }
345
    }
346
347
    /**
348
     * Entrypoint for the ajax request
349
     *
350
     * @param ServerRequestInterface $request
351
     * @param ResponseInterface $response
352
     */
353
    public function updateConnectionsInCacheMenu(ServerRequestInterface $request, ResponseInterface $response)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
354
    {
355
        $this->updateConnections();
356
    }
357
358
    /**
359
     * Updates the Solr connections for a specific root page ID / site.
360
     *
361
     * @param int $rootPageId A site root page id
362
     */
363
    public function updateConnectionByRootPageId($rootPageId)
364
    {
365
        $systemLanguages = $this->getSystemLanguages();
366
        $rootPage = GeneralUtility::makeInstance('ApacheSolrForTypo3\\Solr\\Site',
367
            $rootPageId)->getRootPage();
368
369
        $updatedSolrConnections = array();
370
        foreach ($systemLanguages as $languageId) {
371
            $connection = $this->getConfiguredSolrConnectionByRootPage($rootPage,
372
                $languageId);
373
374
            if (!empty($connection)) {
375
                $updatedSolrConnections[$connection['connectionKey']] = $connection;
376
            }
377
        }
378
379
        $registry = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Registry');
380
        $solrConnections = $registry->get('tx_solr', 'servers', array());
381
382
        $solrConnections = array_merge($solrConnections,
383
            $updatedSolrConnections);
384
        $solrConnections = $this->filterDuplicateConnections($solrConnections);
385
386
        $registry->set('tx_solr', 'servers', $solrConnections);
387
    }
388
389
    /**
390
     * Finds the configured Solr connections. Also respects multi-site
391
     * environments.
392
     *
393
     * @return array An array with connections, each connection with keys rootPageTitle, rootPageUid, solrHost, solrPort, solrPath
394
     */
395
    protected function getConfiguredSolrConnections()
396
    {
397
        $configuredSolrConnections = array();
398
399
        // find website roots and languages for this installation
400
        $rootPages = $this->getRootPages();
401
        $languages = $this->getSystemLanguages();
402
403
        // find solr configurations and add them as function menu entries
404
        foreach ($rootPages as $rootPage) {
405
            foreach ($languages as $languageId) {
406
                $connection = $this->getConfiguredSolrConnectionByRootPage($rootPage,
407
                    $languageId);
408
409
                if (!empty($connection)) {
410
                    $configuredSolrConnections[$connection['connectionKey']] = $connection;
411
                }
412
            }
413
        }
414
415
        return $configuredSolrConnections;
416
    }
417
418
    /**
419
     * Gets the configured Solr connection for a specific root page and language ID.
420
     *
421
     * @param array $rootPage A root page record with at least title and uid
422
     * @param int $languageId ID of a system language
423
     * @return array A solr connection configuration.
424
     */
425
    protected function getConfiguredSolrConnectionByRootPage(
426
        array $rootPage,
427
        $languageId
428
    ) {
429
        $connection = array();
430
431
        $languageId = intval($languageId);
432
        GeneralUtility::_GETset($languageId, 'L');
433
        $connectionKey = $rootPage['uid'] . '|' . $languageId;
434
435
        $pageSelect = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
436
        $rootLine = $pageSelect->getRootLine($rootPage['uid']);
437
438
        $tmpl = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\ExtendedTemplateService');
439
        $tmpl->tt_track = false; // Do not log time-performance information
440
        $tmpl->init();
441
        $tmpl->runThroughTemplates($rootLine); // This generates the constants/config + hierarchy info for the template.
442
443
        // fake micro TSFE to get correct condition parsing
444
        $GLOBALS['TSFE'] = new \stdClass();
445
        $GLOBALS['TSFE']->tmpl = new \stdClass();
446
        $GLOBALS['TSFE']->tmpl->rootLine = $rootLine;
447
        $GLOBALS['TSFE']->sys_page = $pageSelect;
448
        $GLOBALS['TSFE']->id = $rootPage['uid'];
449
        $GLOBALS['TSFE']->page = $rootPage;
450
451
        $tmpl->generateConfig();
452
453
        list($solrSetup) = $tmpl->ext_getSetup($tmpl->setup,
454
            'plugin.tx_solr.solr');
455
        list(, $solrEnabled) = $tmpl->ext_getSetup($tmpl->setup,
456
            'plugin.tx_solr.enabled');
457
        $solrEnabled = !empty($solrEnabled) ? true : false;
458
459
        if (!empty($solrSetup) && $solrEnabled) {
460
            $solrPath = trim($solrSetup['path'], '/');
461
            $solrPath = '/' . $solrPath . '/';
462
463
            $connection = array(
464
                'connectionKey' => $connectionKey,
465
466
                'rootPageTitle' => $rootPage['title'],
467
                'rootPageUid' => $rootPage['uid'],
468
469
                'solrScheme' => $solrSetup['scheme'],
470
                'solrHost' => $solrSetup['host'],
471
                'solrPort' => $solrSetup['port'],
472
                'solrPath' => $solrPath,
473
474
                'language' => $languageId
475
            );
476
            $connection['label'] = $this->buildConnectionLabel($connection);
477
        }
478
479
        return $connection;
480
    }
481
482
    /**
483
     * Gets the language name for a given language ID.
484
     *
485
     * @param int $languageId language ID
486
     * @return string Language name
487
     */
488
    protected function getLanguageName($languageId)
489
    {
490
        $languageName = '';
491
492
        $language = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
493
            'uid, title',
494
            'sys_language',
495
            'uid = ' . (integer)$languageId
496
        );
497
498
        if (count($language)) {
499
            $languageName = $language[0]['title'];
500
        } elseif ($languageId == 0) {
501
            $languageName = 'default';
502
        }
503
504
        return $languageName;
505
    }
506
507
    /**
508
     * Creates a human readable label from the connections' configuration.
509
     *
510
     * @param array $connection Connection configuration
511
     * @return string Connection label
512
     */
513
    protected function buildConnectionLabel(array $connection)
514
    {
515
        $connectionLabel = $connection['rootPageTitle']
516
            . ' (pid: ' . $connection['rootPageUid']
517
            . ', language: ' . $this->getLanguageName($connection['language'])
518
            . ') - '
519
#			. $connection['solrScheme'] . '://'
520
            . $connection['solrHost'] . ':'
521
            . $connection['solrPort']
522
            . $connection['solrPath'];
523
524
        return $connectionLabel;
525
    }
526
527
    /**
528
     * Filters duplicate connections. When detecting the configured connections
529
     * this is done with a little brute force by simply combining all root pages
530
     * with all languages, this method filters out the duplicates.
531
     *
532
     * @param array $connections An array of unfiltered connections, containing duplicates
533
     * @return array An array with connections, no duplicates.
534
     */
535
    protected function filterDuplicateConnections(array $connections)
536
    {
537
        $hashedConnections = array();
538
        $filteredConnections = array();
539
540
        // array_unique() doesn't work on multi dimensional arrays, so we need to flatten it first
541
        foreach ($connections as $key => $connection) {
542
            unset($connection['language']);
543
            $connectionHash = md5(implode('|', $connection));
544
            $hashedConnections[$key] = $connectionHash;
545
        }
546
547
        $hashedConnections = array_unique($hashedConnections);
548
549
        foreach ($hashedConnections as $key => $hash) {
550
            $filteredConnections[$key] = $connections[$key];
551
        }
552
553
        return $filteredConnections;
554
    }
555
556
    /**
557
     * Finds the system's configured languages.
558
     *
559
     * @return array An array of language IDs
560
     */
561
    protected function getSystemLanguages()
562
    {
563
        $languages = array(0);
564
565
        $languageRecords = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
566
            'uid',
567
            'sys_language',
568
            'hidden = 0'
569
        );
570
571
        if (is_array($languageRecords)) {
572
            foreach ($languageRecords as $languageRecord) {
573
                $languages[] = $languageRecord['uid'];
574
            }
575
        }
576
577
        return $languages;
578
    }
579
580
    /**
581
     * Gets the site's root pages. The "Is root of website" flag must be set,
582
     * which usually is the case for pages with pid = 0.
583
     *
584
     * @return array An array of (partial) root page records, containing the uid and title fields
585
     */
586
    protected function getRootPages()
587
    {
588
        $rootPages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
589
            'uid, title',
590
            'pages',
591
            'is_siteroot = 1 AND deleted = 0 AND hidden = 0 AND pid != -1'
592
        );
593
594
        return $rootPages;
595
    }
596
597
    /**
598
     * Finds the page Id of the page marked as "Is site root" even if it's not
599
     * on the root level (pid = 0).
600
     *
601
     * @param array $rootLine A root line as generated by \TYPO3\CMS\Frontend\Page\PageRepository::getRootLine()
602
     * @return int The site root's page Id
603
     */
604 43
    protected function getSiteRootPageIdFromRootLine(array $rootLine)
605
    {
606 43
        $siteRootPageId = 0;
607
608 43
        foreach ($rootLine as $page) {
609 43
            if ($page['is_siteroot']) {
610 43
                $siteRootPageId = $page['uid'];
611 43
                break;
612
            }
613 43
        }
614
615 43
        return $siteRootPageId;
616
    }
617
}
618