-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c741f38
commit bec7038
Showing
5 changed files
with
200 additions
and
1 deletion.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
apps/qubit/modules/settings/actions/diacriticsAction.class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
/* | ||
* This file is part of the Access to Memory (AtoM) software. | ||
* | ||
* Access to Memory (AtoM) is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Access to Memory (AtoM) is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Access to Memory (AtoM). If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
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' => QubitSetting::getByName('diacritics')->getValue(['sourceCulture' => true]), | ||
]; | ||
} | ||
|
||
public function execute($request) | ||
{ | ||
DefaultEditAction::execute($request); | ||
|
||
if ($request->isMethod('post')) { | ||
$this->form->bind($request->getPostParameters(), $request->getFiles()); | ||
|
||
if ($this->form->isValid()) { | ||
// Check that a diacritics mapping yaml file is uploaded when enabling | ||
if (0 === intval($request->getPostParameters()['diacritics']) || (1 === intval($request->getPostParameters()['diacritics']) && 0 !== $request->getFiles()['mappings']['size'])) { | ||
$this->processForm($request); | ||
$this->uploadDiacritics($request); | ||
} else { | ||
$this->getUser()->setFlash('error', $this->context->i18n->__('Error: Unable to upload diacritics mapping.')); | ||
} | ||
|
||
$this->redirect(['module' => 'settings', 'action' => 'diacritics']); | ||
} | ||
} | ||
} | ||
|
||
public function processForm($request) | ||
{ | ||
sfConfig::set('app_diacritics', $request->getPostParameters()['diacritics']); | ||
QubitSetting::findAndSave('diacritics', $request->getPostParameters()['diacritics'], ['sourceCulture' => true]); | ||
} | ||
|
||
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
apps/qubit/modules/settings/templates/diacriticsSuccess.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php decorate_with('layout_2col.php'); ?> | ||
|
||
<?php slot('sidebar'); ?> | ||
|
||
<?php echo get_component('settings', 'menu'); ?> | ||
|
||
<?php end_slot(); ?> | ||
|
||
<?php slot('title'); ?> | ||
<h1><?php echo __('Diacritics settings'); ?></h1> | ||
<?php end_slot(); ?> | ||
|
||
<?php slot('content'); ?> | ||
|
||
<div class="alert alert-info"> | ||
<p><?php echo __('Please rebuild the search index after uploading diacritics mappings.'); ?></p> | ||
<pre>$ php symfony search:populate</pre> | ||
</div> | ||
|
||
<?php echo $form->renderGlobalErrors(); ?> | ||
|
||
<?php echo $form->renderFormTag(url_for(['module' => 'settings', 'action' => 'diacritics']), ['method' => 'post']); ?> | ||
|
||
<?php echo $form->renderHiddenFields(); ?> | ||
|
||
<div id="content"> | ||
|
||
<table class="table sticky-enabled"> | ||
<thead> | ||
<tr> | ||
<th width="30%"><?php echo __('Name'); ?></th> | ||
<th><?php echo __('Value'); ?></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td><?php echo __('Diacritics'); ?></td> | ||
<td><?php echo $form->diacritics; ?></td> | ||
</tr> | ||
<tr> | ||
<td><?php echo __('Mappings YAML'); ?></td> | ||
<td> | ||
<span><?php echo __('YAML file containing char_filter mappings.'); ?></span></br> | ||
<?php echo $form->mappings; ?><br/> | ||
</td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
</div> | ||
|
||
<section class="actions"> | ||
<input class="btn atom-btn-outline-success" type="submit" value="<?php echo __('Save'); ?>"/> | ||
</section> | ||
|
||
</form> | ||
|
||
<?php end_slot(); ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters