Skip to content

Commit

Permalink
Merge branch '1'
Browse files Browse the repository at this point in the history
  • Loading branch information
robbieaverill committed Nov 3, 2017
2 parents 9f8837a + 2bd4e7e commit 5de9514
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 25 deletions.
2 changes: 1 addition & 1 deletion _config/debugbar.yml
Expand Up @@ -19,7 +19,7 @@ LeKoala\DebugBar\DebugBar:
# Maximum number of queries to display
query_limit: 200
# Number of DB queries before a warning will be displayed
warn_query_limit: 10
warn_query_limit: 100
# When a warning is shown for a high number of DB queries, the following link will be used for a
# performance guide
performance_guide_link: https://docs.silverstripe.org/en/developer_guides/performance/
Expand Down
1 change: 0 additions & 1 deletion assets/debugbar.css
Expand Up @@ -232,7 +232,6 @@ a.phpdebugbar-open-btn {
position: absolute;
top: -30px;
background: #efefef;
opacity: .7;
border: 1px solid #ccc;
color: #555;
font-size: 11px;
Expand Down
8 changes: 4 additions & 4 deletions code/Collector/DatabaseCollector.php
Expand Up @@ -39,9 +39,9 @@ public function collect()
$data = $this->collectData($this->timeCollector);

// Check for excessive number of queries
$dbQueryWarningLevel = DebugBar::config()->warn_query_limit;
$dbQueryWarningLevel = DebugBar::config()->get('warn_query_limit');
if ($dbQueryWarningLevel && $data['nb_statements'] > $dbQueryWarningLevel) {
$helpLink = DebugBar::config()->performance_guide_link;
$helpLink = DebugBar::config()->get('performance_guide_link');
Injector::inst()->get(LoggerInterface::class)
->info(
'This page ran more than ' . $dbQueryWarningLevel . ' database queries. You could reduce this by '
Expand Down Expand Up @@ -82,8 +82,8 @@ protected function collectData(TimeDataCollector $timeCollector = null)
$i = 0;
$queries = $this->db->getQueries();

$limit = DebugBar::config()->query_limit;
$warnDurationThreshold = Config::inst()->get(DebugBar::class, 'warn_dbqueries_threshold_seconds');
$limit = DebugBar::config()->get('query_limit');
$warnDurationThreshold = DebugBar::config()->get('warn_dbqueries_threshold_seconds');

$showDb = count(array_unique(array_map(function ($stmt) {
return $stmt['database'];
Expand Down
7 changes: 3 additions & 4 deletions code/Collector/SilverStripeCollector.php
Expand Up @@ -12,7 +12,7 @@
use SilverStripe\Control\Cookie;
use SilverStripe\Core\Convert;
use SilverStripe\i18n\i18n;
use SilverStripe\Security\Member;
use SilverStripe\Security\Security;
use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\View\Requirements;

Expand All @@ -33,7 +33,7 @@ public function collect()
'cookies' => self::getCookieData(),
'parameters' => self::getRequestParameters(),
'requirements' => self::getRequirementsData(),
'user' => Member::currentUserID() ? Member::currentUser()->Title : 'Not logged in',
'user' => Security::getCurrentUser() ? Security::getCurrentUser()->Title : 'Not logged in',
'templates' => self::getTemplateData(),
);
return $data;
Expand Down Expand Up @@ -165,8 +165,7 @@ public function getWidgets()

$userIcon = 'user-times';
$userText = 'Not logged in';
if (Member::currentUserID()) {
$member = Member::currentUser();
if ($member = Security::getCurrentUser()) {
$memberTag = $member->getTitle() . ' (#' . $member->ID . ')';

$userIcon = 'user';
Expand Down
4 changes: 2 additions & 2 deletions code/Collector/TimeDataCollector.php
Expand Up @@ -16,8 +16,8 @@ public function getWidgets()
{
$widgets = parent::getWidgets();

$upperThreshold = DebugBar::config()->warn_request_time_seconds;
$warningRatio = DebugBar::config()->warn_warning_ratio;
$upperThreshold = DebugBar::config()->get('warn_request_time_seconds');
$warningRatio = DebugBar::config()->get('warn_warning_ratio');

// Can be disabled by setting the value to false
if (!is_numeric($upperThreshold)) {
Expand Down
2 changes: 1 addition & 1 deletion code/Controller.php
Expand Up @@ -16,7 +16,7 @@ class Controller extends BaseController
{
public function index(HTTPRequest $request)
{
if (!DebugBar::config()->enable_storage) {
if (!DebugBar::config()->get('enable_storage')) {
return $this->httpError(404, 'Storage not enabled');
}
$debugbar = DebugBar::getDebugBar();
Expand Down
18 changes: 9 additions & 9 deletions code/DebugBar.php
Expand Up @@ -81,7 +81,7 @@ public static function getDebugBar()

if (!Director::isDev() || self::isDisabled() || self::vendorNotInstalled() ||
self::notLocalIp() || Director::is_cli() || self::isDevUrl() ||
(self::isAdminUrl() && !self::config()->enabled_in_admin)
(self::isAdminUrl() && !self::config()->get('enabled_in_admin'))
) {
self::$debugbar = false; // no need to check again
return;
Expand Down Expand Up @@ -139,7 +139,7 @@ public static function initDebugBar()
}

$connector = DB::get_connector();
if (!self::config()->force_proxy && $connector instanceof PDOConnector) {
if (!self::config()->get('force_proxy') && $connector instanceof PDOConnector) {
// Use a little bit of magic to replace the pdo instance
$refObject = new ReflectionObject($connector);
$refProperty = $refObject->getProperty('pdoConnection');
Expand All @@ -164,7 +164,7 @@ public static function initDebugBar()
// Add some SilverStripe specific infos
$debugbar->addCollector(new SilverStripeCollector);

if (self::config()->enable_storage) {
if (self::config()->get('enable_storage')) {
$debugbar->setStorage(new FileStorage(TEMP_FOLDER . '/debugbar'));
}

Expand All @@ -175,7 +175,7 @@ public static function initDebugBar()
$debugbar->addCollector(new PartialCacheCollector);

// Since we buffer everything, why not enable all dev options ?
if (self::config()->auto_debug) {
if (self::config()->get('auto_debug')) {
$_REQUEST['debug'] = true;
$_REQUEST['debug_request'] = true;
}
Expand Down Expand Up @@ -222,7 +222,7 @@ public static function includeRequirements()
$renderer->setBasePath(DEBUGBAR_DIR . '/assets');
$renderer->setBaseUrl(DEBUGBAR_DIR . '/assets');

$includeJquery = self::config()->include_jquery;
$includeJquery = self::config()->get('include_jquery');
// In CMS, jQuery is already included
if (self::isAdminController()) {
$includeJquery = false;
Expand All @@ -244,7 +244,7 @@ public static function includeRequirements()
$renderer->setEnableJqueryNoConflict(false);
}

if (DebugBar::config()->enable_storage) {
if (DebugBar::config()->get('enable_storage')) {
$renderer->setOpenHandlerUrl('__debugbar');
}

Expand Down Expand Up @@ -304,7 +304,7 @@ public static function whyDisabled()
if (self::isDevUrl()) {
return 'Dev tools';
}
if (self::isAdminUrl() && !self::config()->enabled_in_admin) {
if (self::isAdminUrl() && !self::config()->get('enabled_in_admin')) {
return 'In admin';
}
return "I don't know why";
Expand All @@ -317,7 +317,7 @@ public static function vendorNotInstalled()

public static function notLocalIp()
{
if (!self::config()->check_local_ip) {
if (!self::config()->get('check_local_ip')) {
return false;
}
if (isset($_SERVER['REMOTE_ADDR'])) {
Expand All @@ -328,7 +328,7 @@ public static function notLocalIp()

public static function isDisabled()
{
if (getenv('DEBUGBAR_DISABLE') || static::config()->disabled) {
if (getenv('DEBUGBAR_DISABLE') || static::config()->get('disabled')) {
return true;
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions code/Middleware/DebugBarMiddleware.php
Expand Up @@ -80,15 +80,15 @@ protected function afterRequest(HTTPRequest $request, HTTPResponse $response)

// Ajax support
if (Director::is_ajax() && !headers_sent()) {
if (DebugBar::isAdminUrl() && !DebugBar::config()->enabled_in_admin) {
if (DebugBar::isAdminUrl() && !DebugBar::config()->get('enabled_in_admin')) {
return;
}
// Skip anything that is not a GET request
if (!$request->isGET()) {
return;
}
// Always enable in admin because everything is mostly loaded through ajax
if (DebugBar::config()->ajax || DebugBar::isAdminUrl()) {
if (DebugBar::config()->get('ajax') || DebugBar::isAdminUrl()) {
$headers = $debugbar->getDataAsHeaders();

// Prevent throwing js errors in case header size is too large
Expand Down
2 changes: 1 addition & 1 deletion code/Proxy/DatabaseProxy.php
Expand Up @@ -52,7 +52,7 @@ public function __construct($realConn)
$this->schemaManager = $realConn->getSchemaManager();
$this->queryBuilder = $realConn->getQueryBuilder();
$this->queries = array();
$this->findSource = DebugBar::config()->find_source;
$this->findSource = DebugBar::config()->get('find_source');
}

public function getShowQueries()
Expand Down

0 comments on commit 5de9514

Please sign in to comment.