public function deleteForm(AmForms_FormModel $form)
{
$transaction = craft()->db->getCurrentTransaction() === null ? craft()->db->beginTransaction() : null;
try {
// Delete export files
craft()->amForms_exports->deleteExportFilesForForm($form);
// Delete the field layout
craft()->fields->deleteLayoutById($form->fieldLayoutId);
// Delete submission elements
$submissionIds = craft()->db->createCommand()->select('id')->from('amforms_submissions')->where(array('formId' => $form->id))->queryColumn();
craft()->elements->deleteElementById($submissionIds);
// Delete the element and form
craft()->elements->deleteElementById($form->id);
if ($transaction !== null) {
$transaction->commit();
}
return true;
} catch (\Exception $e) {
if ($transaction !== null) {
$transaction->rollback();
}
throw $e;
}
return false;
}