Skip to content

Commit

Permalink
Added elasticsearch support
Browse files Browse the repository at this point in the history
  • Loading branch information
Soner Sayakci committed Feb 10, 2018
1 parent ca5d2f4 commit bd69b07
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 11 deletions.
3 changes: 3 additions & 0 deletions Adminer/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ function adminer_object() {
]);
}

error_reporting(0);
@ini_set('display_errors', 0);

include './Adminer.php';
2 changes: 2 additions & 0 deletions Controllers/Backend/Adminer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public function formAction()

$this->Front()->Plugins()->ViewRenderer()->setNoRender();
$this->View()->dbData = Shopware()->Container()->getParameter('shopware.db');
$this->View()->esData = Shopware()->Container()->getParameter('shopware.es');
$this->View()->postUri = $baseUrl . $pathToPluginFolder . '/Adminer/index.php';
$this->View()->driver = $this->Request()->getParam('adminerAction') === 'index' ? 'server' : 'elastic';

echo $this->View()->fetch('backend/adminer/form.tpl');
die();
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

manage the database in backend

![Adminer in Shopware](http://i.imgur.com/eWSl5K3.png)
## MySQL
![Adminer in Shopware](https://ipfs.io/ipfs/QmdUVhnuzidwqQgyAi7bd4hJAM26GEw7afR7Abx2ep1Kj9)


## ElasticSearch
![Adminer in Shopware](https://ipfs.io/ipfs/QmUpjMBEHM7To2h9WUtE2dFHMDxNA778VS3FM2pEtYWGJ4)

# Installation

## Zip Installation package for the Shopware Plugin Manager

* Download the [latest plugin version](https://github.com/shyim/adminer-for-shopware/releases/latest/) (e.g. `AdminerForShopware-1.1.1.zip`)
* Download the [latest plugin version](https://github.com/shyim/adminer-for-shopware/releases/latest/) (e.g. `AdminerForShopware-1.3.0.zip`)
* Upload and install plugin using Plugin Manager

## Install with composer
Expand Down
13 changes: 11 additions & 2 deletions Resources/menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@
<entries>
<entry>
<name>AdminerMySQL</name>
<label lang="en">Adminer</label>
<label lang="de">Adminer</label>
<label lang="en">Adminer (MySQL)</label>
<label lang="de">Adminer (MySQL)</label>
<controller>Adminer</controller>
<action>index</action>
<class>sprite-gear</class>
<parent identifiedBy="controller">ConfigurationMenu</parent>
</entry>
<entry>
<name>AdminerElastic</name>
<label lang="en">Adminer (ElasticSearch)</label>
<label lang="de">Adminer (ElasticSearch)</label>
<controller>Adminer</controller>
<action>elasticSearch</action>
<class>sprite-gear</class>
<parent identifiedBy="controller">ConfigurationMenu</parent>
</entry>
</entries>
</menu>
13 changes: 13 additions & 0 deletions Resources/services.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>
<service id="adminer.menu_subscriber" class="AdminerForShopware\Subscriber\MenuSubscriber">
<argument>%shopware.es.enabled%</argument>
<tag name="shopware.event_subscriber"/>
</service>
</services>
</container>
4 changes: 3 additions & 1 deletion Resources/views/backend/adminer/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Ext.define('Shopware.apps.Adminer', {
],

launch: function() {
return Ext.create('Shopware.apps.Adminer.view.Window');
return Ext.create('Shopware.apps.Adminer.view.Window', {
action: this.action
});
}
});
14 changes: 9 additions & 5 deletions Resources/views/backend/adminer/form.tpl
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<form action="{$postUri}" method="post">
<input type="hidden" name="auth[driver]" value="server">
<input type="hidden" name="auth[server]" value="{$dbData.host}:{$dbData.port}">
<input type="hidden" name="auth[username]" value="{$dbData.username}">
<input type="hidden" name="auth[password]" value="{$dbData.password|escape}">
<input type="hidden" name="auth[db]" value="{$dbData.dbname}">
<input type="hidden" name="auth[driver]" value="{$driver}">
{if $driver === "server"}
<input type="hidden" name="auth[server]" value="{$dbData.host}:{$dbData.port}">
<input type="hidden" name="auth[username]" value="{$dbData.username}">
<input type="hidden" name="auth[password]" value="{$dbData.password|escape}">
<input type="hidden" name="auth[db]" value="{$dbData.dbname}">
{else}
<input type="hidden" name="auth[server]" value="{$esData.client.hosts[0]}">
{/if}
</form>
<script>
document.querySelector("form").submit();
Expand Down
4 changes: 3 additions & 1 deletion Resources/views/backend/adminer/view/window.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Ext.define('Shopware.apps.Adminer.view.Window', {

me.items = [{
xtype: 'container',
html: '<iframe id="test" src="{url action=form}?__csrf_token=' + token + '"></iframe>',
html: '<iframe id="test" src="{url action=form}?adminerAction=' + me.action +'&__csrf_token=' + token + '"></iframe>',
listeners: {
'afterrender': function () {
this.getEl().dom.children[0].onload = function () {
Expand All @@ -25,5 +25,7 @@ Ext.define('Shopware.apps.Adminer.view.Window', {
}
}];
me.callParent(arguments);

me.setTitle('Adminer (' + (me.action === 'index' ? 'MySQL' : 'ElasticSearch') + ')');
}
});
57 changes: 57 additions & 0 deletions Subscriber/MenuSubscriber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace AdminerForShopware\Subscriber;

use Enlight\Event\SubscriberInterface;

/**
* Class MenuSubscriber
* @package AdminerForShopware\Subscriber
*/
class MenuSubscriber implements SubscriberInterface
{
/**
* @var bool
*/
private $esEnabled;

/**
* MenuSubscriber constructor.
* @param bool $esEnabled
*/
public function __construct($esEnabled)
{
$this->esEnabled = $esEnabled;
}

/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
'Enlight_Controller_Action_PostDispatch_Backend_Index' => 'onPostDispatchBackendIndex'
];
}

public function onPostDispatchBackendIndex(\Enlight_Event_EventArgs $args) {
/** @var \Shopware_Controllers_Backend_Index $subject */
$subject = $args->getSubject();

if ($subject->Request()->getActionName() === 'menu') {
$menu = $subject->View()->getAssign('menu');

foreach ($menu as &$menuItem) {
foreach ($menuItem['children'] as $key => $children) {
if ($children['controller'] === 'Adminer' && $children['action'] === 'elasticSearch') {
if (!$this->esEnabled) {
unset($menuItem['children'][$key]);
}
}
}
}

$subject->View()->assign('menu', $menu);
}
}
}

0 comments on commit bd69b07

Please sign in to comment.