From cd3426b25b0951dcac99f4fff3b050b9b8dd7026 Mon Sep 17 00:00:00 2001 From: Lucas van Staden Date: Thu, 22 Dec 2016 10:15:39 +0800 Subject: [PATCH] pure reformat --- .../Block/Adminhtml/Dashboard/Diagrams.php | 53 ++++---- .../Adminhtml/Dashboard/Tab/Newrelic.php | 44 +++--- .../Form/Field/Button/Accountdetails.php | 66 ++++----- .../Config/Form/Field/Button/Appnames.php | 66 ++++----- .../System/Config/Form/Field/Graphurl.php | 45 ++++--- .../Config/Form/Field/Ignoremessage.php | 45 ++++--- .../System/Config/Form/Field/Ignoremodule.php | 45 ++++--- .../System/Config/Form/Field/Tracers.php | 45 ++++--- .../ProxiBlue/NewRelic/Exception.php | 36 ++--- .../ProxiBlue/NewRelic/Helper/Data.php | 127 ++++++++++-------- .../ProxiBlue/NewRelic/Model/Abstract.php | 49 ++++--- .../System/Config/Source/Select/Appnames.php | 58 ++++---- .../ProxiBlue/NewRelic/Model/Api.php | 2 +- .../ProxiBlue/NewRelic/Model/Cache.php | 44 +++--- .../ProxiBlue/NewRelic/Model/Index.php | 44 +++--- .../NewRelic/Model/Log/Exception.php | 76 ++++++----- .../ProxiBlue/NewRelic/Model/Log/System.php | 58 ++++---- .../NewRelic/Model/Log/Writer/Stream.php | 58 ++++---- .../ProxiBlue/NewRelic/Model/Metrics.php | 49 +++---- .../ProxiBlue/NewRelic/Model/Observer.php | 83 ++++++------ .../NewRelic/Model/Predispatch/Observer.php | 11 +- .../NewRelic/controllers/ApiController.php | 67 ++++----- .../NewRelic/controllers/TestController.php | 50 +++---- .../ProxiBlue/NewRelic/etc/adminhtml.xml | 40 +++--- .../ProxiBlue/NewRelic/etc/system.xml | 12 +- .../mysql4-install-0.0.1.php | 34 ++--- app/code/local/Mage/Core/Exception.php | 31 +++-- .../dashboard/proxiblue_newrelic.phtml | 2 +- 28 files changed, 707 insertions(+), 633 deletions(-) diff --git a/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/Dashboard/Diagrams.php b/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/Dashboard/Diagrams.php index be94fec..4845d30 100755 --- a/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/Dashboard/Diagrams.php +++ b/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/Dashboard/Diagrams.php @@ -1,46 +1,47 @@ -. - **/ +. + **/ ?> addTab('newrelic', array( - 'label' => $this->__('NewRelic'), - 'content' => $this->getLayout()->createBlock('proxiblue_newrelic/adminhtml_dashboard_tab_newrelic')->toHtml(), - )); + $this->addTab( + 'newrelic', array( + 'label' => $this->__('NewRelic'), + 'content' => $this->getLayout()->createBlock('proxiblue_newrelic/adminhtml_dashboard_tab_newrelic') + ->toHtml(), + ) + ); } return $this; - + } } \ No newline at end of file diff --git a/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/Dashboard/Tab/Newrelic.php b/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/Dashboard/Tab/Newrelic.php index 7467b51..1100585 100755 --- a/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/Dashboard/Tab/Newrelic.php +++ b/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/Dashboard/Tab/Newrelic.php @@ -1,34 +1,33 @@ -. - **/ +. + **/ ?> setTemplate('dashboard/proxiblue_newrelic.phtml'); } - public function getEmbededGraphs(){ + public function getEmbededGraphs() + { $embeddedGraphs = unserialize(Mage::getStoreConfig('proxiblue_newrelic/embeded/graph')); if (!is_array($embeddedGraphs)) { $embeddedGraphs = array(); diff --git a/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/System/Config/Form/Field/Button/Accountdetails.php b/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/System/Config/Form/Field/Button/Accountdetails.php index 396cb43..e55e5f9 100755 --- a/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/System/Config/Form/Field/Button/Accountdetails.php +++ b/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/System/Config/Form/Field/Button/Accountdetails.php @@ -1,55 +1,59 @@ -. - **/ +. + **/ ?> -setElement($element); - $url = Mage::helper("adminhtml")->getUrl("proxiblue_newrelic/api/accountDetails/",array('id'=>Mage::getStoreConfig('newrelic/api/api_key'))); + $url = Mage::helper("adminhtml")->getUrl( + "proxiblue_newrelic/api/accountDetails/", array('id' => Mage::getStoreConfig('newrelic/api/api_key')) + ); $html = $this->getLayout()->createBlock('adminhtml/widget_button') - ->setType('button') - ->setClass('scalable') - ->setLabel('Fetch Account Details') - ->setOnClick("fetchAccountDetails('{$url}')") - ->toHtml(); + ->setType('button') + ->setClass('scalable') + ->setLabel('Fetch Account Details') + ->setOnClick("fetchAccountDetails('{$url}')") + ->toHtml(); $html .= $this->addActionJs(); return $html; } - - private function addActionJs(){ + + private function addActionJs() + { $script = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS) . 'newrelic.js'; - $js = ''; + $js = ''; return $js; } } + ?> \ No newline at end of file diff --git a/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/System/Config/Form/Field/Button/Appnames.php b/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/System/Config/Form/Field/Button/Appnames.php index f87d9f0..eadfe3c 100755 --- a/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/System/Config/Form/Field/Button/Appnames.php +++ b/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/System/Config/Form/Field/Button/Appnames.php @@ -1,56 +1,60 @@ -. - **/ +. + **/ ?> -setElement($element); - $url = Mage::helper("adminhtml")->getUrl("proxiblue_newrelic/api/names/",array('id'=>Mage::getStoreConfig('newrelic/api/api_key'))); + $url = Mage::helper("adminhtml")->getUrl( + "proxiblue_newrelic/api/names/", array('id' => Mage::getStoreConfig('newrelic/api/api_key')) + ); $html = $this->getLayout()->createBlock('adminhtml/widget_button') - ->setType('button') - ->setClass('scalable') - ->setLabel('Fetch Application Names') - ->setOnClick("fetchApplicationNames('{$url}')") - ->toHtml(); + ->setType('button') + ->setClass('scalable') + ->setLabel('Fetch Application Names') + ->setOnClick("fetchApplicationNames('{$url}')") + ->toHtml(); $html .= $this->addActionJs(); return $html; } - - private function addActionJs(){ + + private function addActionJs() + { $script = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS) . 'newrelic.js'; - $js = ''; + $js = ''; return $js; } } + ?> \ No newline at end of file diff --git a/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/System/Config/Form/Field/Graphurl.php b/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/System/Config/Form/Field/Graphurl.php index 13e99eb..4b37422 100755 --- a/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/System/Config/Form/Field/Graphurl.php +++ b/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/System/Config/Form/Field/Graphurl.php @@ -1,41 +1,42 @@ -. - **/ +. + **/ ?> addColumn('string', array( + $this->addColumn( + 'string', array( 'label' => Mage::helper('proxiblue_newrelic')->__('String'), 'style' => 'width:300px', - )); + ) + ); $this->_addAfter = false; $this->_addButtonLabel = Mage::helper('proxiblue_newrelic')->__('Add New Graph'); parent::__construct(); diff --git a/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/System/Config/Form/Field/Ignoremessage.php b/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/System/Config/Form/Field/Ignoremessage.php index b53732a..6a75160 100755 --- a/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/System/Config/Form/Field/Ignoremessage.php +++ b/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/System/Config/Form/Field/Ignoremessage.php @@ -1,41 +1,42 @@ -. - **/ +. + **/ ?> addColumn('string', array( + $this->addColumn( + 'string', array( 'label' => Mage::helper('proxiblue_newrelic')->__('String'), 'style' => 'width:200px', - )); + ) + ); $this->_addAfter = false; $this->_addButtonLabel = Mage::helper('proxiblue_newrelic')->__('Add New Ignore'); parent::__construct(); diff --git a/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/System/Config/Form/Field/Ignoremodule.php b/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/System/Config/Form/Field/Ignoremodule.php index b77b4d8..01ad930 100755 --- a/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/System/Config/Form/Field/Ignoremodule.php +++ b/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/System/Config/Form/Field/Ignoremodule.php @@ -1,41 +1,42 @@ -. - **/ +. + **/ ?> addColumn('string', array( + $this->addColumn( + 'string', array( 'label' => Mage::helper('proxiblue_newrelic')->__('Module Name'), 'style' => 'width:200px', - )); + ) + ); $this->_addAfter = false; $this->_addButtonLabel = Mage::helper('proxiblue_newrelic')->__('Add New Ignore'); parent::__construct(); diff --git a/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/System/Config/Form/Field/Tracers.php b/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/System/Config/Form/Field/Tracers.php index d623b3e..098cd59 100644 --- a/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/System/Config/Form/Field/Tracers.php +++ b/app/code/community/ProxiBlue/NewRelic/Block/Adminhtml/System/Config/Form/Field/Tracers.php @@ -1,41 +1,42 @@ -. - **/ +. + **/ ?> addColumn('string', array( + $this->addColumn( + 'string', array( 'label' => Mage::helper('proxiblue_newrelic')->__('class::method'), 'style' => 'width:400px', - )); + ) + ); $this->_addAfter = false; $this->_addButtonLabel = Mage::helper('proxiblue_newrelic')->__('New Tracer'); parent::__construct(); diff --git a/app/code/community/ProxiBlue/NewRelic/Exception.php b/app/code/community/ProxiBlue/NewRelic/Exception.php index 0c63c48..3cb1e68 100755 --- a/app/code/community/ProxiBlue/NewRelic/Exception.php +++ b/app/code/community/ProxiBlue/NewRelic/Exception.php @@ -1,21 +1,21 @@ -. - **/ +. + **/ ?> . - **/ +. + **/ ?> 0) { array_walk($ignoreList, array($this, 'cleanIgnoreList')); //$ignoreList = array_filter($ignoreList, 'strlen'); - return $this->ignoreInString($message, $ignoreList); + return $this->ignoreInString($message, $ignoreList); } } catch (Exception $e) { return true; } return false; // default - ignore none } - + /** * Reformat the config array - * + * * @param array $item * @param string $key */ - public function cleanIgnoreList(&$item, $key) { + public function cleanIgnoreList(&$item, $key) + { $item = $item['string']; } /** * Check if any of the strings are in the message - * + * * @param string $message * @param array $ignores * @return bool */ - private function ignoreInString($message, $ignores) { - $quotedIgnoreArray = array_map(function ($ignore) { - return preg_quote($ignore, '/'); - }, array_values($ignores)); + private function ignoreInString($message, $ignores) + { + $quotedIgnoreArray = array_map( + function ($ignore) { + return preg_quote($ignore, '/'); + }, array_values($ignores) + ); $regexp = '/' . implode('|', $quotedIgnoreArray) . '/i'; - return (bool) preg_match($regexp, $message); + return (bool)preg_match($regexp, $message); } - + /** - * Test the given API key is correct - * + * Test the given API key is correct + * * @param string $apiKey * @return boolean */ - - public function testApiKey($apiKey){ - if($apiKey != Mage::getStoreConfig('newrelic/api/api_key')){ + + public function testApiKey($apiKey) + { + if ($apiKey != Mage::getStoreConfig('newrelic/api/api_key')) { return false; } return true; } - - public function customMetric($name,$value){ - + + public function customMetric($name, $value) + { + if (extension_loaded('newrelic')) { - try { - if(!is_numeric($value)){ + try { + if (!is_numeric($value)) { throw new Exception('Metric value must be numeric value'); } $this->setAppName(); - return newrelic_custom_metric('Custom/'.$name, $value); - } catch (Exception $e) { - Mage::logException($e); - } + return newrelic_custom_metric('Custom/' . $name, $value); + } catch (Exception $e) { + Mage::logException($e); + } } return false; } - + /** * Test if a message should be ignored - * + * * @param string $message * @param string $type * @return boolean */ - public function ignoreModule($module) { + public function ignoreModule($module) + { try { $ignoreList = unserialize(Mage::getStoreConfig('newrelic/settings/ignore_modules')); if (is_array($ignoreList) && count($ignoreList) > 0) { array_walk($ignoreList, array($this, 'cleanIgnoreList')); //$ignoreList = array_filter($ignoreList, 'strlen'); - return $this->ignoreInString($module, $ignoreList); + return $this->ignoreInString($module, $ignoreList); } } catch (Exception $e) { return true; } return false; // default - ignore none } - + /** * Helper function to set the application name used to report */ - public function setAppName($xmit = true){ + public function setAppName($xmit = true) + { if (extension_loaded('newrelic')) { $application_name = Mage::getStoreConfig('newrelic/api/application_name'); $license_key = Mage::getStoreConfig('newrelic/api/license_key'); - return newrelic_set_appname($application_name,$license_key,$xmit); + return newrelic_set_appname($application_name, $license_key, $xmit); } } - public function is_enabled(){ - return Mage::getStoreConfig('newrelic/api/is_enabled'); + public function is_enabled() + { + return Mage::getStoreConfig('newrelic/api/is_enabled'); } } diff --git a/app/code/community/ProxiBlue/NewRelic/Model/Abstract.php b/app/code/community/ProxiBlue/NewRelic/Model/Abstract.php index cdf953c..eac7e75 100755 --- a/app/code/community/ProxiBlue/NewRelic/Model/Abstract.php +++ b/app/code/community/ProxiBlue/NewRelic/Model/Abstract.php @@ -1,7 +1,7 @@ . * */ ?> @@ -22,12 +22,13 @@ /** * Base functions to communicate with new relic - * + * * @category ProxiBlue * @package ProxiBlue_NewRelic * @author Lucas van Staden (support@proxiblue.com.au) * */ -class ProxiBlue_NewRelic_Model_Abstract { +class ProxiBlue_NewRelic_Model_Abstract +{ protected $_eventType = 'Unknown'; protected $_headers; @@ -37,7 +38,8 @@ class ProxiBlue_NewRelic_Model_Abstract { protected $_enabled = true; protected $_userAgentString = 'ProxiBlue NewRelic for Magento'; - public function __construct() { + public function __construct() + { $this->_userAgentString .= '/' . $this->getExtensionVersion(); $this->_userAgentString .= ' (https://github.com/ProxiBlue/NewRelic)'; try { @@ -48,7 +50,7 @@ public function __construct() { $this->setDefaults(0); } catch (Exception $e) { $this->_enabled = false; - mage::logException($e); + Mage::logException($e); } if (empty($this->_account_Id) || empty($this->_api_key) || empty($this->_data_key)) { $this->_enabled = false; @@ -59,7 +61,8 @@ public function __construct() { * Try and load the newrelic configuration for store * @param type $store */ - private function setDefaults($store = null) { + private function setDefaults($store = null) + { $this->_account_Id = Mage::getStoreConfig('newrelic/api/account_id', $store); $this->_api_key = Mage::getStoreConfig('newrelic/api/api_key', $store); $this->_data_key = Mage::getStoreConfig('newrelic/api/data_access_key', $store); @@ -69,16 +72,18 @@ private function setDefaults($store = null) { * If configuration is not set, this will result in false * @return type */ - public function getEnabled() { + public function getEnabled() + { return $this->_enabled; } /** * Record index events via curl * @param string $type - * @return \ProxiBlue_NewRelic_Model_Observer + * @return \ProxiBlue_NewRelic_Model_Observer */ - public function recordEvent($message) { + public function recordEvent($message) + { $type = $this->_eventType . ": " . $message; $application_name = Mage::getStoreConfig('newrelic/api/application_name'); $user = $this->getCurrentUser(); @@ -89,7 +94,9 @@ public function recordEvent($message) { try { $response = $this->talkToNewRelic($data); if (Mage::app()->getStore()->isAdmin() && !empty($response)) { - Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__("Event recorded in NewRelic : " . $type)); + Mage::getSingleton('adminhtml/session')->addSuccess( + Mage::helper('adminhtml')->__("Event recorded in NewRelic : " . $type) + ); } } catch (Exception $e) { throw ProxiBlue_NewRelic_Exception($e); @@ -100,27 +107,33 @@ public function recordEvent($message) { /** * Get the current user, be it admin or frontend */ - public function getCurrentUser() { + public function getCurrentUser() + { if (Mage::app()->getStore()->isAdmin()) { if (is_object(Mage::getSingleton('admin/session')->getUser())) { return Mage::getSingleton('admin/session')->getUser()->getEmail(); } else { return 'Shell Script'; } - } else if (Mage::getSingleton('customer/session')->isLoggedIn()) { - return Mage::getSingleton('customer/session')->getCustomer()->getId() . ' / ' . Mage::getSingleton('customer/session')->getCustomer()->getEmail(); } else { - return 'Guest User - not Logged in'; + if (Mage::getSingleton('customer/session')->isLoggedIn()) { + return Mage::getSingleton('customer/session')->getCustomer()->getId() . ' / ' . Mage::getSingleton( + 'customer/session' + )->getCustomer()->getEmail(); + } else { + return 'Guest User - not Logged in'; + } } } /** * Talk to NewRelic API - * + * * @param array $data * @return string */ - public function talkToNewRelic($data) { + public function talkToNewRelic($data) + { $headers = array( 'x-api-key:' . $this->_api_key, 'User-Agent:' . $this->_userAgentString @@ -134,7 +147,7 @@ public function talkToNewRelic($data) { public function getExtensionVersion() { - return (string) Mage::getConfig()->getNode()->modules->ProxiBlue_NewRelic->version; + return (string)Mage::getConfig()->getNode()->modules->ProxiBlue_NewRelic->version; } diff --git a/app/code/community/ProxiBlue/NewRelic/Model/Adminhtml/System/Config/Source/Select/Appnames.php b/app/code/community/ProxiBlue/NewRelic/Model/Adminhtml/System/Config/Source/Select/Appnames.php index 35ca4e3..c8a6955 100755 --- a/app/code/community/ProxiBlue/NewRelic/Model/Adminhtml/System/Config/Source/Select/Appnames.php +++ b/app/code/community/ProxiBlue/NewRelic/Model/Adminhtml/System/Config/Source/Select/Appnames.php @@ -1,52 +1,52 @@ -. - **/ +. + **/ ?> _appnames = unserialize($appnames); } - + /** * Options getter * @@ -56,12 +56,12 @@ public function toOptionArray() { $optionArray = array(); try { - foreach ($this->_appnames as $appname){ - $optionArray[] = array('value' => $appname, 'label'=>$appname); + foreach ($this->_appnames as $appname) { + $optionArray[] = array('value' => $appname, 'label' => $appname); } - } catch (Exception $e){ + } catch (Exception $e) { Mage::logException($e); - } + } return $optionArray; } diff --git a/app/code/community/ProxiBlue/NewRelic/Model/Api.php b/app/code/community/ProxiBlue/NewRelic/Model/Api.php index 8277431..b8ce024 100644 --- a/app/code/community/ProxiBlue/NewRelic/Model/Api.php +++ b/app/code/community/ProxiBlue/NewRelic/Model/Api.php @@ -54,7 +54,7 @@ public function getApplications() } catch (Exception $e) { return array('error' => $result); } - + } /** diff --git a/app/code/community/ProxiBlue/NewRelic/Model/Cache.php b/app/code/community/ProxiBlue/NewRelic/Model/Cache.php index 6501db1..b1837b6 100755 --- a/app/code/community/ProxiBlue/NewRelic/Model/Cache.php +++ b/app/code/community/ProxiBlue/NewRelic/Model/Cache.php @@ -1,34 +1,34 @@ -. - **/ +. + **/ ?> . - **/ +. + **/ ?> . - **/ +. + **/ ?> ignoreMessage($e->getMessage(), 'exception')){ - self::pushEvent($e); - } + public function recordEvent($e) + { + if (Mage::getStoreConfig('newrelic/settings/record_exception') + && !Mage::helper('proxiblue_newrelic')->ignoreMessage($e->getMessage(), 'exception') + ) { + self::pushEvent($e); + } } - + /** * Static since a store config exception (caused by a module config error) cannot call magento's model objects. * If a store config exception occurs, the exception class logs it direct. - * + * * @param type $e */ - static public function pushEvent($e,$setAppName=true){ + static public function pushEvent($e, $setAppName = true) + { if (extension_loaded('newrelic')) { $message = $e->getMessage(); - $message = (empty($message))?get_class($e):$message; - if($setAppName) { + $message = (empty($message)) ? get_class($e) : $message; + if ($setAppName) { Mage::helper('proxiblue_newrelic')->setAppName(); - } - newrelic_notice_error ($message, $e); - } + } + newrelic_notice_error($message, $e); + } } - + } \ No newline at end of file diff --git a/app/code/community/ProxiBlue/NewRelic/Model/Log/System.php b/app/code/community/ProxiBlue/NewRelic/Model/Log/System.php index ce0dc6f..e618a92 100755 --- a/app/code/community/ProxiBlue/NewRelic/Model/Log/System.php +++ b/app/code/community/ProxiBlue/NewRelic/Model/Log/System.php @@ -1,49 +1,57 @@ -. - **/ +. + **/ ?> ignoreMessage($event['message'], 'system_log')) { - if ($event['priorityName'] == 'DEBUG' && Mage::getStoreConfig('newrelic/settings/system_log_ignore_debug')) { + if (Mage::getStoreConfig('newrelic/settings/record_system_log') + && !Mage::helper('proxiblue_newrelic')->ignoreMessage($event['message'], 'system_log') + ) { + if ($event['priorityName'] == 'DEBUG' + && Mage::getStoreConfig( + 'newrelic/settings/system_log_ignore_debug' + ) + ) { return; } Mage::helper('proxiblue_newrelic')->setAppName(); - newrelic_notice_error($this->_eventType . ': [' . $event['priorityName'] . '] '. $event['message']); + newrelic_notice_error($this->_eventType . ': [' . $event['priorityName'] . '] ' . $event['message']); } } } diff --git a/app/code/community/ProxiBlue/NewRelic/Model/Log/Writer/Stream.php b/app/code/community/ProxiBlue/NewRelic/Model/Log/Writer/Stream.php index 2e014d0..5e7b79b 100755 --- a/app/code/community/ProxiBlue/NewRelic/Model/Log/Writer/Stream.php +++ b/app/code/community/ProxiBlue/NewRelic/Model/Log/Writer/Stream.php @@ -1,41 +1,42 @@ -. - **/ +. + **/ ?> recordEvent($event); - } + } } catch (Exception $e) { // cannot log it else we end up in a loop. - } - } + } + } } \ No newline at end of file diff --git a/app/code/community/ProxiBlue/NewRelic/Model/Metrics.php b/app/code/community/ProxiBlue/NewRelic/Model/Metrics.php index 5505dab..bd21c27 100755 --- a/app/code/community/ProxiBlue/NewRelic/Model/Metrics.php +++ b/app/code/community/ProxiBlue/NewRelic/Model/Metrics.php @@ -1,42 +1,43 @@ -. - **/ +. + **/ ?> customMetric('Registration/Success',1); + Mage::helper('proxiblue_newrelic')->customMetric('Registration/Success', 1); return $this; } } diff --git a/app/code/community/ProxiBlue/NewRelic/Model/Observer.php b/app/code/community/ProxiBlue/NewRelic/Model/Observer.php index bee06b6..6efb262 100755 --- a/app/code/community/ProxiBlue/NewRelic/Model/Observer.php +++ b/app/code/community/ProxiBlue/NewRelic/Model/Observer.php @@ -1,34 +1,34 @@ -. - **/ +. + **/ ?> getEvent(); $newRelic = Mage::getModel('proxiblue_newrelic/cache'); @@ -45,7 +46,7 @@ public function adminhtml_cache_refresh_type(Varien_Event_Observer $observer) { return $this; } } - + /** * Hook to record cache full flush * @param Varien_Event_Observer $observer @@ -53,7 +54,8 @@ public function adminhtml_cache_refresh_type(Varien_Event_Observer $observer) { * @return $this \ProxiBlue_NewRelic_Model_Observer */ - public function adminhtml_cache_flush_all(Varien_Event_Observer $observer) { + public function adminhtml_cache_flush_all(Varien_Event_Observer $observer) + { if (Mage::getStoreConfig('newrelic/settings/record_cache')) { $event = $observer->getEvent(); $newRelic = Mage::getModel('proxiblue_newrelic/cache'); @@ -61,7 +63,7 @@ public function adminhtml_cache_flush_all(Varien_Event_Observer $observer) { return $this; } } - + /** * Hook to record cache storage * @@ -70,14 +72,15 @@ public function adminhtml_cache_flush_all(Varien_Event_Observer $observer) { * @return $this \ProxiBlue_NewRelic_Model_Observer */ - public function adminhtml_cache_flush_system(Varien_Event_Observer $observer) { + public function adminhtml_cache_flush_system(Varien_Event_Observer $observer) + { if (Mage::getStoreConfig('newrelic/settings/record_cache')) { $newRelic = Mage::getModel('proxiblue_newrelic/cache'); $newRelic->recordEvent('Full Flush'); return $this; } } - + /** * Hook to record cache storage * @@ -86,7 +89,8 @@ public function adminhtml_cache_flush_system(Varien_Event_Observer $observer) { * @return $this \ProxiBlue_NewRelic_Model_Observer */ - public function clean_media_cache_after(Varien_Event_Observer $observer) { + public function clean_media_cache_after(Varien_Event_Observer $observer) + { if (Mage::getStoreConfig('newrelic/settings/record_cache')) { $newRelic = Mage::getModel('proxiblue_newrelic/cache'); $newRelic->recordEvent('CSS/JS'); @@ -103,7 +107,8 @@ public function clean_media_cache_after(Varien_Event_Observer $observer) { * @return $this \ProxiBlue_NewRelic_Model_Observer */ - public function clean_catalog_images_cache_after(Varien_Event_Observer $observer) { + public function clean_catalog_images_cache_after(Varien_Event_Observer $observer) + { if (Mage::getStoreConfig('newrelic/settings/record_cache')) { $newRelic = Mage::getModel('proxiblue_newrelic/cache'); $newRelic->recordEvent('media'); @@ -119,7 +124,8 @@ public function clean_catalog_images_cache_after(Varien_Event_Observer $observer * @return $this \ProxiBlue_NewRelic_Model_Observer */ - public function clean_configurable_swatches_cache_after(Varien_Event_Observer $observer) { + public function clean_configurable_swatches_cache_after(Varien_Event_Observer $observer) + { if (Mage::getStoreConfig('newrelic/settings/record_cache')) { $newRelic = Mage::getModel('proxiblue_newrelic/cache'); $newRelic->recordEvent('swatch'); @@ -128,7 +134,6 @@ public function clean_configurable_swatches_cache_after(Varien_Event_Observer $o } - /** * Hook to record index events * @@ -136,10 +141,11 @@ public function clean_configurable_swatches_cache_after(Varien_Event_Observer $o * * @return $this \ProxiBlue_NewRelic_Model_Observer */ - public function controller_action_postdispatch_adminhtml_process_massReindex(Varien_Event_Observer $observer) { + public function controller_action_postdispatch_adminhtml_process_massReindex(Varien_Event_Observer $observer) + { if (Mage::getStoreConfig('newrelic/settings/record_index')) { $vProcessIds = Mage::app()->getRequest()->getParam('process'); - $aProcessIds = (array) $vProcessIds; + $aProcessIds = (array)$vProcessIds; if (empty($aProcessIds) || !is_array($aProcessIds)) { return $this; } else { @@ -148,10 +154,10 @@ public function controller_action_postdispatch_adminhtml_process_massReindex(Var $indexer = Mage::getSingleton('index/indexer'); foreach ($aProcessIds as $processId) { /* @var $process Mage_Index_Model_Process */ - $process = $indexer->getProcessById($processId); - if($process) { + $process = $indexer->getProcessById($processId); + if ($process) { $newRelic->recordEvent($process->getIndexerCode()); - } + } } } catch (Exception $e) { Mage::logException($e); @@ -163,9 +169,10 @@ public function controller_action_postdispatch_adminhtml_process_massReindex(Var /** * Hook to record index events - * @param Varien_Event_Observer $observer + * @param Varien_Event_Observer $observer */ - public function controller_action_postdispatch_adminhtml_process_reindexProcess(Varien_Event_Observer $observer) { + public function controller_action_postdispatch_adminhtml_process_reindexProcess(Varien_Event_Observer $observer) + { $this->controller_action_postdispatch_adminhtml_process_massReindex($observer); } diff --git a/app/code/community/ProxiBlue/NewRelic/Model/Predispatch/Observer.php b/app/code/community/ProxiBlue/NewRelic/Model/Predispatch/Observer.php index 40283d5..1033219 100644 --- a/app/code/community/ProxiBlue/NewRelic/Model/Predispatch/Observer.php +++ b/app/code/community/ProxiBlue/NewRelic/Model/Predispatch/Observer.php @@ -53,7 +53,7 @@ public function controller_action_predispatch(Varien_Event_Observer $observer) return $this; } - if (mage::helper('proxiblue_newrelic')->ignoreModule($request->getModuleName()) === true) { + if (Mage::helper('proxiblue_newrelic')->ignoreModule($request->getModuleName()) === true) { Mage::helper('proxiblue_newrelic')->setAppName(false); newrelic_ignore_transaction(); newrelic_ignore_apdex(); @@ -62,9 +62,8 @@ public function controller_action_predispatch(Varien_Event_Observer $observer) } if (Mage::getStoreConfig('newrelic/settings/named_transactions')) { $route - = - $request->getRouteName() . '/' . $request->getControllerName() . '/' . $request->getActionName( - ); + = $request->getRouteName() . '/' . $request->getControllerName() . '/' + . $request->getActionName(); if (Mage::getStoreConfig('newrelic/settings/add_module_to_named_transactions')) { $route .= ' (module: ' . $request->getModuleName() . ')'; } @@ -82,14 +81,14 @@ public function controller_action_predispatch(Varien_Event_Observer $observer) } } } catch (Exception $e) { - mage::logException($e); + Mage::logException($e); } } /** * Reformat the config array * - * @param array $item + * @param array $item * @param string $key */ public function cleanTacerList(&$item, $key) diff --git a/app/code/community/ProxiBlue/NewRelic/controllers/ApiController.php b/app/code/community/ProxiBlue/NewRelic/controllers/ApiController.php index f74d16a..44af329 100755 --- a/app/code/community/ProxiBlue/NewRelic/controllers/ApiController.php +++ b/app/code/community/ProxiBlue/NewRelic/controllers/ApiController.php @@ -1,52 +1,55 @@ -. - **/ +. + **/ ?> testApiKey($this->getRequest()->getParam('id'))) { + public function namesAction() + { + if (Mage::helper('proxiblue_newrelic')->testApiKey($this->getRequest()->getParam('id'))) { $newRelicApi = Mage::getModel('proxiblue_newrelic/api'); $applications = $newRelicApi->getApplications(); $this->getResponse()->setHeader('Content-type', 'application/json'); - $this->getResponse()->setBody(json_encode(array('result'=>$applications))); - } else { + $this->getResponse()->setBody(json_encode(array('result' => $applications))); + } else { $this->getResponse()->setHeader('Content-type', 'application/json'); - $this->getResponse()->setBody(json_encode(array('error'=>'Invalid API key given'))); - } + $this->getResponse()->setBody(json_encode(array('error' => 'Invalid API key given'))); + } return $this; } - - public function accountDetailsAction() { - if(Mage::helper('proxiblue_newrelic')->testApiKey($this->getRequest()->getParam('id'))) { + + public function accountDetailsAction() + { + if (Mage::helper('proxiblue_newrelic')->testApiKey($this->getRequest()->getParam('id'))) { $newRelicApi = Mage::getModel('proxiblue_newrelic/api'); $accountDetails = $newRelicApi->getAccountDetails(); $this->getResponse()->setHeader('Content-type', 'application/json'); $this->getResponse()->setBody(json_encode($accountDetails)); } else { $this->getResponse()->setHeader('Content-type', 'application/json'); - $this->getResponse()->setBody(json_encode(array('error'=>'Invalid API key given'))); - } + $this->getResponse()->setBody(json_encode(array('error' => 'Invalid API key given'))); + } return $this; - + } } \ No newline at end of file diff --git a/app/code/community/ProxiBlue/NewRelic/controllers/TestController.php b/app/code/community/ProxiBlue/NewRelic/controllers/TestController.php index fa07a1b..3a40e89 100755 --- a/app/code/community/ProxiBlue/NewRelic/controllers/TestController.php +++ b/app/code/community/ProxiBlue/NewRelic/controllers/TestController.php @@ -1,27 +1,29 @@ -. - **/ +. + **/ ?> testApiKey($this->getRequest()->getParam('key'))) { Mage::log('This is a newrelic test system log entry'); die('Test log Entry done. Wait a moment and check newrelic errors.'); @@ -31,7 +33,8 @@ public function systemLogAction() { } } - public function exceptionLogAction() { + public function exceptionLogAction() + { if (Mage::helper('proxiblue_newrelic')->testApiKey($this->getRequest()->getParam('key'))) { try { Mage::throwException('Test exception thrown'); @@ -44,8 +47,9 @@ public function exceptionLogAction() { $this->getResponse()->setBody(json_encode(array('error' => 'Invalid API key given'))); } } - - public function exceptionAction(){ + + public function exceptionAction() + { $this->_forward('exceptionLog'); } diff --git a/app/code/community/ProxiBlue/NewRelic/etc/adminhtml.xml b/app/code/community/ProxiBlue/NewRelic/etc/adminhtml.xml index 11bb019..fdeb63f 100755 --- a/app/code/community/ProxiBlue/NewRelic/etc/adminhtml.xml +++ b/app/code/community/ProxiBlue/NewRelic/etc/adminhtml.xml @@ -1,22 +1,22 @@ - - - - - - - - - - - NewRelic - - - - - - - - - + + + + + + + + + + + NewRelic + + + + + + + + + \ No newline at end of file diff --git a/app/code/community/ProxiBlue/NewRelic/etc/system.xml b/app/code/community/ProxiBlue/NewRelic/etc/system.xml index 0fc70ea..0f15d34 100644 --- a/app/code/community/ProxiBlue/NewRelic/etc/system.xml +++ b/app/code/community/ProxiBlue/NewRelic/etc/system.xml @@ -88,15 +88,15 @@ 1 - - + + text 1 1 1 1 - + @@ -219,14 +219,14 @@ - + text 3 1 1 1 - + @@ -265,7 +265,7 @@ 1 1 1 - How to find your graph urls]]> + How to find your graph urls]]> diff --git a/app/code/community/ProxiBlue/NewRelic/sql/proxiblue_newrelic_setup/mysql4-install-0.0.1.php b/app/code/community/ProxiBlue/NewRelic/sql/proxiblue_newrelic_setup/mysql4-install-0.0.1.php index 557ce16..e658bce 100755 --- a/app/code/community/ProxiBlue/NewRelic/sql/proxiblue_newrelic_setup/mysql4-install-0.0.1.php +++ b/app/code/community/ProxiBlue/NewRelic/sql/proxiblue_newrelic_setup/mysql4-install-0.0.1.php @@ -1,21 +1,21 @@ . - **/ +/** + * This file is part of ProxiBlue NewRelic Module available via GitHub https://github.com/ProxiBlue/NewRelic + * + * ProxiBlue NewRelic Module 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, or + * (at your option) any later version. + * + * ProxiBlue NewRelic Module 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 ProxiBlue NewRelic Module. + * If not, see . + **/ ?> . * */ @@ -26,12 +26,14 @@ * @category Mage * @package Mage_Core */ -class Mage_Core_Exception extends Exception { +class Mage_Core_Exception extends Exception +{ protected $_messages = array(); protected $_lastException = null; - public function addMessage(Mage_Core_Model_Message_Abstract $message) { + public function addMessage(Mage_Core_Model_Message_Abstract $message) + { if (!isset($this->_messages[$message->getType()])) { $this->_messages[$message->getType()] = array(); } @@ -39,7 +41,8 @@ public function addMessage(Mage_Core_Model_Message_Abstract $message) { return $this; } - public function getMessages($type = '') { + public function getMessages($type = '') + { if ('' == $type) { $arrRes = array(); foreach ($this->_messages as $messageType => $messages) { @@ -57,7 +60,8 @@ public function getMessages($type = '') { * @param bool $append * @return Mage_Core_Exception */ - public function setMessage($message, $append = false) { + public function setMessage($message, $append = false) + { if ($append) { $this->message .= $message; } else { @@ -68,9 +72,10 @@ public function setMessage($message, $append = false) { /** * Additions by ProxiBlue to log exceptions with new relic. - * + * */ - public function __construct($message = '', $code = 0, $previous = null) { + public function __construct($message = '', $code = 0, $previous = null) + { parent::__construct($message, $code, $previous); if ($this instanceof Mage_Core_Model_Store_Exception || $this instanceof ProxiBlue_NewRelic_Exception) { // this is a store or newrelic module exception @@ -83,10 +88,12 @@ public function __construct($message = '', $code = 0, $previous = null) { $maxTraceItterations = 100; // 100 seems like a safe test. If this test works, a config option would be created to allow users to set this. foreach ($stackTrace as $_trace) { - if($maxTraceItterations == 0) { + if ($maxTraceItterations == 0) { break; } - if (is_array($_trace) && array_key_exists('class', $_trace) && $_trace['class'] == 'Mage_Core_Model_Config') { + if (is_array($_trace) && array_key_exists('class', $_trace) + && $_trace['class'] == 'Mage_Core_Model_Config' + ) { // some config issue, log it direct ProxiBlue_NewRelic_Model_Log_Exception::pushEvent($this, false); return $this; @@ -96,7 +103,9 @@ public function __construct($message = '', $code = 0, $previous = null) { } $newRelic = Mage::getModel('proxiblue_newrelic/log_Exception'); // make sure we have an object here! - if (is_object($newRelic) && $newRelic instanceof ProxiBlue_NewRelic_Model_Log_Exception && $newRelic->getEnabled()) { + if (is_object($newRelic) && $newRelic instanceof ProxiBlue_NewRelic_Model_Log_Exception + && $newRelic->getEnabled() + ) { $newRelic->recordEvent($this); } } diff --git a/app/design/adminhtml/default/default/template/dashboard/proxiblue_newrelic.phtml b/app/design/adminhtml/default/default/template/dashboard/proxiblue_newrelic.phtml index 55412e4..fc9c4bf 100755 --- a/app/design/adminhtml/default/default/template/dashboard/proxiblue_newrelic.phtml +++ b/app/design/adminhtml/default/default/template/dashboard/proxiblue_newrelic.phtml @@ -1,7 +1,7 @@
getEmbededGraphs() as $graphUrl): ?> - + Error: Embedded data could not be displayed.