bcosca / fatfree

A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!
2.66k stars 446 forks source link

Setting field then issuing ->save() on a dry DB/SQL mapper changed value in the whole table #1198

Closed MDBenson closed 3 years ago

MDBenson commented 4 years ago

This manifested in v3.6.5, not the current version

Somehow this happened:

  1. instantiante $db as instance of DB/SQL
  2. issue $db->load(["pkey = ?", $record_id])
  3. record with $record_id is not found and $db remains dry().
  4. forget to check if(!$db->dry()) (yeah I know, I know).
  5. set $db->field = $value;
  6. issue $db->save();

This changed the entire table so that field was the value given forr every record.

Isolated testing suggests a dry() Mapper should just create a new record for the object instead (correct behavior).

We aren't sure how this happened and are trying to prevent further catastrophe. Can anyone shed any light?

ikkez commented 4 years ago

This was fixed a while ago: https://github.com/bcosca/fatfree-core/pull/285