Magalter_Config - Version 1.1.0.0

Version Notes

1.1.0.0

Download this release

Release Info

Developer Magalter
Extension Magalter_Config
Version 1.1.0.0
Comparing to
See all releases


Code changes from version 1.0.0.1 to 1.1.0.0

app/code/local/Magalter/Config/Block/Versions.php ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Magalter_Config_Block_Versions extends Mage_Adminhtml_Block_System_Config_Form_Fieldset
4
+ {
5
+ public function render(Varien_Data_Form_Element_Abstract $element)
6
+ {
7
+ $html = $this->_getHeaderHtml($element);
8
+ $html .= $this->getLayout()->createBlock('magalterconfig/versions_table')->setTemplate('magalter_config/versions/table.phtml')->toHtml();
9
+ $html .= $this->_getFooterHtml($element);
10
+ return $html;
11
+ }
12
+ }
app/code/local/Magalter/Config/Block/Versions/Table.php ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Magalter_Config_Block_Versions_Table extends Mage_Core_Block_Template
4
+ {
5
+ public function getExtensionsInfo()
6
+ {
7
+ $storeInfo = Mage::getModel('magalterconfig/storage')->load('magalterconfig_magalter_response', 'code');
8
+ $extensionsInfo = array();
9
+ if ($storeInfo->getId())
10
+ {
11
+ $decodedStoreInfo = Zend_Json::decode($storeInfo->getData('value'));
12
+ if (isset($decodedStoreInfo['extensions']))
13
+ {
14
+ $extensionsInfo = $decodedStoreInfo['extensions'];
15
+ }
16
+ }
17
+ return $extensionsInfo;
18
+ }
19
+
20
+ public function getExtensionVersion($code)
21
+ {
22
+ $installedMagalterExtensions = Mage::helper('magalterconfig')->getInstalledMagalterExtesions();
23
+ return isset($installedMagalterExtensions[$code]) ? $installedMagalterExtensions[$code]->version : NULL;
24
+ }
25
+ }
app/code/local/Magalter/Config/Helper/Data.php CHANGED
@@ -3,6 +3,20 @@
3
 
4
  class Magalter_Config_Helper_Data extends Mage_Core_Helper_Abstract
5
  {
6
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
  }
3
 
4
  class Magalter_Config_Helper_Data extends Mage_Core_Helper_Abstract
5
  {
6
+ public function getInstalledMagalterExtesions()
7
+ {
8
+ /* Get all installed Magalter extensions */
9
+ $extensions = Mage::getConfig()->getNode('modules')->children();
10
+ $installedMagalterExtensions = array();
11
+ foreach($extensions as $extensionCode => $extensionDescription)
12
+ {
13
+ if (strstr($extensionCode,'Magalter_') === false)
14
+ {
15
+ continue;
16
+ }
17
+ $installedMagalterExtensions[$extensionCode] = $extensionDescription;
18
+ }
19
+ return $installedMagalterExtensions;
20
+ }
21
 
22
  }
