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

Commit

Permalink
Revise solr module configuration form and add install script
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Snape committed Dec 8, 2014
1 parent ed2aac5 commit b8bae79
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 223 deletions.
26 changes: 26 additions & 0 deletions modules/solr/constant/module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
All rights reserved.
More information http://www.kitware.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/

define('SOLR_HOST_KEY', 'solrHost');
define('SOLR_HOST_DEFAULT_VALUE', 'localhost');
define('SOLR_PORT_KEY', 'solrPort');
define('SOLR_PORT_DEFAULT_VALUE', 8983);
define('SOLR_WEBROOT_KEY', 'solrWebroot');
define('SOLR_WEBROOT_DEFAULT_VALUE', '/solr/');
66 changes: 66 additions & 0 deletions modules/solr/controllers/AdminController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
All rights reserved.
More information http://www.kitware.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/

/** Admin controller for the solr module. */
class Solr_AdminController extends Solr_AppController
{
/** @var array */
public $_models = array('Setting');

/** Index action */
public function indexAction()
{
$this->requireAdminPrivileges();

$this->view->pageTitle = 'Solr Module Configuration';
$form = new Solr_Form_Admin();

if ($this->getRequest()->isPost()) {
$data = $this->getRequest()->getPost();

if ($form->isValid($data)) {
$values = $form->getValues();

foreach ($values as $key => $value) {
$this->Setting->setConfig($key, $value, $this->moduleName);
}
}

$form->populate($data);
} else {
$elements = $form->getElements();

foreach ($elements as $element) {
$name = $element->getName();

if ($name !== 'csrf' && $name !== 'submit') {
$value = $this->Setting->getValueByName($name, $this->moduleName);

if (!is_null($value)) {
$form->setDefault($name, $value);
}
}
}
}

$this->view->form = $form;
session_start();
}
}
84 changes: 0 additions & 84 deletions modules/solr/controllers/ConfigController.php

This file was deleted.

