Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 7a7a3f0f69fd056d762a66618ea74f73f4686cf8 Peter Jaap Blaakmeer committed Aug 22, 2012
@@ -0,0 +1,14 @@
+Magento Exceptions to Codebase
+=================
+
+## Introduction ##
+This Magento extension inserts all the Magento exceptions to your Codebase account (see http://blog.atechmedia.com/2012/08/exception-tracking-in-codebase/).
+
+## Requirements ##
+* Codebase account (www.codebasehq.com)
+* Magento >= 1.5
+
+## Installation ##
+``cd /path/to/your/magento/root
+git clone git@github.com:elgentos/CodebaseExceptions.git CodebaseExceptions
+cp -R CodebaseExceptions/* .``
@@ -0,0 +1,49 @@
+<?php
+
+class Elgentos_CodebaseExceptions_Helper_Data extends Mage_Core_Helper_Abstract {
+
+ public function __construct() {
+ if(Mage::getStoreConfig('codebaseexceptions/general/disabled')) return;
+
+ require_once Mage::getBaseDir('lib') . '/Airbrake/Client.php';
+ require_once Mage::getBaseDir('lib') . '/Airbrake/Configuration.php';
+
+ $apiKey = '0e806c08-1ce1-2a5f-672a-92509a8a9f81'; // This is required
+ $options = array();
+ $requestUri = explode("/",$_SERVER['REQUEST_URI']);
+ $options['action'] = array_pop($requestUri);
+ $options['component'] = implode('/',array_slice($requestUri,-2));
+ $projectRoot = explode('/',$_SERVER['PHP_SELF']);
+ array_pop($projectRoot);
+ $options['projectRoot'] = implode('/',$projectRoot).'/';
+ if(stripos($_SERVER['HTTP_HOST'],'dev.')!==false) {
+ $options['environmentName'] = 'development';
+ $devs = array('peterjaap','janhenk','wouter');
+ foreach($devs as $dev) {
+ if(substr($_SERVER['REQUEST_URI'],1,strlen($dev))==$dev) {
+ $options['environmentName'] .= ' - ' . $dev;
+ }
+ }
+ }
+ $config = new Airbrake\Configuration($apiKey,$options);
+ $this->client = new Airbrake\Client($config);
+ }
+
+ public function insertException($reportData) {
+ if(Mage::getStoreConfig('codebaseexceptions/general/disabled')) return;
+ $backtraceLines = explode("\n",$reportData[1]);
+ foreach($backtraceLines as $backtrace) {
+ $temp = array();
+ $parts = explode(': ',$backtrace);
+ $temp['function'] = $parts[1];
+ $temp['file'] = substr($parts[0],0,stripos($parts[0],'('));
+ $temp['line'] = substr($parts[0],stripos($parts[0],'(')+1,(stripos($parts[0],')')-1)-stripos($parts[0],'('));
+
+ if(!empty($temp['function'])) {
+ $backtraces[] = $temp;
+ }
+ }
+
+ $this->client->notifyOnError($reportData[0],$backtraces);
+ }
+}
@@ -0,0 +1,8 @@
+<?php
+class Elgentos_CodebaseExceptions_IndexController extends Mage_Core_Controller_Front_Action {
+
+ public function testAction() {
+ throw new Exception('This is just a test exception to check whether the extension is working.');
+ }
+
+}
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<config>
+ <acl>
+ <resources>
+ <admin>
+ <children>
+ <system>
+ <children>
+ <config>
+ <children>
+ <codebaseexceptions translate="title" module="codebaseexceptions">
+ <title>CodebaseExceptions</title>
+ </codebaseexceptions>
+ </children>
+ </config>
+ </children>
+ </system>
+ </children>
+ </admin>
+ </resources>
+ </acl>
+</config>
@@ -0,0 +1,59 @@
+<?xml version="1.0"?>
+<config>
+ <modules>
+ <Elgentos_CodebaseExceptions>
+ <version>0.1.0</version>
+ </Elgentos_CodebaseExceptions>
+ </modules>
+ <adminhtml>
+ <translate>
+ <modules>
+ <Elgentos_CodebaseExceptions>
+ <files>
+ <default>Elgentos_CodebaseExceptions.csv</default>
+ </files>
+ </Elgentos_CodebaseExceptions>
+ </modules>
+ </translate>
+
+ <acl>
+ <resources>
+ <admin>
+ <children>
+ <system>
+ <children>
+ <config>
+ <children>
+ <codebaseexceptions translate="title" module="codebaseexceptions">
+ <title>CodebaseExceptions</title>
+ </codebaseexceptions>
+ </children>
+ </config>
+ </children>
+ </system>
+ </children>
+ </admin>
+ </resources>
+ </acl>
+ </adminhtml>
+
+ <frontend>
+ <routers>
+ <exceptions>
+ <use>standard</use>
+ <args>
+ <module>Elgentos_CodebaseExceptions</module>
+ <frontName>exceptions</frontName>
+ </args>
+ </exceptions>
+ </routers>
+ </frontend>
+
+ <global>
+ <helpers>
+ <codebaseexceptions>
+ <class>Elgentos_CodebaseExceptions_Helper</class>
+ </codebaseexceptions>
+ </helpers>
+ </global>
+</config>
@@ -0,0 +1,50 @@
+<?xml version="1.0"?>
+<config>
+ <tabs>
+ <elgentos>
+ <label>Elgentos</label>
+ <sort_order>195</sort_order>
+ </elgentos>
+ </tabs>
+ <sections>
+ <codebaseexceptions translate="label" module="codebaseexceptions">
+ <label>CodebaseExceptions</label>
+ <tab>elgentos</tab>
+ <frontend_type>text</frontend_type>
+ <sort_order>71</sort_order>
+ <show_in_default>1</show_in_default>
+ <show_in_website>1</show_in_website>
+ <show_in_store>1</show_in_store>
+ <groups>
+ <general translate="label">
+ <label>General</label>
+ <expanded>1</expanded>
+ <sort_order>600</sort_order>
+ <show_in_default>1</show_in_default>
+ <show_in_website>1</show_in_website>
+ <show_in_store>1</show_in_store>
+ <fields>
+ <disabled translate="label">
+ <label>Disable module</label>
+ <frontend_type>select</frontend_type>
+ <source_model>adminhtml/system_config_source_yesno</source_model>
+ <sort_order>10</sort_order>
+ <show_in_default>1</show_in_default>
+ <show_in_website>1</show_in_website>
+ <show_in_store>1</show_in_store>
+ </disabled>
+ <apikey translate="label">
+ <label>Codebase Exceptions API key</label>
+ <frontend_type>text</frontend_type>
+
+ <sort_order>20</sort_order>
+ <show_in_default>1</show_in_default>
+ <show_in_website>1</show_in_website>
+ <show_in_store>1</show_in_store>
+ </apikey>
+ </fields>
+ </general>
+ </groups>
+ </codebaseexceptions>
+ </sections>
+</config>
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+ <config>
+ <modules>
+ <Elgentos_CodebaseExceptions>
+ <active>true</active>
+ <codePool>local</codePool>
+ </Elgentos_CodebaseExceptions>
+ </modules>
+ </config>
@@ -0,0 +1,36 @@
+<?php
+/**
+ * Magento
+ *
+ * NOTICE OF LICENSE
+ *
+ * This source file is subject to the Open Software License (OSL 3.0)
+ * that is bundled with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://opensource.org/licenses/osl-3.0.php
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@magentocommerce.com so we can send you a copy immediately.
+ *
+ * DISCLAIMER
+ *
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
+ * versions in the future. If you wish to customize Magento for your
+ * needs please refer to http://www.magentocommerce.com for more information.
+ *
+ * @category Mage
+ * @package Errors
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
+ */
+
+require_once 'processor.php';
+
+$processor = new Error_Processor();
+
+if (isset($reportData) && is_array($reportData)) {
+ $processor->saveReport($reportData);
+ Mage::helper('codebaseexceptions')->insertException($reportData);
+}
+
+$processor->processReport();
@@ -0,0 +1,120 @@
+<?php
+namespace Airbrake;
+
+use Exception;
+
+require_once realpath(__DIR__.'/Record.php');
+require_once realpath(__DIR__.'/Configuration.php');
+require_once realpath(__DIR__.'/Connection.php');
+require_once realpath(__DIR__.'/Version.php');
+require_once realpath(__DIR__.'/Exception.php');
+require_once realpath(__DIR__.'/Notice.php');
+require_once realpath(__DIR__.'/Resque/NotifyJob.php');
+
+/**
+ * Airbrake client class.
+ *
+ * @package Airbrake
+ * @author Drew Butler <drew@abstracting.me>
+ * @copyright (c) 2011 Drew Butler
+ * @license http://www.opensource.org/licenses/mit-license.php
+ */
+class Client
+{
+ protected $configuration = null;
+ protected $connection = null;
+ protected $notice = null;
+
+ /**
+ * Build the Client with the Airbrake Configuration.
+ *
+ * @throws Airbrake\Exception
+ * @param Configuration $configuration
+ */
+ public function __construct(Configuration $configuration)
+ {
+ $configuration->verify();
+
+ $this->configuration = $configuration;
+ $this->connection = new Connection($configuration);
+ }
+
+ /**
+ * Notify on an error message.
+ *
+ * @param string $message
+ * @param array $backtrace
+ * @return string
+ */
+ public function notifyOnError($message, array $backtrace = null)
+ {
+ if (!$backtrace) {
+ $backtrace = debug_backtrace();
+ if (count($backtrace) > 1) {
+ array_shift($backtrace);
+ }
+ }
+
+ $notice = new Notice;
+ $notice->load(array(
+ 'errorClass' => 'PHP Error',
+ 'backtrace' => $backtrace,
+ 'errorMessage' => $message,
+ ));
+
+ return $this->notify($notice);
+ }
+
+ /**
+ * Notify on an exception
+ *
+ * @param Airbrake\Notice $notice
+ * @return string
+ */
+ public function notifyOnException(Exception $exception)
+ {
+ $notice = new Notice;
+ $notice->load(array(
+ 'errorClass' => get_class($exception),
+ 'backtrace' => $this->cleanBacktrace($exception->getTrace() ?: debug_backtrace()),
+ 'errorMessage' => $exception->getMessage(),
+ ));
+
+ return $this->notify($notice);
+ }
+
+ /**
+ * Notify about the notice.
+ *
+ * If there is a PHP Resque client given in the configuration, then use that to queue up a job to
+ * send this out later. This should help speed up operations.
+ *
+ * @param Airbrake\Notice $notice
+ */
+ public function notify(Notice $notice)
+ {
+ if (class_exists('Resque') && $this->configuration->queue) {
+ //print_r($notice);exit;
+ $data = array('notice' => serialize($notice), 'configuration' => serialize($this->configuration));
+ \Resque::enqueue($this->configuration->queue, 'Airbrake\\Resque\\NotifyJob', $data);
+ return;
+ }
+
+ return $this->connection->send($notice);
+ }
+
+ /**
+ * Clean the backtrace of unneeded junk.
+ *
+ * @param array $backtrace
+ * @return array
+ */
+ protected function cleanBacktrace($backtrace)
+ {
+ foreach ($backtrace as &$item) {
+ unset($item['args']);
+ }
+
+ return $backtrace;
+ }
+}
Oops, something went wrong.

0 comments on commit 7a7a3f0

Please sign in to comment.