Status display of the DB how many queries were processed. (SHOW STATUS)
This commit is contained in:
parent
2410dc3203
commit
7e6687132c
57
src/AutoInstallSmaryPlugin.php
Normal file
57
src/AutoInstallSmaryPlugin.php
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Autor: Tobias Matthaiou <developer@tobimat.eu>
|
||||||
|
* Date: 2019-08-20
|
||||||
|
* Time: 21:33
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace tm\oxid\sql\logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class AutoInstallSmaryPlugin
|
||||||
|
*/
|
||||||
|
class AutoInstallSmaryPlugin
|
||||||
|
{
|
||||||
|
public function runInstall()
|
||||||
|
{
|
||||||
|
$oxideshop_ce = new \SplFileInfo(__DIR__ . '/../../../oxid-esales/oxideshop-ce/source/Core/Smarty/Plugin');
|
||||||
|
$smartyPlugin = new \SplFileInfo(__DIR__ . '/Smarty/function.tm_sql_status.php');
|
||||||
|
|
||||||
|
if ($oxideshop_ce->isDir()) {
|
||||||
|
|
||||||
|
$target = new \SplFileInfo($oxideshop_ce->getRealPath() . '/' . $smartyPlugin->getBasename());
|
||||||
|
|
||||||
|
if ($target->isFile() && $this->isSameFile($target, $smartyPlugin)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->createHardLink($smartyPlugin, $target);
|
||||||
|
|
||||||
|
OxidUtilsView::clearSmarty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \SplFileInfo $target
|
||||||
|
* @param \SplFileInfo $
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function isSameFile(\SplFileInfo $target, \SplFileInfo $smartyPlugin)
|
||||||
|
{
|
||||||
|
return @md5_file($target->getPathname()) == @md5_file($smartyPlugin->getRealPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \SplFileInfo $smarty_func_tm_sql_status
|
||||||
|
* @param \SplFileInfo $target
|
||||||
|
*/
|
||||||
|
protected function createHardLink(\SplFileInfo $smartyPlugin, \SplFileInfo $target)
|
||||||
|
{
|
||||||
|
if ($target->isFile()) {
|
||||||
|
@unlink($target->getPathname());
|
||||||
|
}
|
||||||
|
|
||||||
|
link($smartyPlugin->getPathname(), $target->getPathname());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
24
src/OxidUtilsView.php
Normal file
24
src/OxidUtilsView.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Autor: Tobias Matthaiou <developer@tobimat.eu>
|
||||||
|
* Date: 2019-08-20
|
||||||
|
* Time: 21:33
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace tm\oxid\sql\logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class OxidUtilsView
|
||||||
|
* @package tm\oxid\sql\logger
|
||||||
|
*/
|
||||||
|
class OxidUtilsView extends \OxidEsales\Eshop\Core\UtilsView
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes existing Smarty instance
|
||||||
|
*/
|
||||||
|
public static function clearSmarty()
|
||||||
|
{
|
||||||
|
\OxidEsales\Eshop\Core\UtilsView::$_oSmarty = null;
|
||||||
|
}
|
||||||
|
}
|
55
src/Smarty/function.tm_sql_status.php
Normal file
55
src/Smarty/function.tm_sql_status.php
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Smarty plugin
|
||||||
|
* -------------------------------------------------------------
|
||||||
|
* File: function.tm_sql_status.php
|
||||||
|
* Name: tm_sql_status
|
||||||
|
* Purpose: Output info on SQL dabase queries
|
||||||
|
*
|
||||||
|
* Enable: add in config.inc.php line $this->blSQLStatusBox = true
|
||||||
|
* -------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
function smarty_function_tm_sql_status($aParams, &$smarty)
|
||||||
|
{
|
||||||
|
$myConfig = \OxidEsales\Eshop\Core\Registry::getConfig();
|
||||||
|
|
||||||
|
// muss in config.inc.php gesetzt sein
|
||||||
|
|
||||||
|
$box = $myConfig->getConfigParam('blSQLStatusBox');
|
||||||
|
|
||||||
|
if ($box == false) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = \OxidEsales\Eshop\Core\DatabaseProvider::getDb(\OxidEsales\Eshop\Core\DatabaseProvider::FETCH_MODE_ASSOC);
|
||||||
|
$query = "SHOW STATUS WHERE Variable_name IN ( 'Com_select', 'Com_update', 'Com_insert', 'Com_delete' )";
|
||||||
|
|
||||||
|
$iSelects = $iDeletes = $iInserts = $iUpdates = 0;
|
||||||
|
$rows = $db->getAll($query);
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
switch ($row['Variable_name']) {
|
||||||
|
case 'Com_select':
|
||||||
|
$iSelects = (int)$row['Value'];
|
||||||
|
break;
|
||||||
|
case 'Com_update':
|
||||||
|
$iUpdates = (int)$row['Value'];
|
||||||
|
break;
|
||||||
|
case 'Com_insert':
|
||||||
|
$iInserts = (int)$row['Value'];
|
||||||
|
break;
|
||||||
|
case 'Com_delete':
|
||||||
|
$iDeletes = (int)$row['Value'];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$iSum = $iSelects + $iDeletes + $iInserts + $iUpdates;
|
||||||
|
$sTable = '<style>table#tmqueries { border: 1px solid black; position: fixed; bottom: 15px; left: 0; background-color: aliceblue; z-index: 90009} table#tmqueries td { padding: 6px; text-aligb:center }</style>';
|
||||||
|
$sTable .= '<table id="tmqueries">';
|
||||||
|
$sTable .= "<tr><td> All: $iSum </td><td> SELECT: $iSelects </td><td> UPDATE: $iUpdates </td><td> INSERT: $iInserts </td><td> DELETE: $iDeletes </td></tr>";
|
||||||
|
$sTable .= '</table>';
|
||||||
|
|
||||||
|
return $sTable;
|
||||||
|
}
|
@ -12,3 +12,5 @@ function StartSQLLog() {
|
|||||||
function StopSQLLog() {
|
function StopSQLLog() {
|
||||||
\tm\oxid\sql\logger\OxidEsalesDatabase::disableLogger();
|
\tm\oxid\sql\logger\OxidEsalesDatabase::disableLogger();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(new tm\oxid\sql\logger\AutoInstallSmaryPlugin())->runInstall();
|
||||||
|
Loading…
Reference in New Issue
Block a user