6 changes: 3 additions & 3 deletions modules/solr/controllers/components/SolrComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class Solr_SolrComponent extends AppComponent
public function getSolrIndex()
{
$settingModel = MidasLoader::loadModel('Setting');
$solrHost = $settingModel->getValueByName('solrHost', 'solr');
$solrPort = $settingModel->getValueByName('solrPort', 'solr');
$solrWebroot = $settingModel->getValueByName('solrWebroot', 'solr');
$solrHost = $settingModel->getValueByName(SOLR_HOST_KEY, 'solr');
$solrPort = $settingModel->getValueByName(SOLR_PORT_KEY, 'solr');
$solrWebroot = $settingModel->getValueByName(SOLR_WEBROOT_KEY, 'solr');

if ($solrHost === null) {
throw new Zend_Exception('Solr settings not saved');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,21 @@
limitations under the License.
=========================================================================*/

/** module config form */
class Solr_ConfigForm extends AppForm
{
/** create the admin->modules page config form */
public function createConfigForm()
{
$form = new Zend_Form();
$form->setAction($this->webroot.'/solr/config/submit')->setMethod('post');

$host = new Zend_Form_Element_Text('host');
$port = new Zend_Form_Element_Text('port');
$webroot = new Zend_Form_Element_Text('webroot');
require_once BASE_PATH.'/modules/solr/constant/module.php';

$submit = new Zend_Form_Element_Submit('submitConfig');
$submit->setLabel('Save configuration');

$form->addElements(array($host, $port, $webroot, $submit));
/** Install the solr module. */
class Solr_InstallScript extends MIDASModuleInstallScript
{
/** @var string */
public $moduleName = 'solr';

return $form;
/** Post database install. */
public function postInstall()
{
/** @var SettingModel $settingModel */
$settingModel = MidasLoader::loadModel('Setting');
$settingModel->setConfig(SOLR_HOST_KEY, SOLR_HOST_DEFAULT_VALUE, $this->moduleName);
$settingModel->setConfig(SOLR_PORT_KEY, SOLR_PORT_DEFAULT_VALUE, $this->moduleName);
$settingModel->setConfig(SOLR_WEBROOT_KEY, SOLR_WEBROOT_DEFAULT_VALUE, $this->moduleName);
}
}
60 changes: 60 additions & 0 deletions modules/solr/forms/Admin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
All rights reserved.
More information http://www.kitware.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/

/** Admin form for the solr module. */
class Solr_Form_Admin extends Zend_Form
{
/** Initialize this form. */
public function init()
{
$this->setName('solr_admin');
$this->setMethod('POST');

$csrf = new Midas_Form_Element_Hash('csrf');
$csrf->setSalt('VhyLUG4sRzUwa43P96W7kVM8');
$csrf->setDecorators(array('ViewHelper'));

$host = new Zend_Form_Element_Text(SOLR_HOST_KEY);
$host->setLabel('Solr Host');
$host->setRequired(true);
$host->addValidator('NotEmpty', true);
$host->addValidator('Hostname', true);

$port = new Zend_Form_Element_Text(SOLR_PORT_KEY);
$port->setLabel('Solr Port');
$port->setRequired(true);
$port->addValidator('NotEmpty', true);
$port->addValidator('Digits', true);
$port->addValidator('Between', true, array('min' => 1, 'max' => 65535));
$port->setAttrib('maxlength', 5);

$webroot = new Zend_Form_Element_Text(SOLR_WEBROOT_KEY);
$webroot->setLabel('Solr Webroot');
$webroot->setRequired(true);
$webroot->addValidator('NotEmpty', true);

$this->addDisplayGroup(array($host, $port, $webroot), 'global');

$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Save');

$this->addElements(array($csrf, $host, $port, $webroot, $submit));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,8 @@
var midas = midas || {};
midas.solr = midas.solr || {};

midas.solr.validateConfig = function (formData, jqForm, options) {};

midas.solr.successConfig = function (responseText, statusText, xhr, form) {
'use strict';
var jsonResponse;
try {
jsonResponse = $.parseJSON(responseText);
}
catch (e) {
midas.createNotice("An error occured. Please check the logs.", 4000, 'error');
return false;
}
if (jsonResponse === null) {
midas.createNotice('Error', 4000, 'error');
return;
}
if (jsonResponse[0]) {
midas.createNotice(jsonResponse[1], 4000);
$('div.notSavedWarning').remove();
}
else {
midas.createNotice(jsonResponse[1], 4000, 'error');
}
};

$(document).ready(function () {
'use strict';
$('#configForm').ajaxForm({
beforeSubmit: midas.solr.validateConfig,
success: midas.solr.successConfig
});

$('#rebuildIndexButton').click(function () {
$('#rebuildProgressMessage').html('Rebuilding item index...');
$(this).attr('disabled', 'disabled');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
/* MIDAS Server. Copyright Kitware SAS. Licensed under the Apache License 2.0. */

div {
&.notSavedWarning {
color: #F00;
font-weight: bold;
margin-top: 15px;
}
&.rebuildIndexContainer {
margin-top: 20px;
}
Expand Down
45 changes: 45 additions & 0 deletions modules/solr/views/admin/index.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/*=========================================================================
MIDAS Server
Copyright (c) Kitware SAS. 26 rue Louis Guérin. 69100 Villeurbanne, FRANCE
All rights reserved.
More information http://www.kitware.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/

$this->declareVars('form', 'pageTitle');
$this->headTitle($this->escape($this->pageTitle));
$this->headLink()->appendStylesheet($this->baseUrl('modules/solr/public/css/admin/admin.index.css'));
$this->headScript()->appendFile($this->baseUrl('modules/solr/public/js/admin/admin.index.js'));
?>

<div class="viewMain">
<h1><?php echo $this->escape($this->pageTitle); ?></h1>
<div class="instructionContainer">
This module requires you to run a specially configured Apache Solr server. Install instructions and a link to
download the server are hosted <a href="http://midas3.kitware.com/midas/item/19589">here</a>. If you have
existing content in this instance, make sure to rebuild the index using the link at the bottom of this page
once the Solr server is installed and running.
</div>
<?php echo $this->form; ?>
<div class="rebuildIndexContainer">
<p>Click the button below to rebuild the Lucene index on all items.</p>
<div>
<input class="globalButton" type="button" id="rebuildIndexButton" value="Rebuild index" />
</div>
<div id="rebuildProgressBar"></div>
<div id="rebuildProgressMessage"></div>
</div>
<p><a href="<?php echo $this->url(array('controller' => 'admin', 'action' => 'index'), 'default'); ?>#tabs-modules">&laquo; Back to Modules Administration</a></p>
</div>
Loading

0 comments on commit b8bae79

Please sign in to comment.