Fixed entity::delete inconsistent with entity::save

pegasus

Well-known member
Affected version
2.2.15
In entity::save, it is possible to extend _saveToSource in order to do some last minute tasks before saving an entity, compared to _postSave etc, which takes place afterwards.

However, there is no corresponding reverse method in entity::delete. $db->update is called directly, where one would expect a _deleteFromSource method. Such a method would allow us to perform last minute tasks before the entity is removed from the database, which is important in case some tasks require that the entity still exists there. Currently, the only options are:
  • performing such tasks during _preDelete (which is both non-semantic and outside the transaction)
  • by extending _getUpdateCondition (which is potentially dangerous given its wider usage)
  • by writing a ::customDelete function and using it in place of the "final" ::delete (which creates potential conflicts if another add-on expects to use ::delete)

Please add _deleteFromSource as follows:
Code:
protected function _deleteFromSource()
{
	return $db->delete($this->_structure->table, $this->_getUpdateCondition());
}
Replacing the line:
Code:
$rowAffected = $db->delete($this->_structure->table, $this->_getUpdateCondition());
With:
Code:
$rowAffected = $this->_deleteFromSource();
 
Thank you for reporting this issue, it has now been resolved. We are aiming to include any changes that have been made in a future XF release (2.2.16).

Change log:
Add _deleteFromSource method to support performing tasks right before entity deletion
There may be a delay before changes are rolled out to the XenForo Community.
 
Back
Top Bottom