This repository has been archived by the owner on May 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
int. ticket #30916
- Loading branch information
Showing
6 changed files
with
128 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace IMI\Contao\Command\Indexer\Search; | ||
|
||
use IMI\Contao\Application; | ||
use IMI\Contao\Command\AbstractContaoCommand; | ||
use IMI\Contao\System\IndexerSearchBackend; | ||
use IMI\Contao\System\PurgeData; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
class BuildCommand extends AbstractContaoCommand | ||
{ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('indexer:search:build') | ||
->setDescription('Build search index'); | ||
} | ||
|
||
|
||
|
||
|
||
/** | ||
* @param \Symfony\Component\Console\Input\InputInterface $input | ||
* @param \Symfony\Component\Console\Output\OutputInterface $output | ||
* @return int|void | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->detectContao($output, true); | ||
if (!$this->initContao()) { | ||
return; | ||
} | ||
|
||
$backend = new IndexerSearchBackend(); | ||
$searchablePages = $backend->getSearchablePages(); | ||
|
||
if (!$GLOBALS['TL_CONFIG']['enableSearch']) { | ||
$output->writeln('Search has to be enabled'); | ||
die(); | ||
} | ||
|
||
$arrContextOptions=array( | ||
"ssl"=>array( | ||
"verify_peer"=>false, | ||
"verify_peer_name"=>false, | ||
), | ||
); | ||
|
||
foreach ($searchablePages as $url) { | ||
@file_get_contents($url, false, stream_context_create($arrContextOptions)); | ||
$code = $http_response_header[0]; | ||
if (strpos($code, ' 200 ') !== false) { | ||
$output->writeln("<info>$code</info> $url"); | ||
} else { | ||
$output->writeln("<error>$code</error> $url"); | ||
} | ||
} | ||
$output->writeln('<info>DCAs generated. You might want to clean / rebuild the DCA cache.</info>'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,5 @@ public function listRunOnce() | |
} | ||
|
||
return $result; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
namespace IMI\Contao\System; | ||
|
||
|
||
/** | ||
* @category IMI | ||
* @package _ | ||
*/ | ||
class IndexerSearchBackend extends Backend { | ||
/** | ||
* Mostly copied from \Contao\Automator::generateSitemap | ||
* @param int $intId | ||
*/ | ||
public function getSearchablePages() | ||
{ | ||
$time = \Date::floorToMinute(); | ||
$objDatabase = \Database::getInstance(); | ||
|
||
// Get all published root pages | ||
$objRoot = $objDatabase->execute("SELECT id, language, sitemapName FROM tl_page WHERE type='root' AND createSitemap='1' AND sitemapName!='' AND (start='' OR start<='$time') AND (stop='' OR stop>'" . ($time + 60) . "') AND published='1'"); | ||
|
||
// Return if there are no pages | ||
if ($objRoot->numRows < 1) | ||
{ | ||
return; | ||
} | ||
|
||
$result = array(); | ||
|
||
// Create the XML file | ||
while ($objRoot->next()) | ||
{ | ||
$objFile = new \File('share/' . $objRoot->sitemapName . '.xml', true); | ||
|
||
// Find the searchable pages | ||
$arrPages = \Backend::findSearchablePages($objRoot->id, '', true); | ||
|
||
// HOOK: take additional pages | ||
if (isset($GLOBALS['TL_HOOKS']['getSearchablePages']) && is_array($GLOBALS['TL_HOOKS']['getSearchablePages'])) | ||
{ | ||
foreach ($GLOBALS['TL_HOOKS']['getSearchablePages'] as $callback) | ||
{ | ||
$this->import($callback[0]); | ||
$arrPages = $this->{$callback[0]}->{$callback[1]}($arrPages, $objRoot->id, true, $objRoot->language); | ||
} | ||
} | ||
|
||
// Add pages | ||
foreach ($arrPages as $strUrl) | ||
{ | ||
$result[] = $strUrl; | ||
} | ||
} | ||
|
||
return $result; | ||
} | ||
} |