Beamngain_Logdownload - Version 0.1.0

Version Notes

This plugin allows you to download the log file generated by magento i,e at following path : app/var/log/.
Generally in magento application it become hard to debug the issue which is related to system, exception or general PHP error.
This extension allow you to download file other than log file like system and exception file. You only need to specify the correct file name.

Download this release

Release Info

Developer Quality Unit, LLC
Extension Beamngain_Logdownload
Version 0.1.0
Comparing to
See all releases


Version 0.1.0

app/code/local/Beamngain/Logdownload/Block/Adminhtml/System/Config/Form/DownloadButton.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Beamngain_Logdownload_Block_Adminhtml_System_Config_Form_DownloadButton extends Mage_Adminhtml_Block_System_Config_Form_Field {
4
+
5
+ /**
6
+ * Set template
7
+ */
8
+
9
+ protected function _construct() {
10
+ parent::_construct();
11
+ $this->setTemplate('beamngain/system/config/form/download_button.phtml');
12
+ }
13
+
14
+ /**
15
+ * Return element html
16
+ *
17
+ * @param Varien_Data_Form_Element_Abstract $element
18
+ * @return string
19
+ */
20
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
21
+ return $this->_toHtml();
22
+ }
23
+
24
+ /**
25
+ * Generate button html
26
+ *
27
+ * @return string
28
+ */
29
+ public function getButtonHtml() {
30
+ $button = $this->getLayout()->createBlock('adminhtml/widget_button')->setData(array('id' => 'locayta_log_download_button', 'label' => Mage::helper('logdownload')->__('Download Log File'), 'onclick' => 'javascript:download_log_file(); return false;'));
31
+
32
+ return $button->toHtml();
33
+ }
34
+
35
+ /**
36
+ * Return log check url for button
37
+ *
38
+ * @return string
39
+ */
40
+ public function getAjaxUrl() {
41
+ return Mage::helper("adminhtml")->getUrl("adminhtml/logdownload_log/check");
42
+ }
43
+
44
+
45
+ /**
46
+ * Return log download url for button
47
+ *
48
+ * @return string
49
+ */
50
+ public function getDownloadUrl() {
51
+ return Mage::helper("adminhtml")->getUrl("adminhtml/logdownload_log/download");
52
+ }
53
+ }
app/code/local/Beamngain/Logdownload/Helper/Data.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * General helper
5
+ */
6
+ class Beamngain_Logdownload_Helper_Data extends Mage_Core_Helper_Abstract {
7
+
8
+ }
app/code/local/Beamngain/Logdownload/controllers/Adminhtml/Logdownload/LogController.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * A Log controller, used to download the logs
5
+ */
6
+ class Beamngain_Logdownload_Adminhtml_Logdownload_LogController extends Mage_Core_Controller_Front_Action {
7
+
8
+ /**
9
+ * Read log file
10
+ */
11
+ public function read_file($file, $lines) {
12
+ //global $fsize;
13
+ $handle = fopen($file, "r");
14
+ $linecounter = $lines;
15
+ $pos = -2;
16
+ $beginning = false;
17
+ $text = array();
18
+ while ($linecounter > 0) {
19
+ $t = " ";
20
+ while ($t != "\n") {
21
+ if (fseek($handle, $pos, SEEK_END) == -1) {
22
+ $beginning = true;
23
+ break;
24
+ }
25
+ $t = fgetc($handle);
26
+ $pos --;
27
+ }
28
+ $linecounter --;
29
+ if ($beginning) {
30
+ rewind($handle);
31
+ }
32
+ $text[$lines - $linecounter - 1] = fgets($handle);
33
+ if ($beginning)
34
+ break;
35
+ }
36
+ fclose($handle);
37
+ return array_reverse($text);
38
+ }
39
+
40
+ /**
41
+ * check log file
42
+ */
43
+ public function checkAction() {
44
+
45
+ $fileName = Mage::getStoreConfig('logdownload/general/log_file_name');
46
+ $filePath = Mage::getBaseDir('var') . "/log/" . $fileName;
47
+
48
+ if (file_exists($filePath)) {
49
+ if (is_readable($filePath)) {
50
+ echo Mage::helper('logdownload')->__('success');
51
+ } else {
52
+ echo Mage::helper('logdownload')->__('file is not readable.');
53
+ }
54
+ } else {
55
+
56
+ echo Mage::helper('logdownload')->__('The provided file path is not valid.');
57
+
58
+
59
+ }
60
+
61
+ }
62
+
63
+ /**
64
+ * Download log file
65
+ */
66
+ public function downloadAction() {
67
+
68
+
69
+ $fileName = Mage::getStoreConfig('logdownload/general/log_file_name');
70
+ $filePath = Mage::getBaseDir('var') . "/log/" . $fileName;
71
+ $line_count_bottom = Mage::getStoreConfig('logdownload/general/log_count_bottom');
72
+
73
+
74
+ $fileSize = filesize($filePath);
75
+ header("Content-type: text/plain");
76
+ header("Cache-Control: private");
77
+ header("Content-Disposition: attachment; filename=" . $fileName);
78
+
79
+ if ($line_count_bottom && (!$line_count_bottom == '')) {
80
+ $fsize = round(filesize($filePath) / 1024 / 1024, 2);
81
+ $lines = $this->read_file($filePath, $line_count_bottom);
82
+ $output = '';
83
+ foreach ($lines as $line) {
84
+ $output .= $line;
85
+ }
86
+ echo $output;
87
+ } else {
88
+
89
+ // Output file.
90
+ readfile($filePath);
91
+ exit();
92
+ }
93
+
94
+ }
95
+
96
+ }
app/code/local/Beamngain/Logdownload/etc/adminhtml.xml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <adminhtml>
3
+ <acl>
4
+ <resources>
5
+ <admin>
6
+ <children>
7
+ <system>
8
+ <children>
9
+ <config>
10
+ <children>
11
+ <logdownload>
12
+ <title>Beam and Gain - All</title>
13
+ </logdownload>
14
+ </children>
15
+ </config>
16
+ </children>
17
+ </system>
18
+ </children>
19
+ </admin>
20
+ </resources>
21
+ </acl>
22
+ </adminhtml>
app/code/local/Beamngain/Logdownload/etc/config.xml ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Beamngain_Logdownload>
5
+ <version>0.1.0</version>
6
+ </Beamngain_Logdownload>
7
+ </modules>
8
+ <admin>
9
+ <routers>
10
+ <adminhtml>
11
+ <args>
12
+ <modules>
13
+ <logdownload before="Mage_Adminhtml">Beamngain_Logdownload_Adminhtml</logdownload>
14
+ </modules>
15
+ </args>
16
+ </adminhtml>
17
+ </routers>
18
+ </admin>
19
+ <adminhtml>
20
+ <translate>
21
+ <modules>
22
+ <logdownload>
23
+ <files>
24
+ <default>logdownload.csv</default>
25
+ </files>
26
+ </logdownload>
27
+ </modules>
28
+ </translate>
29
+ </adminhtml>
30
+ <global>
31
+ <helpers>
32
+ <logdownload>
33
+ <class>Beamngain_Logdownload_Helper</class>
34
+ </logdownload>
35
+ </helpers>
36
+ </global>
37
+ <default>
38
+ <logdownload>
39
+ <general>
40
+ <log_file_name>system.log</log_file_name>
41
+ <log_count_bottom>100</log_count_bottom>
42
+ </general>
43
+ </logdownload>
44
+ </default>
45
+ </config>
app/code/local/Beamngain/Logdownload/etc/system.xml ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <logdownload_tab translate="label" module="logdownload">
5
+ <label>Beam and Gain Extensions</label>
6
+ <sort_order>10</sort_order>
7
+ </logdownload_tab>
8
+ </tabs>
9
+ <sections>
10
+ <logdownload translate="label" module="logdownload">
11
+ <label>Log Download</label>
12
+ <tab>logdownload_tab</tab>
13
+ <sort_order>100</sort_order>
14
+ <show_in_default>1</show_in_default>
15
+ <show_in_website>1</show_in_website>
16
+ <show_in_store>1</show_in_store>
17
+ <groups>
18
+ <general translate="label">
19
+ <label>Settings</label>
20
+ <frontend_type>text</frontend_type>
21
+ <sort_order>10</sort_order>
22
+ <show_in_default>1</show_in_default>
23
+ <show_in_website>1</show_in_website>
24
+ <show_in_store>1</show_in_store>
25
+ <fields>
26
+ <log_file_name translate="label">
27
+ <label>Name of log file</label>
28
+ <frontend_type>text</frontend_type>
29
+ <comment>Specify log file name and save before click download button.</comment>
30
+ <sort_order>10</sort_order>
31
+ <show_in_default>1</show_in_default>
32
+ <show_in_website>1</show_in_website>
33
+ <show_in_store>1</show_in_store>
34
+ <validate>required-entry</validate>
35
+ </log_file_name>
36
+ <log_count_bottom translate="label">
37
+ <label>Number of line</label>
38
+ <frontend_type>text</frontend_type>
39
+ <comment>Leave blank to download whole log file otherwise specify last number of lines before click download button.</comment>
40
+ <sort_order>12</sort_order>
41
+ <show_in_default>1</show_in_default>
42
+ <show_in_website>1</show_in_website>
43
+ <show_in_store>1</show_in_store>
44
+ <validate>validate-digits validate-greater-than-zero validate-not-negative-number validate-digits-range digits-range-10-500</validate>
45
+ </log_count_bottom>
46
+ <log_download translate="label">
47
+ <label>Download Log</label>
48
+ <frontend_model>Beamngain_Logdownload_Block_Adminhtml_System_Config_Form_DownloadButton</frontend_model>
49
+ <sort_order>20</sort_order>
50
+ <show_in_default>1</show_in_default>
51
+ <show_in_website>1</show_in_website>
52
+ <show_in_store>1</show_in_store>
53
+ </log_download>
54
+ </fields>
55
+ </general>
56
+ </groups>
57
+ </logdownload>
58
+ </sections>
59
+ </config>
app/design/adminhtml/default/default/template/beamngain/system/config/form/download_button.phtml ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ <script type="text/javascript">
4
+
5
+ //<![CDATA[
6
+
7
+ function download_log_file() {
8
+
9
+ ;
10
+
11
+ new Ajax.Request('<?php echo $this->getAjaxUrl() ?>', {
12
+
13
+ method: 'POST',
14
+
15
+ onSuccess: function(transport){
16
+
17
+ if(transport.status==200){
18
+
19
+ if(transport.responseText == 'success'){
20
+ window.location = '<?php echo $this->getDownloadUrl() ?>';
21
+ } else {
22
+ document.getElementById('feedStatus').innerHTML = transport.responseText;
23
+ document.getElementById('error-msg').style.display = 'block';
24
+ }
25
+ return false;
26
+
27
+ }
28
+
29
+ },
30
+
31
+ onFailure: function(){
32
+
33
+ alert('error');
34
+
35
+ }
36
+
37
+ });
38
+
39
+ }
40
+
41
+ //]]>
42
+
43
+ </script>
44
+
45
+ <?php echo $this->getButtonHtml() ?>
46
+
47
+
48
+ <div id="error-msg" class="error-msg" style="display:none;padding: 10px;margin-top: 10px;">
49
+ <span class="feedStatus" id="feedStatus">
50
+ Success
51
+ </span>
52
+ </div>
app/etc/modules/Beamngain_Logdownload.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Beamngain_Logdownload>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Beamngain_Logdownload>
8
+ </modules>
9
+ </config>
app/locale/en_US/logdownload.csv ADDED
@@ -0,0 +1 @@
 
