DragonByte Tech
Well-known member
- Affected version
- 2.3.4
Problem: If you call
Proof of concept:
Suggested fix:
$entity->preSave()
, \XF\Mvc\Entity\Entity::$_writePending
is set to true
. If you subsequently call $entity->saveIfChanged()
, and no changes are detected, you cannot write to the entity later, unless you manually call $entity->reset()
.Proof of concept:
PHP:
$user = \XF::em()->find(\XF\Entity\User::class, 1);
$user->username = 'Admin'; // Set this to whatever the user name of userId 1 is
if (!$user->preSave())
{
throw new \XF\PrintableException("error");
}
$user->saveIfChanged();
$user->email = 'xfbug@example.com'; // This will fail with LogicException: Attempted to set 'email' while a save was pending without forceSet
Suggested fix:
Diff:
Index: src/XF/Mvc/Entity/Entity.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/XF/Mvc/Entity/Entity.php b/src/XF/Mvc/Entity/Entity.php
--- a/src/XF/Mvc/Entity/Entity.php
+++ b/src/XF/Mvc/Entity/Entity.php
@@ -1362,6 +1362,8 @@
{
if (!$this->_newValues && $this->isUpdate())
{
+ $this->_writePending = false;
+
$saved = false;
return true;
}