protected function _cleanupOldFiles(Model $model, array $fields) {
        $columns = $this->_columns[$model->alias];
        $data = $this->_doFind($model, array($model->alias . '.' . $model->primaryKey => $model->id));

        if (empty($data[$model->alias])) {
            return;
        }

        foreach ($fields as $column => $value) {
            if (empty($data[$model->alias][$column])) {
                continue;
            }

            if (!empty($this->settings[$model->alias][$columns[$column]])) {
                $attachment = $this->_settingsCallback($model, $this->settings[$model->alias][$columns[$column]]);

                if (!$attachment['cleanup']) {
                    continue;
                }
            }

            // Delete if previous value doesn't match new value
            $previous = $data[$model->alias][$column];

            if ($previous !== $value) {
                $this->_deleteFile($model, $columns[$column], $previous, $column);
            }
        }
    }
protected function _cleanupOldFiles(Model $model, array $fields) {
        $columns = $this->_columns[$model->alias];
        $data = $this->_doFind($model, array($model->alias . '.' . $model->primaryKey => $model->id));

        if (empty($data[$model->alias])) {
            return;
        }

        foreach ($fields as $column => $value) {
            if (empty($data[$model->alias][$column])) {
                continue;
            }

            if (!empty($this->settings[$model->alias][$columns[$column]])) {
                $attachment = $this->_settingsCallback($model, $this->settings[$model->alias][$columns[$column]]);

                if (!$attachment['cleanup']) {
                    continue;
                }
            }

            // Delete if previous value doesn't match new value
            $previous = $data[$model->alias][$column];

            if ($previous !== $value) {
                $this->_deleteFile($model, $columns[$column], $previous, $column);
            }
        }
    }
protected function _cleanupOldFiles ( Model $ model , array $ fields ) { $ columns = $ this -> _columns [ $ model -> alias ] ; $ data = $ this -> _doFind ( $ model , array ( $ model -> alias . '.' . $ model -> primaryKey => $ model -> id ) ) ; if ( empty ( $ data [ $ model -> alias ] ) ) { return ; } foreach ( $ fields as $ column => $ value ) { if ( empty ( $ data [ $ model -> alias ] [ $ column ] ) ) { continue ; } if ( ! empty ( $ this -> settings [ $ model -> alias ] [ $ columns [ $ column ] ] ) ) { $ attachment = $ this -> _settingsCallback ( $ model , $ this -> settings [ $ model -> alias ] [ $ columns [ $ column ] ] ) ; if ( ! $ attachment [ 'cleanup' ] ) { continue ; } } // Delete if previous value doesn't match new value $ previous = $ data [ $ model -> alias ] [ $ column ] ; if ( $ previous !== $ value ) { $ this -> _deleteFile ( $ model , $ columns [ $ column ] , $ previous , $ column ) ; } } }
Delete previous files if a record is being overwritten.

@param Model $model
@param array $fields
@return void
Delete previous files if a record is being overwritten .