Skip to content

Commit

Permalink
Added "Test Connection" button + Dutch translations
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroenvermeulen committed May 15, 2014
1 parent 00d3246 commit fb1c6ae
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 113 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
/app/etc/modules/Phoenix_*
/app/etc/config.xml
/app/etc/local.xml*
/app/locale
/app/locale/*/*.csv
!/app/locale/*/JeroenVermeulen_Solarium.csv
/app/locale/*/template
/app/Mage.php
/cron.php
/cron.sh
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
/**
* JeroenVermeulen_Solarium
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade this Module to
* newer versions in the future.
*
* @category JeroenVermeulen
* @package JeroenVermeulen_Solarium
* @copyright Copyright (c) 2014 Jeroen Vermeulen (http://www.jeroenvermeulen.eu)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

class JeroenVermeulen_Solarium_Block_Adminhtml_System_Config_Form_Fieldset_Server
extends Mage_Adminhtml_Block_System_Config_Form_Fieldset
{

/**
* Show version info
* @param Varien_Data_Form_Element_Abstract $element
* @return string
*/
protected function _getFooterHtml( $element ) {
$helper = Mage::helper( 'jeroenvermeulen_solarium' );
ob_start();
?>
<table class="form-list">
<tbody>
<tr>
<td class="label">&nbsp;</td>
<td>
<button type="button" onclick="solariumTestConnection();">
<?php echo htmlspecialchars( $helper->__('Test Connection') ); ?>
</button>
</td>
</tr>
</tbody>
</table>
<table class="form-list">
<tbody id="solarium_test_connection_result" style="display: none;" >
<tr >
<td class="label">&nbsp;</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<script type="text/javascript">
function solariumTestConnection() {
function solariumTestMessage( message, setClass ) {
if ( !setClass ) {
setClass = '';
}
var resultRow = '';
resultRow += '<tr>';
resultRow += '<td class="label"><?php echo htmlspecialchars( $helper->__('Connection Test') ); ?></td>';
resultRow += '<td class="' + setClass + '">' + message + '</td>';
resultRow += '</tr>';
$('solarium_test_connection_result').update( resultRow ).show();
}
var params = {
host: $('jeroenvermeulen_solarium_server_host').value,
port: $('jeroenvermeulen_solarium_server_port').value,
path: $('jeroenvermeulen_solarium_server_path').value,
core: $('jeroenvermeulen_solarium_server_core').value,
auth: $('jeroenvermeulen_solarium_server_requires_authentication').value,
username: $('jeroenvermeulen_solarium_server_username').value,
password: $('jeroenvermeulen_solarium_server_password').value,
timeout: $('jeroenvermeulen_solarium_server_search_timeout').value
};
solariumTestMessage( <?php echo json_encode( $helper->__('Connecting...') ); ?> );
new Ajax.Request( <?php echo json_encode( Mage::helper("adminhtml")->getUrl("adminhtml/solarium/testConnection") ); ?>, {
'parameters': params,
'onComplete': function( $response ) {
$('solarium_test_connection_result').update( $response.responseText ).show();
},
'onFailure': function( $response ) {
solariumTestMessage( <?php echo json_encode( $helper->__('ERROR') ); ?> + ' ' + response.status + ': ' + $response.responseText, 'not-available' );
}
});
}
</script>
<?php
return ob_get_clean() . parent::_getFooterHtml( $element );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class JeroenVermeulen_Solarium_Model_CatalogSearch_Indexer_Fulltext extends Mage
public function getDescription() {
$result = parent::getDescription();
if ( JeroenVermeulen_Solarium_Model_Engine::isEnabled() ) {
$result .= ' - ' . Mage::helper( 'jeroenvermeulen_solarium' )->__( 'POWERED BY SOLARIUM' );
$helper = Mage::helper( 'jeroenvermeulen_solarium' );
$result .= ' - ' . $helper->__( 'POWERED BY SOLARIUM' );
}
return $result;
}
Expand Down
26 changes: 15 additions & 11 deletions app/code/community/JeroenVermeulen/Solarium/Model/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,21 @@ public function getLastQueryTime() {
/**
* Return an array with version info, to show in backend.
*
* @param bool $extended - When true we will output more information
* @return array
*/
public function getVersionInfo() {
public function getVersionInfo( $extended = false ) {
$helper = Mage::helper( 'jeroenvermeulen_solarium' );
$versions = array();
$versions[ 'Operating System' ] = php_uname();
$versions[ 'PHP' ] = phpversion();
$versions[ 'Magento' ] = Mage::getVersion();
$versions[ 'Extension' ] = $helper->getExtensionVersion();
$versions[ 'Solarium Library' ] = Solarium\Client::VERSION;
$versions[ 'Solr' ] = $helper->__( 'unknown' );
$versions[ 'Java' ] = $helper->__( 'unknown' );
if ( $extended ) {
$versions[ 'Operating System' ] = php_uname();
$versions[ 'PHP' ] = phpversion();
$versions[ 'Magento' ] = Mage::getVersion();
$versions[ 'Extension' ] = $helper->getExtensionVersion();
$versions[ 'Solarium Library' ] = Solarium\Client::VERSION;
}
$versions[ 'Solr version' ] = $helper->__( 'unknown' );
$versions[ 'Java version' ] = $helper->__( 'unknown' );
if ( $this->isWorking() ) {
try {
/**
Expand All @@ -234,10 +237,10 @@ public function getVersionInfo() {
$query->setHandler( 'system' );
$data = $this->_client->ping( $query, 'admin' )->getData();
if ( !empty( $data[ 'lucene' ][ 'solr-impl-version' ] ) ) {
$versions[ 'Solr' ] = $data[ 'lucene' ][ 'solr-impl-version' ];
$versions[ 'Solr version' ] = $data[ 'lucene' ][ 'solr-impl-version' ];
}
if ( !empty( $data[ 'jvm' ][ 'name' ] ) && !empty( $data[ 'jvm' ][ 'version' ] ) ) {
$versions[ 'Java' ] = $data[ 'jvm' ][ 'name' ] . ' ' . $data[ 'jvm' ][ 'version' ];
$versions[ 'Java version' ] = $data[ 'jvm' ][ 'name' ] . ' ' . $data[ 'jvm' ][ 'version' ];
}
} catch ( Exception $e ) {
Mage::log( sprintf( '%s->%s: %s', __CLASS__, __FUNCTION__, $e->getMessage() ), Zend_Log::ERR );
Expand Down Expand Up @@ -508,7 +511,8 @@ public function query( $storeId, $queryString, $try = 1 ) {
}

/**
* @param $queryString
* @param integer $storeId - Store View Id
* @param string $queryString - What the user is typing
* @return null|string
*/
public function getAutoSuggestions( $storeId, $queryString ) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
<?php

/**
* Class JeroenVermeulen_Solarium_Admin_SolariumController
*
* Controller for actions from the Magento Admin interface
*/
class JeroenVermeulen_Solarium_Admin_SolariumController extends Mage_Adminhtml_Controller_Action
{

// URL: http://[MAGROOT]/admin/solarium/ajax/key/###########/
public function ajaxAction() {
/**
*
*
* Example URL: http://[MAGE-ROOT]/admin/solarium/testConnection/key/###########/
*/
public function testConnectionAction() {
$request = $this->getRequest();
$helper = Mage::helper( 'jeroenvermeulen_solarium' );
$config = array( 'general/enabled' => true,
'server/host' => $request->getParam('host', false),
'server/port' => $request->getParam('port', false),
Expand All @@ -18,7 +28,37 @@ public function ajaxAction() {
$config['server/password'] = Mage::helper('core')->encrypt( $request->getParam('password', false) );
}
$engine = Mage::getModel( 'jeroenvermeulen_solarium/engine', $config );
$result = $engine->isWorking() ? 'Success' : 'ERROR';
$class = 'error';
$state = 'FAILED';
if ( $engine->isWorking() ) {
$class = 'available';
$state = 'Success';
}
$versions = $engine->getVersionInfo();
ob_start();
?>
<tr id="solarium_test_connection_result">
<td class="label">
<?php echo htmlspecialchars( $helper->__('Connection Test') ); ?>
</td>
<td class="<?php echo htmlspecialchars( $class ); ?>">
<?php echo htmlspecialchars( $helper->__( $state ) ); ?>
</td>
</tr>
<?php
foreach ( $versions as $label => $value ):
?>
<tr>
<td class="label">
<?php echo htmlspecialchars( $helper->__( $label ) ); ?>
</td>
<td>
<?php echo htmlspecialchars( $value ); ?>
</td>
</tr>
<?php
endforeach;
$result = ob_get_clean();
$this->getResponse()->setBody( $result );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class JeroenVermeulen_Solarium_AjaxController extends Mage_Core_Controller_Front
/**
* Override default suggestAction to add our own block
*
* URL: http://[MAGROOT]/solarium/ajax/suggest/?q=comp -->
* URL: http://[MAGE-ROOT]/solarium/ajax/suggest/?q=comp -->
*/
public function suggestAction()
{
Expand Down
22 changes: 20 additions & 2 deletions app/code/community/JeroenVermeulen/Solarium/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@
</events>
</global>
<frontend>
<translate>
<modules>
<jeroenvermeulen_solarium>
<files>
<default>JeroenVermeulen_Solarium.csv</default>
</files>
</jeroenvermeulen_solarium>
</modules>
</translate>
<layout>
<updates>
<jeroenvermeulen_solarium>
Expand All @@ -98,7 +107,7 @@
<jeroenvermeulen_solarium>
<use>standard</use>
<args>
<!-- URL: http://[MAGROOT]/solarium/[ACTION]/key/xxxxxxxxxxx/ -->
<!-- URL: http://[MAGROOT]/solarium/[ACTION]/key/[NONCE]/ -->
<module>JeroenVermeulen_Solarium</module>
<frontName>solarium</frontName>
</args>
Expand All @@ -110,14 +119,23 @@
<adminhtml>
<args>
<modules>
<!-- URL: http://[MAGROOT]/admin/[CONTROLLER]/[ACTION]/key/xxxxxxxxxxx/ -->
<!-- URL: http://[MAGROOT]/admin/[CONTROLLER]/[ACTION]/key/[NONCE]/ -->
<JeroenVermeulen_Solarium after="Mage_Adminhtml">JeroenVermeulen_Solarium_Admin</JeroenVermeulen_Solarium>
</modules>
</args>
</adminhtml>
</routers>
</admin>
<adminhtml>
<translate>
<modules>
<jeroenvermeulen_solarium>
<files>
<default>JeroenVermeulen_Solarium.csv</default>
</files>
</jeroenvermeulen_solarium>
</modules>
</translate>
<layout>
<updates>
<jeroenvermeulen_solarium>
Expand Down
Loading

0 comments on commit fb1c6ae

Please sign in to comment.