35
35
36
36
class Mollie_Mpm_Helper_Data extends Mage_Core_Helper_Abstract
37
37
{
38
+ public $ update_url = 'https://github.com/mollie/Magento ' ;
39
+ public $ should_update = 'maybe ' ;
38
40
39
41
/**
40
42
* Get payment bank status by order_id
@@ -155,7 +157,7 @@ public function getApiKey()
155
157
*/
156
158
public function getConfig ($ paymentmethod = NULL , $ key = NULL )
157
159
{
158
- $ arr = array ('active ' , 'apikey ' , 'description ' , 'skip_invoice ' , 'skip_order_mails ' , 'skip_invoice_mails ' , 'show_images ' , 'show_bank_list ' , ' webhook_tested ' );
160
+ $ arr = array ('active ' , 'apikey ' , 'description ' , 'skip_invoice ' , 'skip_order_mails ' , 'skip_invoice_mails ' , 'show_images ' , 'show_bank_list ' );
159
161
$ paymentmethods = array ('mollie ' );
160
162
161
163
if (in_array ($ key , $ arr ) && in_array ($ paymentmethod , $ paymentmethods ))
@@ -170,8 +172,19 @@ public function getConfig($paymentmethod = NULL, $key = NULL)
170
172
*/
171
173
public function getModuleStatus ($ method_count , $ method_limit )
172
174
{
175
+ /* Precedence:
176
+ * 1) Missing files
177
+ * 2) Magento version
178
+ * 3) New version on github
179
+ * 4) Method limit
180
+ * 5) Disabled check
181
+ * 6) Deprecated files
182
+ */
183
+
173
184
$ core = Mage::helper ('core ' );
174
- // check missing files
185
+
186
+
187
+ // 1) Check missing files
175
188
$ needFiles = array ();
176
189
$ modFiles = array (
177
190
Mage::getBaseDir ('lib ' ) . "/Mollie/src/Mollie/API/Client.php " ,
@@ -223,7 +236,7 @@ public function getModuleStatus($method_count, $method_limit)
223
236
}
224
237
225
238
226
- // check version
239
+ // 2) Check magento version
227
240
if ( version_compare (Mage::getVersion (), '1.4.1.0 ' , '< ' ))
228
241
{
229
242
return '<b> ' .$ core ->__ ('Version incompatible! ' ).'</b><br />
@@ -235,7 +248,14 @@ public function getModuleStatus($method_count, $method_limit)
235
248
}
236
249
237
250
238
- // check method count
251
+ // 3) Check github version
252
+ if ($ this ->should_update === 'yes ' )
253
+ {
254
+ return '<b> ' .$ core ->__ ('Status ' ).'</b><br /><span style="color:#EB5E00"> ' .$ core ->__ ('Module status: Outdated! ' ).'</span> ' ;
255
+ }
256
+
257
+
258
+ // 4) Check method limit
239
259
if ($ method_count > $ method_limit )
240
260
{
241
261
return '<b> ' .$ core ->__ ('Module outdated! ' ).'</b><br />
@@ -247,14 +267,14 @@ public function getModuleStatus($method_count, $method_limit)
247
267
}
248
268
249
269
250
- // Check if webhook is set
251
- if (!Mage::Helper ('mpm/data ' )->getConfig ('mollie ' , 'webhook_tested ' ))
270
+ // 5) Check if disabled
271
+ if (!Mage::Helper ('mpm/data ' )->getConfig ('mollie ' , 'active ' ))
252
272
{
253
- return '<b> ' .$ core ->__ ('Webhook not set! ' ).'</b><br /><span style="color:red; "> ' .$ core ->__ ('Warning: It seems you have not set a webhook in your Mollie profile. ' ).'</span><br / > ' ;
273
+ return '<b> ' .$ core ->__ ('Status ' ).'</b><br /><span style="color:#EB5E00 "> ' .$ core ->__ ('Module status: Disabled! ' ).'</span> ' ;
254
274
}
255
275
256
276
257
- // check deprecated files
277
+ // 6) Check deprecated files
258
278
$ deprFiles = array ();
259
279
$ oldFiles = array (
260
280
Mage::getRoot () .'/code/community/Mollie/Mpm/Block/Payment/Idl/Fail.php ' ,
@@ -273,11 +293,13 @@ public function getModuleStatus($method_count, $method_limit)
273
293
}
274
294
}
275
295
296
+
276
297
if (count ($ deprFiles ) > 0 )
277
298
{
278
299
return '<b> ' .$ core ->__ ('Outdated file(s) found! ' ).'</b><br /> ' . implode ('<br /> ' , $ deprFiles ) . '<br /> ' .$ core ->__ ('These aren‘t needed any longer; you might as well delete them. ' );
279
300
}
280
301
302
+ // All is fine
281
303
return '<b> ' .$ core ->__ ('Status ' ).'</b><br /><span style="color:green"> ' .$ core ->__ ('Module status: OK! ' ).'</span> ' ;
282
304
}
283
305
@@ -286,4 +308,56 @@ public function getModuleVersion()
286
308
return Mage::getConfig ()->getNode ('modules ' )->children ()->Mollie_Mpm ->version ;
287
309
}
288
310
311
+ /**
312
+ * @return string
313
+ */
314
+ public function _getUpdateMessage ()
315
+ {
316
+ $ core = Mage::helper ('core ' );
317
+ $ update_message = '' ;
318
+ $ update_xml = $ this ->_getUpdateXML ();
319
+ if ($ update_xml === FALSE )
320
+ {
321
+ $ this ->should_update = 'maybe ' ;
322
+ $ update_message = $ core ->__ ('Warning: Could not retrieve update xml file from github. ' , 'mollie ' );
323
+ }
324
+ else
325
+ {
326
+ /** @var SimpleXMLElement $tags */
327
+ $ tags = new SimpleXMLElement ($ update_xml );
328
+ if (!empty ($ tags ) && isset ($ tags ->entry , $ tags ->entry [0 ], $ tags ->entry [0 ]->id ))
329
+ {
330
+ $ title = $ tags ->entry [0 ]->id ;
331
+ $ latest_version = preg_replace ("/[^0-9,.]/ " , "" , substr ($ title , strrpos ($ title , '/ ' )));
332
+ $ this_version = $ this ->getModuleVersion ();
333
+ if (!version_compare ($ this_version , $ latest_version , '>= ' ))
334
+ {
335
+ $ update_message = sprintf (
336
+ $ core ->__ ('<a href=%s/releases>You are currently using version %s. We strongly recommend you to upgrade to the new version %s!</a> ' , 'mollie ' ),
337
+ $ this ->update_url , $ this_version , $ latest_version
338
+ );
339
+ $ this ->should_update = 'yes ' ;
340
+ }
341
+ else
342
+ {
343
+ $ this ->should_update = 'no ' ;
344
+ }
345
+ }
346
+ else
347
+ {
348
+ $ this ->should_update = 'maybe ' ;
349
+ $ update_message = $ core ->__ ('Warning: Update xml file from github follows an unexpected format. ' , 'mollie ' );
350
+ }
351
+ }
352
+ return $ update_message ;
353
+ }
354
+
355
+ /**
356
+ * @return string
357
+ */
358
+ protected function _getUpdateXML ()
359
+ {
360
+ return @file_get_contents ($ this ->update_url . '/releases.atom ' );
361
+ }
362
+
289
363
}
0 commit comments