+ | + |
---|---|
+ | diacritics; ?> | +
+ |
+
+ mappings; ?> + |
+
diff --git a/apps/qubit/modules/settings/actions/diacriticsAction.class.php b/apps/qubit/modules/settings/actions/diacriticsAction.class.php new file mode 100644 index 0000000000..d47529abe8 --- /dev/null +++ b/apps/qubit/modules/settings/actions/diacriticsAction.class.php @@ -0,0 +1,84 @@ +. + */ + +class SettingsDiacriticsAction extends SettingsEditAction +{ + // Arrays not allowed in class constants + public static $NAMES = [ + 'diacritics', + ]; + + public function earlyExecute() + { + parent::earlyExecute(); + + $this->updateMessage = $this->i18n->__('Diacritics settings saved.'); + + $this->settingDefaults = [ + 'diacritics' => 0, + ]; + } + + public function execute($request) + { + parent::execute($request); + } + + public function uploadDiacritics($request) + { + $file = $request->getFiles('mappings'); + $diacriticsMappingPath = sfConfig::get('sf_plugins_dir').DIRECTORY_SEPARATOR.'arElasticSearchPlugin'.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'diacritics_mapping.yml'; + + if (1 === (int) $request->getPostParameters()['diacritics']) { + if ('application/x-yaml' === $request->getFiles()['mappings']['type']) { + // Move uploaded file to replace diacritics_mapping.yml. + try { + $file = Qubit::moveUploadFile($file); + } catch (sfException $e) { + $this->getUser()->setFlash('error', $e->getMessage()); + } + + // Replace /config/diacritics_mapping.yml with uploaded file + $uploadMappingPath = $file['tmp_name']; + $diacriticsMappings = file_get_contents($uploadMappingPath); + file_put_contents($diacriticsMappingPath, $diacriticsMappings); + $this->getUser()->setFlash('notice', $this->context->i18n->__('Diacritics setting updated. Rebuild the search index for the changes to be applied.')); + } else { + QubitSetting::findAndSave('diacritics', 0, ['sourceCulture' => true]); + $this->getUser()->setFlash('error', $this->context->i18n->__('Error: Unable to upload diacritics mapping. Must be a YAML file.')); + } + } else { + // Reset diacritics yaml when disabling the setting + unlink($diacriticsMappingPath); + } + } + + protected function addField($name) + { + switch ($name) { + case 'diacritics': + $this->form->setDefault($name, $this->settingDefaults[$name]); + $this->form->setWidget($name, new sfWidgetFormSelectRadio(['choices' => [0 => $this->i18n->__('Disabled'), 1 => $this->i18n->__('Enabled')]], ['class' => 'radio'])); + $this->form->setValidator($name, new sfValidatorChoice(['choices' => [1, 0]])); + $this->form->setWidget('mappings', new sfWidgetFormInputFile()); + $this->form->setValidator('mappings', new sfValidatorFile()); + + break; + } + } +} diff --git a/apps/qubit/modules/settings/actions/editAction.class.php b/apps/qubit/modules/settings/actions/editAction.class.php index e868af28d7..acb91d0030 100644 --- a/apps/qubit/modules/settings/actions/editAction.class.php +++ b/apps/qubit/modules/settings/actions/editAction.class.php @@ -28,7 +28,7 @@ public function execute($request) // Handle posted data if ($request->isMethod('post')) { - $this->form->bind($request->getPostParameters()); + $this->form->bind($request->getPostParameters(), $request->getFiles()); if ($this->form->isValid()) { $this->processForm(); @@ -39,6 +39,10 @@ public function execute($request) $this->getUser()->setFlash('notice', $this->updateMessage); } + if (null !== $request->getFiles() && 'SettingsDiacriticsAction' === get_called_class()) { + $this->uploadDiacritics($request); + } + $this->redirect([ 'module' => $this->getContext()->getModuleName(), 'action' => $this->getContext()->getActionName(), diff --git a/apps/qubit/modules/settings/actions/menuComponent.class.php b/apps/qubit/modules/settings/actions/menuComponent.class.php index 2948c80290..621f2ae063 100644 --- a/apps/qubit/modules/settings/actions/menuComponent.class.php +++ b/apps/qubit/modules/settings/actions/menuComponent.class.php @@ -39,6 +39,10 @@ public function execute($request) 'label' => $i18n->__('Default template'), 'action' => 'template', ], + [ + 'label' => $i18n->__('Diacritics'), + 'action' => 'diacritics', + ], [ 'label' => $i18n->__('Digital object derivatives'), 'action' => 'digitalObjectDerivatives', diff --git a/apps/qubit/modules/settings/templates/diacriticsSuccess.php b/apps/qubit/modules/settings/templates/diacriticsSuccess.php new file mode 100644 index 0000000000..47075e3a6b --- /dev/null +++ b/apps/qubit/modules/settings/templates/diacriticsSuccess.php @@ -0,0 +1,57 @@ + + + + + + + + + +
+ + + + +$ php symfony search:populate+
+ | + |
---|---|
+ | diacritics; ?> | +
+ |
+
+ mappings; ?> + |
+
$ php symfony search:populate+
+ | + |
---|---|
+ | diacritics; ?> | +
+ |
+
+ mappings; ?> + |
+