Skip to content
Snippets Groups Projects
Commit 3ca00167 authored by Jared Hancock's avatar Jared Hancock
Browse files

forms: Cleanup file attachments when custom data is deleted

parent a4a31194
No related branches found
No related tags found
No related merge requests found
...@@ -1130,6 +1130,15 @@ class DynamicFormEntryAnswer extends VerySimpleModel { ...@@ -1130,6 +1130,15 @@ class DynamicFormEntryAnswer extends VerySimpleModel {
$v = $this->toString(); $v = $this->toString();
return is_string($v) ? $v : (string) $this->getValue(); return is_string($v) ? $v : (string) $this->getValue();
} }
function delete() {
if (!parent::delete())
return false;
// Allow the field to cleanup anything else in the database
$this->getField()->db_cleanup();
return true;
}
} }
class SelectionField extends FormField { class SelectionField extends FormField {
......
...@@ -397,6 +397,15 @@ class FormField { ...@@ -397,6 +397,15 @@ class FormField {
return $this->toString($this->value); return $this->toString($this->value);
} }
/**
* When data for this field is deleted permanently from some storage
* backend (like a database), other associated data may need to be
* cleaned as well. This hook allows fields to participate when the data
* for a field is cleaned up.
*/
function db_cleanup() {
}
/** /**
* Returns an HTML friendly value for the data in the field. * Returns an HTML friendly value for the data in the field.
*/ */
...@@ -1678,6 +1687,14 @@ class FileUploadField extends FormField { ...@@ -1678,6 +1687,14 @@ class FileUploadField extends FormField {
} }
return implode(', ', $files); return implode(', ', $files);
} }
function db_cleanup() {
// Delete associated attachments from the database, if any
$this->getFiles();
if (isset($this->attachments)) {
$this->attachments->deleteAll();
}
}
} }
class Widget { class Widget {
......
...@@ -336,6 +336,15 @@ class Organization extends OrganizationModel { ...@@ -336,6 +336,15 @@ class Organization extends OrganizationModel {
return $this->save(); return $this->save();
} }
function delete() {
if (!parent::delete())
return false;
foreach ($this->getDynamicData(false) as $entry) {
$entry->delete();
}
}
static function fromVars($vars) { static function fromVars($vars) {
if (!($org = Organization::lookup(array('name' => $vars['name'])))) { if (!($org = Organization::lookup(array('name' => $vars['name'])))) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment