Skip to content

Commit 2a9ceff

Browse files
committed
Save partial search keyword indexes for drafts
1 parent 42ea5b9 commit 2a9ceff

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
- Improved the styling of entry drafts within entry indexes. ([#7517](https://github.com/craftcms/cms/issues/7517))
1818
- Field groups are now soft-deleted.
1919
- Color fields’ text inputs are now updated based on the color input’s `input` event rather than `change`. ([#7529](https://github.com/craftcms/cms/issues/7529))
20+
- Entry drafts’ search keywords now get partially indexed.
21+
- The `resave/entries` command now supports a `--drafts` flag.
2022

2123
### Fixed
2224
- Fixed a bug where saving an entry to a site other than default would return `null` when using the GraphiQL API mutations. ([#7468](https://github.com/craftcms/cms/issues/7468))

src/console/controllers/ResaveController.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
*/
3232
class ResaveController extends Controller
3333
{
34+
/**
35+
* @var bool Whether to resave element drafts.
36+
* @since 3.6.5
37+
*/
38+
public $drafts = false;
39+
3440
/**
3541
* @var int|string The ID(s) of the elements to resave.
3642
*/
@@ -124,6 +130,7 @@ public function options($actionID)
124130
case 'entries':
125131
$options[] = 'section';
126132
$options[] = 'type';
133+
$options[] = 'drafts';
127134
break;
128135
case 'matrix-blocks':
129136
$options[] = 'field';
@@ -238,6 +245,10 @@ public function saveElements(ElementQueryInterface $query): int
238245
/** @var ElementInterface $elementType */
239246
$elementType = $query->elementType;
240247

248+
if ($this->drafts) {
249+
$query->drafts();
250+
}
251+
241252
if ($this->elementId) {
242253
$query->id(is_int($this->elementId) ? $this->elementId : explode(',', $this->elementId));
243254
}

src/queue/jobs/UpdateSearchIndex.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ public function execute($queue)
4747
{
4848
$class = $this->elementType;
4949
$elements = $class::find()
50+
->drafts(null)
5051
->id($this->elementId)
5152
->siteId($this->siteId)
5253
->anyStatus()

src/services/Elements.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2529,15 +2529,15 @@ private function _saveElementInternal(ElementInterface $element, bool $runValida
25292529
}
25302530

25312531
// Update search index
2532-
if ($updateSearchIndex && !$isDraftOrRevision) {
2532+
if ($updateSearchIndex && !$element->getIsRevision()) {
25332533
if (Craft::$app->getRequest()->getIsConsoleRequest()) {
25342534
Craft::$app->getSearch()->indexElementAttributes($element);
25352535
} else {
25362536
Queue::push(new UpdateSearchIndex([
25372537
'elementType' => get_class($element),
25382538
'elementId' => $element->id,
25392539
'siteId' => $propagate ? '*' : $element->siteId,
2540-
'fieldHandles' => $element->getDirtyFields(),
2540+
'fieldHandles' => $element->getIsDraft() ? [] : $element->getDirtyFields(),
25412541
]), 2048);
25422542
}
25432543
}

0 commit comments

Comments
 (0)