src/Venturecraft/Revisionable/RevisionableTrait.php
/**
    * Invoked before a model is saved. Return false to abort the operation.
    *
    * @return bool
    */
Invoked before a model is saved. Return false to abort the operation.
@return bool
Invoked before a model is saved . Return false to abort the operation . @return bool
public function preSave()
    {
        if (!isset($this->revisionEnabled) || $this->revisionEnabled) {
            $this->originalData = $this->original;
            $this->updatedData = $this->attributes;
            foreach ($this->updatedData as $key => $val) {
                $castCheck = ['object', 'array'];
                if (isset($this->casts[$key]) && in_array(gettype($val), $castCheck) && in_array($this->casts[$key], $castCheck) && isset($this->originalData[$key])) {
                    $updatedData = $this->sortJsonKeys(json_decode($this->updatedData[$key], true));
                    $this->updatedData[$key] = json_encode($updatedData);
                    $this->originalData[$key] = json_encode(json_decode($this->originalData[$key], true));
                } else if (gettype($val) == 'object' && !method_exists($val, '__toString')) {
                    unset($this->originalData[$key]);
                    unset($this->updatedData[$key]);
                    array_push($this->dontKeep, $key);
                }
            }
            $this->dontKeep = isset($this->dontKeepRevisionOf) ?
                array_merge($this->dontKeepRevisionOf, $this->dontKeep)
                : $this->dontKeep;
            $this->doKeep = isset($this->keepRevisionOf) ?
                array_merge($this->keepRevisionOf, $this->doKeep)
                : $this->doKeep;
            unset($this->attributes['dontKeepRevisionOf']);
            unset($this->attributes['keepRevisionOf']);
            $this->dirtyData = $this->getDirty();
            $this->updating = $this->exists;
        }
    }
public function preSave ( ) { if ( ! isset ( $ this -> revisionEnabled ) || $ this -> revisionEnabled ) { $ this -> originalData = $ this -> original ; $ this -> updatedData = $ this -> attributes ; foreach ( $ this -> updatedData as $ key => $ val ) { $ castCheck = [ 'object' , 'array' ] ; if ( isset ( $ this -> casts [ $ key ] ) && in_array ( gettype ( $ val ) , $ castCheck ) && in_array ( $ this -> casts [ $ key ] , $ castCheck ) && isset ( $ this -> originalData [ $ key ] ) ) { $ updatedData = $ this -> sortJsonKeys ( json_decode ( $ this -> updatedData [ $ key ] , true ) ) ; $ this -> updatedData [ $ key ] = json_encode ( $ updatedData ) ; $ this -> originalData [ $ key ] = json_encode ( json_decode ( $ this -> originalData [ $ key ] , true ) ) ; } else if ( gettype ( $ val ) == 'object' && ! method_exists ( $ val , '__toString' ) ) { unset ( $ this -> originalData [ $ key ] ) ; unset ( $ this -> updatedData [ $ key ] ) ; array_push ( $ this -> dontKeep , $ key ) ; } } $ this -> dontKeep = isset ( $ this -> dontKeepRevisionOf ) ? array_merge ( $ this -> dontKeepRevisionOf , $ this -> dontKeep ) : $ this -> dontKeep ; $ this -> doKeep = isset ( $ this -> keepRevisionOf ) ? array_merge ( $ this -> keepRevisionOf , $ this -> doKeep ) : $ this -> doKeep ; unset ( $ this -> attributes [ 'dontKeepRevisionOf' ] ) ; unset ( $ this -> attributes [ 'keepRevisionOf' ] ) ; $ this -> dirtyData = $ this -> getDirty ( ) ; $ this -> updating = $ this -> exists ; } }
Invoked before a model is saved.
Invoked before a model is saved .
// if there's no revisionEnabled. Or if there is, if it's true // we can only safely compare basic items, // so for now we drop any object based items, like DateTime // Sorts the keys of a JSON object due Normalization performed by MySQL // So it doesn't set false flag if it is changed only order of key or whitespace after comma // the below is ugly, for sure, but it's required so we can save the standard model // then use the keep / dontkeep values for later, in the isRevisionable method