josegonzalez/upload — Issue #43: Notice & Warning when deleting record with no uploads
Author: ceallred
Created: 2012-01-23 00:16:24+00:00
State: open

Notice (8): Undefined index: User [APP/Plugin/Upload/Model/Behavior/UploadBehavior.php, line 329]
Warning (2): Invalid argument supplied for foreach() [APP/Plugin/Upload/Model/Behavior/UploadBehavior.php, line 329]

I get these errors when deleting a record without any uploads stored on the server which for me is a common occurrence.

Haven't had time to work through the code, but rigged it by basically checking for an empty array before calling unlink like below:

public function afterDelete(&$model) {
$result = array();
if(!empty($this->__filesToRemove[$model->alias])){ // Added to fix warnings on delete w/o upload
foreach ($this->__filesToRemove[$model->alias] as $file) {
$result[] = $this->unlink($file);
}
} // added this too
return $result;
}

Do you see any issues with this method? Am I missing something that causes the error in the first place?