Skip to content

Commit f218894

Browse files
authored
FIX mixeval edit (#660)
When user tried to edit and save a mixed eval, the creator_id was incorrectly updated to 0 causing the user can't access the eval. The controller calls saveAll with 'validate' equals to 'only' to simulate a save to perform validation. Within the cake library, it will reset the model's default values, including the creator_id. To avoid the creator_id reset to zero when edited, set the 'created' date field. Previously the 'created' field was set to current datetime whenever the record is saved. This logic was removed recently as it incorrectly update the field when the record is being edited. This fix tries to set the 'created' field to the existing value when the record is being edited.
1 parent 82995da commit f218894

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

app/controllers/mixevals_controller.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,13 @@ function edit($id)
642642
// Save changes if there are any
643643
if (!empty($this->data)) {
644644
$this->_dataSavePrep();
645+
// This is kind of a hack. Inside _transactionSave, it will call saveAll with 'validate' option
646+
// equals to 'only' to perform validation. In turn, the cake library Model's __save function
647+
// will call create() to reset the model with default values, including the 'creator_id'.
648+
// Setting the created date here will let TraceableBehavior to update the creator_id properly and
649+
// avoid saving the creator_id as 0.
650+
$eval = $this->Mixeval->findById($id);
651+
$this->data['Mixeval']['created'] = $eval['Mixeval']['created'];
645652
$this->_transactionalSave();
646653
} else {
647654

0 commit comments

Comments
 (0)