Commit 2d32214d authored by jaapjansma's avatar jaapjansma
Browse files

Possible to delete imported form processors (unless those are in an extension).

parent bb68dafe
Version 1.14 (under development)
============
* Possible to delete imported form processors (unless those are in an extension).
Version 1.13.2
============
......
......@@ -147,7 +147,12 @@
$formProcessorInstance = new CRM_FormProcessor_BAO_FormProcessorInstance();
$formProcessorInstance->id = $id;
$formProcessorInstance->delete();
if ($formProcessorInstance->find(TRUE)) {
if (!empty($formProcessorInstance->source_file)) {
\Civi\FormProcessor\Exporter\ExportToJson::deleteUploadedFile($formProcessorInstance->source_file);
}
$formProcessorInstance->delete();
}
CRM_Utils_Hook::post('delete', 'FormProcessorInstance', $id, CRM_Core_DAO::$_nullArray);
......
......@@ -34,7 +34,8 @@ class CRM_FormProcessor_Form_Import extends CRM_Core_Form {
CRM_Core_Session::setStatus(E::ts('Imported file should be a json file'), '', 'error');
} else {
$config = CRM_Core_Config::singleton();
$filename = $values['uploadFile']['name'];
$uniqID = md5(uniqid(rand(), TRUE));
$filename = $values['uploadFile']['name'].'.'.$uniqID;
$directoryName = $config->customFileUploadDir . 'FormProcessor';
CRM_Utils_File::createDir($directoryName);
CRM_Utils_File::restrictAccess($directoryName.DIRECTORY_SEPARATOR, TRUE);
......
......@@ -70,6 +70,39 @@ class ExportToJson {
return $form_processor;
}
/**
* Returns true when the filename is uploaded to the system.
* This will allow us to delete the file.
*
* @param $filename
* @return bool
*/
public static function isUploadedFile($filename) {
$fullFilePath = $filename;
if (!file_exists($fullFilePath)) {
$config = \CRM_Core_Config::singleton();
$fullFilePath = $config->customFileUploadDir . 'FormProcessor' . DIRECTORY_SEPARATOR . $filename;
return true;
}
return false;
}
/**
* Delete an uploaded file from the file system.
*
* @param $filename
*/
public static function deleteUploadedFile($filename) {
$fullFilePath = $filename;
if (!file_exists($fullFilePath)) {
$config = \CRM_Core_Config::singleton();
$fullFilePath = $config->customFileUploadDir . 'FormProcessor' . DIRECTORY_SEPARATOR . $filename;
if (file_exists($fullFilePath) && is_file($fullFilePath)) {
unlink($fullFilePath);
}
}
}
public function importFromFile($filename) {
$fullFilePath = $filename;
if (!file_exists($fullFilePath)) {
......
......@@ -50,7 +50,7 @@ Required vars: formProcessors
{{ts('Disable')}}
</a>
<a class="action-item crm-hover-button"
ng-show="formProcessor.status == 1"
ng-show="formProcessor.status == 1 || formProcessor.uploaded_source_file"
crm-confirm="{type: 'delete', obj: formProcessor}"
on-yes="deleteFormProcessor(formProcessor)">
{{ts('Delete')}}
......
......@@ -31,6 +31,9 @@ function civicrm_api3_form_processor_instance_get($params) {
if (is_object($returnValues[$index]['output_handler'])) {
$returnValues[$index]['output_handler'] = $returnValues[$index]['output_handler']->toArray();
}
if (!empty($returnValues[$index]['source_file'])) {
$returnValues[$index]['uploaded_source_file'] = \Civi\FormProcessor\Exporter\ExportToJson::isUploadedFile($returnValues[$index]['source_file']);
}
$returnValues[$index]['try_out_url'] = \CRM_Utils_System::url('civicrm/admin/automation/formprocessor/run', ['_qf_formProcessorName' => $formProcessor['name']], TRUE, NULL, FALSE);
$returnValues[$index]['export_url'] = \CRM_Utils_System::url('civicrm/admin/automation/formprocessor/export', ['reset' => 1, "id" =>$formProcessor['id'], "action" => "export"], TRUE, NULL, FALSE);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment