Bug Points are not deducted after deleting a rating in XFRM

dritream

Customer
Hello. The question is explained in the topic.

When a review is deleted, the points remain. They are only removed if the review is permanently deleted by a moderator — meaning the event itself is completely removed, and logically the points are deducted because the event no longer exists.

However, if a user deletes their own review, the points are not deducted.

I tried to handle this using Event negation amount, but apparently this setting is not related to this behavior.
 
I think I’ve found why Credits does not deduct points when a user deletes their own XFRM review (soft delete), while it does deduct when a moderator permanently deletes it.

What’s happening

In XFRM, deleting a review as a user is a soft delete, implemented as an update:
• XFRM\Entity\ResourceRating::softDelete() sets rating_state = 'deleted' and calls save()
So this is a state change on update (visible → deleted), not a hard delete.

Your Credits integration for XFRM ratings is in:
DBTech/Credits/XFRM/Entity/ResourceRating.php

Currently it:
• applies points only on insert (_preSave/_postSave return early when $this->isUpdate())
• undoes points only on hard delete (_preDelete/_postDelete)

Because of the early return on update, Credits never sees the rating_state transition caused by soft delete, so points remain.

What I changed (and it works)

I modified DBTech/Credits/XFRM/Entity/ResourceRating.php to handle update state transitions similarly to how you handle posts in DBTech/Credits/XF/Entity/Post.php (using isStateChanged(..., 'visible')).

Specifically:
1. In both _preSave() and _postSave(), I removed the || $this->isUpdate() from the early return:

PHP:
if (!$this->user_id || $this->isUpdate()) { return; }



PHP:
if (!$this->user_id) { return; }

2. I added an update branch that detects:

PHP:
$visibilityChange = $this->isStateChanged('rating_state', 'visible');

and then:
• if $visibilityChange == 'leave' (visible → deleted): call testUndo/undo for resourcerate and resourcerated
• if $visibilityChange == 'enter' (deleted → visible): call testApply/apply for the same handlers

Insert logic remains unchanged.

After this patch:
• creating a review grants points as before
• soft deleting a review by the author deducts points correctly
• undeleting restores the points
 
Hi,

Thank you for the detailed report, much appreciated! I've applied the changes as a hotfix to v6.1.3 as I'm currently working on a refactor aimed at improving UX surrounding event configuration, so it would take some time to release a new version with this fix included.
 
Hello @dritream,

We hope your ticket regarding DragonByte Credits has been addressed to your satisfaction. This ticket has now been scheduled to be closed.

If your ticket has not been resolved, you can reply to this thread at any point in the next 7 days in order to reopen the ticket, afterwards this thread will be closed.

Please do not reply to this thread if your ticket has been resolved.

Thank you.


- DragonByte Technologies, Ltd.
 

DragonByte Credits

XenForo 1.5.3+ XenForo 2.0.x XenForo 2.1.x XenForo 2.2.x XenForo 2.3.x
Seller
DragonByte Technologies
Release date
Last update
Total downloads
5,328
Customer rating
4.67 star(s) 6 ratings
Back
Top