app/code/local/Magalter/Config/Model/Mysql4/Storage.php ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Magalter_Config_Model_Mysql4_Storage extends Mage_Core_Model_Mysql4_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ $this->_init('magalterconfig/storage', 'id');
8
+ }
9
+ }
app/code/local/Magalter/Config/Model/Mysql4/Storage/Collection.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Magalter_Config_Model_Mysql4_Storage_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('magalterconfig/storage');
9
+ }
10
+ }
app/code/local/Magalter/Config/Model/Observer.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Magalter_Config_Model_Observer
4
+ {
5
+ const SYNC_URL = "http://www.magalter.com/service/requests/index";
6
+
7
+ public function connectToWebservice()
8
+ {
9
+ $nextUpdateTime = Mage::getModel('magalterconfig/storage')
10
+ ->load('magalterconfig_next_update_time', 'code')
11
+ ->getData('value');
12
+
13
+ /* Check if update time comes */
14
+ if ($nextUpdateTime && $nextUpdateTime > Mage::getModel('core/date')->gmtTimestamp()) return;
15
+
16
+ /* Get all installed Magalter extensions versions */
17
+ $extensions = Mage::getConfig()->getNode('modules')->children();
18
+ $installedExtensionsVersions = array();
19
+ foreach($extensions as $extensionName => $extensionDescription)
20
+ {
21
+ if (strstr($extensionName,'Magalter_') === false) {
22
+ continue;
23
+ }
24
+ $installedExtensionsVersions[] = $extensionName.'-'.$extensionDescription->version;
25
+ }
26
+
27
+ if (!sizeof($installedExtensionsVersions)) return;
28
+
29
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
30
+ /* Request params building */
31
+ $params = 'website='.$baseUrl.'&extensions='.implode(',', $installedExtensionsVersions);
32
+
33
+ try
34
+ {
35
+ $ch = curl_init();
36
+ /* curl post request with 5 seconds timeout, string will be returned */
37
+ curl_setopt($ch, CURLOPT_POST, 1);
38
+ curl_setopt($ch, CURLOPT_URL,self::SYNC_URL);
39
+ curl_setopt($ch, CURLOPT_POSTFIELDS,$params);
40
+ curl_setopt($ch, CURLOPT_TIMEOUT, 5);
41
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
42
+
43
+ $result = curl_exec($ch); //execute and get the results
44
+ curl_close ($ch);
45
+
46
+ $oneDay = 60 * 60 * 24;
47
+ /* Result can be false because of exception or if curl_exec returns false */
48
+ if ($result)
49
+ {
50
+ /* Check if JSON is correct. If not, exception by Zend_Json will be thrown */
51
+ Zend_Json::decode($result);
52
+
53
+ Mage::getModel('magalterconfig/storage')
54
+ ->load('magalterconfig_magalter_response', 'code')
55
+ ->setData('code', 'magalterconfig_magalter_response')
56
+ ->setData('value', $result)
57
+ ->save();
58
+
59
+ /* If all is fine then next update is needed to be processed in 7 days */
60
+ Mage::getModel('magalterconfig/storage')
61
+ ->load('magalterconfig_next_update_time', 'code')
62
+ ->setData('code', 'magalterconfig_next_update_time')
63
+ ->setData('value', Mage::getModel('core/date')->gmtTimestamp() + 7 * $oneDay)
64
+ ->save();
65
+ }
66
+ else
67
+ {
68
+ throw new Exception('Incorrect result');
69
+ }
70
+ }
71
+ catch (Exception $ex)
72
+ {
73
+ /* If exception found then set next update day to the next day, except 7 days as usual */
74
+ Mage::getModel('magalterconfig/storage')
75
+ ->load('magalterconfig_next_update_time', 'code')
76
+ ->setData('code', 'magalterconfig_next_update_time')
77
+ ->setData('value', Mage::getModel('core/date')->gmtTimestamp() + $oneDay)
78
+ ->save();
79
+ }
80
+ }
81
+ }
app/code/local/Magalter/Config/Model/Storage.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Magalter_Config_Model_Storage extends Mage_Core_Model_Abstract
4
+ {
5
+ public function _construct()
6
+ {
7
+ parent::_construct();
8
+ $this->_init('magalterconfig/storage');
9
+ }
10
+ }
app/code/local/Magalter/Config/etc/config.xml CHANGED
@@ -2,15 +2,97 @@
2
  <config>
3
  <modules>
4
  <Magalter_Config>
5
- <version>1.0.0.1</version>
6
  </Magalter_Config>
7
  </modules>
8
 
9
  <global>
10
- <helpers>
11
- <config>
 
 
 
 
 
12
  <class>Magalter_Config_Helper</class>
13
- </config>
14
- </helpers>
15
- </global>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  </config>
2
  <config>
3
  <modules>
4
  <Magalter_Config>
5
+ <version>1.1.0.0</version>
6
  </Magalter_Config>
7
  </modules>
8
 
9
  <global>
10
+ <blocks>
11
+ <magalterconfig>
12
+ <class>Magalter_Config_Block</class>
13
+ </magalterconfig>
14
+ </blocks>
15
+ <helpers>
16
+ <magalterconfig>
17
  <class>Magalter_Config_Helper</class>
