Skip to content

Commit

Permalink
added a debug message and a template global provider to display conte…
Browse files Browse the repository at this point in the history
…nts according to the urls
  • Loading branch information
fonsekaean committed Nov 14, 2018
1 parent 8076d76 commit 1313664
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
17 changes: 15 additions & 2 deletions src/Extensions/SearchDocumentGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@
use SilverStripe\ORM\DataExtension;
use SilverStripe\ORM\DataObject;
use SilverStripe\Versioned\Versioned;
use SilverStripe\View\TemplateGlobalProvider;
use SilverStripers\ElementalSearch\Model\SearchDocument;

class SearchDocumentGenerator extends DataExtension
class SearchDocumentGenerator extends DataExtension implements TemplateGlobalProvider
{

public function getGenerateSearchLink()
{
$owner = $this->owner;
if(method_exists($owner, 'Link')) {
return $owner->Link();
return $owner->Link() . '&SearchGen=1';
}
$class = get_class($owner);
throw new Exception(
Expand Down Expand Up @@ -112,5 +113,17 @@ public static function find_document(DataObject $object)
return $doc;
}

public static function is_search()
{
return isset($_REQUEST['SearchGen']) ? true : false;
}

public static function get_template_global_variables()
{
return [
'IsSearch' => 'is_search'
];
}


}
4 changes: 3 additions & 1 deletion src/Model/SearchDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ public function makeSearchContent()
}

$this->Title = $origin->getTitle();
$this->Content = $contents;
if($contents) {
$this->Content = $contents;
}
$this->write();
SSViewer::set_themes($themes);
Versioned::set_reading_mode($mode);
Expand Down
11 changes: 9 additions & 2 deletions src/Tasks/GenerateSearchDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,15 @@ public function run($request)
$classes = $this->getAllSearchDocClasses();
foreach ($classes as $class) {
foreach ($list = DataList::create($class) as $record) {
echo 'Making record for ' . $record->getTitle() . '<br>';
SearchDocumentGenerator::make_document_for($record);
echo sprintf(
'Making record for %s type %s, link %s',
$record->getTitle(),
$record->ClassName,
$record->getGenerateSearchLink()) . '<br>';
try {
SearchDocumentGenerator::make_document_for($record);
} catch (Exception $e) {
}
}
}
echo 'Completed';
Expand Down

0 comments on commit 1313664

Please sign in to comment.