Deindex entries if user is suspended or deleted #277
-
Is there a way to or support deindexing of entries if a user is suspended or when a user is deleted (and entries are not passed to another user)? My scenario is that a user is suspended because the violated the community rules, if a user is suspended their content is also not visible, it would also be good to deindex their entries so they are not discoverable. The same goes for deindexing if a user is deleted. Is there a way to support this in Scout or would it have to be a custom setup in a custom module? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
@janhenckens Any thoughts on this or the possibility to use a method from the plugin via a custom module to update/remove/add an item to an index upon certain events where an element isn't necessarily being saved |
Beta Was this translation helpful? Give feedback.
-
To deindex an item you can call the Code-wise that could look like this: Event::on(
Users::class,
Users::EVENT_AFTER_SUSPEND_USER,
function (UserEvent $event) {
$userContent = Entry::findAll(['relatedTo' => $event->user]);
foreach($userContent as $entry){
$entry->unsearchable();
}
}
); |
Beta Was this translation helpful? Give feedback.
craft\services\Users
has events that run on suspend and unsuspend, both before and after so those should be what you need for this.To deindex an item you can call the
unsearchable()
behaviour on it, and to reindex them again if the account is restored can usesearchable()
.Code-wise that could look like this: