Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit b8bae79

Browse files
author
Jamie Snape
committed
Revise solr module configuration form and add install script
1 parent ed2aac5 commit b8bae79

File tree

11 files changed

+214
-223
lines changed

11 files changed

+214
-223
lines changed

modules/solr/constant/module.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
define('SOLR_HOST_KEY', 'solrHost');
22+
define('SOLR_HOST_DEFAULT_VALUE', 'localhost');
23+
define('SOLR_PORT_KEY', 'solrPort');
24+
define('SOLR_PORT_DEFAULT_VALUE', 8983);
25+
define('SOLR_WEBROOT_KEY', 'solrWebroot');
26+
define('SOLR_WEBROOT_DEFAULT_VALUE', '/solr/');
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
/** Admin controller for the solr module. */
22+
class Solr_AdminController extends Solr_AppController
23+
{
24+
/** @var array */
25+
public $_models = array('Setting');
26+
27+
/** Index action */
28+
public function indexAction()
29+
{
30+
$this->requireAdminPrivileges();
31+
32+
$this->view->pageTitle = 'Solr Module Configuration';
33+
$form = new Solr_Form_Admin();
34+
35+
if ($this->getRequest()->isPost()) {
36+
$data = $this->getRequest()->getPost();
37+
38+
if ($form->isValid($data)) {
39+
$values = $form->getValues();
40+
41+
foreach ($values as $key => $value) {
42+
$this->Setting->setConfig($key, $value, $this->moduleName);
43+
}
44+
}
45+
46+
$form->populate($data);
47+
} else {
48+
$elements = $form->getElements();
49+
50+
foreach ($elements as $element) {
51+
$name = $element->getName();
52+
53+
if ($name !== 'csrf' && $name !== 'submit') {
54+
$value = $this->Setting->getValueByName($name, $this->moduleName);
55+
56+
if (!is_null($value)) {
57+
$form->setDefault($name, $value);
58+
}
59+
}
60+
}
61+
}
62+
63+
$this->view->form = $form;
64+
session_start();
65+
}
66+
}

modules/solr/controllers/ConfigController.php

Lines changed: 0 additions & 84 deletions
This file was deleted.

