ice_import - Version 1.7.23

Version Notes

Bug fix:

- Add noticing
- Fix user permissions
- Renaming some attributes
- Add explanations
- Add new option 'run reindex'
- Added new option to change cron scheduled time
- Added new feature settings
- Added transactions

Download this release

Release Info

Developer IceShop
Extension ice_import
Version 1.7.23
Comparing to
See all releases


Code changes from version 1.7.15 to 1.7.23

Files changed (61) hide show
  1. app/code/community/ICEshop/Iceimport/Block/Adminhtml/Dashboard.php +106 -0
  2. app/code/community/ICEshop/Iceimport/Block/Adminhtml/Images/List/Grid.php +151 -150
  3. app/code/community/ICEshop/Iceimport/Block/Adminhtml/Notifications.php +192 -45
  4. app/code/community/ICEshop/Iceimport/Block/Adminhtml/System/Config/Form/Button.php +48 -48
  5. app/code/community/ICEshop/Iceimport/Block/Adminhtml/System/Config/Form/Exportall.php +48 -48
  6. app/code/community/ICEshop/Iceimport/Block/Adminhtml/System/Config/Form/Updatebutton.php +48 -48
  7. app/code/community/ICEshop/Iceimport/Helper/Data.php +131 -131
  8. app/code/community/ICEshop/Iceimport/Helper/Db.php +429 -429
  9. app/code/community/ICEshop/Iceimport/Helper/Format.php +250 -250
  10. app/code/community/ICEshop/Iceimport/Helper/System/System.php +461 -461
  11. app/code/community/ICEshop/Iceimport/Helper/System/Systemcheck.php +847 -781
  12. app/code/community/ICEshop/Iceimport/Model/Convert/Adapter/Product.php +568 -348
  13. app/code/community/ICEshop/Iceimport/Model/Dataflow/Batch/Import.php +53 -53
  14. app/code/community/ICEshop/Iceimport/Model/Dataflow/Convert/Adapter/Io.php +35 -0
  15. app/code/community/ICEshop/Iceimport/Model/Dataflow/Convert/Parser/Csv.php +239 -193
  16. app/code/community/ICEshop/Iceimport/Model/Observer.php +475 -439
  17. app/code/community/ICEshop/Iceimport/Model/System/Config/Checksystem.php +10 -10
  18. app/code/community/ICEshop/Iceimport/Model/System/Config/Defaulttax.php +19 -19
  19. app/code/community/ICEshop/Iceimport/Model/System/Config/Explanations.php +11 -0
  20. app/code/community/ICEshop/Iceimport/Model/System/Config/Fields/Attributes.php +84 -0
  21. app/code/community/ICEshop/Iceimport/Model/System/Config/Iceshoplink.php +10 -10
  22. app/code/community/ICEshop/Iceimport/Model/System/Config/Profiles.php +19 -0
  23. app/code/community/ICEshop/Iceimport/Model/System/Config/Stock.php +22 -0
  24. app/code/community/ICEshop/Iceimport/Model/System/Config/Websites.php +19 -0
  25. app/code/community/ICEshop/Iceimport/Model/System/Config/Yesno.php +15 -15
  26. app/code/community/ICEshop/Iceimport/controllers/Adminhtml/IceimagesController.php +16 -11
  27. app/code/community/ICEshop/Iceimport/controllers/Adminhtml/IceimportController.php +1482 -1181
  28. app/code/community/ICEshop/Iceimport/controllers/Adminhtml/IceimportimagesController.php +22 -17
  29. app/code/community/ICEshop/Iceimport/controllers/Adminhtml/System/Convert/GuiController.php +90 -0
  30. app/code/community/ICEshop/Iceimport/etc/adminhtml.xml +30 -30
  31. app/code/community/ICEshop/Iceimport/etc/config.xml +149 -143
  32. app/code/community/ICEshop/Iceimport/etc/system.xml +481 -372
  33. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/{mysql4-install-1.7.15.php → mysql4-install-1.7.22.php} +79 -75
  34. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/mysql4-upgrade-0.1.0-1.7.0.php +0 -69
  35. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/mysql4-upgrade-1.4.0-1.7.0.php +0 -69
  36. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/mysql4-upgrade-1.5.0-1.7.0.php +0 -67
  37. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/mysql4-upgrade-1.6.0-1.7.0.php +0 -67
  38. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/mysql4-upgrade-1.6.0-1.7.5.php +0 -87
  39. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/mysql4-upgrade-1.7.14-1.7.15.php +0 -75
  40. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/mysql4-upgrade-1.7.15-1.7.22.php +7 -0
  41. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/mysql4-upgrade-1.7.16-1.7.22.php +7 -0
  42. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/mysql4-upgrade-1.7.17-1.7.22.php +7 -0
  43. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/mysql4-upgrade-1.7.18-1.7.22.php +7 -0
  44. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/mysql4-upgrade-1.7.19-1.7.22.php +7 -0
  45. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/mysql4-upgrade-1.7.20-1.7.22.php +7 -0
  46. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/mysql4-upgrade-1.7.21-1.7.22.php +7 -0
  47. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/mysql4-upgrade-1.7.5-1.7.9.php +0 -87
  48. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/mysql4-upgrade-1.7.6-1.7.9.php +0 -87
  49. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/mysql4-upgrade-1.7.8-1.7.22.php +9 -0
  50. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/mysql4-upgrade-1.7.9-1.7.13 +0 -75
  51. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/uninstall-old-version.php +0 -49
  52. app/code/community/ICEshop/Iceimport/sql/iceimport_setup/upgrade_run.php +11 -0
  53. app/design/adminhtml/default/default/layout/ICEshop_Iceimport.xml +40 -17
  54. app/design/adminhtml/default/default/template/iceshop/iceimport/dashboard.phtml +64 -0
  55. app/design/adminhtml/default/default/template/iceshop/iceimport/notifications.phtml +89 -20
  56. app/etc/modules/ICEshop_Iceimport.xml +9 -9
  57. js/ICEshop/Iceimport/dashboard.js +22 -0
  58. js/ICEshop/Iceimport/jquery-1.11.1.min.js +3 -3
  59. js/ICEshop/Iceimport/script.js +276 -246
  60. package.xml +15 -10
  61. skin/adminhtml/default/default/iceshop/iceimport/styles.css +156 -123
