Commit f067ce2d authored by jaapjansma's avatar jaapjansma

remove try out url from export

parent 9af35ff4
......@@ -3,10 +3,10 @@
namespace Civi\FormProcessor\Exporter;
class ExportToJson {
/**
* Exports a form processor to json.
*
*
* @param int $form_processor_id
* The form processor.
* @return string
......@@ -21,19 +21,20 @@ class ExportToJson {
unset($form_processor['modified_date']);
unset($form_processor['status']);
unset($form_processor['source_file']);
unset($form_processor['try_out_url']);
$form_processor['output_handler'] = $form_processor['output_handler']['name'];
foreach($form_processor['inputs'] as $key => $input) {
unset($form_processor['inputs'][$key]['id']);
unset($form_processor['inputs'][$key]['form_processor_instance_id']);
$form_processor['inputs'][$key]['type'] = $input['type']['name'];
foreach($input['validators'] as $validator_key => $validator) {
unset($form_processor['inputs'][$key]['validators'][$validator_key]['id']);
unset($form_processor['inputs'][$key]['validators'][$validator_key]['entity']);
unset($form_processor['inputs'][$key]['validators'][$validator_key]['entity_id']);
unset($form_processor['inputs'][$key]['validators'][$validator_key]['entity_id']);
$form_processor['inputs'][$key]['validators'][$validator_key]['validator'] = $validator['validator']['name'];
}
}
......@@ -45,17 +46,17 @@ class ExportToJson {
unset($form_processor['actions'][$key]['condition_configuration']['title']);
}
}
foreach($form_processor['default_data_inputs'] as $key => $input) {
unset($form_processor['default_data_inputs'][$key]['id']);
unset($form_processor['default_data_inputs'][$key]['form_processor_instance_id']);
$form_processor['default_data_inputs'][$key]['type'] = $input['type']['name'];
foreach($input['validators'] as $validator_key => $validator) {
unset($form_processor['default_data_inputs'][$key]['validators'][$validator_key]['id']);
unset($form_processor['default_data_inputs'][$key]['validators'][$validator_key]['entity']);
unset($form_processor['default_data_inputs'][$key]['validators'][$validator_key]['entity_id']);
unset($form_processor['default_data_inputs'][$key]['validators'][$validator_key]['entity_id']);
$form_processor['default_data_inputs'][$key]['validators'][$validator_key]['validator'] = $validator['validator']['name'];
}
}
......@@ -65,17 +66,17 @@ class ExportToJson {
unset($form_processor['default_data_actions'][$key]['weight']);
}
return $form_processor;
return $form_processor;
}
public function import($data, $filename) {
$form_processor_id = \CRM_FormProcessor_BAO_FormProcessorInstance::getId($data['name']);
$form_processor_id = \CRM_FormProcessor_BAO_FormProcessorInstance::getId($data['name']);
$status = \CRM_FormProcessor_BAO_FormProcessorInstance::getStatus($data['name']);
$new_status = null;
$new_id = null;
\CRM_FormProcessor_BAO_FormProcessorInstance::setFormProcessorToImportingState($data['name']);
switch ($status) {
case \CRM_FormProcessor_Status::IN_DATABASE:
// Update to overriden
......@@ -103,7 +104,7 @@ class ExportToJson {
return $return;
}
private function importFormProcessor($data, $filename, $form_processor_id) {
$params = $data;
unset($params['inputs']);
......@@ -117,13 +118,13 @@ class ExportToJson {
$params['source_file'] = $filename;
$result = \CRM_FormProcessor_BAO_FormProcessorInstance::add($params);
$id = $result['id'];
// Clear all existing inputs and actions
\CRM_FormProcessor_BAO_FormProcessorInput::deleteWithFormProcessorInstanceId($id);
\CRM_FormProcessor_BAO_FormProcessorAction::deleteWithFormProcessorInstanceId($id);
\CRM_FormProcessor_BAO_FormProcessorDefaultDataInput::deleteWithFormProcessorInstanceId($id);
\CRM_FormProcessor_BAO_FormProcessorDefaultDataAction::deleteWithFormProcessorInstanceId($id);
foreach($data['inputs'] as $input) {
$params = $input;
unset($params['validators']);
......@@ -136,7 +137,7 @@ class ExportToJson {
\CRM_FormProcessor_BAO_FormProcessorValidation::add($validator);
}
}
$weight = 1;
foreach($data['actions'] as $action) {
$params = $action;
......@@ -145,7 +146,7 @@ class ExportToJson {
$result = \CRM_FormProcessor_BAO_FormProcessorAction::add($params);
$weight ++;
}
foreach($data['default_data_inputs'] as $input) {
$params = $input;
unset($params['validators']);
......@@ -158,7 +159,7 @@ class ExportToJson {
\CRM_FormProcessor_BAO_FormProcessorValidation::add($validator);
}
}
$weight = 1;
foreach($data['default_data_actions'] as $action) {
$params = $action;
......@@ -167,13 +168,13 @@ class ExportToJson {
$result = \CRM_FormProcessor_BAO_FormProcessorDefaultDataAction::add($params);
$weight ++;
}
return $id;
}
/**
* Imports form processor from files in an extension directory.
*
*
* This scans the extension directory form-processors/ for json files.
*/
public function importFromExtensions() {
......@@ -183,18 +184,18 @@ class ExportToJson {
foreach($extensions as $ext_file) {
$data = json_decode($ext_file['data'], true);
$return[$ext_file['file']] = $this->import($data, $ext_file['file']);
$importedIds[] = $return[$ext_file['file']]['new_id'];
$importedIds[] = $return[$ext_file['file']]['new_id'];
}
// Remove all form processors which are in code or overridden but not imported
$dao = \CRM_Core_DAO::executeQuery("SELECT id, name FROM civicrm_form_processor_instance WHERE id NOT IN (".implode($importedIds, ",").") AND status IN (".\CRM_FormProcessor_Status::IN_CODE.", ".\CRM_FormProcessor_Status::OVERRIDDEN.")");
while ($dao->fetch()) {
\CRM_FormProcessor_BAO_FormProcessorInstance::deleteWithId($dao->id);
$return['deleted form processors'][] = $dao->id.": ".$dao->name;
}
return $return;
return $return;
}
/**
* Revert a form processor to the state in code.
*/
......@@ -214,10 +215,10 @@ class ExportToJson {
$this->importFormProcessor($data, $dao->source_file, $form_processor_id);
return true;
}
/**
* Returns a list with form-processor files within an extension folder.
*
*
* @return array
*/
private function getExtensionFileListWithFormProcessors() {
......@@ -227,20 +228,20 @@ class ExportToJson {
if ($ext['status'] != 'installed') {
continue;
}
$path = $ext['path'].'/form-processors';
if (!is_dir($path)) {
continue;
}
foreach (glob($path."/*.json") as $file) {
$return[] = array(
'file' => $ext['key']. '/form-processors/'.basename($file),
'data' => file_get_contents($file),
);
);
}
}
return $return;
}
}
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