modules/solr/controllers/components/SolrComponent.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class Solr_SolrComponent extends AppComponent
2727
public function getSolrIndex()
2828
{
2929
$settingModel = MidasLoader::loadModel('Setting');
30-
$solrHost = $settingModel->getValueByName('solrHost', 'solr');
31-
$solrPort = $settingModel->getValueByName('solrPort', 'solr');
32-
$solrWebroot = $settingModel->getValueByName('solrWebroot', 'solr');
30+
$solrHost = $settingModel->getValueByName(SOLR_HOST_KEY, 'solr');
31+
$solrPort = $settingModel->getValueByName(SOLR_PORT_KEY, 'solr');
32+
$solrWebroot = $settingModel->getValueByName(SOLR_WEBROOT_KEY, 'solr');
3333

3434
if ($solrHost === null) {
3535
throw new Zend_Exception('Solr settings not saved');

modules/solr/controllers/forms/ConfigForm.php renamed to modules/solr/database/InstallScript.php

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,21 @@
1818
limitations under the License.
1919
=========================================================================*/
2020

21-
/** module config form */
22-
class Solr_ConfigForm extends AppForm
23-
{
24-
/** create the admin->modules page config form */
25-
public function createConfigForm()
26-
{
27-
$form = new Zend_Form();
28-
$form->setAction($this->webroot.'/solr/config/submit')->setMethod('post');
29-
30-
$host = new Zend_Form_Element_Text('host');
31-
$port = new Zend_Form_Element_Text('port');
32-
$webroot = new Zend_Form_Element_Text('webroot');
21+
require_once BASE_PATH.'/modules/solr/constant/module.php';
3322

34-
$submit = new Zend_Form_Element_Submit('submitConfig');
35-
$submit->setLabel('Save configuration');
36-
37-
$form->addElements(array($host, $port, $webroot, $submit));
23+
/** Install the solr module. */
24+
class Solr_InstallScript extends MIDASModuleInstallScript
25+
{
26+
/** @var string */
27+
public $moduleName = 'solr';
3828

39-
return $form;
29+
/** Post database install. */
30+
public function postInstall()
31+
{
32+
/** @var SettingModel $settingModel */
33+
$settingModel = MidasLoader::loadModel('Setting');
34+
$settingModel->setConfig(SOLR_HOST_KEY, SOLR_HOST_DEFAULT_VALUE, $this->moduleName);
35+
$settingModel->setConfig(SOLR_PORT_KEY, SOLR_PORT_DEFAULT_VALUE, $this->moduleName);
36+
$settingModel->setConfig(SOLR_WEBROOT_KEY, SOLR_WEBROOT_DEFAULT_VALUE, $this->moduleName);
4037
}
4138
}

modules/solr/forms/Admin.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
/** Admin form for the solr module. */
22+
class Solr_Form_Admin extends Zend_Form
23+
{
24+
/** Initialize this form. */
25+
public function init()
26+
{
27+
$this->setName('solr_admin');
28+
$this->setMethod('POST');
29+
30+
$csrf = new Midas_Form_Element_Hash('csrf');
31+
$csrf->setSalt('VhyLUG4sRzUwa43P96W7kVM8');
32+
$csrf->setDecorators(array('ViewHelper'));
33+
34+
$host = new Zend_Form_Element_Text(SOLR_HOST_KEY);
35+
$host->setLabel('Solr Host');
36+
$host->setRequired(true);
37+
$host->addValidator('NotEmpty', true);
38+
$host->addValidator('Hostname', true);
39+
40+
$port = new Zend_Form_Element_Text(SOLR_PORT_KEY);
41+
$port->setLabel('Solr Port');
42+
$port->setRequired(true);
43+
$port->addValidator('NotEmpty', true);
44+
$port->addValidator('Digits', true);
45+
$port->addValidator('Between', true, array('min' => 1, 'max' => 65535));
46+
$port->setAttrib('maxlength', 5);
47+
48+
$webroot = new Zend_Form_Element_Text(SOLR_WEBROOT_KEY);
49+
$webroot->setLabel('Solr Webroot');
50+
$webroot->setRequired(true);
51+
$webroot->addValidator('NotEmpty', true);
52+
53+
$this->addDisplayGroup(array($host, $port, $webroot), 'global');
54+
55+
$submit = new Zend_Form_Element_Submit('submit');
56+
$submit->setLabel('Save');
57+
58+
$this->addElements(array($csrf, $host, $port, $webroot, $submit));
59+
}
60+
}
File renamed without changes.

modules/solr/public/js/config/config.index.js renamed to modules/solr/public/js/admin/admin.index.js

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,8 @@
55
var midas = midas || {};
66
midas.solr = midas.solr || {};
77

8-
midas.solr.validateConfig = function (formData, jqForm, options) {};
9-
10-
midas.solr.successConfig = function (responseText, statusText, xhr, form) {
11-
'use strict';
12-
var jsonResponse;
13-
try {
14-
jsonResponse = $.parseJSON(responseText);
15-
}
16-
catch (e) {
17-
midas.createNotice("An error occured. Please check the logs.", 4000, 'error');
18-
return false;
19-
}
20-
if (jsonResponse === null) {
21-
midas.createNotice('Error', 4000, 'error');
22-
return;
23-
}
24-
if (jsonResponse[0]) {
25-
midas.createNotice(jsonResponse[1], 4000);
26-
$('div.notSavedWarning').remove();
27-
}
28-
else {
29-
midas.createNotice(jsonResponse[1], 4000, 'error');
30-
}
31-
};
32-
338
$(document).ready(function () {
349
'use strict';
35-
$('#configForm').ajaxForm({
36-
beforeSubmit: midas.solr.validateConfig,
37-
success: midas.solr.successConfig
38-
});
39-
4010
$('#rebuildIndexButton').click(function () {
4111
$('#rebuildProgressMessage').html('Rebuilding item index...');
4212
$(this).attr('disabled', 'disabled');

modules/solr/public/scss/config/config.index.scss renamed to modules/solr/public/scss/admin/admin.index.scss

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
/* MIDAS Server. Copyright Kitware SAS. Licensed under the Apache License 2.0. */
22

33
div {
4-
&.notSavedWarning {
5-
color: #F00;
6-
font-weight: bold;
7-
margin-top: 15px;
8-
}
94
&.rebuildIndexContainer {
105
margin-top: 20px;
116
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/*=========================================================================
3+
MIDAS Server
4+
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
5+
All rights reserved.
6+
More information http://www.kitware.com
7+
8+
Licensed under the Apache License, Version 2.0 (the "License");
9+
you may not use this file except in compliance with the License.
10+
You may obtain a copy of the License at
11+
12+
http://www.apache.org/licenses/LICENSE-2.0.txt
13+
14+
Unless required by applicable law or agreed to in writing, software
15+
distributed under the License is distributed on an "AS IS" BASIS,
16+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
See the License for the specific language governing permissions and
18+
limitations under the License.
19+
=========================================================================*/
20+
21+
$this->declareVars('form', 'pageTitle');
22+
$this->headTitle($this->escape($this->pageTitle));
23+
$this->headLink()->appendStylesheet($this->baseUrl('modules/solr/public/css/admin/admin.index.css'));
24+
$this->headScript()->appendFile($this->baseUrl('modules/solr/public/js/admin/admin.index.js'));
25+
?>
26+
27+
<div class="viewMain">
28+
<h1><?php echo $this->escape($this->pageTitle); ?></h1>
29+
<div class="instructionContainer">
30+
This module requires you to run a specially configured Apache Solr server. Install instructions and a link to
31+
download the server are hosted <a href="http://midas3.kitware.com/midas/item/19589">here</a>. If you have
32+
existing content in this instance, make sure to rebuild the index using the link at the bottom of this page
33+
once the Solr server is installed and running.
34+
</div>
35+
<?php echo $this->form; ?>
36+
<div class="rebuildIndexContainer">
37+
<p>Click the button below to rebuild the Lucene index on all items.</p>
38+
<div>
39+
<input class="globalButton" type="button" id="rebuildIndexButton" value="Rebuild index" />
40+
</div>
41+
<div id="rebuildProgressBar"></div>
42+
<div id="rebuildProgressMessage"></div>
43+
</div>
44+
<p><a href="<?php echo $this->url(array('controller' => 'admin', 'action' => 'index'), 'default'); ?>#tabs-modules">&laquo; Back to Modules Administration</a></p>
45+
</div>

0 commit comments

Comments
 (0)