diff --git a/src/Extensions/SearchDocumentGenerator.php b/src/Extensions/SearchDocumentGenerator.php index 1c8cf26..b652aec 100644 --- a/src/Extensions/SearchDocumentGenerator.php +++ b/src/Extensions/SearchDocumentGenerator.php @@ -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( @@ -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' + ]; + } + } diff --git a/src/Model/SearchDocument.php b/src/Model/SearchDocument.php index ec20104..a9a480b 100644 --- a/src/Model/SearchDocument.php +++ b/src/Model/SearchDocument.php @@ -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); diff --git a/src/Tasks/GenerateSearchDocument.php b/src/Tasks/GenerateSearchDocument.php index e61aaf5..f77b15d 100644 --- a/src/Tasks/GenerateSearchDocument.php +++ b/src/Tasks/GenerateSearchDocument.php @@ -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() . '
'; - SearchDocumentGenerator::make_document_for($record); + echo sprintf( + 'Making record for %s type %s, link %s', + $record->getTitle(), + $record->ClassName, + $record->getGenerateSearchLink()) . '
'; + try { + SearchDocumentGenerator::make_document_for($record); + } catch (Exception $e) { + } } } echo 'Completed';