Skip to content

Commit

Permalink
Fix invalid use of model. Fixes #29.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrbasso committed Feb 27, 2010
1 parent 5911316 commit 22811c5
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions models/behaviors/meio_upload.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ function _uploadFile(&$model, $data = null) {
// Take care of removal flagged field // Take care of removal flagged field
// However, this seems to be kind of code duplicating, see line ~711 // However, this seems to be kind of code duplicating, see line ~711
if (!empty($data[$model->alias][$fieldName]['remove'])) { if (!empty($data[$model->alias][$fieldName]['remove'])) {
$this->_markForDeletion($model->alias, $model->primaryKey, $fieldName, $data, $options['default']); $this->_markForDeletion($model, $fieldName, $data, $options['default']);
$data = $this->_unsetDataFields($model->alias, $fieldName, $data, $options); $data = $this->_unsetDataFields($model->alias, $fieldName, $data, $options);
$result = array('return' => true, 'data' => $data); $result = array('return' => true, 'data' => $data);
continue; continue;
Expand Down Expand Up @@ -1106,23 +1106,22 @@ function _setFileToRemove(&$model, $fieldName) {
/** /**
* Marks files for deletion in the beforeSave() callback * Marks files for deletion in the beforeSave() callback
* *
* @param $modelName string name of the Model * @param $model Reference to model
* @param $modelPrimaryKey string field of the Model that is the primary key
* @param $fieldName string name of field that holds a reference to the file * @param $fieldName string name of field that holds a reference to the file
* @param $data array * @param $data array
* @param $default * @param $default
* @return void * @return void
* @author Jose Diaz-Gonzalez * @author Jose Diaz-Gonzalez
**/ **/
function _markForDeletion($modelName, $modelPrimaryKey, $fieldName, $data, $default) { function _markForDeletion(&$model, $fieldName, $data, $default) {
if (!empty($data[$modelName][$fieldName]['remove'])) { if (!empty($data[$model->alias][$fieldName]['remove'])) {
if ($default) { if ($default) {
$data[$modelName][$fieldName] = $default; $data[$model->alias][$fieldName] = $default;
} else { } else {
$data[$modelName][$fieldName] = ''; $data[$model->alias][$fieldName] = '';
} }
//if the record is already saved in the database, set the existing file to be removed after the save is sucessfull //if the record is already saved in the database, set the existing file to be removed after the save is sucessfull
if (!empty($data[$modelName][$modelPrimaryKey])) { if (!empty($data[$model->alias][$model->primaryKey])) {
$this->_setFileToRemove($model, $fieldName); $this->_setFileToRemove($model, $fieldName);
} }
} }
Expand Down

0 comments on commit 22811c5

Please sign in to comment.