Skip to content

Commit

Permalink
prevent creating search docs for unpublished pages
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsekaean committed Dec 5, 2019
1 parent 9b8fb43 commit b91d2c1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
14 changes: 11 additions & 3 deletions src/Extensions/SearchDocumentGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,18 @@ public static function case_create_document(DataObject $object)
{
$schema = DataObject::getSchema();
$fields = $schema->databaseFields($object->ClassName);
if(array_key_exists('ShowInSearch', $fields)) {
return $object->getField('ShowInSearch');
$ret = true;
if (self::is_versioned($object)) {
if (!$object->isPublished()) {
$ret = false;
}
}
if ($ret) {
if (array_key_exists('ShowInSearch', $fields)) {
$ret = $object->getField('ShowInSearch');
}
}
return true;
return $ret;
}

public static function is_versioned(DataObject $object)
Expand Down
2 changes: 1 addition & 1 deletion src/ORM/Connect/MySQLDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function searchEngine(

foreach ($records as $record) {
$object = DataList::create($record['ClassName'])->byID($record['ID']);
if ($object->canView()) {
if ($object && $object->canView()) {
$objects[] = $object;
}
}
Expand Down

0 comments on commit b91d2c1

Please sign in to comment.