Welcome Guest, Not a member yet? Register   Sign In
Request for Soft Delete to not touch or change the updatedField
#1

(This post was last modified: 05-29-2023, 07:03 PM by jinbatsu.)

Currently I'm seeing that while deleting with soft delete, it also change the updatedField date.
So the actual updatedField date is replaced by Soft Delete.

/system/Model.php
line: 449-551
PHP Code:
            if ($this->useTimestamps && $this->updatedField) {
                $set[$this->updatedField] = $this->setDate();
            

And also, for insert data, it should be only fill createdField only, the updatedField should be NULL.
/system/BaseModel.php
line: 772-774
PHP Code:
        if ($this->useTimestamps && $this->updatedField && ! array_key_exists($this->updatedField$data)) {
            $data[$this->updatedField] = $date;
        

Meanwhile, I commented those line, so that updatedField is in actual date.
I hope this can be implement in the next version.
Thanks
Reply
#2

(This post was last modified: 05-30-2023, 11:26 AM by jinbatsu.)

I finally use custome base model which can solve this case.

PHP Code:
protected function cbBeforeInsert(array $data) {
        unset(
$data['data'][$this->updatedField]); // to remove change date while insert
        
$data['data']['created_by'] = user_id();
        return 
$data;
    }
    protected function 
cbBeforeUpdate(array $data) {
        
$data['data']['updated_by'] = user_id();
        return 
$data;
    }

    protected function 
cbBeforeDelete(array $data) {
        
$purge  $data['purge'];
        
//$id   = $data['id'];
        
if(! $purge) {
            
$this->useTimestamps false;
        }
        return 
$data;
    }

    protected function 
cbAfterDelete(array $data) {
        
$purge  $data['purge'];
        
$id     $data['id'];
        
$result $data['result'];
        if(! 
$purge && $result) {
            
$dataUpdate = [
                
'deleted_by' => user_id(),
            ];
            
$builder $this->db->table($this->table);
            
$update $builder->update($dataUpdate, ['id' => $id]);
            
$data['result'] = $update true false;
        }
        
$this->useTimestamps true;
        return 
$data;
    } 

So, I'm not depend on /system/ files, to stay update  Wink
Reply




Theme © iAndrew 2016 - Forum software by © MyBB