18
+ </magalterconfig>
19
+ </helpers>
20
+ <models>
21
+ <magalterconfig>
22
+ <class>Magalter_Config_Model</class>
23
+ <resourceModel>magalterconfig_mysql4</resourceModel>
24
+ </magalterconfig>
25
+ <magalterconfig_mysql4>
26
+ <class>Magalter_Config_Model_Mysql4</class>
27
+ <entities>
28
+ <storage>
29
+ <table>magalter_config_storage</table>
30
+ </storage>
31
+ </entities>
32
+ </magalterconfig_mysql4>
33
+ </models>
34
+ <resources>
35
+ <magalterconfig_setup>
36
+ <setup>
37
+ <module>Magalter_Config</module>
38
+ </setup>
39
+ <connection>
40
+ <use>core_setup</use>
41
+ </connection>
42
+ </magalterconfig_setup>
43
+ <magalterconfig_write>
44
+ <connection>
45
+ <use>core_write</use>
46
+ </connection>
47
+ </magalterconfig_write>
48
+ <magalterconfig_read>
49
+ <connection>
50
+ <use>core_read</use>
51
+ </connection>
52
+ </magalterconfig_read>
53
+ </resources>
54
+ </global>
55
+
56
+ <adminhtml>
57
+ <layout>
58
+ <updates>
59
+ <magalterconfig>
60
+ <file>magalter_config.xml</file>
61
+ </magalterconfig>
62
+ </updates>
63
+ </layout>
64
+ <acl>
65
+ <resources>
66
+ <all>
67
+ <title>Allow Everything</title>
68
+ </all>
69
+ <admin>
70
+ <children>
71
+ <system>
72
+ <children>
73
+ <config>
74
+ <children>
75
+ <magalterconfig>
76
+ <title>Magalter Config Section</title>
77
+ </magalterconfig>
78
+ </children>
79
+ </config>
80
+ </children>
81
+ </system>
82
+ </children>
83
+ </admin>
84
+ </resources>
85
+ </acl>
86
+ <events>
87
+ <controller_action_predispatch>
88
+ <observers>
89
+ <magalter_connect_to_webservice_event>
90
+ <type>singleton</type>
91
+ <class>magalterconfig/observer</class>
92
+ <method>connectToWebservice</method>
93
+ </magalter_connect_to_webservice_event>
94
+ </observers>
95
+ </controller_action_predispatch>
96
+ </events>
97
+ </adminhtml>
98
  </config>
app/code/local/Magalter/Config/etc/system.xml CHANGED
@@ -1,9 +1,30 @@
1
  <?xml version="1.0"?>
2
  <config>
3
  <tabs>
4
- <magalter translate="label" module="config">
5
  <label>Magalter</label>
6
  <sort_order>150</sort_order>
7
  </magalter>
8
- </tabs>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  </config>
1
  <?xml version="1.0"?>
2
  <config>
3
  <tabs>
4
+ <magalter translate="label" module="magalterconfig">
5
  <label>Magalter</label>
6
  <sort_order>150</sort_order>
7
  </magalter>
8
+ </tabs>
9
+ <sections>
10
+ <magalterconfig translate="label" module="magalterconfig">
11
+ <label>Magalter Extensions</label>
12
+ <tab>magalter</tab>
13
+ <frontend_type>text</frontend_type>
14
+ <sort_order>100</sort_order>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>1</show_in_website>
17
+ <show_in_store>1</show_in_store>
18
+ <groups>
19
+ <general>
20
+ <label>Check Version</label>
21
+ <sort_order>5</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
+ <frontend_model>magalterconfig/versions</frontend_model>
26
+ </general>
27
+ </groups>
28
+ </magalterconfig>
29
+ </sections>
30
  </config>