app/code/community/ICEshop/Iceimport/Block/Adminhtml/Dashboard.php ADDED
@@ -0,0 +1,106 @@
1
+ <?php
2
+
3
+ class ICEshop_Iceimport_Block_Adminhtml_Dashboard extends Mage_Adminhtml_Block_Template
4
+ {
5
+ /**
6
+ * Get statistics for dashboard
7
+ * @return array
8
+ */
9
+ public function getStatistics()
10
+ {
11
+ $helper = Mage::helper('iceimport');
12
+ $db = Mage::helper('iceimport/db');
13
+ $checker = Mage::helper('iceimport/system_systemcheck')->init();
14
+
15
+ $table_name = $db->getTableName('dataflow_profile_history');
16
+
17
+ //get data
18
+ $last_started_by_cron = $db->getLogEntryByKey('iceimport_import_started');
19
+ $last_finished_by_cron = $db->getLogEntryByKey('iceimport_import_ended');
20
+ $import_status_cron = $db->getLogEntryByKey('iceimport_import_status_cron');
21
+ $last_imported_products_count = $db->getLogEntryByKey('iceimport_count_imported_products');
22
+ $import_filename = $db->getLogEntryByKey('import_filename');
23
+ $productivity = $checker->getModulePerformance($last_imported_products_count, $last_started_by_cron, $last_finished_by_cron);
24
+ $currently_imported_products = $db->getRowsCount($db->_prefix . "iceshop_iceimport_imported_product_ids");
25
+ $data_flows = $db->getRowCountByField($db->getTableName('dataflow_batch_import'), 'batch_id', false, ' ORDER BY 1 DESC LIMIT 50');
26
+
27
+ $last_run = $db->readQuery("SELECT `performed_at` FROM {$table_name} WHERE `profile_id` = 3 ORDER BY `performed_at` DESC LIMIT 1");
28
+ $last_deleted_products_count = $db->getLogEntryByKey('iceimport_count_delete_product');
29
+
30
+ if (!empty($currently_imported_products) && ($import_status_cron['log_value'] == 'Running' || $import_status_cron['log_value'] == 'Failed')) {
31
+ $additional = array(
32
+ 'label' => $helper->__("Currently products imported"),
33
+ 'value' => $currently_imported_products . ' from ' . $data_flows[0]['row_count']
34
+ );
35
+ }
36
+
37
+ //packing response
38
+ $response = array(
39
+ array(
40
+ 'label' => $helper->__('Started last time at'),
41
+ 'value' => (!empty($last_started_by_cron['log_value'])) ? $last_started_by_cron['log_value'] : $helper->__("Never started till now")
42
+ ),
43
+ array(
44
+ 'label' => $helper->__('Finished last time at'),
45
+ 'value' => (!empty($last_finished_by_cron['log_value'])) ? $last_finished_by_cron['log_value'] : $helper->__("Never finished till now"),
46
+ ),
47
+ array(
48
+ 'label' => $helper->__('Import cron process status'),
49
+ 'value' => (!empty($import_status_cron['log_value'])) ? $import_status_cron['log_value'] : $helper->__("Never started till now"),
50
+ ),
51
+ array(
52
+ 'label' => $helper->__('Products imported last time'),
53
+ 'value' => (!empty($last_imported_products_count['log_value'])) ? $last_imported_products_count['log_value'] : 0,
54
+ ),
55
+ array(
56
+ 'label' => $helper->__('Import file name'),
57
+ 'value' => (!empty($import_filename['log_value'])) ? $import_filename['log_value'] : $helper->__("Never started till now"),
58
+ )
59
+ );
60
+
61
+ if (!empty($additional))
62
+ $response[] = $additional;
63
+
64
+ return $response;
65
+ }
66
+
67
+ /**
68
+ * @return string
69
+ */
70
+ public function getProfiles($profileName = null)
71
+ {
72
+ $html = '';
73
+ $database_query = Mage::getSingleton('core/resource')->getConnection('core_write');
74
+ $db = Mage::helper('iceimport/db');
75
+ $tablePrefix = '';
76
+ $tPrefix = (array)Mage::getConfig()->getTablePrefix();
77
+ if (!empty($tPrefix)) {
78
+ $tablePrefix = $tPrefix[0];
79
+ }
80
+ $profiles = $database_query->fetchAll("SELECT `profile_id`, `name` FROM `{$tablePrefix}dataflow_profile`");
81
+ if (!empty($profiles)) {
82
+ $html .= '<select id="ice_export_profiles">';
83
+ foreach ($profiles as $profile) {
84
+ if ((!empty($profileName)) && ($profileName == $profile["name"])) {
85
+ $html .= '<option value="' . $profile["profile_id"] . '" selected = "true">' . $profile["name"] . "</option>";
86
+ } else {
87
+ $html .= '<option value="' . $profile["profile_id"] . '">' . $profile["name"] . "</option>";
88
+ }
89
+ }
90
+ $html .= '</select>';
91
+ }
92
+ return $html;
93
+
94
+ }
95
+
96
+ /**
97
+ * Get index management url
98
+ *
99
+ * @return string
100
+ */
101
+ public function getManageUrl()
102
+ {
103
+ return Mage::helper("adminhtml")->getUrl("*/system_config/edit", array('section' => 'iceshop_iceimport_importprod_root'));
104
+ }
105
+
106
+ }
app/code/community/ICEshop/Iceimport/Block/Adminhtml/Images/List/Grid.php CHANGED
@@ -1,151 +1,152 @@
1
- <?php
2
-
3
- class ICEshop_Iceimport_Block_Adminhtml_Images_List_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
- {
5
- public function __construct()
6
- {
7
- parent::__construct();
8
- $this->setId('iceimportGrid');
9
- $this->setUseAjax(true);
10
- // $this->setVarNameFilter('iceimport_filter');
11
- // $this->setDefaultLimit($this->getCountImagesNotImport());
12
- // $this->setPagerVisibility(false);
13
- // $this->setFilterVisibility(false);
14
- // $this->setSaveParametersInSession(true);
15
- $this->_prepareCollection;
16
- }
17
-
18
- protected function _getStore()
19
- {
20
- $storeId = (int) $this->getRequest()->getParam('store', 0);
21
- return Mage::app()->getStore($storeId);
22
- }
23
-
24
- protected function _prepareCollection()
25
- {
26
-
27
- $store = $this->_getStore();
28
- $collection = Mage::getModel('catalog/product')->getCollection();
29
- $collection->addAttributeToSort('entity_id', 'DESC');
30
-
31
- $collection->getSelect()->joinLeft( array('pt'=> 'iceshop_iceimport_image_queue'),
32
- 'e.`entity_id` = pt.`entity_id`', array('*'))->where("pt.`is_downloaded`=2")->limit(20, 10);
33
-
34
- if($this->checkExistingAttribute('catalog_product', 'sku')){
35
- $collection->addAttributeToSelect('sku');
36
- }
37
-
38
- if ($store->getId()) {
39
- $adminStore = Mage_Core_Model_App::ADMIN_STORE_ID;
40
-
41
- if($this->checkExistingAttribute('catalog_product', 'mpn')){
42
- $collection->joinAttribute(
43
- 'mpn',
44
- 'catalog_product/mpn',
45
- 'entity_id',
46
- null,
47
- 'inner',
48
- $adminStore
49
- );
50
- }
51
- $collection->joinAttribute(
52
- 'image_url',
53
- 'iceshop_iceimport_image_queue/image_url',
54
- 'entity_id',
55
- null,
56
- 'inner',
57
- $store->getId()
58
- );
59
- }
60
- else {
61
- if($this->checkExistingAttribute('catalog_product', 'mpn')){
62
- $collection->joinAttribute('mpn', 'catalog_product/mpn', 'entity_id', null, 'inner');
63
- }
64
- }
65
-
66
- $this->setCollection($collection);
67
-
68
- parent::_prepareCollection();
69
- $this->getCollection()->addWebsiteNamesToResult();
70
- return $this;
71
-
72
- }
73
-
74
- public function checkExistingAttribute($group, $attribut){
75
- $eav = Mage::getModel('eav/config');
76
- $attribute = $eav->getAttribute($group, $attribut);
77
- return $attribute->getId();
78
- }
79
-
80
-
81
- protected function _prepareColumns()
82
- {
83
- if ($this->_isExport) {
84
- $this->setDefaultLimit($this->getCountImagesNotImport());
85
- }
86
- $this->addColumn('entity_id',
87
- array(
88
- 'header'=> Mage::helper('catalog')->__('ID'),
89
- 'width' => '50px',
90
- 'type' => 'number',
91
- 'index' => 'entity_id',
92
- ));
93
- $this->addColumn('image_url',
94
- array(
95
- 'header'=> Mage::helper('catalog')->__('Url'),
96
- 'index' => 'image_url',
97
- 'filter' => FALSE
98
- ));
99
-
100
- if($this->checkExistingAttribute('catalog_product', 'sku')){
101
- $this->addColumn('sku',
102
- array(
103
- 'header'=> Mage::helper('catalog')->__('SKU'),
104
- 'width' => '80px',
105
- 'index' => 'sku',
106
- ));
107
- }
108
-
109
- if($this->checkExistingAttribute('catalog_product', 'mpn')){
110
- $this->addColumn('mpn',
111
- array(
112
- 'header'=> Mage::helper('catalog')->__('Manufacturer product number'),
113
- 'width' => '80px',
114
- 'index' => 'mpn',
115
- ));
116
- }
117
- $this->addExportType('*/iceimport/exportIceimportimagesCsv', Mage::helper('iceimport')->__('CSV'));
118
- $this->addExportType('*/iceimport/exportIceimportimagesExcel', Mage::helper('iceimport')->__('Excel XML'));
119
-
120
- return parent::_prepareColumns();
121
- }
122
-
123
- public function getGridUrl()
124
- {
125
- return $this->getUrl('*/iceimport/grid', array('_current'=>true));
126
- }
127
-
128
- public function getRowUrl($row)
129
- {
130
- return $this->getUrl('*/catalog_product/edit', array(
131
- 'store'=>$this->getRequest()->getParam('store'),
132
- 'id'=>$row->getId())
133
- );
134
- }
135
-
136
- public function getCountImagesNotImport(){
137
- try{
138
- $db_res = Mage::getSingleton('core/resource')->getConnection('core_write');
139
- $tablePrefix = '';
140
- $tPrefix = (array)Mage::getConfig()->getTablePrefix();
141
- if (!empty($tPrefix)) {
142
- $tablePrefix = $tPrefix[0];
143
- }
144
- return $return_resulr = $db_res->fetchOne("SELECT COUNT(*) FROM `{$tablePrefix}iceshop_iceimport_image_queue`
145
- WHERE `is_downloaded` = 2");
146
-
147
- } catch (Exception $e){
148
- }
149
- }
150
-
151
}
1
+ <?php
2
+
3
+ class ICEshop_Iceimport_Block_Adminhtml_Images_List_Grid extends Mage_Adminhtml_Block_Widget_Grid
4
+ {
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->setId('iceimportGrid');
9
+ $this->setUseAjax(true);
10
+ // $this->setVarNameFilter('iceimport_filter');
11
+ // $this->setDefaultLimit($this->getCountImagesNotImport());
12
+ // $this->setPagerVisibility(false);
13
+ // $this->setFilterVisibility(false);
14
+ // $this->setSaveParametersInSession(true);
15
+ $this->_prepareCollection;
16
+ }
17
+
18
+ protected function _getStore()
19
+ {
20
+ $storeId = (int) $this->getRequest()->getParam('store', 0);
21
+ return Mage::app()->getStore($storeId);
22
+ }
23
+
24
+ protected function _prepareCollection()
25
+ {
26
+
27
+ $store = $this->_getStore();
28
+ $collection = Mage::getModel('catalog/product')->getCollection();
29
+ $collection->addAttributeToSort('entity_id', 'DESC');
30
+
31
+ $prefix = Mage::getConfig()->getTablePrefix();
32
+ $collection->getSelect()->joinLeft( array('pt'=> $prefix.'iceshop_iceimport_image_queue'),
33
+ 'e.`entity_id` = pt.`entity_id`', array('*'))->where("pt.`is_downloaded`=2")->limit(20, 10);
34
+
35
+ if($this->checkExistingAttribute('catalog_product', 'sku')){
36
+ $collection->addAttributeToSelect('sku');
37
+ }
38
+
39
+ if ($store->getId()) {
40
+ $adminStore = Mage_Core_Model_App::ADMIN_STORE_ID;
41
+
42
+ if($this->checkExistingAttribute('catalog_product', 'mpn')){
43
+ $collection->joinAttribute(
44
+ 'mpn',
45
+ 'catalog_product/mpn',
46
+ 'entity_id',
47
+ null,
48
+ 'inner',
49
+ $adminStore
50
+ );
51
+ }
52
+ $collection->joinAttribute(
53
+ 'image_url',
54
+ 'iceshop_iceimport_image_queue/image_url',
55
+ 'entity_id',
56
+ null,
57
+ 'inner',
58
+ $store->getId()
59
+ );
60
+ }
61
+ else {
62
+ if($this->checkExistingAttribute('catalog_product', 'mpn')){
63
+ $collection->joinAttribute('mpn', 'catalog_product/mpn', 'entity_id', null, 'inner');
64
+ }
65
+ }
66
+
67
+ $this->setCollection($collection);
68
+
69
+ parent::_prepareCollection();
70
+ $this->getCollection()->addWebsiteNamesToResult();
71
+ return $this;
72
+
73
+ }
74
+
75
+ public function checkExistingAttribute($group, $attribut){
76
+ $eav = Mage::getModel('eav/config');
77
+ $attribute = $eav->getAttribute($group, $attribut);
78
+ return $attribute->getId();
79
+ }
80
+
81
+
82
+ protected function _prepareColumns()
83
+ {
84
+ if ($this->_isExport) {
85
+ $this->setDefaultLimit($this->getCountImagesNotImport());
86
+ }
87
+ $this->addColumn('entity_id',
88
+ array(
89
+ 'header'=> Mage::helper('catalog')->__('ID'),
90
+ 'width' => '50px',
91
+ 'type' => 'number',
92
+ 'index' => 'entity_id',
93
+ ));
94
+ $this->addColumn('image_url',
95
+ array(
96
+ 'header'=> Mage::helper('catalog')->__('Url'),
97
+ 'index' => 'image_url',
98
+ 'filter' => FALSE
99
+ ));
100
+
101
+ if($this->checkExistingAttribute('catalog_product', 'sku')){
102
+ $this->addColumn('sku',
103
+ array(
104
+ 'header'=> Mage::helper('catalog')->__('SKU'),
105
+ 'width' => '80px',
106
+ 'index' => 'sku',
107
+ ));
108
+ }
109
+
110
+ if($this->checkExistingAttribute('catalog_product', 'mpn')){
111
+ $this->addColumn('mpn',
112
+ array(
113
+ 'header'=> Mage::helper('catalog')->__('Manufacturer product number'),
114
+ 'width' => '80px',
115
+ 'index' => 'mpn',
116
+ ));
117
+ }
118
+ $this->addExportType('*/iceimport/exportIceimportimagesCsv', Mage::helper('iceimport')->__('CSV'));
119
+ $this->addExportType('*/iceimport/exportIceimportimagesExcel', Mage::helper('iceimport')->__('Excel XML'));
120
+
121
+ return parent::_prepareColumns();
122
+ }
123
+
124
+ public function getGridUrl()
125
+ {
126
+ return $this->getUrl('*/iceimport/grid', array('_current'=>true));
127
+ }
128
+
129
+ public function getRowUrl($row)
130
+ {
131
+ return $this->getUrl('*/catalog_product/edit', array(
132
+ 'store'=>$this->getRequest()->getParam('store'),
133
+ 'id'=>$row->getId())
134
+ );
135
+ }
136
+
137
+ public function getCountImagesNotImport(){
138
+ try{
139
+ $db_res = Mage::getSingleton('core/resource')->getConnection('core_write');
140
+ $tablePrefix = '';
141
+ $tPrefix = (array)Mage::getConfig()->getTablePrefix();
142
+ if (!empty($tPrefix)) {
143
+ $tablePrefix = $tPrefix[0];
144
+ }
145
+ return $return_resulr = $db_res->fetchOne("SELECT COUNT(*) FROM `{$tablePrefix}iceshop_iceimport_image_queue`
146
+ WHERE `is_downloaded` = 2");
147
+
148
+ } catch (Exception $e){
149
+ }
150
+ }
151
+
152
}
app/code/community/ICEshop/Iceimport/Block/Adminhtml/Notifications.php CHANGED
@@ -1,45 +1,192 @@
1
- <?php
2
-
3
- /**
4
- * Class ICEshop_Iceimport_Block_Adminhtml_Notifications
5
- */
6
- class ICEshop_Iceimport_Block_Adminhtml_Notifications extends Mage_Adminhtml_Block_Template
7
- {
8
- /**
9
- * @return array|string
10
- */
11
- public function getIceimportProblemsDigest()
12
- {
13
- $checker = Mage::helper('iceimport/system_systemcheck')->init();
14
- $problems_digest = $checker->getExtensionProblemsDigest();
15
- $response = array();
16
- if($checker->checkSetWarning()){
17
- if ($problems_digest->getCount() != 0) {
18
- $problems = $problems_digest->getProblems();
19
- foreach ($problems as $problem_name => $problem_value) {
20
- $response[] = array($problem_name => $problem_value);
21
- }
22
- }
23
- }
24
- return $response;
25
- }
26
-
27
- /**
28
- * Get index management url
29
- *
30
- * @return string
31
- */
32
- public function getManageUrl()
33
- {
34
- return Mage::helper("adminhtml")->getUrl("*/system_config/edit", array('section' => 'iceimport_information'));
35
- }
36
-
37
- /**
38
- * Check is notification available to current user
39
- * @return bool
40
- */
41
- public function isAllowed()
42
- {
43
- return Mage::getSingleton('admin/session')->isAllowed('system/config/iceshop_iceimport_importprod_root');
44
- }
45
- }
1
+ <?php
2
+
3
+ /**
4
+ * Class ICEshop_Iceimport_Block_Adminhtml_Notifications
5
+ */
6
+ class ICEshop_Iceimport_Block_Adminhtml_Notifications extends Mage_Adminhtml_Block_Template
7
+ {
8
+ /**
9
+ * @return array|string
10
+ */
11
+ public function getIceimportProblemsDigest()
12
+ {
13
+ $checker = Mage::helper('iceimport/system_systemcheck')->init();
14
+ $problems_digest = $checker->getExtensionProblemsDigest();
15
+ $response = array();
16
+ if($checker->checkSetWarning()){
17
+ if ($problems_digest->getCount() != 0) {
18
+ $problems = $problems_digest->getProblems();
19
+ foreach ($problems as $problem_name => $problem_value) {
20
+ $response[] = array($problem_name => $problem_value);
21
+ }
22
+ }
23
+ }
24
+ return $response;
25
+ }
26
+
27
+ /**
28
+ * Get index management url
29
+ *
30
+ * @return string
31
+ */
32
+ public function getManageUrl()
33
+ {
34
+ return Mage::helper("adminhtml")->getUrl("*/system_config/edit", array('section' => 'iceimport_information'));
35
+ }
36
+
37
+ /**
38
+ * Get index management url
39
+ *
40
+ * @return string
41
+ */
42
+ public function getSettingsPage()
43
+ {
44
+ return Mage::helper("adminhtml")->getUrl("*/system_config/edit", array('section' => 'iceshop_iceimport_importprod_root'));
45
+ }
46
+
47
+ /**
48
+ * Check is notification available to current user
49
+ * @return bool
50
+ */
51
+ public function isAllowed()
52
+ {
53
+ return Mage::getSingleton('admin/session')->isAllowed('system/config/iceshop_iceimport_importprod_root');
54
+ }
55
+
56
+ /*
57
+ * Check last import date
58
+ * @return bool
59
+ */
60
+ public function checkLastFinishedImport(){
61
+
62
+ $message_1 = 'The import of your assortment via Iceimport did not start. Is something changed in the configuration? See the dashboard for more information. Please contact our support team at supportdesk@iceshop.nl';
63
+ $message_2 = 'Iceimport started but did not yet finished or failed. Is something changed with your shop? See the dashboard for more information. Please contact our support team at supportdesk@iceshop.nl';
64
+
65
+ $warningTime = 60*60*30; // 30 hours
66
+ $timezoneLocal = Mage::app()->getStore()->getConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE);
67
+ $db = Mage::helper('iceimport/db');
68
+ $last_started_timestamp = $db->getLogEntryByKey('iceimport_import_started');
69
+ $last_finished_timestamp = $db->getLogEntryByKey('iceimport_import_ended');
70
+
71
+ //get only time if this isset
72
+ $last_started_timestamp = ((isset($last_started_timestamp['log_value']))&&($last_started_timestamp['log_value'] != ''))?$last_started_timestamp['log_value']:'';
73
+ $last_finished_timestamp = ((isset($last_finished_timestamp['log_value']))&&($last_finished_timestamp['log_value'] != ''))?$last_finished_timestamp['log_value']:'';
74
+ $currentDateTime = Mage::getModel('core/date')->timestamp(time());
75
+ //case 1
76
+ if(($last_started_timestamp != '') && ($last_finished_timestamp == '')){
77
+ $start_time_ice = $this->parseCustomDate($last_started_timestamp);
78
+ if($start_time_ice){
79
+ if(($currentDateTime-$start_time_ice)>$warningTime){
80
+ return $message_1;
81
+ }
82
+ }
83
+ }
84
+ //case 2
85
+ if(($last_started_timestamp != '') && ($last_finished_timestamp != '')){
86
+ $finish_time_ice = $this->parseCustomDate($last_finished_timestamp);
87
+ if($finish_time_ice){
88
+ if(($currentDateTime-$finish_time_ice)>$warningTime){
89
+ return $message_2;
90
+ }
91
+ }
92
+ }
93
+ return false;
94
+ }
95
+
96
+ public function parseCustomDate($date){
97
+ if(($date != '') && ($date != null) && ($date != false)) {
98
+ //we first explode string to date and time and after expolde to year month date and hour minute seconds
99
+ $date = explode(' ',$date);
100
+ if(isset($date[0])){
101
+ $date['date'] = explode('/',$date[0]);
102
+ unset($date[0]);
103
+ }
104
+ if(isset($date[1])){
105
+ $date['time'] = explode(':',$date[1]);
106
+ unset($date[1]);
107
+ }
108
+ //check if all exists and in need out quantity
109
+ if((isset($date['time'])) && (isset($date['date'])) && (count($date['time']) == 3) && (count($date['date']) == 3)){
110
+ $unix_timestamp = mktime($date['time'][0],$date['time'][1], $date['time'][2],$date['date'][0], $date['date'][1], $date['date'][2]);
111
+ return $unix_timestamp;
112
+ }
113
+ return false;
114
+ }
115
+ return false;
116
+ }
117
+
118
+ /**
119
+ * Check warning flag
120
+ * @return bool
121
+ */
122
+ public function checkWarning()
123
+ {
124
+ $message = 'At last import was attempt to delete more old products than allowed in Iceimport configuration, please go to configuration page and check the parameter (Tolerance of difference (%)).';
125
+ $db = Mage::helper('iceimport/db');
126
+ $log_record = $db->getLogEntryByKey('try_delete_product_percentage_warning_flag');
127
+ if ((!empty($log_record)) && ($log_record['log_value'] == 'SHOW')) {
128
+ return $message;
129
+ }
130
+ return false;
131
+ }
132
+
133
+ /**
134
+ * Check first launch of admin panel after install/reinstall module
135
+ * @return bool|string
136
+ */
137
+ public function firstLaunch()
138
+ {
139
+ $message = 'We detected that its your first launch of admin panel after install/reinstall ICEImport module. For this reason we recommend you check settings of module (Attributes mapping etc.)';
140
+ $db = Mage::helper('iceimport/db');
141
+ $log_record = $db->getLogEntryByKey('first_start');
142
+ if ((!empty($log_record)) && ($log_record['log_value'] == 'yes')) {
143
+ $accept = Mage::app()->getRequest()->getParam('accept');
144
+ $section = Mage::app()->getRequest()->getParam('section');
145
+ if (($accept == 1) && ($section == 'iceshop_iceimport_importprod_root')) {
146
+ $db->deleteLogEntry('first_start');
147
+ return false;
148
+ } else {
149
+ return $message;
150
+ }
151
+ } else {
152
+ return false;
153
+ }
154
+ }
155
+
156
+ /**
157
+ * Get settings page with parameter accept
158
+ *
159
+ * @return string
160
+ */
161
+ public function getSettingsPageWithAccepting()
162
+ {
163
+ return Mage::helper("adminhtml")->getUrl("*/system_config/edit", array('section' => 'iceshop_iceimport_importprod_root', 'accept' => true));
164
+ }
165
+
166
+ /**
167
+ * Check of attribute mapping
168
+ * @return bool|string
169
+ */
170
+ public function checkSetMapping()
171
+ {
172
+ $message = "The Iceimport extensions doesn't work properly, please go to configuration page and check settings which not set.";
173
+
174
+ $checks = array(
175
+ 'iceshop_iceimport_importprod_root/importprod/attribute_mapping_mpn',
176
+ 'iceshop_iceimport_importprod_root/importprod/attribute_mapping_brand_name',
177
+ 'iceshop_iceimport_importprod_root/importprod/attribute_mapping_ean',
178
+ );
179
+
180
+ $resource = Mage::getSingleton('core/resource');
181
+ $tableName = $resource->getTableName('core_config_data');
182
+ $readConnection = $resource->getConnection('core_read');
183
+ foreach ($checks as $check) {
184
+ $query = 'SELECT * FROM ' . $tableName . ' WHERE path = "' . $check . '"';
185
+ $results = $readConnection->fetchAll($query);
186
+ if (empty($results)) {
187
+ return $message;
188
+ }
189
+ }
190
+ return false;
191
+ }
192
+ }
app/code/community/ICEshop/Iceimport/Block/Adminhtml/System/Config/Form/Button.php CHANGED
@@ -1,49 +1,49 @@
1
- <?php
2
- class Iceshop_Iceimport_Block_Adminhtml_System_Config_Form_Button extends Mage_Adminhtml_Block_System_Config_Form_Field
3
- {
4
- /*
5
- * Set templated
6
- */
7
- protected function _construct()
8
- {
9
- parent::_construct();
10
- }
11
-
12
- /**
13
- * Return element html
14
- *
15
- * @param Varien_Data_Form_Element_Abstract $element
16
- * @return string
17
- */
18
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
19
- {
20
- return $this->_toHtml();
21
- }
22
-
23
- /**
24
- * Return ajax url for button
25
- *
26
- * @return string
27
- */
28
- public function getAjaxCheckUrl()
29
- {
30
- return Mage::helper('adminhtml')->getUrl('adminhtml/iceimportimages/check/');
31
- }
32
-
33
- /**
34
- * Generate button html
35
- *
36
- * @return string
37
- */
38
- public function getButtonHtml()
39
- {
40
- $prod_button = $this->getLayout()->createBlock('adminhtml/widget_button')
41
- ->setData(array(
42
- 'id' => 'iceimport_images_button',
43
- 'label' => $this->helper('adminhtml')->__('Import images'),
44
- 'onclick' => 'javascript:import_prod_images(1,0); return false;'
45
- ));
46
- $buttons = $prod_button->toHtml();
47
- return $buttons;
48
- }
49
}
1
+ <?php
2
+ class Iceshop_Iceimport_Block_Adminhtml_System_Config_Form_Button extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+ /*
5
+ * Set templated
6
+ */
7
+ protected function _construct()
8
+ {
9
+ parent::_construct();
10
+ }
11
+
12
+ /**
13
+ * Return element html
14
+ *
15
+ * @param Varien_Data_Form_Element_Abstract $element
16
+ * @return string
17
+ */
18
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
19
+ {
20
+ return $this->_toHtml();
21
+ }
22
+
23
+ /**
24
+ * Return ajax url for button
25
+ *
26
+ * @return string
27
+ */
28
+ public function getAjaxCheckUrl()
29
+ {
30
+ return Mage::helper('adminhtml')->getUrl('adminhtml/iceimportimages/check/');
31
+ }
32
+
33
+ /**
34
+ * Generate button html
35
+ *
36
+ * @return string
37
+ */
38
+ public function getButtonHtml()
39
+ {
40
+ $prod_button = $this->getLayout()->createBlock('adminhtml/widget_button')
41
+ ->setData(array(
42
+ 'id' => 'iceimport_images_button',
43
+ 'label' => $this->helper('adminhtml')->__('Import images'),
44
+ 'onclick' => 'javascript:import_prod_images(1,0); return false;'
45
+ ));
46
+ $buttons = $prod_button->toHtml();
47
+ return $buttons;
48
+ }
49
}
app/code/community/ICEshop/Iceimport/Block/Adminhtml/System/Config/Form/Exportall.php CHANGED
@@ -1,49 +1,49 @@
1
- <?php
2
- class Iceshop_Iceimport_Block_Adminhtml_System_Config_Form_Exportall extends Mage_Adminhtml_Block_System_Config_Form_Field
3
- {
4
- /*
5
- * Set templated
6
- */
7
- protected function _construct()
8
- {
9
- parent::_construct();
10
- }
11
-
12
- /**
13
- * Return element html
14
- *
15
- * @param Varien_Data_Form_Element_Abstract $element
16
- * @return string
17
- */
18
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
19
- {
20
- return $this->_toHtml();
21
- }
22
-
23
- /**
24
- * Return ajax url for button
25
- *
26
- * @return string
27
- */
28
- public function getAjaxCheckUrl()
29
- {
30
- return Mage::helper('adminhtml')->getUrl('adminhtml/iceimport/exportIceimportimagesCsvAll/');
31
- }
32
-
33
- /**
34
- * Generate button html
35
- *
36
- * @return string
37
- */
38
- public function getButtonHtml()
39
- {
40
- $prod_button = $this->getLayout()->createBlock('adminhtml/widget_button')
41
- ->setData(array(
42
- 'id' => 'iceimport_exportall_button',
43
- 'label' => $this->helper('adminhtml')->__('Export All to CSV'),
44
- 'onclick' => "setLocation('" . $this->getUrl('adminhtml/iceimport/exportIceimportimagesCsvAll/') . "')"
45
- ));
46
- $buttons = $prod_button->toHtml();
47
- return $buttons;
48
- }
49
}
1
+ <?php
2
+ class Iceshop_Iceimport_Block_Adminhtml_System_Config_Form_Exportall extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+ /*
5
+ * Set templated
6
+ */
7
+ protected function _construct()
8
+ {
9
+ parent::_construct();
10
+ }
11
+
12
+ /**
13
+ * Return element html
14
+ *
15
+ * @param Varien_Data_Form_Element_Abstract $element
16
+ * @return string
17
+ */
18
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
19
+ {
20
+ return $this->_toHtml();
21
+ }
22
+
23
+ /**
24
+ * Return ajax url for button
25
+ *
26
+ * @return string
27
+ */
28
+ public function getAjaxCheckUrl()
29
+ {
30
+ return Mage::helper('adminhtml')->getUrl('adminhtml/iceimport/exportIceimportimagesCsvAll/');
31
+ }
32
+
33
+ /**
34
+ * Generate button html
35
+ *
36
+ * @return string
37
+ */
38
+ public function getButtonHtml()
39
+ {
40
+ $prod_button = $this->getLayout()->createBlock('adminhtml/widget_button')
41
+ ->setData(array(
42
+ 'id' => 'iceimport_exportall_button',
43
+ 'label' => $this->helper('adminhtml')->__('Export All to CSV'),
44
+ 'onclick' => "setLocation('" . $this->getUrl('adminhtml/iceimport/exportIceimportimagesCsvAll/') . "')"
45
+ ));
46
+ $buttons = $prod_button->toHtml();
47
+ return $buttons;
48
+ }
49
}
app/code/community/ICEshop/Iceimport/Block/Adminhtml/System/Config/Form/Updatebutton.php CHANGED
@@ -1,49 +1,49 @@
1
- <?php
2
- class Iceshop_Iceimport_Block_Adminhtml_System_Config_Form_Updatebutton extends Mage_Adminhtml_Block_System_Config_Form_Field
3
- {
4
- /*
5
- * Set templated
6
- */
7
- protected function _construct()
8
- {
9
- parent::_construct();
10
- }
11
-
12
- /**
13
- * Return element html
14
- *
15
- * @param Varien_Data_Form_Element_Abstract $element
16
- * @return string
17
- */
18
- protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
19
- {
20
- return $this->_toHtml();
21
- }
22
-
23
- /**
24
- * Return ajax url for button
25
- *
26
- * @return string
27
- */
28
- public function getAjaxCheckUrl()
29
- {
30
- return Mage::helper('adminhtml')->getUrl('adminhtml/iceimportimages/check/');
31
- }
32
-
33
- /**
34
- * Generate button html
35
- *
36
- * @return string
37
- */
38
- public function getButtonHtml()
39
- {
40
- $prod_button = $this->getLayout()->createBlock('adminhtml/widget_button')
41
- ->setData(array(
42
- 'id' => 'iceimport_images_button',
43
- 'label' => $this->helper('adminhtml')->__('Try again'),
44
- 'onclick' => 'javascript:import_prod_images(1,1); return false;'
45
- ));
46
- $buttons = $prod_button->toHtml();
47
- return $buttons;
48
- }
49
}
1
+ <?php
2
+ class Iceshop_Iceimport_Block_Adminhtml_System_Config_Form_Updatebutton extends Mage_Adminhtml_Block_System_Config_Form_Field
3
+ {
4
+ /*
5
+ * Set templated
6
+ */
7
+ protected function _construct()
8
+ {
9
+ parent::_construct();
10
+ }
11
+
12
+ /**
13
+ * Return element html
14
+ *
15
+ * @param Varien_Data_Form_Element_Abstract $element
16
+ * @return string
17
+ */
18
+ protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
19
+ {
20
+ return $this->_toHtml();
21
+ }
22
+
23
+ /**
24
+ * Return ajax url for button
25
+ *
26
+ * @return string
27
+ */
28
+ public function getAjaxCheckUrl()
29
+ {
30
+ return Mage::helper('adminhtml')->getUrl('adminhtml/iceimportimages/check/');
31
+ }
32
+
33
+ /**
34
+ * Generate button html
35
+ *
36
+ * @return string
37
+ */
38
+ public function getButtonHtml()
39
+ {
40
+ $prod_button = $this->getLayout()->createBlock('adminhtml/widget_button')
41
+ ->setData(array(
42
+ 'id' => 'iceimport_images_button',
43
+ 'label' => $this->helper('adminhtml')->__('Try again'),
44
+ 'onclick' => 'javascript:import_prod_images(1,1); return false;'
45
+ ));
46
+ $buttons = $prod_button->toHtml();
47
+ return $buttons;
48
+ }
49
}
app/code/community/ICEshop/Iceimport/Helper/Data.php CHANGED
@@ -1,132 +1,132 @@
1
- <?php
2
-
3
- class ICEshop_Iceimport_Helper_Data extends Mage_Core_Helper_Abstract
4
- {
5
-
6
- /**
7
- * @param $extension_name
8
- * @return bool
9
- */
10
- public function isExtensionInstalled($extension_name)
11
- {
12
- if (!empty($extension_name)) {
13
- $modules = Mage::getConfig()->getNode('modules')->children();
14
- $modules = (array)$modules;
15
- if (array_key_exists($extension_name, (array)$modules)) {
16
- return true;
17
- }
18
- }
19
- return false;
20
- }
21
-
22
-
23
- /**
24
- * @param bool $json_encoded
25
- * @return array|string
26
- */
27
- public function getSystemInfo($json_encoded = false)
28
- {
29
- $results = array();
30
- try {
31
- $checker = Mage::helper('iceimport/system_systemcheck')->init();
32
- if (!empty($checker)) {
33
- $results['server'] = $checker->getSystem()->getServer()->getData();
34
- //$results['system'] = $checker->getSystem()->getMagento()->getData();
35
- //$results['php'] = $checker->getSystem()->getPhp()->getData();
36
- //$results['mysql'] = $checker->getSystem()->getMysql()->getData();
37
- //$results['requirements'] = $checker->getSystem()->getRequirements()->getData();
38
- }
39
- } catch (Exception $e) {
40
- }
41
-
42
- if ($json_encoded == true) {
43
- return json_encode($results);
44
- }
45
- return $results;
46
- }
47
-
48
- protected function _getButtonSettings($settings)
49
- {
50
- $default_settings = array(
51
- 'getBeforeHtml' => '',
52
- 'getId' => '',
53
- 'getElementName' => '',
54
- 'getTitle' => '',
55
- 'getType' => '',
56
- 'getClass' => '',
57
- 'getOnClick' => '',
58
- 'getStyle' => '',
59
- 'getValue' => '',
60
- 'getDisabled' => '',
61
- 'getLabel' => '',
62
- 'getAfterHtml' => ''
63
- );
64
- if (!empty($settings) && is_array($settings)) {
65
- foreach ($settings as $key => $setting) {
66
- $camel_key = str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
67
- $default_settings['get' . $camel_key] = $setting;
68
- }
69
- }
70
- return $default_settings;
71
- }
72
-
73
- /**
74
- * @param $settings
75
- * @return string
76
- */
77
- public function getButtonHtml($settings)
78
- {
79
- $settings = $this->_getButtonSettings($settings);
80
- $html = $settings['getBeforeHtml'] . '<button '
81
- . ($settings['getId'] ? ' id="' . $settings['getId'] . '"' : '')
82
- . ($settings['getElementName'] ? ' name="' . $settings['getElementName'] . '"' : '')
83
- . ' title="'
84
- . htmlspecialchars($settings['getTitle'] ? $settings['getTitle'] : $settings['getLabel'], ENT_QUOTES, null, false)
85
- . '"'
86
- . ' type="' . $settings['getType'] . '"'
87
- . ' class="scalable ' . $settings['getClass'] . ($settings['getDisabled'] ? ' disabled' : '') . '"'
88
- . ' onclick="' . $settings['getOnClick'] . '"'
89
- . ' style="' . $settings['getStyle'] . '"'
90
- . ($settings['getValue'] ? ' value="' . $settings['getValue'] . '"' : '')
91
- . ($settings['getDisabled'] ? ' disabled="disabled"' : '')
92
- . '><span><span><span>' . $settings['getLabel'] . '</span></span></span></button>' . $settings['getAfterHtml'];
93
-
94
- return $html;
95
- }
96
-
97
- /**
98
- * Sorts a multi-dimensional array with the given values
99
- *
100
- * Seen and modified from: http://www.firsttube.com/read/sorting-a-multi-dimensional-array-with-php/
101
- *
102
- * @param array $arr Array to sort
103
- * @param string $key Field to sort
104
- * @param string $dir Direction to sort
105
- * @return array Sorted array
106
- */
107
- public function sortMultiDimArr($arr, $key, $dir = 'ASC')
108
- {
109
- foreach ($arr as $k => $v) {
110
- $b[$k] = strtolower($v[$key]);
111
- }
112
-
113
- if ($dir == 'ASC') {
114
- asort($b);
115
- } else {
116
- arsort($b);
117
- }
118
- foreach ($b as $key => $val) {
119
- $c[] = $arr[$key];
120
- }
121
-
122
- return $c;
123
- }
124
-
125
- public function toCamelCase($str, $capitalise_first_char = false) {
126
- if($capitalise_first_char) {
127
- $str[0] = strtoupper($str[0]);
128
- }
129
- $func = create_function('$c', 'return strtoupper($c[1]);');
130
- return preg_replace_callback('/_([a-z])/', $func, $str);
131
- }
132
}
1
+ <?php
2
+
3
+ class ICEshop_Iceimport_Helper_Data extends Mage_Core_Helper_Abstract
4
+ {
5
+
6
+ /**
7
+ * @param $extension_name
8
+ * @return bool
9
+ */
10
+ public function isExtensionInstalled($extension_name)
11
+ {
12
+ if (!empty($extension_name)) {
13
+ $modules = Mage::getConfig()->getNode('modules')->children();
14
+ $modules = (array)$modules;
15
+ if (array_key_exists($extension_name, (array)$modules)) {
16
+ return true;
17
+ }
18
+ }
19
+ return false;
20
+ }
21
+
22
+
23
+ /**
24
+ * @param bool $json_encoded
25
+ * @return array|string
26
+ */
27
+ public function getSystemInfo($json_encoded = false)
28
+ {
29
+ $results = array();
30
+ try {
31
+ $checker = Mage::helper('iceimport/system_systemcheck')->init();
32
+ if (!empty($checker)) {
33
+ $results['server'] = $checker->getSystem()->getServer()->getData();
34
+ //$results['system'] = $checker->getSystem()->getMagento()->getData();
35
+ //$results['php'] = $checker->getSystem()->getPhp()->getData();
36
+ //$results['mysql'] = $checker->getSystem()->getMysql()->getData();
37
+ //$results['requirements'] = $checker->getSystem()->getRequirements()->getData();
38
+ }
39
+ } catch (Exception $e) {
40
+ }
41
+
42
+ if ($json_encoded == true) {
43
+ return json_encode($results);
44
+ }
45
+ return $results;
46
+ }
47
+
48
+ protected function _getButtonSettings($settings)
49
+ {
50
+ $default_settings = array(
51
+ 'getBeforeHtml' => '',
52
+ 'getId' => '',
53
+ 'getElementName' => '',
54
+ 'getTitle' => '',
55
+ 'getType' => '',
56
+ 'getClass' => '',
57
+ 'getOnClick' => '',
58
+ 'getStyle' => '',
59
+ 'getValue' => '',
60
+ 'getDisabled' => '',
61
+ 'getLabel' => '',
62
+ 'getAfterHtml' => ''
63
+ );
64
+ if (!empty($settings) && is_array($settings)) {
65
+ foreach ($settings as $key => $setting) {
66
+ $camel_key = str_replace(' ', '', ucwords(str_replace('_', ' ', $key)));
67
+ $default_settings['get' . $camel_key] = $setting;
68
+ }
69
+ }
70
+ return $default_settings;
71
+ }
72
+
73
+ /**
74
+ * @param $settings
75
+ * @return string
76
+ */
77
+ public function getButtonHtml($settings)
78
+ {
79
+ $settings = $this->_getButtonSettings($settings);
80
+ $html = $settings['getBeforeHtml'] . '<button '
81
+ . ($settings['getId'] ? ' id="' . $settings['getId'] . '"' : '')
82
+ . ($settings['getElementName'] ? ' name="' . $settings['getElementName'] . '"' : '')
83
+ . ' title="'
84
+ . htmlspecialchars($settings['getTitle'] ? $settings['getTitle'] : $settings['getLabel'], ENT_QUOTES, null, false)
85
+ . '"'
86
+ . ' type="' . $settings['getType'] . '"'
87
+ . ' class="scalable ' . $settings['getClass'] . ($settings['getDisabled'] ? ' disabled' : '') . '"'
88
+ . ' onclick="' . $settings['getOnClick'] . '"'
89
+ . ' style="' . $settings['getStyle'] . '"'
90
+ . ($settings['getValue'] ? ' value="' . $settings['getValue'] . '"' : '')
91
+ . ($settings['getDisabled'] ? ' disabled="disabled"' : '')
92
+ . '><span><span><span>' . $settings['getLabel'] . '</span></span></span></button>' . $settings['getAfterHtml'];
93
+
94
+ return $html;
95
+ }
96
+
97
+ /**
98
+ * Sorts a multi-dimensional array with the given values
99
+ *
100
+ * Seen and modified from: http://www.firsttube.com/read/sorting-a-multi-dimensional-array-with-php/
101
+ *
102
+ * @param array $arr Array to sort
103
+ * @param string $key Field to sort
104
+ * @param string $dir Direction to sort
105
+ * @return array Sorted array
106
+ */
107
+ public function sortMultiDimArr($arr, $key, $dir = 'ASC')
108
+ {
109
+ foreach ($arr as $k => $v) {
110
+ $b[$k] = strtolower($v[$key]);
111
+ }
112
+
113
+ if ($dir == 'ASC') {
114
+ asort($b);
115
+ } else {
116
+ arsort($b);
117
+ }
118
+ foreach ($b as $key => $val) {
119
+ $c[] = $arr[$key];
120
+ }
121
+
122
+ return $c;
123
+ }
124
+
125
+ public function toCamelCase($str, $capitalise_first_char = false) {
126
+ if($capitalise_first_char) {
127
+ $str[0] = strtoupper($str[0]);
128
+ }
129
+ $func = create_function('$c', 'return strtoupper($c[1]);');
130
+ return preg_replace_callback('/_([a-z])/', $func, $str);
131
+ }
132
}
app/code/community/ICEshop/Iceimport/Helper/Db.php CHANGED
@@ -1,430 +1,430 @@
1
- <?php
2
-
3
- /**
4
- * Class ICEshop_Iceimport_Helper_Db
5
- */
6
- class ICEshop_Iceimport_Helper_Db extends Mage_Core_Helper_Abstract
7
- {
8
-
9
- /**
10
- * @var object
11
- */
12
- private $_resource;
13
-
14
- /**
15
- * @var object
16
- */
17
- private $_reader;
18
-
19
- /**
20
- * @var object
21
- */
22
- private $_writer;
23
-
24
- /**
25
- * @var string
26
- */
27
- public $_prefix = '';
28
-
29
- /**
30
- * int
31
- */
32
- const LOG_ROWS_LIMIT = 500;
33
-
34
- /**
35
- * __construct
36
- */
37
- public function __construct()
38
- {
39
- try {
40
- $this->_resource = Mage::getSingleton('core/resource');
41
- $this->_writer = $this->_resource->getConnection('core_write');
42
- $this->_reader = $this->_resource->getConnection('core_read');
43
- $prefix = Mage::getConfig()->getTablePrefix();
44
- if (!empty($prefix[0])) {
45
- $this->_prefix = $prefix[0];
46
- }
47
- return true;
48
- } catch (Exception $e) {
49
- return false;
50
- }
51
- }
52
-
53
- /**
54
- * @param $table_name
55
- * @param bool|array $conditions
56
- * @return mixed
57
- */
58
- public function getRowsCount($table_name, $conditions = false)
59
- {
60
- $sql = "SELECT COUNT(*) AS `row_count` FROM `{$table_name}`";
61
- if (!empty($conditions) && is_array($conditions)) {
62
- $sql .= ' WHERE ';
63
- foreach ($conditions as $key => $condition) {
64
- if (is_array($condition)) {
65
- if ($key > 0) {
66
- $sql .= ' ' . $condition['conjunction'] . ' ';
67
- }
68
- $sql .= $condition['field'] . ' ' . $condition['comparison'] . ' ';
69
- switch ($condition['value_type']) {
70
- case 'num':
71
- $sql .= $condition['value'];
72
- break;
73
- case 'str':
74
- $sql .= '\'' . $condition['value'] . '\'';
75
- break;
76
- }
77
- } elseif (is_string($condition)) {
78
- $sql .= $condition;
79
- }
80
- }
81
-
82
- } elseif (!empty($conditions) && is_string($conditions)) {
83
- $sql .= $conditions;
84
- }
85
- $result = $this->_reader->fetchAll($sql);
86
- $result = array_shift($result);
87
- return $result['row_count'];
88
- }
89
-
90
- /**
91
- * @param $table_name
92
- * @param $field_name
93
- * @param bool|string $before_group
94
- * @param bool|string $after_group
95
- * @return mixed
96
- */
97
- public function getRowCountByField($table_name, $field_name, $before_group = false, $after_group = false)
98
- {
99
- $approved_before_group = '';
100
- if ($before_group != false && is_string($before_group)) {
101
- $approved_before_group = $before_group;
102
- }
103
- $approved_after_group = '';
104
- if ($after_group != false && is_string($after_group)) {
105
- $approved_after_group = $after_group;
106
- }
107
- // select is_default, count(is_default) from icecat_products_images group by is_default;
108
- $sql = "SELECT `{$field_name}`, COUNT(`{$field_name}`) as `row_count` FROM `{$table_name}`{$approved_before_group} GROUP BY `{$field_name}`{$approved_after_group}";
109
- $result = $this->_reader->fetchAll($sql);
110
- return $result;
111
- }
112
-
113
- /**
114
- * @param $table_name
115
- * @param $field_name
116
- * @return bool
117
- */
118
- public function checkIsFieldExists($table_name, $field_name)
119
- {
120
- if (!$this->_checkProcedureExists('FIELD_EXISTS')) {
121
- //recreate the procedure FIELD_EXISTS
122
- $this->_recreateFieldExistsProcedure();
123
- }
124
- $sql = "CALL FIELD_EXISTS(@_exists, '{$table_name}', '{$field_name}', NULL);";
125
- $this->_reader->query($sql);
126
-
127
- $sql = "SELECT @_exists;";
128
- $res = $this->_reader->fetchCol($sql);
129
- if (!array_shift($res)) {
130
- //field exists
131
- return false;
132
- }
133
- return true;
134
- }
135
-
136
- /**
137
- * @param $procedure_name
138
- * @return bool
139
- */
140
- private function _checkProcedureExists($procedure_name)
141
- {
142
- $sql = "SET @_exists = (SELECT COUNT(ROUTINE_NAME) FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE = 'PROCEDURE' AND ROUTINE_SCHEMA = database() AND ROUTINE_NAME = '{$procedure_name}')";
143
- $this->_reader->query($sql);
144
-
145
- $sql = "SELECT @_exists;";
146
- $res = $this->_reader->fetchCol($sql);
147
- $res = array_shift($res);
148
- if ($res > 0) {
149
- //field exists
150
- return true;
151
- }
152
- return false;
153
- }
154
-
155
- /**
156
- *
157
- */
158
- private function _recreateFieldExistsProcedure()
159
- {
160
- $sql = "CREATE PROCEDURE FIELD_EXISTS(
161
- OUT _exists BOOLEAN, -- return value
162
- IN tableName CHAR(255), -- name of table to look for
163
- IN columnName CHAR(255), -- name of column to look for
164
- IN dbName CHAR(255) -- optional specific db
165
- ) BEGIN
166
- -- try to lookup db if none provided
167
- SET @_dbName := IF(dbName IS NULL, database(), dbName);
168
-
169
- IF CHAR_LENGTH(@_dbName) = 0
170
- THEN -- no specific or current db to check against
171
- SELECT
172
- FALSE
173
- INTO _exists;
174
- ELSE -- we have a db to work with
175
- SELECT
176
- IF(count(*) > 0, TRUE, FALSE)
177
- INTO _exists
178
- FROM information_schema.COLUMNS c
179
- WHERE
180
- c.TABLE_SCHEMA = @_dbName
181
- AND c.TABLE_NAME = tableName
182
- AND c.COLUMN_NAME = columnName;
183
- END IF;
184
- END;";
185
- $this->_writer->query($sql);
186
- }
187
-
188
- /**
189
- * @param $sql
190
- * @return bool
191
- */
192
- public function readQuery($sql)
193
- {
194
- if (!empty($sql) && is_string($sql)) {
195
- return $this->_reader->fetchAll($sql);
196
- }
197
- return false;
198
- }
199
-
200
- /**
201
- * @param $key
202
- * @param $value
203
- * @param string $type
204
- * @return bool
205
- */
206
- public function insertLogEntry($key, $value, $type = 'info')
207
- {
208
- if ($type == 'error') {
209
- $this->rotateLog();
210
- }
211
- if (!empty($key)) {
212
- return $this->_writer->query("INSERT INTO `{$this->_prefix}iceshop_extensions_logs` (`log_key`, `log_value`, `log_type`)
213
- VALUES ('{$key}', '{$value}', '{$type}')
214
- ON DUPLICATE KEY UPDATE `log_value` = VALUES(`log_value`), `log_type` = VALUES(`log_type`)");
215
- }
216
- return false;
217
- }
218
-
219
- /**
220
- * @param string $log_type
221
- * @return bool
222
- */
223
- public function rotateLog($log_type = 'error')
224
- {
225
- $sql = "SELECT COUNT(*) AS row_amount
226
- FROM `{$this->_prefix}iceshop_extensions_logs`
227
- WHERE `log_type` = '{$log_type}';";
228
- $value = $this->_reader->fetchAll($sql);
229
- $row_amount = 0;
230
- if (array_key_exists(0, $value)) {
231
- $row_amount = $value[0]['row_amount'];
232
- }
233
- if ($row_amount > self::LOG_ROWS_LIMIT) {
234
- $rows_to_delete = $row_amount - self::LOG_ROWS_LIMIT;
235
- return $this->_writer->query("DELETE
236
- FROM `{$this->_prefix}iceshop_extensions_logs`
237
- WHERE `log_type` = '{$log_type}'
238
- ORDER BY `log_id` ASC
239
- LIMIT {$rows_to_delete}");
240
- }
241
- return false;
242
- }
243
-
244
- /**
245
- * @param $key
246
- * @return bool
247
- */
248
- public function getLogEntryByKey($key)
249
- {
250
- if (!empty($key)) {
251
- $sql = "SELECT `log_value`, `log_type`
252
- FROM `{$this->_prefix}iceshop_extensions_logs`
253
- WHERE `log_key` = '{$key}'
254
- ORDER BY `log_id` DESC
255
- LIMIT 1;";
256
- $value = $this->_reader->fetchAll($sql);
257
- if (array_key_exists(0, $value)) {
258
- return $value[0];
259
- }
260
- }
261
- return false;
262
- }
263
-
264
- /**
265
- * @param bool $type
266
- * @param string $comparison
267
- * @param int $limit
268
- * @return array|bool
269
- */
270
- public function getLogByType($type = false, $comparison = 'eq', $limit = 10)
271
- {
272
- $comparison_whitelist = array('eq', 'neq');
273
- if (!in_array($comparison, $comparison_whitelist)) {
274
- $comparison = 'eq';
275
- }
276
- if (!empty($type)) {
277
- if ($type == 'report') {
278
- $result_arr = array();
279
- $sql = "SELECT `log_value`, `timecol`
280
- FROM `{$this->_prefix}iceshop_extensions_logs`
281
- WHERE `log_type` = 'error'
282
- AND (`timecol` > DATE_SUB(now(), INTERVAL 1 DAY))
283
- ORDER BY `log_id` DESC
284
- LIMIT {$limit};";
285
- $results = $this->_reader->fetchAll($sql);
286
- foreach ($results as $row) {
287
- $result_arr[] = $row;
288
- }
289
- return (!empty($result_arr)) ? $result_arr : false;
290
- } else {
291
- switch($comparison) {
292
- case 'eq':
293
- $result_arr = array();
294
- $sql = "SELECT `log_value`, `timecol`
295
- FROM `{$this->_prefix}iceshop_extensions_logs`
296
- WHERE `log_type` = '{$type}'
297
- ORDER BY `log_id` DESC
298
- LIMIT {$limit};";
299
- $results = $this->_reader->fetchAll($sql);
300
- foreach ($results as $row) {
301
- $result_arr[] = $row;
302
- }
303
- return (!empty($result_arr)) ? $result_arr : false;
304
- break;
305
-
306
- case 'neq':
307
- $result_arr = array();
308
- $sql = "SELECT `log_value`, `timecol`
309
- FROM `{$this->_prefix}iceshop_extensions_logs`
310
- WHERE `log_type` <> '{$type}'
311
- ORDER BY `log_id` DESC
312
- LIMIT {$limit};";
313
- $results = $this->_reader->fetchAll($sql);
314
- foreach ($results as $row) {
315
- $result_arr[] = $row;
316
- }
317
- return (!empty($result_arr)) ? $result_arr : false;
318
- break;
319
- }
320
- }
321
- } else {
322
- $sql = "SELECT `log_value`, `log_type`, `timecol`
323
- FROM `{$this->_prefix}iceshop_extensions_logs`
324
- ORDER BY `log_id` DESC
325
- LIMIT {$limit};";
326
- return $this->_reader->fetchAll($sql);
327
- }
328
- }
329
-
330
- /**
331
- * @param $key
332
- * @return bool
333
- */
334
- public function deleteLogEntry($key)
335
- {
336
- if (!empty($key)) {
337
- return $this->_writer->query("DELETE
338
- FROM `{$this->_prefix}iceshop_extensions_logs`
339
- WHERE `log_key` = '{$key}';");
340
- }
341
- return false;
342
- }
343
-
344
- /**
345
- * @param $table_name
346
- * @return bool
347
- */
348
- public function getTableName($table_name)
349
- {
350
- if (!empty($table_name) && is_string($table_name)) {
351
- return $this->_resource->getTableName($table_name);
352
- }
353
- return false;
354
- }
355
-
356
-
357
- /**
358
- * @param string $setting_key
359
- * @param string $setting_value
360
- * @access public
361
- * @return bool
362
- */
363
- public function setConfigData($setting_key, $setting_value)
364
- {
365
- if (isset($setting_key) && isset($setting_value)) {
366
- $table_name = $this->getTableName('core/config_data');
367
- $sql = "REPLACE INTO `{$table_name}`(`path`, `value`) VALUES(:setting_key, :setting_value);";
368
- $binds = array(
369
- 'setting_key' => $this->_getConfigKey($setting_key),
370
- 'setting_value' => $setting_value
371
- );
372
- $this->_writer->query($sql, $binds);
373
- return true;
374
- }
375
- return false;
376
- }
377
-
378
- /**
379
- * @param string $setting_key
380
- * @access public
381
- * @return bool|string
382
- */
383
- public function getConfigData($setting_key)
384
- {
385
- if (isset($setting_key)) {
386
- $table_name = $this->getTableName('core/config_data');
387
- $sql = "SELECT `value` FROM `{$table_name}` WHERE `path` = :setting_key;";
388
- $binds = array(
389
- 'setting_key' => $this->_getConfigKey($setting_key)
390
- );
391
- $result = $this->_reader->query($sql, $binds);
392
- while ( $row = $result->fetch() ) {
393
- return $row['value'];
394
- }
395
- }
396
- return false;
397
- }
398
-
399
- /**
400
- * @param string $setting_key
401
- * @access private
402
- * @return bool|string
403
- */
404
- private function _getConfigKey($setting_key)
405
- {
406
- if (isset($setting_key)) {
407
- return 'iceimport/storage/' . $setting_key;
408
- }
409
- return false;
410
- }
411
-
412
- /**
413
- * @param string $setting_key
414
- * @access public
415
- * @return bool
416
- */
417
- public function unsetConfigData($setting_key)
418
- {
419
- if (isset($setting_key)) {
420
- $table_name = $this->getTableName('core/config_data');
421
- $sql = "DELETE FROM `{$table_name}` WHERE `path` = :setting_key;";
422
- $binds = array(
423
- 'setting_key' => $this->_getConfigKey($setting_key)
424
- );
425
- $this->_writer->query($sql, $binds);
426
- return true;
427
- }
428
- return false;
429
- }
430
}
1
+ <?php
2
+
3
+ /**
4
+ * Class ICEshop_Iceimport_Helper_Db
5
+ */
6
+ class ICEshop_Iceimport_Helper_Db extends Mage_Core_Helper_Abstract
7
+ {
8
+
9
+ /**
10
+ * @var object
11
+ */
12
+ private $_resource;
13
+
14
+ /**
15
+ * @var object
16
+ */
17
+ private $_reader;
18
+
19
+ /**
20
+ * @var object
21
+ */
22
+ private $_writer;
23
+
24
+ /**
25
+ * @var string
26
+ */
27
+ public $_prefix = '';
28
+
29
+ /**
30
+ * int
31
+ */
32
+ const LOG_ROWS_LIMIT = 500;
33
+
34
+ /**
35
+ * __construct
36
+ */
37
+ public function __construct()
38
+ {
39
+ try {
40
+ $this->_resource = Mage::getSingleton('core/resource');
41
+ $this->_writer = $this->_resource->getConnection('core_write');
42
+ $this->_reader = $this->_resource->getConnection('core_read');
43
+ $prefix = Mage::getConfig()->getTablePrefix();
44
+ if (!empty($prefix[0])) {
45
+ $this->_prefix = $prefix[0];
46
+ }
47
+ return true;
48
+ } catch (Exception $e) {
49
+ return false;
50
+ }
51
+ }
52
+
53
+ /**
54
+ * @param $table_name
55
+ * @param bool|array $conditions
56
+ * @return mixed
57
+ */
58
+ public function getRowsCount($table_name, $conditions = false)
59
+ {
60
+ $sql = "SELECT COUNT(*) AS `row_count` FROM `{$table_name}`";
61
+ if (!empty($conditions) && is_array($conditions)) {
62
+ $sql .= ' WHERE ';
63
+ foreach ($conditions as $key => $condition) {
64
+ if (is_array($condition)) {
65
+ if ($key > 0) {
66
+ $sql .= ' ' . $condition['conjunction'] . ' ';
67
+ }
68
+ $sql .= $condition['field'] . ' ' . $condition['comparison'] . ' ';
69
+ switch ($condition['value_type']) {
70
+ case 'num':
71
+ $sql .= $condition['value'];
72
+ break;
73
+ case 'str':
74
+ $sql .= '\'' . $condition['value'] . '\'';
75
+ break;
76
+ }
77
+ } elseif (is_string($condition)) {
78
+ $sql .= $condition;
79
+ }
80
+ }
81
+
82
+ } elseif (!empty($conditions) && is_string($conditions)) {
83
+ $sql .= $conditions;
84
+ }
85
+ $result = $this->_reader->fetchAll($sql);
86
+ $result = array_shift($result);
87
+ return $result['row_count'];
88
+ }
89
+
90
+ /**
91
+ * @param $table_name
92
+ * @param $field_name
93
+ * @param bool|string $before_group
94
+ * @param bool|string $after_group
95
+ * @return mixed
96
+ */
97
+ public function getRowCountByField($table_name, $field_name, $before_group = false, $after_group = false)
98
+ {
99
+ $approved_before_group = '';
100
+ if ($before_group != false && is_string($before_group)) {
101
+ $approved_before_group = $before_group;
102
+ }
103
+ $approved_after_group = '';
104
+ if ($after_group != false && is_string($after_group)) {
105
+ $approved_after_group = $after_group;
106
+ }
107
+ // select is_default, count(is_default) from icecat_products_images group by is_default;
108
+ $sql = "SELECT `{$field_name}`, COUNT(`{$field_name}`) as `row_count` FROM `{$table_name}`{$approved_before_group} GROUP BY `{$field_name}`{$approved_after_group}";
109
+ $result = $this->_reader->fetchAll($sql);
110
+ return $result;
111
+ }
112
+
113
+ /**
114
+ * @param $table_name
115
+ * @param $field_name
116
+ * @return bool
117
+ */
118
+ public function checkIsFieldExists($table_name, $field_name)
119
+ {
120
+ if (!$this->_checkProcedureExists('FIELD_EXISTS')) {
121
+ //recreate the procedure FIELD_EXISTS
122
+ $this->_recreateFieldExistsProcedure();
123
+ }
124
+ $sql = "CALL FIELD_EXISTS(@_exists, '{$table_name}', '{$field_name}', NULL);";
125
+ $this->_reader->query($sql);
126
+
127
+ $sql = "SELECT @_exists;";
128
+ $res = $this->_reader->fetchCol($sql);
129
+ if (!array_shift($res)) {
130
+ //field exists
131
+ return false;
132
+ }
133
+ return true;
134
+ }
135
+
136
+ /**
137
+ * @param $procedure_name
138
+ * @return bool
139
+ */
140
+ private function _checkProcedureExists($procedure_name)
141
+ {
142
+ $sql = "SET @_exists = (SELECT COUNT(ROUTINE_NAME) FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE = 'PROCEDURE' AND ROUTINE_SCHEMA = database() AND ROUTINE_NAME = '{$procedure_name}')";
143
+ $this->_reader->query($sql);
144
+
145
+ $sql = "SELECT @_exists;";
146
+ $res = $this->_reader->fetchCol($sql);
147
+ $res = array_shift($res);
148
+ if ($res > 0) {
149
+ //field exists
150
+ return true;
151
+ }
152
+ return false;
153
+ }
154
+
155
+ /**
156
+ *
157
+ */
158
+ private function _recreateFieldExistsProcedure()
159
+ {
160
+ $sql = "CREATE PROCEDURE FIELD_EXISTS(
161
+ OUT _exists BOOLEAN, -- return value
162
+ IN tableName CHAR(255), -- name of table to look for
163
+ IN columnName CHAR(255), -- name of column to look for
164
+ IN dbName CHAR(255) -- optional specific db
165
+ ) BEGIN
166
+ -- try to lookup db if none provided
167
+ SET @_dbName := IF(dbName IS NULL, database(), dbName);
168
+
169
+ IF CHAR_LENGTH(@_dbName) = 0
170
+ THEN -- no specific or current db to check against
171
+ SELECT
172
+ FALSE
173
+ INTO _exists;
174
+ ELSE -- we have a db to work with
175
+ SELECT
176
+ IF(count(*) > 0, TRUE, FALSE)
177
+ INTO _exists
178
+ FROM information_schema.COLUMNS c
179
+ WHERE
180
+ c.TABLE_SCHEMA = @_dbName
181
+ AND c.TABLE_NAME = tableName
182
+ AND c.COLUMN_NAME = columnName;
183
+ END IF;
184
+ END;";
185
+ $this->_writer->query($sql);
186
+ }
187
+
188
+ /**
189
+ * @param $sql
190
+ * @return bool
191
+ */
192
+ public function readQuery($sql)
193
+ {
194
+ if (!empty($sql) && is_string($sql)) {
195
+ return $this->_reader->fetchAll($sql);
196
+ }
197
+ return false;
198
+ }
199
+
200
+ /**
201
+ * @param $key
202
+ * @param $value
203
+ * @param string $type
204
+ * @return bool
205
+ */
206
+ public function insertLogEntry($key, $value, $type = 'info')
207
+ {
208
+ if ($type == 'error') {
209
+ $this->rotateLog();
210
+ }
211
+ if (!empty($key)) {
212
+ return $this->_writer->query("INSERT INTO `{$this->_prefix}iceshop_extensions_logs` (`log_key`, `log_value`, `log_type`)
213
+ VALUES ('{$key}', '{$value}', '{$type}')
214
+ ON DUPLICATE KEY UPDATE `log_value` = VALUES(`log_value`), `log_type` = VALUES(`log_type`)");
215
+ }
216
+ return false;
217
+ }
218
+
219
+ /**
220
+ * @param string $log_type
221
+ * @return bool
222
+ */
223
+ public function rotateLog($log_type = 'error')
224
+ {
225
+ $sql = "SELECT COUNT(*) AS row_amount
226
+ FROM `{$this->_prefix}iceshop_extensions_logs`
227
+ WHERE `log_type` = '{$log_type}';";
228
+ $value = $this->_reader->fetchAll($sql);
229
+ $row_amount = 0;
230
+ if (array_key_exists(0, $value)) {
231
+ $row_amount = $value[0]['row_amount'];
232
+ }
233
+ if ($row_amount > self::LOG_ROWS_LIMIT) {
234
+ $rows_to_delete = $row_amount - self::LOG_ROWS_LIMIT;
235
+ return $this->_writer->query("DELETE
236
+ FROM `{$this->_prefix}iceshop_extensions_logs`
237
+ WHERE `log_type` = '{$log_type}'
238
+ ORDER BY `log_id` ASC
239
+ LIMIT {$rows_to_delete}");
240
+ }
241
+ return false;
242
+ }
243
+
244
+ /**
245
+ * @param $key
246
+ * @return bool
247
+ */
248
+ public function getLogEntryByKey($key)
249
+ {
250
+ if (!empty($key)) {
251
+ $sql = "SELECT `log_value`, `log_type`
252
+ FROM `{$this->_prefix}iceshop_extensions_logs`
253
+ WHERE `log_key` = '{$key}'
254
+ ORDER BY `log_id` DESC
255
+ LIMIT 1;";
256
+ $value = $this->_reader->fetchAll($sql);
257
+ if (array_key_exists(0, $value)) {
258
+ return $value[0];
259
+ }
260
+ }
261
+ return false;
262
+ }
263
+
264
+ /**
265
+ * @param bool $type
266
+ * @param string $comparison
267
+ * @param int $limit
268
+ * @return array|bool
269
+ */
270
+ public function getLogByType($type = false, $comparison = 'eq', $limit = 10)
271
+ {
272
+ $comparison_whitelist = array('eq', 'neq');
273
+ if (!in_array($comparison, $comparison_whitelist)) {
274
+ $comparison = 'eq';
275
+ }
276
+ if (!empty($type)) {
277
+ if ($type == 'report') {
278
+ $result_arr = array();
279
+ $sql = "SELECT `log_value`, `timecol`
280
+ FROM `{$this->_prefix}iceshop_extensions_logs`
281
+ WHERE `log_type` = 'error'
282
+ AND (`timecol` > DATE_SUB(now(), INTERVAL 1 DAY))
283
+ ORDER BY `log_id` DESC
284
+ LIMIT {$limit};";
285
+ $results = $this->_reader->fetchAll($sql);
286
+ foreach ($results as $row) {
287
+ $result_arr[] = $row;
288
+ }
289
+ return (!empty($result_arr)) ? $result_arr : false;
290
+ } else {
291
+ switch($comparison) {
292
+ case 'eq':
293
+ $result_arr = array();
294
+ $sql = "SELECT `log_value`, `timecol`
295
+ FROM `{$this->_prefix}iceshop_extensions_logs`
296
+ WHERE `log_type` = '{$type}'
297
+ ORDER BY `log_id` DESC
298
+ LIMIT {$limit};";
299
+ $results = $this->_reader->fetchAll($sql);
300
+ foreach ($results as $row) {
301
+ $result_arr[] = $row;
302
+ }
303
+ return (!empty($result_arr)) ? $result_arr : false;
304
+ break;
305
+
306
+ case 'neq':
307
+ $result_arr = array();
308
+ $sql = "SELECT `log_value`, `timecol`
309
+ FROM `{$this->_prefix}iceshop_extensions_logs`
310
+ WHERE `log_type` <> '{$type}'
311
+ ORDER BY `log_id` DESC
312
+ LIMIT {$limit};";
313
+ $results = $this->_reader->fetchAll($sql);
314
+ foreach ($results as $row) {
315
+ $result_arr[] = $row;
316
+ }
317
+ return (!empty($result_arr)) ? $result_arr : false;
318
+ break;
319
+ }
320
+ }
321
+ } else {
322
+ $sql = "SELECT `log_value`, `log_type`, `timecol`
323
+ FROM `{$this->_prefix}iceshop_extensions_logs`
324
+ ORDER BY `log_id` DESC
325
+ LIMIT {$limit};";
326
+ return $this->_reader->fetchAll($sql);
327
+ }
328
+ }
329
+
330
+ /**
331
+ * @param $key
332
+ * @return bool
333
+ */
334
+ public function deleteLogEntry($key)
335
+ {
336
+ if (!empty($key)) {
337
+ return $this->_writer->query("DELETE
338
+ FROM `{$this->_prefix}iceshop_extensions_logs`
339
+ WHERE `log_key` = '{$key}';");
340
+ }
341
+ return false;
342
+ }
343
+
344
+ /**
345
+ * @param $table_name
346
+ * @return bool
347
+ */
348
+ public function getTableName($table_name)
349
+ {
350
+ if (!empty($table_name) && is_string($table_name)) {
351
+ return $this->_resource->getTableName($table_name);
352
+ }
353
+ return false;
354
+ }
355
+
356
+
357
+ /**
358
+ * @param string $setting_key
359
+ * @param string $setting_value
360
+ * @access public
361
+ * @return bool
362
+ */
363
+ public function setConfigData($setting_key, $setting_value)
364
+ {
365
+ if (isset($setting_key) && isset($setting_value)) {
366
+ $table_name = $this->getTableName('core/config_data');
367
+ $sql = "REPLACE INTO `{$table_name}`(`path`, `value`) VALUES(:setting_key, :setting_value);";
368
+ $binds = array(
369
+ 'setting_key' => $this->_getConfigKey($setting_key),
370
+ 'setting_value' => $setting_value
371
+ );
372
+ $this->_writer->query($sql, $binds);
373
+ return true;
374
+ }
375
+ return false;
376
+ }
377
+
378
+ /**
379
+ * @param string $setting_key
380
+ * @access public
381
+ * @return bool|string
382
+ */
383
+ public function getConfigData($setting_key)
384
+ {
385
+ if (isset($setting_key)) {
386
+ $table_name = $this->getTableName('core/config_data');
387
+ $sql = "SELECT `value` FROM `{$table_name}` WHERE `path` = :setting_key;";
388
+ $binds = array(
389
+ 'setting_key' => $this->_getConfigKey($setting_key)
390
+ );
391
+ $result = $this->_reader->query($sql, $binds);
392
+ while ( $row = $result->fetch() ) {
393
+ return $row['value'];
394
+ }
395
+ }
396
+ return false;
397
+ }
398
+
399
+ /**
400
+ * @param string $setting_key
401
+ * @access private
402
+ * @return bool|string
403
+ */
404
+ private function _getConfigKey($setting_key)
405
+ {
406
+ if (isset($setting_key)) {
407
+ return 'iceimport/storage/' . $setting_key;
408
+ }
409
+ return false;
410
+ }
411
+
412
+ /**
413
+ * @param string $setting_key
414
+ * @access public
415
+ * @return bool
416
+ */
417
+ public function unsetConfigData($setting_key)
418
+ {
419
+ if (isset($setting_key)) {
420
+ $table_name = $this->getTableName('core/config_data');
421
+ $sql = "DELETE FROM `{$table_name}` WHERE `path` = :setting_key;";
422
+ $binds = array(
423
+ 'setting_key' => $this->_getConfigKey($setting_key)
424
+ );
425
+ $this->_writer->query($sql, $binds);
426
+ return true;
427
+ }
428
+ return false;
429
+ }
430
}
app/code/community/ICEshop/Iceimport/Helper/Format.php CHANGED
@@ -1,251 +1,251 @@
1
- <?php
2
- /******************************************************************************
3
- * Copyright (c) 2010 Jevon Wright and others.
4
- * All rights reserved. This program and the accompanying materials
5
- * are made available under the terms of the Eclipse Public License v1.0
6
- * which accompanies this distribution, and is available at
7
- * http://www.eclipse.org/legal/epl-v10.html
8
- *
9
- * Contributors:
10
- * Jevon Wright - initial API and implementation
11
- ****************************************************************************/
12
-
13
- /**
14
- * Tries to convert the given HTML into a plain text format - best suited for
15
- * e-mail display, etc.
16
- *
17
- * <p>In particular, it tries to maintain the following features:
18
- * <ul>
19
- * <li>Links are maintained, with the 'href' copied over
20
- * <li>Information in the &lt;head&gt; is lost
21
- * </ul>
22
- *
23
- * @param html the input HTML
24
- * @return the HTML converted, as best as possible, to text
25
- */
26
- class ICEshop_Iceimport_Helper_Format extends Mage_Core_Helper_Abstract
27
- {
28
- /**
29
- * @param $html
30
- * @return mixed|string
31
- */
32
- public function convert_html_to_text($html)
33
- {
34
- $html = $this->fix_newlines($html);
35
-
36
- $doc = new DOMDocument();
37
- if (!$doc->loadHTML($html))
38
- return "Could not load HTML - badly formed?";
39
-
40
- $output = $this->iterate_over_node($doc);
41
-
42
- // remove leading and trailing spaces on each line
43
- $output = preg_replace("/[ \t]*\n[ \t]*/im", "\n", $output);
44
-
45
- // remove leading and trailing whitespace
46
- $output = trim($output);
47
-
48
- return $output;
49
- }
50
-
51
- /**
52
- * Unify newlines; in particular, \r\n becomes \n, and
53
- * then \r becomes \n. This means that all newlines (Unix, Windows, Mac)
54
- * all become \ns.
55
- *
56
- * @param text text with any number of \r, \r\n and \n combinations
57
- * @return the fixed text
58
- */
59
- private function fix_newlines($text)
60
- {
61
- // replace \r\n to \n
62
- $text = str_replace("\r\n", "\n", $text);
63
- // remove \rs
64
- $text = str_replace("\r", "\n", $text);
65
-
66
- return $text;
67
- }
68
-
69
- /**
70
- * @param $node
71
- * @return null|string
72
- */
73
- private function next_child_name($node)
74
- {
75
- // get the next child
76
- $nextNode = $node->nextSibling;
77
- while ($nextNode != null) {
78
- if ($nextNode instanceof DOMElement) {
79
- break;
80
- }
81
- $nextNode = $nextNode->nextSibling;
82
- }
83
- $nextName = null;
84
- if ($nextNode instanceof DOMElement && $nextNode != null) {
85
- $nextName = strtolower($nextNode->nodeName);
86
- }
87
-
88
- return $nextName;
89
- }
90
-
91
- /**
92
- * @param $node
93
- * @return null|string
94
- */
95
- private function prev_child_name($node)
96
- {
97
- // get the previous child
98
- $nextNode = $node->previousSibling;
99
- while ($nextNode != null) {
100
- if ($nextNode instanceof DOMElement) {
101
- break;
102
- }
103
- $nextNode = $nextNode->previousSibling;
104
- }
105
- $nextName = null;
106
- if ($nextNode instanceof DOMElement && $nextNode != null) {
107
- $nextName = strtolower($nextNode->nodeName);
108
- }
109
-
110
- return $nextName;
111
- }
112
-
113
- /**
114
- * @param $node
115
- * @return mixed|string
116
- */
117
- private function iterate_over_node($node)
118
- {
119
- if ($node instanceof DOMText) {
120
- return preg_replace("/\\s+/im", " ", $node->wholeText);
121
- }
122
- if ($node instanceof DOMDocumentType) {
123
- // ignore
124
- return "";
125
- }
126
-
127
- $nextName = $this->next_child_name($node);
128
- $prevName = $this->prev_child_name($node);
129
-
130
- $name = strtolower($node->nodeName);
131
-
132
- // start whitespace
133
- switch ($name) {
134
- case "hr":
135
- return "------\n";
136
-
137
- case "style":
138
- case "head":
139
- case "title":
140
- case "meta":
141
- case "script":
142
- // ignore these tags
143
- return "";
144
-
145
- case "h1":
146
- case "h2":
147
- case "h3":
148
- case "h4":
149
- case "h5":
150
- case "h6":
151
- // add two newlines
152
- $output = "\n";
153
- break;
154
-
155
- case "p":
156
- case "div":
157
- // add one line
158
- $output = "\n";
159
- break;
160
-
161
- default:
162
- // print out contents of unknown tags
163
- $output = "";
164
- break;
165
- }
166
-
167
- // debug
168
- //$output .= "[$name,$nextName]";
169
-
170
- for ($i = 0; $i < $node->childNodes->length; $i++) {
171
- $n = $node->childNodes->item($i);
172
-
173
- $text = $this->iterate_over_node($n);
174
-
175
- $output .= $text;
176
- }
177
-
178
- // end whitespace
179
- switch ($name) {
180
- case "style":
181
- case "head":
182
- case "title":
183
- case "meta":
184
- case "script":
185
- // ignore these tags
186
- return "";
187
-
188
- case "tr":
189
- case "h1":
190
- case "h2":
191
- case "h3":
192
- case "h4":
193
- case "h5":
194
- case "h6":
195
- $output .= "\n";
196
- break;
197
-
198
- case "td":
199
- $output .= "\t";
200
- break;
201
-
202
- case "p":
203
- case "br":
204
- // add one line
205
- if ($nextName != "div")
206
- $output .= "\n";
207
- break;
208
-
209
- case "div":
210
- // add one line only if the next child isn't a div
211
- if ($nextName != "div" && $nextName != null)
212
- $output .= "\n";
213
- break;
214
-
215
- case "a":
216
- // links are returned in [text](link) format
217
- $href = $node->getAttribute("href");
218
- if ($href == null) {
219
- // it doesn't link anywhere
220
- if ($node->getAttribute("name") != null) {
221
- $output = "[$output]";
222
- }
223
- } else {
224
- if ($href == $output) {
225
- // link to the same address: just use link
226
- $output;
227
- } else {
228
- // replace it
229
- $output = "[$output]($href)";
230
- }
231
- }
232
-
233
- // does the next node require additional whitespace?
234
- switch ($nextName) {
235
- case "h1":
236
- case "h2":
237
- case "h3":
238
- case "h4":
239
- case "h5":
240
- case "h6":
241
- $output .= "\n";
242
- break;
243
- }
244
-
245
- default:
246
- // do nothing
247
- }
248
-
249
- return $output;
250
- }
251
}
1
+ <?php
2
+ /******************************************************************************
3
+ * Copyright (c) 2010 Jevon Wright and others.
4
+ * All rights reserved. This program and the accompanying materials
5
+ * are made available under the terms of the Eclipse Public License v1.0
6
+ * which accompanies this distribution, and is available at
7
+ * http://www.eclipse.org/legal/epl-v10.html
8
+ *
9
+ * Contributors:
10
+ * Jevon Wright - initial API and implementation
11
+ ****************************************************************************/
12
+
13
+ /**
14
+ * Tries to convert the given HTML into a plain text format - best suited for
15
+ * e-mail display, etc.
16
+ *
17
+ * <p>In particular, it tries to maintain the following features:
18
+ * <ul>
19
+ * <li>Links are maintained, with the 'href' copied over
20
+ * <li>Information in the &lt;head&gt; is lost
21
+ * </ul>
22
+ *
23
+ * @param html the input HTML
24
+ * @return the HTML converted, as best as possible, to text
25
+ */
26
+ class ICEshop_Iceimport_Helper_Format extends Mage_Core_Helper_Abstract
27
+ {
28
+ /**
29
+ * @param $html
30
+ * @return mixed|string
31
+ */
32
+ public function convert_html_to_text($html)
33
+ {
34
+ $html = $this->fix_newlines($html);
35
+
36
+ $doc = new DOMDocument();
37
+ if (!$doc->loadHTML($html))
38
+ return "Could not load HTML - badly formed?";
39
+
40
+ $output = $this->iterate_over_node($doc);
41
+
42
+ // remove leading and trailing spaces on each line
43
+ $output = preg_replace("/[ \t]*\n[ \t]*/im", "\n", $output);
44
+
45
+ // remove leading and trailing whitespace
46
+ $output = trim($output);
47
+
48
+ return $output;
49
+ }
50
+
51
+ /**
52
+ * Unify newlines; in particular, \r\n becomes \n, and
53
+ * then \r becomes \n. This means that all newlines (Unix, Windows, Mac)
54
+ * all become \ns.
55
+ *
56
+ * @param text text with any number of \r, \r\n and \n combinations
57
+ * @return the fixed text
58
+ */
59
+ private function fix_newlines($text)
60
+ {
61
+ // replace \r\n to \n
62
+ $text = str_replace("\r\n", "\n", $text);
63
+ // remove \rs
64
+ $text = str_replace("\r", "\n", $text);
65
+
66
+ return $text;
67
+ }
68
+
69
+ /**
70
+ * @param $node
71
+ * @return null|string
72
+ */
73
+ private function next_child_name($node)
74
+ {
75
+ // get the next child
76
+ $nextNode = $node->nextSibling;
77
+ while ($nextNode != null) {
78
+ if ($nextNode instanceof DOMElement) {
79
+ break;
80
+ }
81
+ $nextNode = $nextNode->nextSibling;
82
+ }
83
+ $nextName = null;
84
+ if ($nextNode instanceof DOMElement && $nextNode != null) {
85
+ $nextName = strtolower($nextNode->nodeName);
86
+ }
87
+
88
+ return $nextName;
89
+ }
90
+
91
+ /**
92
+ * @param $node
93
+ * @return null|string
94
+ */
95
+ private function prev_child_name($node)
96
+ {
97
+ // get the previous child
98
+ $nextNode = $node->previousSibling;
99
+ while ($nextNode != null) {
100
+ if ($nextNode instanceof DOMElement) {
101
+ break;
102
+ }
103
+ $nextNode = $nextNode->previousSibling;
104
+ }
105
+ $nextName = null;
106
+ if ($nextNode instanceof DOMElement && $nextNode != null) {
107
+ $nextName = strtolower($nextNode->nodeName);
108
+ }
109
+
110
+ return $nextName;
111
+ }
112
+
113
+ /**
114
+ * @param $node
115
+ * @return mixed|string
116
+ */
117
+ private function iterate_over_node($node)
118
+ {
119
+ if ($node instanceof DOMText) {
120
+ return preg_replace("/\\s+/im", " ", $node->wholeText);
121
+ }
122
+ if ($node instanceof DOMDocumentType) {
123
+ // ignore
124
+ return "";
125
+ }
126
+
127
+ $nextName = $this->next_child_name($node);
128
+ $prevName = $this->prev_child_name($node);
129
+
130
+ $name = strtolower($node->nodeName);
131
+
132
+ // start whitespace
133
+ switch ($name) {
134
+ case "hr":
135
+ return "------\n";
136
+
137
+ case "style":
138
+ case "head":
139
+ case "title":
140
+ case "meta":
141
+ case "script":
142
+ // ignore these tags
143
+ return "";
144
+
145
+ case "h1":
146
+ case "h2":
147
+ case "h3":
148
+ case "h4":
149
+ case "h5":
150
+ case "h6":
151
+ // add two newlines
152
+ $output = "\n";
153
+ break;
154
+
155
+ case "p":
156
+ case "div":
157
+ // add one line
158
+ $output = "\n";
159
+ break;
160
+
161
+ default:
162
+ // print out contents of unknown tags
163
+ $output = "";
164
+ break;
165
+ }
166
+
167
+ // debug
168
+ //$output .= "[$name,$nextName]";
169
+
170
+ for ($i = 0; $i < $node->childNodes->length; $i++) {
171
+ $n = $node->childNodes->item($i);
172
+
173
+ $text = $this->iterate_over_node($n);
174
+
175
+ $output .= $text;
176
+ }
177
+
178
+ // end whitespace
179
+ switch ($name) {
180
+ case "style":
181
+ case "head":
182
+ case "title":
183
+ case "meta":
184
+ case "script":
185
+ // ignore these tags
186
+ return "";
187
+
188
+ case "tr":
189
+ case "h1":
190
+ case "h2":
191
+ case "h3":
192
+ case "h4":
193
+ case "h5":
194
+ case "h6":
195
+ $output .= "\n";
196
+ break;
197
+
198
+ case "td":
199
+ $output .= "\t";
200
+ break;
201
+
202
+ case "p":
203
+ case "br":
204
+ // add one line
205
+ if ($nextName != "div")
206
+ $output .= "\n";
207
+ break;
208
+
209
+ case "div":
210
+ // add one line only if the next child isn't a div
211
+ if ($nextName != "div" && $nextName != null)
212
+ $output .= "\n";
213
+ break;
214
+
215
+ case "a":
216
+ // links are returned in [text](link) format
217
+ $href = $node->getAttribute("href");
218
+ if ($href == null) {
219
+ // it doesn't link anywhere
220
+ if ($node->getAttribute("name") != null) {
221
+ $output = "[$output]";
222
+ }
223
+ } else {
224
+ if ($href == $output) {
225
+ // link to the same address: just use link
226
+ $output;
227
+ } else {
228
+ // replace it
229
+ $output = "[$output]($href)";
230
+ }
231
+ }
232
+
233
+ // does the next node require additional whitespace?
234
+ switch ($nextName) {
235
+ case "h1":
236
+ case "h2":
237
+ case "h3":
238
+ case "h4":
239
+ case "h5":
240
+ case "h6":
241
+ $output .= "\n";
242
+ break;
243
+ }
244
+
245
+ default:
246
+ // do nothing
247
+ }
248
+
249
+ return $output;
250
+ }
251
}
app/code/community/ICEshop/Iceimport/Helper/System/System.php CHANGED
@@ -1,461 +1,461 @@
1
- <?php
2
-
3
- /**
4
- * Class Iceshop_Iceimport_Helper_System_System
5
- */
6
- class Iceshop_Iceimport_Helper_System_System extends Mage_Core_Helper_Abstract
7
- {
8
- /**
9
- * Sorts a multi-dimensional array with the given values
10
- *
11
- * Seen and modified from: http://www.firsttube.com/read/sorting-a-multi-dimensional-array-with-php/
12
- *
13
- * @param array $arr Array to sort
14
- * @param string $key Field to sort
15
- * @param string $dir Direction to sort
16
- * @return array Sorted array
17
- */
18
- public function sortMultiDimArr($arr, $key, $dir = 'ASC')
19
- {
20
- foreach ($arr as $k => $v) {
21
- $b[$k] = strtolower($v[$key]);
22
- }
23
-
24
- if ($dir == 'ASC') {
25
- asort($b);
26
- } else {
27
- arsort($b);
28
- }
29
- foreach ($b as $key => $val) {
30
- $c[] = $arr[$key];
31
- }
32
-
33
- return $c;
34
- }
35
-
36
- /**
37
- * Activate/Deactivate a Magento module
38
- *
39
- * @param string $name
40
- * @return string
41
- */
42
- public function deactivateModule($name)
43
- {
44
- $isDeactivationPossible = true;
45
- foreach (Mage::getConfig()->getNode('modules')->children() as $moduleName => $item) {
46
- if ($moduleName == $name) {
47
- continue;
48
- }
49
- if ($item->depends) {
50
- foreach ($item->depends->children() as $depend) {
51
- if ($depend->getName() == $name) {
52
- if ((string)Mage::getConfig()->getModuleConfig($moduleName)->is('active', 'true')) {
53
- $isDeactivationPossible = false;
54
- }
55
- }
56
- }
57
- }
58
- }
59
-
60
- if ($isDeactivationPossible) {
61
- $xmlPath = Mage::getBaseDir() . DS . 'app' . DS . 'etc' . DS . 'modules' . DS . $name . '.xml';
62
- if (file_exists($xmlPath)) {
63
- $xmlObj = new Varien_Simplexml_Config($xmlPath);
64
-
65
- $currentValue = (string)$xmlObj->getNode('modules/' . $name . '/active');
66
- if ($currentValue == 'true') {
67
- $value = false;
68
- } else {
69
- $value = true;
70
- }
71
-
72
- $xmlObj->setNode(
73
- 'modules/' . $name . '/active',
74
- $value ? 'true' : 'false'
75
- );
76
-
77
- if (is_writable($xmlPath)) {
78
- $xmlData = $xmlObj->getNode()->asNiceXml();
79
- @file_put_contents($xmlPath, $xmlData);
80
- Mage::app()->getCacheInstance()->clean();
81
- if ($value) {
82
- $status = $this->__('The module "%s" has been successfully activated.', $name);
83
- } else {
84
- $status = $this->__('The module "%s" has been successfully deactivated.', $name);
85
- }
86
- } else {
87
- $status = $this->__('File %s is not writable.', $xmlPath);
88
- }
89
- } else {
90
- $status = $this->__(
91
- 'Module %s is probably not installed. File %s does not exist.',
92
- $name,
93
- $xmlPath
94
- );
95
- }
96
- } else {
97
- $status = $this->__('Module can\'t be deactivated because it is a dependency of another module which is still active.');
98
- }
99
-
100
- return $status;
101
- }
102
-
103
- /**
104
- * Retrieve a collection of all rewrites
105
- *
106
- * @return Varien_Data_Collection Collection
107
- */
108
- public function getRewriteCollection()
109
- {
110
- $collection = new Varien_Data_Collection();
111
- $rewrites = $this->_loadRewrites();
112
-
113
- foreach ($rewrites as $rewriteNodes) {
114
- foreach ($rewriteNodes as $n) {
115
- $nParent = $n->xpath('..');
116
- $module = (string)$nParent[0]->getName();
117
- $nSubParent = $nParent[0]->xpath('..');
118
- $component = (string)$nSubParent[0]->getName();
119
-
120
- if (!in_array($component, array('blocks', 'helpers', 'models'))) {
121
- continue;
122
- }
123
-
124
- $pathNodes = $n->children();
125
- foreach ($pathNodes as $pathNode) {
126
- $path = (string)$pathNode->getName();
127
- $completePath = $module . '/' . $path;
128
-
129
- $rewriteClassName = (string)$pathNode;
130
-
131
- $instance = Mage::getConfig()->getGroupedClassName(
132
- substr($component, 0, -1),
133
- $completePath
134
- );
135
-
136
- $collection->addItem(
137
- new Varien_Object(
138
- array(
139
- 'path' => $completePath,
140
- 'rewrite_class' => $rewriteClassName,
141
- 'active_class' => $instance,
142
- 'status' => ($instance == $rewriteClassName)
143
- )
144
- )
145
- );
146
- }
147
- }
148
- }
149
-
150
- return $collection;
151
- }
152
-
153
- /**
154
- * Return all rewrites
155
- *
156
- * @return array All rwrites
157
- */
158
- protected function _loadRewrites()
159
- {
160
- $fileName = 'config.xml';
161
- $modules = Mage::getConfig()->getNode('modules')->children();
162
-
163
- $return = array();
164
- foreach ($modules as $modName => $module) {
165
- if ($module->is('active')) {
166
- $configFile = Mage::getConfig()->getModuleDir('etc', $modName) . DS . $fileName;
167
- if (file_exists($configFile)) {
168
- $xml = file_get_contents($configFile);
169
- $xml = simplexml_load_string($xml);
170
-
171
- if ($xml instanceof SimpleXMLElement) {
172
- $return[$modName] = $xml->xpath('//rewrite');
173
- }
174
- }
175
- }
176
- }
177
-
178
- return $return;
179
- }
180
-
181
- /**
182
- * Retrieve a collection of all modules
183
- *
184
- * @return Varien_Data_Collection Collection
185
- */
186
- public function getModulesCollection()
187
- {
188
- $sortValue = Mage::app()->getRequest()->getParam('sort', 'name');
189
- $sortValue = strtolower($sortValue);
190
-
191
- $sortDir = Mage::app()->getRequest()->getParam('dir', 'ASC');
192
- $sortDir = strtoupper($sortDir);
193
-
194
- $modules = $this->_loadModules();
195
- $modules = $this->sortMultiDimArr($modules, $sortValue, $sortDir);
196
-
197
- $collection = new Varien_Data_Collection();
198
- foreach ($modules as $val) {
199
- $item = new Varien_Object($val);
200
- $collection->addItem($item);
201
- }
202
-
203
- return $collection;
204
- }
205
-
206
- /**
207
- * Loads the module configurations and checks for some criteria and
208
- * returns an array with the current modules in the Magento instance.
209
- *
210
- * @return array Modules
211
- */
212
- protected function _loadModules()
213
- {
214
- $modules = array();
215
- $config = Mage::getConfig();
216
- foreach ($config->getNode('modules')->children() as $item) {
217
- $active = ($item->active == 'true') ? true : false;
218
- $codePool = (string)$config->getModuleConfig($item->getName())->codePool;
219
- $path = $config->getOptions()->getCodeDir() . DS . $codePool . DS . uc_words($item->getName(), DS);
220
- $pathExists = file_exists($path);
221
- $pathExists = $pathExists ? true : false;
222
- $configExists = file_exists($path . '/etc/config.xml');
223
- $configExists = $configExists ? true : false;
224
- $version = (string)$config->getModuleConfig($item->getName())->version;
225
-
226
- $dependencies = '-';
227
- if ($item->depends) {
228
- $depends = array();
229
- foreach ($item->depends->children() as $depend) {
230
- $depends[] = $depend->getName();
231
- }
232
- if (is_array($depends) && count($depends) > 0) {
233
- asort($depends);
234
- $dependencies = implode("\n", $depends);
235
- }
236
- }
237
-
238
- $modules[$item->getName()] = array(
239
- 'name' => $item->getName(),
240
- 'active' => $active,
241
- 'code_pool' => $codePool,
242
- 'path' => $path,
243
- 'path_exists' => $pathExists,
244
- 'config_exists' => $configExists,
245
- 'version' => $version,
246
- 'dependencies' => $dependencies
247
- );
248
- }
249
-
250
- return $modules;
251
- }
252
-
253
- /**
254
- * Retrieve a collection of all events
255
- *
256
- * @return Varien_Data_Collection Collection
257
- */
258
- public function getEventsCollection()
259
- {
260
- $sortValue = Mage::app()->getRequest()->getParam('sort', 'event');
261
- $sortValue = strtolower($sortValue);
262
-
263
- $sortDir = Mage::app()->getRequest()->getParam('dir', 'ASC');
264
- $sortDir = strtoupper($sortDir);
265
-
266
- $events = $this->_loadEvents();
267
- $events = $this->sortMultiDimArr($events, $sortValue, $sortDir);
268
-
269
- $collection = new Varien_Data_Collection();
270
- foreach ($events as $item) {
271
- $values = $item['children'];
272
- if (is_array($values)) {
273
- asort($values);
274
- }
275
-
276
- $val = array(
277
- 'event' => $item['event'],
278
- 'location' => implode("\n", $values)
279
- );
280
-
281
- $item = new Varien_Object($val);
282
- $collection->addItem($item);
283
- }
284
-
285
- return $collection;
286
- }
287
-
288
- /**
289
- * Return all events
290
- *
291
- * @return array All events
292
- */
293
- protected function _loadEvents()
294
- {
295
- $fileName = 'config.xml';
296
- $modules = Mage::getConfig()->getNode('modules')->children();
297
-
298
-