1
+ "Download Log File","Download Log File"
package.xml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Beamngain_Logdownload</name>
4
+ <version>0.1.0</version>
5
+ <stability>stable</stability>
6
+ <license>OSL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>This plugin allows you to download the log file generated by magento default.</summary>
10
+ <description>This plugin allows you to download the log file generated by magento i,e at following path : app/var/log/.&#xD;
11
+ Generally in magento application it become hard to debug the issue which is related to system, exception or general PHP error.&#xD;
12
+ This extension allow you to download file other than log file like system and exception file. You only need to specify the correct file name.&#xD;
13
+ </description>
14
+ <notes>This plugin allows you to download the log file generated by magento i,e at following path : app/var/log/.&#xD;
15
+ Generally in magento application it become hard to debug the issue which is related to system, exception or general PHP error.&#xD;
16
+ This extension allow you to download file other than log file like system and exception file. You only need to specify the correct file name.</notes>
17
+ <authors><author><name/><user>support</user><email>info@beamngain.com</email></author></authors>
18
+ <date>2016-07-02</date>
19
+ <time>13:28:13</time>
20
+ <contents><target name="magelocal"><dir name="Beamngain"><dir name="Logdownload"><dir name="Block"><dir name="Adminhtml"><dir name="System"><dir name="Config"><dir name="Form"><file name="DownloadButton.php" hash="127a8ae454622d0b844d14aa03bb3db6"/></dir></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="6bfa2e98565a2ef3530b8b865ce03bb2"/></dir><dir name="controllers"><dir name="Adminhtml"><dir name="Logdownload"><file name="LogController.php" hash="3a9a245287482d85c483b403ed94016b"/></dir></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="89a79ac18b53802662d694b1c206d912"/><file name="config.xml" hash="b0b2f74b01aa7f1bd56b605ab755e1b8"/><file name="system.xml" hash="73c6e28a708c23db257b259002302e61"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="beamngain"><dir name="system"><dir name="config"><dir name="form"><file name="download_button.phtml" hash="001f8d9be3d9aecf62bda6d2e20943ce"/></dir></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Beamngain_Logdownload.xml" hash="43d8bcd6f7953f47d6c20f8328fad64f"/></dir></target><target name="magelocale"><dir name="en_US"><file name="logdownload.csv" hash="0da0c0826c2e4549241efb221ecaece6"/></dir></target></contents>
21
+ <compatible/>
22
+ <dependencies><required><php><min>5.2.0</min><max>7.0.0</max></php></required></dependencies>
23
+ </package>