app/code/local/Magalter/Config/sql/magalterconfig_setup/mysql4-install-1.1.0.0.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ $installer = $this;
5
+
6
+ $installer->startSetup();
7
+
8
+ $installer->run("
9
+
10
+ CREATE TABLE IF NOT EXISTS {$this->getTable('magalterconfig/storage')} (
11
+ `id` int(11) NOT NULL auto_increment,
12
+ `code` varchar(255) NOT NULL,
13
+ `value` TEXT,
14
+ PRIMARY KEY (`id`)
15
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
16
+
17
+ ");
18
+
19
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/magalter_config.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <adminhtml_system_config_edit>
4
+ <reference name="head">
5
+ <action method="addCss"><stylesheet>css/magalter_config.css</stylesheet></action>
6
+ </reference>
7
+ </adminhtml_system_config_edit>
8
+ </layout>
app/design/adminhtml/default/default/template/magalter_config/versions/table.phtml ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ $extensionsInfo = $this->getExtensionsInfo();
3
+ ?>
4
+ <table class="magalterconfig-table">
5
+ <thead>
6
+ <tr>
7
+ <th><?php echo $this->__('Name') ?></th>
8
+ <th><?php echo $this->__('Available Version') ?></th>
9
+ <th><?php echo $this->__('Installed Version') ?></th>
10
+ <th></th>
11
+ </tr>
12
+ </thead>
13
+ <tbody>
14
+ <?php foreach ($extensionsInfo as $code => $info): ?>
15
+ <?php $currentVersion = isset($info['version']) ? $info['version'] : NULL; ?>
16
+ <?php $installedVersion = $this->getExtensionVersion($code); ?>
17
+ <tr>
18
+ <td><?php echo isset($info['name']) ? $info['name'] : 'N/A' ?></td>
19
+ <td><?php echo $currentVersion ? $currentVersion : 'N/A' ?></td>
20
+ <td><?php echo $installedVersion ? $installedVersion : 'N/A' ?></td>
21
+ <td>
22
+ <?php if ($currentVersion == $installedVersion): ?>
23
+ <?php echo $this->__('OK') ?>
24
+ <?php else: ?>
25
+ <a href="<?php echo isset($info['url']) ? base64_decode($info['url']) : 'http://www.magalter.com' ?>">
26
+ <?php echo $this->__('Get update') ?>
27
+ </a>
28
+ <?php endif; ?>
29
+ </td>
30
+ </tr>
31
+ <?php endforeach; ?>
32
+ </tbody>
33
+ </table>
34
+
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Magalter_Config</name>
4
- <version>1.0.0.1</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.magalter.com/license">Custom License</license>
7
  <channel>community</channel>
8
  <extends/>
9
- <summary>Magalter configuration extension</summary>
10
- <description>Magalter configuration extension</description>
11
- <notes>Magalter configuration extension</notes>
12
  <authors><author><name>Magalter</name><user>magalter</user><email>admin@magalter.com</email></author></authors>
13
- <date>2011-11-14</date>
14
- <time>23:00:20</time>
15
- <contents><target name="magelocal"><dir name="Magalter"><dir name="Config"><dir name="Helper"><file name="Data.php" hash="49377d074fbfce4b2c504c741d86cd5f"/></dir><dir name="etc"><file name="config.xml" hash="a5fdee867b01007fad1d3da7808686ed"/><file name="system.xml" hash="841f6b6aa6034d5c4ddaa887f91d56ff"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Magalter_Config.xml" hash="ab239b707d6a04aa4369ab322d8137c1"/></dir></target></contents>
16
  <compatible/>
17
- <dependencies><required><php><min>5.2.0</min><max>5.3.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Magalter_Config</name>
4
+ <version>1.1.0.0</version>
5
  <stability>stable</stability>
6
  <license uri="http://www.magalter.com/license">Custom License</license>
7
  <channel>community</channel>
8
  <extends/>
9
+ <summary>Magalter configuration extension, needed for correct work of other Magalter extensions</summary>
10
+ <description>Magalter configuration extension, needed for correct work of other Magalter extensions</description>
11
+ <notes>1.1.0.0</notes>
12
  <authors><author><name>Magalter</name><user>magalter</user><email>admin@magalter.com</email></author></authors>
13
+ <date>2011-12-21</date>
14
+ <time>22:59:29</time>
15
+ <contents><target name="magelocal"><dir name="Magalter"><dir name="Config"><dir name="Block"><dir name="Versions"><file name="Table.php" hash="74558c4e23a6469b9c2631aadcd03525"/></dir><file name="Versions.php" hash="b814757aeb8971a7f7ae545a8010b055"/></dir><dir name="Helper"><file name="Data.php" hash="0f692760f612c0a408191bd9cd05c978"/></dir><dir name="Model"><dir name="Mysql4"><dir name="Storage"><file name="Collection.php" hash="24be2283e3680e4c4f78c3d878fb874a"/></dir><file name="Storage.php" hash="fe13f5bc086b191cb8e8666d0ab49ab5"/></dir><file name="Observer.php" hash="7c44738318a2b386a189c2f866813443"/><file name="Storage.php" hash="8c21521c51ccbf7f586c860f5e47a363"/></dir><dir name="etc"><file name="config.xml" hash="425cd5d33ac8f6ffeb2710c221508a9b"/><file name="system.xml" hash="c7dab470f339e7589dd73ce295a99a1d"/></dir><dir name="sql"><dir name="magalterconfig_setup"><file name="mysql4-install-1.1.0.0.php" hash="2e4575231696f54f7c86d0d2768ba4aa"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Magalter_Config.xml" hash="ab239b707d6a04aa4369ab322d8137c1"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="css"><file name="magalter_config.css" hash="1be18d448a55870e7a61c0e4d44a6d43"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="magalter_config"><dir name="versions"><file name="table.phtml" hash="89780aebc30251d2826d14a7eb843111"/></dir></dir></dir><dir name="layout"><file name="magalter_config.xml" hash="dfaa6354395532a1912ae1898b3b57ae"/></dir></dir></dir></dir></target></contents>
16
  <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
  </package>
skin/adminhtml/default/default/css/magalter_config.css ADDED
@@ -0,0 +1,2 @@
 
 
1
+ .magalterconfig-table { border-collapse: collapse; }
2
+ .magalterconfig-table th, .magalterconfig-table td { border: 1px gray solid; padding: 2px; }