fix tests, edit reset_install.sh, manage payment modules, change debugbar namespace to theliadebugbar
This commit is contained in:
48
local/modules/TheliaDebugBar/Config/config.xml
Executable file
48
local/modules/TheliaDebugBar/Config/config.xml
Executable file
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<config xmlns="http://thelia.net/schema/dic/config"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd">
|
||||
|
||||
<loops>
|
||||
<!-- sample definition
|
||||
<loop name="MySuperLoop" class="MyModule\Loop\MySuperLoop" />
|
||||
-->
|
||||
</loops>
|
||||
|
||||
<forms>
|
||||
<!--
|
||||
<form name="MyFormName" class="MyModule\Form\MySuperForm" />
|
||||
-->
|
||||
</forms>
|
||||
|
||||
<commands>
|
||||
<!--
|
||||
<command class="MyModule\Command\MySuperCommand" />
|
||||
-->
|
||||
</commands>
|
||||
|
||||
<templateDirectives>
|
||||
<!-- Sample definition
|
||||
<templateDirectives class="MyModule\Directive\MyTemplateDirective" name="my_filter"/>
|
||||
-->
|
||||
</templateDirectives>
|
||||
|
||||
|
||||
<services>
|
||||
<service id="debugBar" class="DebugBar\DebugBar"/>
|
||||
|
||||
<service id="smarty.debugbar" class="TheliaDebugBar\Smarty\Plugin\DebugBar">
|
||||
<argument type="service" id="debugBar"/>
|
||||
<argument >%kernel.debug%</argument>
|
||||
<tag name="thelia.parser.register_plugin"/>
|
||||
</service>
|
||||
|
||||
<service id="debugBar.listener" class="TheliaDebugBar\Listeners\DebugBarListeners">
|
||||
<argument type="service" id="service_container"/>
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
</service>
|
||||
</services>
|
||||
|
||||
|
||||
</config>
|
||||
0
local/modules/TheliaDebugBar/Config/plugin.xml
Executable file
0
local/modules/TheliaDebugBar/Config/plugin.xml
Executable file
6
local/modules/TheliaDebugBar/Config/schema.xml
Executable file
6
local/modules/TheliaDebugBar/Config/schema.xml
Executable file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<database defaultIdMethod="native" name="thelia" namespace="TheliaDebugBar\Model">
|
||||
<!--
|
||||
See propel documentation on http://propelorm.org for all information about schema file
|
||||
-->
|
||||
</database>
|
||||
285
local/modules/TheliaDebugBar/DataCollector/PropelCollector.php
Executable file
285
local/modules/TheliaDebugBar/DataCollector/PropelCollector.php
Executable file
@@ -0,0 +1,285 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace TheliaDebugBar\DataCollector;
|
||||
|
||||
use DebugBar\DataCollector\DataCollector;
|
||||
use DebugBar\DataCollector\Renderable;
|
||||
use Propel\Runtime\Propel;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
|
||||
/**
|
||||
* Class PropelCollector
|
||||
* @package TheliaDebugBar\DataCollector
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class PropelCollector extends DataCollector implements Renderable, LoggerInterface
|
||||
{
|
||||
|
||||
protected $statements = array();
|
||||
|
||||
protected $accumulatedTime = 0;
|
||||
|
||||
protected $peakMemory = 0;
|
||||
|
||||
protected $alternativeLogger;
|
||||
|
||||
public function __construct(LoggerInterface $alternativeLogger = null)
|
||||
{
|
||||
$serviceContainer = Propel::getServiceContainer();
|
||||
$serviceContainer->setLogger('defaultLogger', $this);
|
||||
|
||||
$con = Propel::getConnection(\Thelia\Model\Map\ProductTableMap::DATABASE_NAME);
|
||||
$con->setLogMethods(array(
|
||||
'exec',
|
||||
'query',
|
||||
'execute', // these first three are the default
|
||||
'beginTransaction',
|
||||
'commit',
|
||||
'rollBack',
|
||||
));
|
||||
|
||||
$this->alternativeLogger = $alternativeLogger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the DebugBar when data needs to be collected
|
||||
*
|
||||
* @return array Collected data
|
||||
*/
|
||||
function collect()
|
||||
{
|
||||
return array(
|
||||
'nb_statements' => count($this->statements),
|
||||
'nb_failed_statements' => 0,
|
||||
'accumulated_duration' => $this->accumulatedTime,
|
||||
'accumulated_duration_str' => $this->formatDuration($this->accumulatedTime),
|
||||
'peak_memory_usage' => $this->peakMemory,
|
||||
'peak_memory_usage_str' => $this->formatBytes($this->peakMemory),
|
||||
'statements' => $this->statements
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the unique name of the collector
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'propel';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hash where keys are control names and their values
|
||||
* an array of options as defined in {@see DebugBar\JavascriptRenderer::addControl()}
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getWidgets()
|
||||
{
|
||||
return array(
|
||||
"propel" => array(
|
||||
"widget" => "PhpDebugBar.Widgets.SQLQueriesWidget",
|
||||
"map" => "propel",
|
||||
"default" => "[]"
|
||||
),
|
||||
"propel:badge" => array(
|
||||
"map" => "propel.nb_statements",
|
||||
"default" => 0
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs with an arbitrary level.
|
||||
*
|
||||
* @param mixed $level
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function log($level, $message, array $context = array())
|
||||
{
|
||||
list($sql, $duration_str) = $this->parseAndLogSqlQuery($message);
|
||||
|
||||
$message = "$sql ($duration_str)";
|
||||
|
||||
if ($this->alternativeLogger) {
|
||||
$this->alternativeLogger->log($level, $message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a log line to extract query information
|
||||
*
|
||||
* @param string $message
|
||||
*/
|
||||
protected function parseAndLogSqlQuery($message)
|
||||
{
|
||||
$parts = explode('|', $message, 3);
|
||||
$duration = 0;
|
||||
$memory = 0;
|
||||
if (count($parts) > 1) {
|
||||
$sql = trim($parts[2]);
|
||||
|
||||
if (preg_match('/([0-9]+\.[0-9]+)/', $parts[0], $matches)) {
|
||||
$duration = (float) $matches[1];
|
||||
}
|
||||
|
||||
if (preg_match('/([0-9]+\.[0-9]+)([A-Z]{1,2})/', $parts[1], $matches)) {
|
||||
$memory = (float) $matches[1];
|
||||
if ($matches[2] == 'KB') {
|
||||
$memory *= 1024;
|
||||
} else if ($matches[2] == 'MB') {
|
||||
$memory *= 1024 * 1024;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$sql = $parts[0];
|
||||
}
|
||||
|
||||
|
||||
$this->statements[] = array(
|
||||
'sql' => $sql,
|
||||
'is_success' => true,
|
||||
'duration' => $duration,
|
||||
'duration_str' => $this->formatDuration($duration),
|
||||
'memory' => $memory,
|
||||
'memory_str' => $this->formatBytes($memory)
|
||||
);
|
||||
$this->accumulatedTime += $duration;
|
||||
$this->peakMemory = max($this->peakMemory, $memory);
|
||||
return array($sql, $this->formatDuration($duration));
|
||||
}
|
||||
|
||||
/**
|
||||
* System is unusable.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function emergency($message, array $context = array())
|
||||
{
|
||||
$this->log(\Thelia\Log\Tlog::EMERGENCY, $message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Action must be taken immediately.
|
||||
*
|
||||
* Example: Entire website down, database unavailable, etc. This should
|
||||
* trigger the SMS alerts and wake you up.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function alert($message, array $context = array())
|
||||
{
|
||||
$this->log(\Thelia\Log\Tlog::ALERT, $message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Critical conditions.
|
||||
*
|
||||
* Example: Application component unavailable, unexpected exception.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function critical($message, array $context = array())
|
||||
{
|
||||
$this->log(\Thelia\Log\Tlog::CRITICAL, $message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runtime errors that do not require immediate action but should typically
|
||||
* be logged and monitored.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function error($message, array $context = array())
|
||||
{
|
||||
$this->log(\Thelia\Log\Tlog::ERROR, $message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exceptional occurrences that are not errors.
|
||||
*
|
||||
* Example: Use of deprecated APIs, poor use of an API, undesirable things
|
||||
* that are not necessarily wrong.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function warning($message, array $context = array())
|
||||
{
|
||||
$this->log(\Thelia\Log\Tlog::WARNING, $message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normal but significant events.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function notice($message, array $context = array())
|
||||
{
|
||||
$this->log(\Thelia\Log\Tlog::NOTICE, $message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Interesting events.
|
||||
*
|
||||
* Example: User logs in, SQL logs.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function info($message, array $context = array())
|
||||
{
|
||||
$this->log(\Thelia\Log\Tlog::INFO, $message, $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Detailed debug information.
|
||||
*
|
||||
* @param string $message
|
||||
* @param array $context
|
||||
* @return null
|
||||
*/
|
||||
public function debug($message, array $context = array())
|
||||
{
|
||||
$this->log(\Thelia\Log\Tlog::DEBUG, $message, $context);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
83
local/modules/TheliaDebugBar/Listeners/DebugBarListeners.php
Executable file
83
local/modules/TheliaDebugBar/Listeners/DebugBarListeners.php
Executable file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace TheliaDebugBar\Listeners;
|
||||
|
||||
use DebugBar\DataCollector\MemoryCollector;
|
||||
use DebugBar\DataCollector\MessagesCollector;
|
||||
use DebugBar\DataCollector\PhpInfoCollector;
|
||||
use TheliaDebugBar\DataCollector\PropelCollector;
|
||||
use DebugBar\DataCollector\TimeDataCollector;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Thelia\Action\BaseAction;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
|
||||
|
||||
/**
|
||||
* Class DebugBarListeners
|
||||
* @package TheliaDebugBar\Listeners
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class DebugBarListeners extends BaseAction implements EventSubscriberInterface {
|
||||
|
||||
public function initDebugBar()
|
||||
{
|
||||
$debugBar = $this->container->get("debugBar");
|
||||
|
||||
|
||||
$debugBar->addCollector(new PhpInfoCollector());
|
||||
//$debugBar->addCollector(new MessagesCollector());
|
||||
//$debugBar->addCollector(new RequestDataCollector());
|
||||
$debugBar->addCollector(new TimeDataCollector());
|
||||
$debugBar->addCollector(new MemoryCollector());
|
||||
$debugBar->addCollector(new PropelCollector(\Thelia\Log\Tlog::getInstance()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of event names this subscriber wants to listen to.
|
||||
*
|
||||
* The array keys are event names and the value can be:
|
||||
*
|
||||
* * The method name to call (priority defaults to 0)
|
||||
* * An array composed of the method name to call and the priority
|
||||
* * An array of arrays composed of the method names to call and respective
|
||||
* priorities, or 0 if unset
|
||||
*
|
||||
* For instance:
|
||||
*
|
||||
* * array('eventName' => 'methodName')
|
||||
* * array('eventName' => array('methodName', $priority))
|
||||
* * array('eventName' => array(array('methodName1', $priority), array('methodName2'))
|
||||
*
|
||||
* @return array The event names to listen to
|
||||
*
|
||||
* @api
|
||||
*/
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
TheliaEvents::BOOT => array("initDebugBar", 128)
|
||||
);
|
||||
}
|
||||
}
|
||||
118
local/modules/TheliaDebugBar/Smarty/Plugin/DebugBar.php
Executable file
118
local/modules/TheliaDebugBar/Smarty/Plugin/DebugBar.php
Executable file
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace TheliaDebugBar\Smarty\Plugin;
|
||||
use Thelia\Core\Template\Smarty\AbstractSmartyPlugin;
|
||||
use Thelia\Core\Template\Smarty\an;
|
||||
use Thelia\Core\Template\Smarty\SmartyPluginDescriptor;
|
||||
use DebugBar\DebugBar as BaseDebugBar;
|
||||
use Thelia\Tools\URL;
|
||||
|
||||
/**
|
||||
* Class DebugBar
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class DebugBar extends AbstractSmartyPlugin
|
||||
{
|
||||
protected $debugBar;
|
||||
protected $debugMode;
|
||||
|
||||
public function __construct(BaseDebugBar $debugbar, $debugMode)
|
||||
{
|
||||
$this->debugBar = $debugbar;
|
||||
$this->debugMode = $debugMode;
|
||||
}
|
||||
|
||||
public function render($params, \Smarty_Internal_Template $template)
|
||||
{
|
||||
$render = "";
|
||||
if ($this->debugMode) {
|
||||
$render = $this->debugBar->getJavascriptRenderer()->render();
|
||||
}
|
||||
|
||||
return $render;
|
||||
}
|
||||
|
||||
public function renderCss($params, \Smarty_Internal_Template $template)
|
||||
{
|
||||
$render = "";
|
||||
if($this->debugMode)
|
||||
{
|
||||
$webFile = "cache/debugbar.css";
|
||||
$cssFile = THELIA_WEB_DIR ."/".$webFile;
|
||||
|
||||
if(!file_exists($cssFile)) {
|
||||
$javascriptRenderer = $this->debugBar->getJavascriptRenderer();
|
||||
$assetCss = $javascriptRenderer->getAsseticCollection("css");
|
||||
|
||||
foreach($assetCss->all() as $asset) {
|
||||
if(strpos($asset->getSourcePath(), "font-awesome") !== false) {
|
||||
$assetCss->removeLeaf($asset);
|
||||
}
|
||||
}
|
||||
|
||||
file_put_contents($cssFile, $assetCss->dump());
|
||||
}
|
||||
$render = sprintf('<link rel="stylesheet" href="%s">', URL::getInstance()->absoluteUrl($webFile, array(), URL::PATH_TO_FILE));
|
||||
}
|
||||
return $render;
|
||||
}
|
||||
|
||||
public function renderJs($params, \Smarty_Internal_Template $template)
|
||||
{
|
||||
$render = "";
|
||||
if($this->debugMode)
|
||||
{
|
||||
$webFile = "cache/debugbar.js";
|
||||
$cacheFile = THELIA_WEB_DIR ."/".$webFile;
|
||||
|
||||
if (!file_exists($cacheFile)) {
|
||||
$javascriptRenderer = $this->debugBar->getJavascriptRenderer();
|
||||
$assetJs = $javascriptRenderer->getAsseticCollection("js");
|
||||
|
||||
foreach($assetJs->all() as $asset) {
|
||||
if(strpos($asset->getSourcePath(), "jquery") !== false) {
|
||||
$assetJs->removeLeaf($asset);
|
||||
}
|
||||
}
|
||||
|
||||
file_put_contents($cacheFile, $assetJs->dump());
|
||||
}
|
||||
|
||||
$render = sprintf('<script src="%s"></script>', URL::getInstance()->absoluteUrl($webFile, array(), URL::PATH_TO_FILE));
|
||||
}
|
||||
return $render;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return an array of SmartyPluginDescriptor
|
||||
*/
|
||||
public function getPluginDescriptors()
|
||||
{
|
||||
return array(
|
||||
new SmartyPluginDescriptor("function", "debugbar_rendercss", $this, "renderCss"),
|
||||
new SmartyPluginDescriptor("function", "debugbar_renderjs", $this, "renderJs"),
|
||||
new SmartyPluginDescriptor("function", "debugbar_renderresult", $this, "render")
|
||||
);
|
||||
}
|
||||
}
|
||||
54
local/modules/TheliaDebugBar/TheliaDebugBar.php
Executable file
54
local/modules/TheliaDebugBar/TheliaDebugBar.php
Executable file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace TheliaDebugBar;
|
||||
|
||||
use Thelia\Module\BaseModule;
|
||||
|
||||
class TheliaDebugBar extends BaseModule
|
||||
{
|
||||
/**
|
||||
* YOU HAVE TO IMPLEMENT HERE ABSTRACT METHODD FROM BaseModule Class
|
||||
* Like install and destroy
|
||||
*/
|
||||
|
||||
public function afterActivation()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function install()
|
||||
{
|
||||
// TODO: Implement install() method.
|
||||
}
|
||||
|
||||
public function destroy()
|
||||
{
|
||||
// TODO: Implement destroy() method.
|
||||
}
|
||||
|
||||
public function getCode()
|
||||
{
|
||||
return 'TheliaDebugBar';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user