Lanot_Scheduler - Version 1.0.0

Version Notes

The first release with necessary features

Download this release

Release Info

Developer Lanot
Extension Lanot_Scheduler
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

Files changed (41) hide show
  1. app/code/community/Lanot/Core/Block/Adminhtml/Grid/Abstract.php +405 -0
  2. app/code/community/Lanot/Core/Block/Adminhtml/System/Config/Form/Field.php +48 -0
  3. app/code/community/Lanot/Core/Block/Adminhtml/System/Extension.php +243 -0
  4. app/code/community/Lanot/Core/Controller/Adminhtml/AbstractController.php +347 -0
  5. app/code/community/Lanot/Core/Helper/Data.php +23 -0
  6. app/code/community/Lanot/Core/Model/Extension.php +54 -0
  7. app/code/community/Lanot/Core/Model/Item/Interface.php +43 -0
  8. app/code/community/Lanot/Core/controllers/System/ConfigController.php +40 -0
  9. app/code/community/Lanot/Core/etc/adminhtml.xml +31 -0
  10. app/code/community/Lanot/Core/etc/config.xml +67 -0
  11. app/code/community/Lanot/Core/etc/system.xml +52 -0
  12. app/code/community/Lanot/Scheduler/Block/Adminhtml/Job.php +42 -0
  13. app/code/community/Lanot/Scheduler/Block/Adminhtml/Job/Edit.php +66 -0
  14. app/code/community/Lanot/Scheduler/Block/Adminhtml/Job/Edit/Form.php +40 -0
  15. app/code/community/Lanot/Scheduler/Block/Adminhtml/Job/Edit/Tab/Main.php +158 -0
  16. app/code/community/Lanot/Scheduler/Block/Adminhtml/Job/Edit/Tabs.php +44 -0
  17. app/code/community/Lanot/Scheduler/Block/Adminhtml/Job/Grid.php +126 -0
  18. app/code/community/Lanot/Scheduler/Block/Adminhtml/Queue.php +37 -0
  19. app/code/community/Lanot/Scheduler/Block/Adminhtml/Queue/Grid.php +234 -0
  20. app/code/community/Lanot/Scheduler/Block/Adminhtml/Queue/View.php +93 -0
  21. app/code/community/Lanot/Scheduler/Block/Adminhtml/Systemjob.php +38 -0
  22. app/code/community/Lanot/Scheduler/Block/Adminhtml/Systemjob/Grid.php +91 -0
  23. app/code/community/Lanot/Scheduler/Helper/Admin.php +32 -0
  24. app/code/community/Lanot/Scheduler/Helper/Data.php +207 -0
  25. app/code/community/Lanot/Scheduler/Model/Job.php +254 -0
  26. app/code/community/Lanot/Scheduler/Model/Mysql4/Job.php +102 -0
  27. app/code/community/Lanot/Scheduler/Model/Mysql4/Job/Collection.php +35 -0
  28. app/code/community/Lanot/Scheduler/Model/Observer.php +67 -0
  29. app/code/community/Lanot/Scheduler/controllers/Adminhtml/JobController.php +82 -0
  30. app/code/community/Lanot/Scheduler/controllers/Adminhtml/QueueController.php +96 -0
  31. app/code/community/Lanot/Scheduler/controllers/Adminhtml/SystemjobController.php +28 -0
  32. app/code/community/Lanot/Scheduler/etc/adminhtml.xml +83 -0
  33. app/code/community/Lanot/Scheduler/etc/config.xml +100 -0
  34. app/code/community/Lanot/Scheduler/etc/system.xml +63 -0
  35. app/code/community/Lanot/Scheduler/sql/lanot_scheduler_setup/mysql4-install-1.0.0.php +48 -0
  36. app/design/adminhtml/default/default/layout/lanot_scheduler.xml +62 -0
  37. app/design/adminhtml/default/default/template/lanot/scheduler/widget/form/renderer/fieldset.phtml +65 -0
  38. app/design/adminhtml/default/default/template/lanot/scheduler/widget/form/renderer/fieldset/element.phtml +45 -0
  39. app/etc/modules/Lanot_Core.xml +12 -0
  40. app/etc/modules/Lanot_Scheduler.xml +13 -0
  41. package.xml +18 -0
app/code/community/Lanot/Core/Block/Adminhtml/Grid/Abstract.php ADDED
@@ -0,0 +1,405 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Core
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ /**
22
+ * Core Grid abstract
23
+ *
24
+ * @version 1.2.0
25
+ * @author Lanot
26
+ */
27
+ class Lanot_Core_Block_Adminhtml_Grid_Abstract
28
+ extends Mage_Adminhtml_Block_Widget_Grid
29
+ {
30
+ protected $_gridId = 'lanot_core_list_grid';
31
+ protected $_entityIdField = 'entity_id';
32
+ protected $_itemParam = 'entity_id';
33
+ protected $_formFieldName = 'entity';
34
+ protected $_columnPrefix = '';
35
+ protected $_checkboxFieldName = 'in_selected';
36
+ protected $_isTabGrid = false;
37
+
38
+ /** @var Mage_Core_Model_Abstract */
39
+ protected $_item = null;
40
+ protected $_selectedLinks = null;
41
+ protected $_eventPrefix = '';
42
+
43
+ /**
44
+ * Init Grid default properties
45
+ *
46
+ */
47
+ public function __construct()
48
+ {
49
+ parent::__construct();
50
+
51
+ $this->setId($this->_gridId);
52
+ $this->setDefaultSort('sort_order');
53
+ $this->setDefaultDir('ASC');
54
+ $this->setSaveParametersInSession(true);
55
+ $this->setUseAjax(true);
56
+
57
+ if ($this->isReadonly()) {
58
+ $this->setFilterVisibility(false);
59
+ }
60
+ }
61
+
62
+ /**
63
+ * @return Mage_Core_Model_Resource_Db_Collection_Abstract
64
+ */
65
+ protected function _getCollection()
66
+ {
67
+ return $this->_getItemModel()->getCollection();
68
+ }
69
+
70
+ /**
71
+ * @return Lanot_Core_Block_Adminhtml_Grid_Abstract
72
+ */
73
+ protected function _prepareCollection()
74
+ {
75
+ $collection = $this->_getCollection();
76
+
77
+ //filter colelction if it show in tab
78
+ if ($this->_isTabGrid && $this->isReadonly()) {
79
+ $valueIds = $this->_getSelectedLinks();
80
+ if (empty($valueIds)) {
81
+ $valueIds = array(0);
82
+ }
83
+ $collection->addFieldToFilter($this->_entityIdField, array('in' => $valueIds));
84
+ }
85
+
86
+ Mage::dispatchEvent($this->_eventPrefix . 'lanot_grid_prepare_collection', array(
87
+ 'grid' => $this,
88
+ 'collection' => $collection)
89
+ );
90
+
91
+ $this->setCollection($collection);
92
+
93
+ return parent::_prepareCollection();
94
+ }
95
+
96
+ /**
97
+ * @param $row
98
+ * @return string
99
+ */
100
+ public function getRowUrl($row)
101
+ {
102
+ return (!$this->_isTabGrid) ? $this->getUrl('*/*/edit', array('id' => $row->getId())) : '#';
103
+ }
104
+
105
+ /**
106
+ * @return string
107
+ */
108
+ public function getGridUrl()
109
+ {
110
+ return (!$this->_isTabGrid) ?
111
+ $this->getUrl('*/*/grid', array('_current' => true, '_secure'=>true)) :
112
+ $this->getUrl('*/*/ajaxgridonly', array('_current' => true, '_secure'=>true));
113
+ }
114
+
115
+ /**
116
+ * Prepare Grid columns
117
+ *
118
+ * @return Lanot_Core_Block_Adminhtml_Grid_Abstract
119
+ */
120
+ protected function _prepareColumns()
121
+ {
122
+ Mage::dispatchEvent($this->_eventPrefix . 'lanot_grid_prepare_columns_before', array('grid' => $this));
123
+
124
+ if ($this->_isTabGrid) {
125
+ $this->addColumn('in_selected', array(
126
+ 'header_css_class' => 'a-center',
127
+ 'type' => 'checkbox',
128
+ 'name' => 'in_selected',
129
+ 'values' => $this->_getSelectedLinks(),
130
+ 'align' => 'center',
131
+ 'index' => $this->_entityIdField,
132
+ ));
133
+ }
134
+
135
+ $this->addColumn($this->_entityIdField, array(
136
+ 'header' => $this->_getHelper()->__('ID'),
137
+ 'index' => $this->_entityIdField,
138
+ 'type' => 'number',
139
+ 'width' => '50px',
140
+ ));
141
+
142
+ $this->addColumn('title', array(
143
+ 'header' => $this->_getHelper()->__('Title'),
144
+ 'index' => 'title',
145
+ ));
146
+
147
+ $this->addColumn('is_active', array(
148
+ 'header' => $this->_getHelper()->__('Active'),
149
+ 'index' => 'is_active',
150
+ 'type' => 'options',
151
+ 'options' => $this->_getItemModel()->getAvailableStatuses(),
152
+ 'width' => '100px',
153
+ ));
154
+
155
+ $this->addColumn('updated_at', array(
156
+ 'header' => $this->_getHelper()->__('Updated'),
157
+ 'index' => 'updated_at',
158
+ 'width' => '150px',
159
+ ));
160
+
161
+ if (!$this->_isTabGrid) {
162
+ $this->addColumn('action',
163
+ array(
164
+ 'header' => $this->_getHelper()->__('Action'),
165
+ 'width' => '70px',
166
+ 'align' => 'center',
167
+ 'type' => 'action',
168
+ 'getter' => 'getId',
169
+ 'actions' => array(
170
+ array(
171
+ 'caption' => $this->_getHelper()->__('Edit'),
172
+ 'url' => array('base' => '*/*/edit'),
173
+ 'field' => 'id'
174
+ )
175
+ ),
176
+ 'filter' => false,
177
+ 'sortable' => false,
178
+ 'index' => 'banner',
179
+ ));
180
+ }
181
+
182
+ Mage::dispatchEvent($this->_eventPrefix . 'lanot_grid_prepare_columns', array('grid' => $this));
183
+
184
+ return parent::_prepareColumns();
185
+ }
186
+
187
+ /**
188
+ * @return Lanot_Core_Block_Adminhtml_Grid_Abstract
189
+ */
190
+ protected function _prepareMassaction()
191
+ {
192
+ if (!$this->isMassActionAllowed()) {
193
+ return $this;
194
+ }
195
+
196
+ $this->setMassactionIdField($this->_entityIdField);
197
+ $this->getMassactionBlock()->setFormFieldName($this->_formFieldName);
198
+
199
+ $this->getMassactionBlock()->addItem('active_enable', array(
200
+ 'label' => $this->_getHelper()->__('Enable'),
201
+ 'url' => $this->getUrl('*/*/mass', array('type' => 'enable'))
202
+ ));
203
+
204
+ $this->getMassactionBlock()->addItem('active_disable', array(
205
+ 'label' => $this->_getHelper()->__('Disable'),
206
+ 'url' => $this->getUrl('*/*/mass', array('type' => 'disable'))
207
+ ));
208
+
209
+ $this->getMassactionBlock()->addItem('delete', array(
210
+ 'label' => $this->_getHelper()->__('Delete'),
211
+ 'confirm' => $this->_getHelper()->__('Are you sure?'),
212
+ 'url' => $this->getUrl('*/*/mass', array('type' => 'delete')),
213
+ ));
214
+
215
+ Mage::dispatchEvent($this->_eventPrefix . 'lanot_grid_prepare_massaction', array('grid' => $this));
216
+
217
+ return $this;
218
+ }
219
+
220
+ /**
221
+ * Retrieve selected values
222
+ *
223
+ * @return array
224
+ */
225
+ public function getSelectedLinks()
226
+ {
227
+ if (null === $this->_selectedLinks) {
228
+ $this->_selectedLinks = $this->_getItem()->getSelectedLinks();
229
+ }
230
+ return $this->_selectedLinks;
231
+ }
232
+
233
+ /**
234
+ * Retrieve selected values
235
+ *
236
+ * @return array
237
+ */
238
+ protected function _getSelectedLinks()
239
+ {
240
+ return $this->getSelectedLinks();
241
+ }
242
+
243
+ /**
244
+ * Add column to grid
245
+ *
246
+ * @param string $columnId
247
+ * @param array || Varien_Object $column
248
+ * @return Mage_Adminhtml_Block_Widget_Grid
249
+ */
250
+ public function addColumn($columnId, $column)
251
+ {
252
+ return parent::addColumn($this->_columnPrefix . $columnId, $column);
253
+ }
254
+
255
+ /**
256
+ * Retrieve grid column by column id
257
+ *
258
+ * @param string $columnId
259
+ * @return Varien_Object || false
260
+ */
261
+ public function getColumn($columnId)
262
+ {
263
+ if ($this->_columnPrefix && strpos($columnId, $this->_columnPrefix) !== 0) {
264
+ $columnId = $this->_columnPrefix . $columnId;
265
+ }
266
+ return parent::getColumn($columnId);
267
+ }
268
+
269
+ /**
270
+ * Remove existing column
271
+ *
272
+ * @param string $columnId
273
+ * @return Mage_Adminhtml_Block_Widget_Grid
274
+ */
275
+ public function removeColumn($columnId)
276
+ {
277
+ if ($this->_columnPrefix && strpos($columnId, $this->_columnPrefix) !== 0) {
278
+ $columnId = $this->_columnPrefix . $columnId;
279
+ }
280
+ return $this->_removeColumn($columnId);
281
+ }
282
+
283
+ /**
284
+ * @return Lanot_Core_Block_Adminhtml_Grid_Abstract
285
+ */
286
+ protected function _getItem()
287
+ {
288
+ if ($this->_item !== null) {
289
+ return $this->_item;
290
+ }
291
+
292
+ $itemId = $this->getRequest()->getParam($this->_itemParam);
293
+ $this->_item = $this->_getItemModel();
294
+ if ($itemId) {
295
+ $this->_item->load($itemId);
296
+ }
297
+ return $this->_item;
298
+ }
299
+
300
+ /**
301
+ * @param $column
302
+ * @return Lanot_Core_Block_Adminhtml_Grid_Abstract
303
+ */
304
+ protected function _addColumnFilterToCollection($column)
305
+ {
306
+ // Set custom filter by selected values
307
+ if ($this->_isTabGrid && $column->getId() == $this->_checkboxFieldName) {
308
+ $valueIds = $this->_getSelectedLinks();
309
+ if (empty($valueIds)) {
310
+ $valueIds = 0;
311
+ }
312
+
313
+ if ($column->getFilter()->getValue()) {
314
+ $this->getCollection()->addFieldToFilter($this->_entityIdField, array('in' => $valueIds));
315
+ } else {
316
+ if($valueIds) {
317
+ $this->getCollection()->addFieldToFilter($this->_entityIdField, array('nin' => $valueIds));
318
+ }
319
+ }
320
+ } else {
321
+ parent::_addColumnFilterToCollection($column);
322
+ }
323
+ return $this;
324
+ }
325
+
326
+ /**
327
+ * @fix: Old versions
328
+ * Remove existing column
329
+ *
330
+ * @param string $columnId
331
+ * @return Mage_Adminhtml_Block_Widget_Grid
332
+ */
333
+ protected function _removeColumn($columnId)
334
+ {
335
+ if (isset($this->_columns[$columnId])) {
336
+ unset($this->_columns[$columnId]);
337
+ if ($this->_lastColumnId == $columnId) {
338
+ $this->_lastColumnId = key($this->_columns);
339
+ }
340
+ }
341
+ return $this;
342
+ }
343
+
344
+ //--------------------------- methods must be overwritten -----------------------------//
345
+ /**
346
+ * Checks when this block is readonly
347
+ *
348
+ * @return boolean
349
+ */
350
+ public function isReadonly()
351
+ {
352
+ return false;
353
+ }
354
+
355
+ /**
356
+ * Checks when this block is not available
357
+ *
358
+ * @return boolean
359
+ */
360
+ public function isMassActionAllowed()
361
+ {
362
+ return !$this->_isTabGrid;
363
+ }
364
+
365
+ /**
366
+ * @return Mage_Core_Model_Abstract
367
+ */
368
+ protected function _getItemModel()
369
+ {
370
+ return null;
371
+ }
372
+
373
+ /**
374
+ * @return Mage_Core_Helper_Abstract
375
+ */
376
+ protected function _getHelper()
377
+ {
378
+ return null;
379
+ }
380
+
381
+ /**
382
+ * @return Mage_Core_Helper_Abstract
383
+ */
384
+ protected function _getAclHelper()
385
+ {
386
+ return null;
387
+ }
388
+ //--------------------------- methods must be overwritten-----------------------------//
389
+
390
+ /**
391
+ * @return string
392
+ */
393
+ public function getColumnPrefix()
394
+ {
395
+ return $this->_columnPrefix;
396
+ }
397
+
398
+ /**
399
+ * @return string
400
+ */
401
+ public function getEntityIdField()
402
+ {
403
+ return $this->_entityIdField;
404
+ }
405
+ }
app/code/community/Lanot/Core/Block/Adminhtml/System/Config/Form/Field.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Core
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Lanot_Core_Block_Adminhtml_System_Config_Form_Field
22
+ extends Mage_Adminhtml_Block_System_Config_Form_Field
23
+ {
24
+ public function render(Varien_Data_Form_Element_Abstract $element)
25
+ {
26
+ $cols = $element->getData('additional_columns');
27
+
28
+ $id = $element->getHtmlId();
29
+
30
+ $useContainerId = $element->getData('use_container_id');
31
+ $html = '<tr id="row_' . $id . '">'
32
+ . '<td class="label"><label for="'.$id.'">'.$element->getLabel().'</label></td>';
33
+
34
+ $html.= '<td class="value">';
35
+ $html.= $this->_getElementHtml($element);
36
+ $html.= '</td>';
37
+
38
+ if (!empty($cols) && is_array($cols)) {
39
+ foreach($cols as $key => $val) {
40
+ $html.= '<td class="value class-' . $key . '">';
41
+ $html.= $val;
42
+ $html.= '</td>';
43
+ }
44
+ }
45
+ $html.= '</tr>';
46
+ return $html;
47
+ }
48
+ }
app/code/community/Lanot/Core/Block/Adminhtml/System/Extension.php ADDED
@@ -0,0 +1,243 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Core
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Lanot_Core_Block_Adminhtml_System_Extension
22
+ extends Mage_Adminhtml_Block_System_Config_Form_Fieldset
23
+ {
24
+ protected $_fieldRenderer;
25
+ protected $_feedData = array();
26
+ protected $_activeModules = array();
27
+
28
+ /**
29
+ * @param Varien_Data_Form_Element_Abstract $element
30
+ * @return string
31
+ */
32
+ public function render(Varien_Data_Form_Element_Abstract $element)
33
+ {
34
+ $this->_feedData = $this->_getUpgrades();//@todo:
35
+
36
+ $html = $this->_getHeaderHtml($element);
37
+
38
+ //#1. Populate by installed modules
39
+ foreach ($this->_getAllModules() as $moduleName) {
40
+ if ((strpos($moduleName, 'Lanot_') === 0)
41
+ && ($moduleName != 'Lanot_Core')
42
+ && $this->_getEnabled($moduleName)
43
+ ) {
44
+ $this->_activeModules[$moduleName] = true;
45
+ $html.= $this->_getFieldHtml($element, $moduleName);
46
+ }
47
+ }
48
+
49
+ //#2. Populate by new modules
50
+ $isFirst = true;
51
+ if (!empty($this->_feedData)) {
52
+ foreach($this->_feedData as $moduleName => $moduleData) {
53
+ if (!isset($this->_activeModules[$moduleName])) {
54
+ if ($isFirst) {
55
+ $title = $this->_getHelper()->__('New Modules');
56
+ $html.= '<tr><td colspan="4"><br /><b>' . $title . '</b></td></tr>';
57
+ }
58
+
59
+ $html.= $this->_getFieldHtml($element, $moduleName);
60
+ $isFirst = false;
61
+ }
62
+ }
63
+ }
64
+
65
+ $html.= $this->_getFooterHtml($element);
66
+
67
+ return $html;
68
+ }
69
+
70
+ /**
71
+ * @return array
72
+ */
73
+ protected function _getAllModules()
74
+ {
75
+ $modules = array_keys((array)Mage::getConfig()->getNode('modules')->children());
76
+ sort($modules);
77
+ return $modules;
78
+ }
79
+
80
+ /**
81
+ * @return object
82
+ */
83
+ protected function _getFieldRenderer()
84
+ {
85
+ if (empty($this->_fieldRenderer)) {
86
+ $this->_fieldRenderer = Mage::getBlockSingleton('lanot_core/adminhtml_system_config_form_field');
87
+ }
88
+ return $this->_fieldRenderer;
89
+ }
90
+
91
+ /**
92
+ * @param $fieldset
93
+ * @param $moduleName
94
+ * @return string
95
+ */
96
+ protected function _getFieldHtml($fieldset, $moduleName)
97
+ {
98
+ $field = $fieldset->addField($moduleName, 'label',
99
+ array(
100
+ 'name' => 'LanotInstalledExtensions_'.$moduleName,
101
+ 'label' => $moduleName,
102
+ 'value' => $this->_getVersion($moduleName),
103
+ 'additional_columns' => $this->_getAdditionalColData($moduleName),
104
+ ))->setRenderer($this->_getFieldRenderer());
105
+
106
+ return $field->toHtml();
107
+ }
108
+
109
+ /**
110
+ * @return string
111
+ */
112
+ protected function _getButtonHtml()
113
+ {
114
+ $url = $this->getUrl('*/*/lanotupgrades', array('_current' => true, '_secure' => true));
115
+ $field = $this->getLayout()->createBlock('adminhtml/widget_button')
116
+ ->setData(array(
117
+ 'label' => Mage::helper('lanot_core')->__('Check Upgrades and Offers'),
118
+ 'onclick' => "window.location.href='" . $url . "'",
119
+ 'class' => 'task'
120
+ ));
121
+
122
+ return $field->toHtml();
123
+ }
124
+
125
+ /**
126
+ * @param $moduleName
127
+ * @return string
128
+ */
129
+ public function _getVersion($moduleName) {
130
+ $node = Mage::getConfig()->getNode()->modules->{$moduleName};
131
+ if ($node && $node->version) {
132
+ return (string) $node->version;
133
+ }
134
+ return 'N/A';
135
+ }
136
+
137
+ /**
138
+ * @param $moduleName
139
+ * @return string
140
+ */
141
+ public function _getEnabled($moduleName) {
142
+ $node = Mage::getConfig()->getNode()->modules->{$moduleName};
143
+ if ($node && $node->active && ($node->active == 'true')) {
144
+ return (string) $node->version;
145
+ }
146
+ return false;
147
+ }
148
+
149
+ /**
150
+ * Return header html for fieldset
151
+ *
152
+ * @param Varien_Data_Form_Element_Abstract $element
153
+ * @return string
154
+ */
155
+ protected function _getHeaderHtml($element)
156
+ {
157
+ $html = parent::_getHeaderHtml($element);
158
+ if (empty($this->_feedData)) {
159
+ $html .= sprintf(
160
+ '<tr><th>%s</th><th>%s</th></tr>',
161
+ $this->_getHelper()->__('Module'),
162
+ $this->_getHelper()->__('Installed Version')
163
+ );
164
+ } else {
165
+ $html .= sprintf(
166
+ '<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>',
167
+ $this->_getHelper()->__('Module'),
168
+ $this->_getHelper()->__('Installed Version'),
169
+ $this->_getHelper()->__('Last Version'),
170
+ $this->_getHelper()->__('Upgrade & Offers')
171
+ );
172
+ }
173
+ return $html;
174
+ }
175
+
176
+ /**
177
+ * Return footer html for fieldset
178
+ * Add extra tooltip comments to elements
179
+ *
180
+ * @param Varien_Data_Form_Element_Abstract $element
181
+ * @return string
182
+ */
183
+ protected function _getFooterHtml($element)
184
+ {
185
+ $tooltipsExist = false;
186
+ $html = '</tbody></table>';
187
+
188
+ $html.= $this->_getButtonHtml();
189
+
190
+ foreach ($element->getSortedElements() as $field) {
191
+ if ($field->getTooltip()) {
192
+ $tooltipsExist = true;
193
+ $html .= sprintf('<div id="row_%s_comment" class="system-tooltip-box" style="display:none;">%s</div>',
194
+ $field->getId(), $field->getTooltip()
195
+ );
196
+ }
197
+ }
198
+
199
+ $html .= '</fieldset>' . $this->_getExtraJs($element, $tooltipsExist);
200
+ return $html;
201
+ }
202
+
203
+ /**
204
+ * @return array
205
+ */
206
+ protected function _getUpgrades()
207
+ {
208
+ return Mage::registry('lanot_upgrades_and_offers');
209
+ }
210
+
211
+ /**
212
+ * @return Lanot_Core_Helper_Data
213
+ */
214
+ protected function _getHelper()
215
+ {
216
+ return Mage::helper('lanot_core');
217
+ }
218
+
219
+ /**
220
+ * @param $moduleName
221
+ * @return array
222
+ */
223
+ protected function _getAdditionalColData($moduleName)
224
+ {
225
+ $data = array();
226
+ if (!empty($this->_feedData) && isset($this->_feedData[$moduleName])) {
227
+ $item = $this->_feedData[$moduleName];
228
+ $notes = $item['notes'];
229
+ if (empty($notes) && isset($item['link'])) {
230
+ $notes .= sprintf("<a href='%s' target='_blank'>%s</a> <br />",
231
+ $item['link'],
232
+ $item['title']
233
+ );
234
+ }
235
+ $data['version'] = !empty($item['version']) ? $item['version'] : 'N/A';
236
+ $data['notes'] = !empty($notes) ? $notes : 'N/A';
237
+ } elseif (!empty($this->_feedData)) {
238
+ $data['version'] = 'N/A';
239
+ $data['notes'] = 'N/A';
240
+ }
241
+ return $data;
242
+ }
243
+ }
app/code/community/Lanot/Core/Controller/Adminhtml/AbstractController.php ADDED
@@ -0,0 +1,347 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Core
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ /**
22
+ * Core Controller Abstract
23
+ * @version 1.0.0
24
+ * @author Lanot
25
+ */
26
+ class Lanot_Core_Controller_Adminhtml_AbstractController
27
+ extends Mage_Adminhtml_Controller_Action
28
+ {
29
+ protected $_msgTitle = 'Items';
30
+ protected $_msgHeader = 'Items';
31
+ protected $_msgItemDoesNotExist = 'Item does not exist.';
32
+ protected $_msgItemNotFound = 'Unable to find an item. #%s';
33
+ protected $_msgItemEdit = 'Edit Item';
34
+ protected $_msgItemNew = 'New Item';
35
+ protected $_msgItemSaved = 'The item has been saved.';
36
+ protected $_msgItemDeleted = 'The item has been deleted.';
37
+ protected $_msgError = 'An error occurred while edit the item.';
38
+ protected $_msgErrorItems = 'An error occurred while edit the items. %s';
39
+ protected $_msgItems = 'The items %s has been';
40
+
41
+ protected $_menuActive = null;
42
+ protected $_aclSection = null;
43
+
44
+ /**
45
+ * Check the permission to run it
46
+ *
47
+ * @return boolean
48
+ */
49
+ protected function _isAllowed()
50
+ {
51
+ switch ($this->getRequest()->getActionName()) {
52
+ case 'new':
53
+ case 'edit':
54
+ case 'save':
55
+ case 'mass':
56
+ return $this->_getAclHelper()->isActionAllowed($this->_aclSection . '/save');
57
+ break;
58
+ case 'delete':
59
+ return $this->_getAclHelper()->isActionAllowed($this->_aclSection . '/delete');
60
+ break;
61
+ default:
62
+ return $this->_getAclHelper()->isActionAllowed($this->_aclSection);
63
+ break;
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Init actions
69
+ *
70
+ * @return Lanot_Core_Controller_Adminhtml_AbstractController
71
+ */
72
+ protected function _initAction()
73
+ {
74
+ // load layout, set active menu and breadcrumbs
75
+ $this->loadLayout()
76
+ ->_setActiveMenu($this->_menuActive)
77
+ ->_addBreadcrumb(
78
+ $this->_getHelper()->__($this->_msgTitle),
79
+ $this->_getHelper()->__($this->_msgTitle)
80
+ )
81
+ ->_addBreadcrumb(
82
+ $this->_getHelper()->__($this->_msgHeader),
83
+ $this->_getHelper()->__($this->_msgHeader)
84
+ );
85
+
86
+ return $this;
87
+ }
88
+
89
+ /**
90
+ * Index action
91
+ */
92
+ public function indexAction()
93
+ {
94
+ $this->_title($this->__($this->_msgTitle))
95
+ ->_title($this->__($this->_msgHeader))
96
+ ->_initAction()
97
+ ->renderLayout();
98
+ }
99
+
100
+ /**
101
+ * Grid action
102
+ */
103
+ public function gridAction()
104
+ {
105
+ $this->_loadLayouts();
106
+ }
107
+
108
+ /**
109
+ * Create new Item
110
+ */
111
+ public function newAction()
112
+ {
113
+ $this->_forward('edit');
114
+ }
115
+
116
+ /**
117
+ * Edit item
118
+ */
119
+ public function editAction()
120
+ {
121
+ $this->_title($this->__($this->_msgTitle))
122
+ ->_title($this->__($this->_msgHeader));
123
+
124
+ // 1. instance model
125
+ $model = $this->_getItemModel();
126
+
127
+ // 2. if exists id, check it and load data
128
+ $itemId = $this->getRequest()->getParam('id');
129
+ if ($itemId) {
130
+ $model->load($itemId);
131
+ if (!$model->getId()) {
132
+ $this->_getSession()->addError($this->_getHelper()->__($this->_msgItemNotFound, $itemId));
133
+ return $this->_redirect('*/*/');
134
+ }
135
+ // prepare title
136
+ $this->_title($model->getTitle());
137
+ $breadCrumb = $this->_getHelper()->__($this->_msgItemEdit);
138
+ } else {
139
+ $this->_title($this->_getHelper()->__($this->_msgItemNew));
140
+ $breadCrumb = $this->_getHelper()->__($this->_msgItemNew);
141
+ }
142
+ // 3. Set entered data if was error when we do save
143
+ $data = $this->_getSession()->getFormData(true);
144
+ if (!empty($data)) {
145
+ $model->addData($data);
146
+ }
147
+ // 4. Register model to use later in blocks
148
+ $this->_registerItem($model);
149
+
150
+ // Init breadcrumbs
151
+ $this->_initAction()->_addBreadcrumb($breadCrumb, $breadCrumb);
152
+
153
+ // 5. render layout
154
+ $this->renderLayout();
155
+ }
156
+
157
+ /**
158
+ * Save action
159
+ */
160
+ public function saveAction()
161
+ {
162
+ $redirectPath = '*/*';
163
+ $redirectParams = array();
164
+ $hasError = false;
165
+ // check if data sent
166
+ $data = $this->getRequest()->getPost();
167
+ if ($data) {
168
+ $data = $this->_preparePostData($data);
169
+
170
+ //1. instance model
171
+ $model = $this->_getItemModel();
172
+ //2. if exists id, try to load data
173
+ $itemId = $this->getRequest()->getParam('id');
174
+ if ($itemId) {
175
+ $model->load($itemId);
176
+ }
177
+ $model->addData($data);
178
+
179
+ try {
180
+ //3. save the data
181
+ $model->save();
182
+ //4. display success message
183
+ $msg = $this->_getHelper()->__($this->_msgItemSaved);
184
+ $this->_getSession()->addSuccess($msg);
185
+ //5. check if 'Save and Continue'
186
+ if ($this->getRequest()->getParam('back')) {
187
+ $redirectPath = '*/*/edit';
188
+ $redirectParams = array('id' => $model->getId());
189
+ }
190
+ } catch (Mage_Core_Exception $e) {
191
+ $hasError = true;
192
+ $this->_getSession()->addError($e->getMessage());
193
+ } catch (Exception $e) {
194
+ $hasError = true;
195
+ $msg = $this->_getHelper()->__($this->_msgError);
196
+ $this->_getSession()->addException($e, $msg);
197
+ }
198
+ //6. check if errors happened
199
+ if ($hasError) {
200
+ $this->_getSession()->setFormData($data);
201
+ $redirectPath = '*/*/edit';
202
+ $redirectParams = array('id' => $this->getRequest()->getParam('id'));
203
+ }
204
+ }
205
+
206
+ if ($this->getRequest()->getParam('store')) {
207
+ $redirectParams['store'] = $this->getRequest()->getParam('store');
208
+ }
209
+ //7. go to grid or edit form
210
+ $this->_redirect($redirectPath, $redirectParams);
211
+ }
212
+
213
+ /**
214
+ * Delete action
215
+ */
216
+ public function deleteAction()
217
+ {
218
+ $itemId = $this->getRequest()->getParam('id');
219
+ if ($itemId) {
220
+ try {
221
+ // 1. instance model
222
+ $model = $this->_getItemModel();
223
+ // 2. if exists id, load data
224
+ $model->load($itemId);
225
+ // 3. check if elements exists
226
+ if (!$model->getId()) {
227
+ $msg = $this->_getHelper()->__($this->_msgItemDoesNotExist);
228
+ Mage::throwException($msg);
229
+ }
230
+ // 4. delete item
231
+ $model->delete();
232
+ // display success message
233
+ $msg = $this->_getHelper()->__($this->_msgItemDeleted);
234
+ $this->_getSession()->addSuccess($msg);
235
+ } catch (Mage_Core_Exception $e) {
236
+ $this->_getSession()->addError($e->getMessage());
237
+ } catch (Exception $e) {
238
+ $msg = $this->_getHelper()->__($this->_msgError, $e->getMessage());
239
+ $this->_getSession()->addException($e, $msg);
240
+ }
241
+ }
242
+ // 5. go to grid
243
+ $this->_redirect('*/*/');
244
+ }
245
+
246
+ /**
247
+ * Mass Update/Delete Action
248
+ */
249
+ public function massAction()
250
+ {
251
+ $msg = '';
252
+ $key = $this->getRequest()->getParam('massaction_prepare_key');
253
+ $itemIds = $this->getRequest()->getParam($key);
254
+ $type = $this->getRequest()->getParam('type');
255
+ $active = $this->_getItemModel()->getStatusDisabled();
256
+
257
+ if (is_array($itemIds) && count($itemIds)) {
258
+ try {
259
+ foreach ($itemIds as $itemId) {
260
+ // 1. instance banner model
261
+ $model = $this->_getItemModel();
262
+ // 2. if exists id, load data
263
+ $model->load($itemId);
264
+ // 3. check if elements exists
265
+ if (!$model->getId()) {
266
+ Mage::throwException($this->_getHelper()->__($this->_msgItemNotFound));
267
+ }
268
+ // 4. main logic
269
+ switch ($type) {
270
+ case 'enable':
271
+ $active = $this->_getItemModel()->getStatusEnabled();
272
+ case 'disable':
273
+ $model->setIsActive($active);
274
+ $model->save();
275
+ $msg = $this->_msgItems .
276
+ (($active == $this->_getItemModel()->getStatusDisabled()) ? ' disabled' : ' enabled') . '.';
277
+ break;
278
+ case 'delete':
279
+ $model->delete();
280
+ $msg = $this->_msgItems . ' deleted.';
281
+ break;
282
+ }
283
+ }
284
+ // display success message
285
+ $this->_getSession()->addSuccess($this->_getHelper()->__($msg, implode(', ', $itemIds)));
286
+ } catch (Mage_Core_Exception $e) {
287
+ $this->_getSession()->addError($e->getMessage());
288
+ } catch (Exception $e) {
289
+ $this->_getSession()->addException($e, $this->_getHelper()->__($this->_msgErrorItems, $e->getMessage()));
290
+ }
291
+ }
292
+ // 5. go to grid
293
+ $this->_redirect('*/*/');
294
+ }
295
+
296
+ /**
297
+ * @param array $data
298
+ * @return array
299
+ */
300
+ protected function _preparePostData($data)
301
+ {
302
+ return $data;
303
+ }
304
+
305
+ /**
306
+ * @return Mage_Core_Helper_Abstract
307
+ */
308
+ protected function _getHelper()
309
+ {
310
+ return null;
311
+ }
312
+
313
+ /**
314
+ * @return Mage_Core_Helper_Abstract
315
+ */
316
+ protected function _getAclHelper()
317
+ {
318
+ return null;
319
+ }
320
+
321
+ /**
322
+ * @return Mage_Core_Model_Abstract
323
+ */
324
+ protected function _getItemModel()
325
+ {
326
+ return null;
327
+ }
328
+
329
+ /**
330
+ * @param Mage_Core_Model_Abstract $model
331
+ * @return Lanot_Core_Controller_Adminhtml_AbstractController
332
+ */
333
+ protected function _registerItem(Mage_Core_Model_Abstract $model)
334
+ {
335
+ return $this;
336
+ }
337
+
338
+ /**
339
+ * @return Lanot_Core_Controller_Adminhtml_AbstractController
340
+ */
341
+ protected function _loadLayouts()
342
+ {
343
+ $this->loadLayout();
344
+ $this->renderLayout();
345
+ return $this;
346
+ }
347
+ }
app/code/community/Lanot/Core/Helper/Data.php ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Core
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Lanot_Core_Helper_Data extends Mage_Core_Helper_Abstract
22
+ {
23
+ }
app/code/community/Lanot/Core/Model/Extension.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Lanot_Core_Model_Extension
4
+ {
5
+ const URL_FEED = 'http://www.lanot.biz/rss/catalog/extensions';
6
+ const CACHE_TAG = 'LANOT_EXTENSIONS';
7
+ const CACHE_LIFETIME = 7200;
8
+
9
+ /**
10
+ * @param $email
11
+ * @return array
12
+ */
13
+ public function getFeedData($email) {
14
+ $data = array();
15
+ $url = self::URL_FEED;
16
+ if (!empty($email)) {
17
+ $url .= "?email=" . urlencode(base64_encode($email));
18
+ }
19
+
20
+ $cacheKey = 'lanot_extensions_' . md5($url);
21
+ if (Mage::app()->useCache('config') && $cache = Mage::app()->loadCache($cacheKey)) {
22
+ return unserialize($cache);
23
+ }
24
+
25
+ @$content = file_get_contents($url);
26
+ if (!empty($content)) {
27
+ $xml = new Varien_Simplexml_Config($content);
28
+ if ($xml->getNode('channel/item')) {
29
+ /** @var $item Varien_Simplexml_Element */
30
+ foreach($xml->getNode('channel/item') as $item) {
31
+ $item = $item->asArray();
32
+ if (!empty($item['description'])) {
33
+ @$descr = json_decode($item['description'], true);
34
+ if (!empty($descr) && is_array($descr)) {
35
+ $item = array_merge($item, $descr);
36
+ } else {
37
+ continue;
38
+ }
39
+
40
+ if (isset($item['code'])) {
41
+ $data[$item['code']] = $item;
42
+ }
43
+ }
44
+ }
45
+ }
46
+ }
47
+
48
+ if (Mage::app()->useCache('config')) {
49
+ Mage::app()->saveCache(serialize($data), $cacheKey, array(self::CACHE_TAG), self::CACHE_LIFETIME);
50
+ }
51
+
52
+ return $data;
53
+ }
54
+ }
app/code/community/Lanot/Core/Model/Item/Interface.php ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Core
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ /**
22
+ * Model's interface abstract
23
+ *
24
+ * @version 1.0.0
25
+ * @author Lanot
26
+ */
27
+ interface Lanot_Core_Model_Item_Interface
28
+ {
29
+ /**
30
+ * @return array
31
+ */
32
+ public function getAvailableStatuses();
33
+
34
+ /**
35
+ * @return int
36
+ */
37
+ public function getStatusDisabled();
38
+
39
+ /**
40
+ * @return int
41
+ */
42
+ public function getStatusEnabled();
43
+ }
app/code/community/Lanot/Core/controllers/System/ConfigController.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Core
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+ require_once('Mage/Adminhtml/controllers/System/ConfigController.php');
21
+
22
+ class Lanot_Core_System_ConfigController extends Mage_Adminhtml_System_ConfigController
23
+ {
24
+ public function lanotupgradesAction()
25
+ {
26
+ $email = Mage::getStoreConfig('lanot_core/account/email');
27
+ $data = $this->_getExtensionModel()->getFeedData($email);
28
+ Mage::register('lanot_upgrades_and_offers', $data);
29
+
30
+ return $this->_forward('edit');
31
+ }
32
+
33
+ /**
34
+ * @return Lanot_Core_Model_Extension
35
+ */
36
+ protected function _getExtensionModel()
37
+ {
38
+ return Mage::getModel('lanot_core/extension');
39
+ }
40
+ }
app/code/community/Lanot/Core/etc/adminhtml.xml ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento admin config
5
+ *
6
+ * @author Lanot
7
+ */
8
+ -->
9
+ <config>
10
+ <acl>
11
+ <resources>
12
+ <admin>
13
+ <children>
14
+
15
+ <system>
16
+ <children>
17
+ <config>
18
+ <children>
19
+ <lanot_core translate="title" module="lanot_core">
20
+ <title>Lanot Default Settings</title>
21
+ </lanot_core>
22
+ </children>
23
+ </config>
24
+ </children>
25
+ </system>
26
+
27
+ </children>
28
+ </admin>
29
+ </resources>
30
+ </acl>
31
+ </config>
app/code/community/Lanot/Core/etc/config.xml ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Lanot_Core>
5
+ <version>2.0.1</version>
6
+ </Lanot_Core>
7
+ </modules>
8
+
9
+ <global>
10
+ <helpers>
11
+ <lanot_core>
12
+ <class>Lanot_Core_Helper</class>
13
+ </lanot_core>
14
+ </helpers>
15
+ <blocks>
16
+ <lanot_core>
17
+ <class>Lanot_Core_Block</class>
18
+ </lanot_core>
19
+ </blocks>
20
+ <models>
21
+ <lanot_core>
22
+ <class>Lanot_Core_Model</class>
23
+ </lanot_core>
24
+ </models>
25
+ </global>
26
+
27
+ <admin>
28
+ <routers>
29
+ <adminhtml>
30
+ <args>
31
+ <modules>
32
+ <Lanot_Core before="Mage_Adminhtml">Lanot_Core</Lanot_Core>
33
+ </modules>
34
+ </args>
35
+ </adminhtml>
36
+ </routers>
37
+ </admin>
38
+
39
+ <adminhtml>
40
+ <!-- translations -->
41
+ <translate>
42
+ <modules>
43
+ <Lanot_Core>
44
+ <files>
45
+ <default>Lanot_Core.csv</default>
46
+ </files>
47
+ </Lanot_Core>
48
+ </modules>
49
+ </translate>
50
+ <!-- translations -->
51
+ </adminhtml>
52
+
53
+ <frontend>
54
+ <!-- translations -->
55
+ <translate>
56
+ <modules>
57
+ <Lanot_Core>
58
+ <files>
59
+ <default>Lanot_Core.csv</default>
60
+ </files>
61
+ </Lanot_Core>
62
+ </modules>
63
+ </translate>
64
+ <!-- translations -->
65
+ </frontend>
66
+
67
+ </config>
app/code/community/Lanot/Core/etc/system.xml ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <lanot translate="label">
5
+ <label>Lanot Extensions</label>
6
+ <sort_order>200</sort_order>
7
+ </lanot>
8
+ </tabs>
9
+ <sections>
10
+ <lanot_core>
11
+ <class>separator-top</class>
12
+ <label>General</label>
13
+ <tab>lanot</tab>
14
+ <frontend_type>text</frontend_type>
15
+ <sort_order>0</sort_order>
16
+ <show_in_default>1</show_in_default>
17
+ <show_in_website>0</show_in_website>
18
+ <show_in_store>0</show_in_store>
19
+ <groups>
20
+
21
+ <account translate="label">
22
+ <label>Lanot Account</label>
23
+ <frontend_type>text</frontend_type>
24
+ <sort_order>1</sort_order>
25
+ <show_in_default>1</show_in_default>
26
+ <show_in_website>0</show_in_website>
27
+ <show_in_store>0</show_in_store>
28
+ <fields>
29
+ <email translate="label comment">
30
+ <label>Account Email</label>
31
+ <comment>Account Email is requried for getting upgrades and special offers</comment>
32
+ <frontend_type>text</frontend_type>
33
+ <sort_order>10</sort_order>
34
+ <show_in_default>1</show_in_default>
35
+ <show_in_website>0</show_in_website>
36
+ <show_in_store>0</show_in_store>
37
+ </email>
38
+ </fields>
39
+ </account>
40
+
41
+ <extensions translate="label">
42
+ <label>Lanot Modules</label>
43
+ <frontend_model>lanot_core/adminhtml_system_extension</frontend_model>
44
+ <sort_order>10</sort_order>
45
+ <show_in_default>1</show_in_default>
46
+ <show_in_website>0</show_in_website>
47
+ <show_in_store>0</show_in_store>
48
+ </extensions>
49
+ </groups>
50
+ </lanot_core>
51
+ </sections>
52
+ </config>
app/code/community/Lanot/Scheduler/Block/Adminhtml/Job.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Scheduler
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Lanot_Scheduler_Block_Adminhtml_Job
22
+ extends Mage_Adminhtml_Block_Widget_Grid_Container
23
+ {
24
+ /**
25
+ * Block constructor
26
+ */
27
+ public function __construct()
28
+ {
29
+ $this->_blockGroup = 'lanot_scheduler';
30
+ $this->_controller = 'adminhtml_job';
31
+ $this->_headerText = Mage::helper('lanot_scheduler')->__('Manage Custom Cron Jobs');
32
+
33
+ parent::__construct();
34
+
35
+ if (Mage::helper('lanot_scheduler/admin')->isActionAllowed('manage_jobs')) {
36
+ $this->_updateButton('add', 'label', Mage::helper('lanot_scheduler')->__('Add New Job'));
37
+ } else {
38
+ $this->_removeButton('add');
39
+ }
40
+ }
41
+ }
42
+
app/code/community/Lanot/Scheduler/Block/Adminhtml/Job/Edit.php ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Scheduler
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Lanot_Scheduler_Block_Adminhtml_Job_Edit
22
+ extends Mage_Adminhtml_Block_Widget_Form_Container
23
+ {
24
+ /**
25
+ * Initialize edit form container
26
+ *
27
+ */
28
+ public function __construct()
29
+ {
30
+ $this->_blockGroup = 'lanot_scheduler';
31
+ $this->_controller = 'adminhtml_job';
32
+
33
+ parent::__construct();
34
+
35
+ //check permissions
36
+ if (Mage::helper('lanot_scheduler/admin')->isActionAllowed('manage_jobs')) {
37
+ $this->_updateButton('save', 'label', Mage::helper('lanot_scheduler')->__('Save Job Item'));
38
+ $this->_addButton('saveandcontinue', array(
39
+ 'label' => Mage::helper('adminhtml')->__('Save and Continue Edit'),
40
+ 'onclick' => 'saveAndContinueEdit()',
41
+ 'class' => 'save',
42
+ ), -100);
43
+
44
+ $this->_updateButton('delete', 'label', Mage::helper('lanot_scheduler')->__('Delete Job Item'));
45
+
46
+ $this->_formScripts[] = "
47
+ function saveAndContinueEdit(){
48
+ editForm.submit($('edit_form').action+'back/edit/');
49
+ }";
50
+ } else {
51
+ $this->_removeButton('save');
52
+ $this->_removeButton('delete');
53
+ }
54
+ }
55
+
56
+ public function getHeaderText()
57
+ {
58
+ $header = Mage::helper('lanot_scheduler')->__('New Cron Job');
59
+ $model = Mage::helper('lanot_scheduler')->getJobItemInstance();
60
+ if ($model->getId()) {
61
+ $title = $this->escapeHtml($model->getTitle());
62
+ $header = Mage::helper('lanot_scheduler')->__("Edit Cron Job '%s'", $title);
63
+ }
64
+ return $header;
65
+ }
66
+ }
app/code/community/Lanot/Scheduler/Block/Adminhtml/Job/Edit/Form.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Scheduler
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Lanot_Scheduler_Block_Adminhtml_Job_Edit_Form
22
+ extends Mage_Adminhtml_Block_Widget_Form
23
+ {
24
+ /**
25
+ * @return Lanot_Scheduler_Block_Adminhtml_Job_Edit_Form
26
+ */
27
+ protected function _prepareForm()
28
+ {
29
+ $form = new Varien_Data_Form(array(
30
+ 'id' => 'edit_form',
31
+ 'action' => $this->getUrl('*/*/save'),
32
+ 'method' => 'post',
33
+ 'enctype' => 'multipart/form-data'
34
+ ));
35
+
36
+ $form->setUseContainer(true);
37
+ $this->setForm($form);
38
+ return parent::_prepareForm();
39
+ }
40
+ }
app/code/community/Lanot/Scheduler/Block/Adminhtml/Job/Edit/Tab/Main.php ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Scheduler
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Lanot_Scheduler_Block_Adminhtml_Job_Edit_Tab_Main
22
+ extends Mage_Adminhtml_Block_Widget_Form
23
+ implements Mage_Adminhtml_Block_Widget_Tab_Interface
24
+ {
25
+ /**
26
+ * Prepare form elements for tab
27
+ *
28
+ * @return Mage_Adminhtml_Block_Widget_Form
29
+ */
30
+ protected function _prepareForm()
31
+ {
32
+ $isElementDisabled = !$this->_getAclHelper()->isActionAllowed('manage_jobs');
33
+ $model = $this->_getHelper()->getJobItemInstance();
34
+
35
+ $form = new Varien_Data_Form();
36
+ $form->setHtmlIdPrefix('job_main_');
37
+
38
+ $fieldset = $form->addFieldset('base_fieldset', array(
39
+ 'legend' => $this->_getHelper()->__('Cron Job Info'),
40
+ ));
41
+
42
+ if ($model->getId()) {
43
+ $fieldset->addField('job_id', 'hidden', array(
44
+ 'name' => 'id',
45
+ ));
46
+
47
+ $fieldset->addField('job_code', 'label', array(
48
+ 'name' => 'view_job_code',
49
+ 'label' => $this->_getHelper()->__('Job Code'),
50
+ 'bold' => true,
51
+ ));
52
+ }
53
+
54
+ $fieldset->addField('title', 'text', array(
55
+ 'name' => 'title',
56
+ 'label' => $this->_getHelper()->__('Title'),
57
+ 'title' => $this->_getHelper()->__('Title'),
58
+ 'required' => true,
59
+ 'disabled' => $isElementDisabled,
60
+ ));
61
+
62
+ $fieldset->addField('model', 'text', array(
63
+ 'name' => 'model',
64
+ 'label' => $this->_getHelper()->__('Model'),
65
+ 'title' => $this->_getHelper()->__('Model'),
66
+ 'required' => true,
67
+ 'disabled' => $isElementDisabled,
68
+ 'after_element_html' => $this->_getHelper()->__('<span>Provide an existing Magento model, class and method that can be executed in format: <b>model/class::method</b>. Where model is an alias of your module.<br />Example: <b>catalog/observer::reindexProductPrices</b> </span>'),
69
+ ));
70
+
71
+ $scheduleFieldset = $form->addFieldset('schedule_fieldset', array(
72
+ 'legend' => $this->_getHelper()->__('Schedule'),
73
+ 'table_class' => 'custom-form-list',
74
+ 'after_element_html' =>
75
+ $this->_getHelper()->__('<div>Press CTRL + Mouse click to choose several options</div>') .
76
+ $this->_getHelper()->__('<br /><div>Schedule examples: %s</div>',
77
+ $this->_getHelper()->getCronJobExamples()
78
+ )
79
+ ))->setRenderer($this->_getRenderedFieldset());
80
+
81
+
82
+ foreach($this->_getHelper()->getScheduleDescription() as $key => $label) {
83
+ $scheduleFieldset->addField($key, 'multiselect', array(
84
+ 'name' => $key,
85
+ 'label' => $this->_getHelper()->__($label),
86
+ 'title' => $this->_getHelper()->__($label),
87
+ 'required' => true,
88
+ 'disabled' => $isElementDisabled,
89
+ 'values' => $this->_getHelper()->prepareCronJobOptions($key, true),
90
+ 'style' => 'width: 120px;',
91
+ ))->setRenderer($this->_getRenderedFieldsetElement());
92
+ }
93
+
94
+ $form->setValues($model->getData());
95
+
96
+ Mage::dispatchEvent('adminhtml_lanot_scheduler_job_edit_tab_main_prepare_form', array(
97
+ 'form' => $form,
98
+ 'sticker' => $model
99
+ ));
100
+
101
+ $this->setForm($form);
102
+ return parent::_prepareForm();
103
+ }
104
+
105
+ /**
106
+ * @return Lanot_Scheduler_Helper_Data
107
+ */
108
+ protected function _getHelper()
109
+ {
110
+ return Mage::helper('lanot_scheduler');
111
+ }
112
+
113
+ /**
114
+ * @return Lanot_Scheduler_Helper_Admin
115
+ */
116
+ protected function _getAclHelper()
117
+ {
118
+ return Mage::helper('lanot_scheduler/admin');
119
+ }
120
+
121
+ public function getTabLabel()
122
+ {
123
+ return $this->_getHelper()->__('Job Info');
124
+ }
125
+
126
+ public function getTabTitle()
127
+ {
128
+ return $this->getTabLabel();
129
+ }
130
+
131
+ public function canShowTab()
132
+ {
133
+ return true;
134
+ }
135
+
136
+ public function isHidden()
137
+ {
138
+ return !$this->canShowTab();
139
+ }
140
+
141
+ /**
142
+ * @return Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset_Element
143
+ */
144
+ protected function _getRenderedFieldsetElement()
145
+ {
146
+ return Mage::getBlockSingleton('adminhtml/widget_form_renderer_fieldset_element')
147
+ ->setTemplate('lanot/scheduler/widget/form/renderer/fieldset/element.phtml');
148
+ }
149
+
150
+ /**
151
+ * @return Mage_Adminhtml_Block_Widget_Form_Renderer_Fieldset
152
+ */
153
+ protected function _getRenderedFieldset()
154
+ {
155
+ return Mage::getBlockSingleton('adminhtml/widget_form_renderer_fieldset')
156
+ ->setTemplate('lanot/scheduler/widget/form/renderer/fieldset.phtml');
157
+ }
158
+ }
app/code/community/Lanot/Scheduler/Block/Adminhtml/Job/Edit/Tabs.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Scheduler
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Lanot_Scheduler_Block_Adminhtml_Job_Edit_Tabs
22
+ extends Mage_Adminhtml_Block_Widget_Tabs
23
+ {
24
+ /**
25
+ * Initialize tabs and define tabs block settings
26
+ *
27
+ */
28
+ public function __construct()
29
+ {
30
+ parent::__construct();
31
+
32
+ $this->setId('page_tabs');
33
+ $this->setDestElementId('edit_form');
34
+ $this->setTitle($this->_getHelper()->__('Job Info'));
35
+ }
36
+
37
+ /**
38
+ * @return Lanot_Scheduler_Helper_Data
39
+ */
40
+ protected function _getHelper()
41
+ {
42
+ return Mage::helper('lanot_scheduler');
43
+ }
44
+ }
app/code/community/Lanot/Scheduler/Block/Adminhtml/Job/Grid.php ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Scheduler
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Lanot_Scheduler_Block_Adminhtml_Job_Grid
22
+ extends Lanot_Core_Block_Adminhtml_Grid_Abstract
23
+ {
24
+ protected $_gridId = 'jobGrid';
25
+ protected $_entityIdField = 'job_id';
26
+ protected $_itemParam = 'job_id';
27
+ protected $_formFieldName = 'job';
28
+ protected $_eventPrefix = 'job_';
29
+
30
+ /**
31
+ * Checks when this block is readonly
32
+ *
33
+ * @return boolean
34
+ */
35
+ public function isReadonly()
36
+ {
37
+ return !$this->_getAclHelper()->isActionAllowed('manage_jobs');
38
+ }
39
+
40
+ /**
41
+ * @return Lanot_Scheduler_Model_Job
42
+ */
43
+ protected function _getItemModel()
44
+ {
45
+ return Mage::getModel('lanot_scheduler/job');
46
+ }
47
+
48
+ /**
49
+ * Prepare Grid columns
50
+ *
51
+ * @return Lanot_Scheduler_Block_Adminhtml_Job_Grid
52
+ */
53
+ protected function _prepareColumns()
54
+ {
55
+ $this->addColumnAfter('job_code', array(
56
+ 'header' => $this->_getHelper()->__('Job Code'),
57
+ 'index' => 'job_id',
58
+ 'width' => '15%',
59
+ 'frame_callback' => array($this, 'prepareJobCode'),
60
+ ), 'title');
61
+
62
+ $this->addColumnAfter('schedule', array(
63
+ 'header' => $this->_getHelper()->__('Schedule'),
64
+ 'index' => 'job_id',
65
+ 'filter' => false,
66
+ 'width' => '15%',
67
+ 'frame_callback' => array($this, 'prepareSchedule'),
68
+ ), 'job_code');
69
+
70
+ $this->addColumnAfter('model', array(
71
+ 'header' => $this->_getHelper()->__('Model'),
72
+ 'index' => 'model',
73
+ 'width' => '20%',
74
+ ), 'schedule');
75
+
76
+ parent::_prepareColumns();
77
+
78
+ $this->removeColumn('is_active');
79
+ }
80
+
81
+ /**
82
+ * Decorate status column values
83
+ *
84
+ * @return string
85
+ */
86
+ public function prepareSchedule($value, $row, $column, $isExport)
87
+ {
88
+ return $row->getSchedule();
89
+ }
90
+
91
+ /**
92
+ * Decorate status column values
93
+ *
94
+ * @return string
95
+ */
96
+ public function prepareJobCode($value, $row, $column, $isExport)
97
+ {
98
+ return $row->getJobCode();
99
+ }
100
+
101
+ /**
102
+ * @return Lanot_Scheduler_Helper_Data
103
+ */
104
+ protected function _getHelper()
105
+ {
106
+ return Mage::helper('lanot_scheduler');
107
+ }
108
+
109
+ /**
110
+ * @return Lanot_Scheduler_Helper_Admin
111
+ */
112
+ protected function _getAclHelper()
113
+ {
114
+ return Mage::helper('lanot_scheduler/admin');
115
+ }
116
+
117
+ /**
118
+ * Checks when this block is not available
119
+ *
120
+ * @return boolean
121
+ */
122
+ public function isMassActionAllowed()
123
+ {
124
+ return false;
125
+ }
126
+ }
app/code/community/Lanot/Scheduler/Block/Adminhtml/Queue.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Scheduler
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Lanot_Scheduler_Block_Adminhtml_Queue
22
+ extends Mage_Adminhtml_Block_Widget_Grid_Container
23
+ {
24
+ /**
25
+ * Block constructor
26
+ */
27
+ public function __construct()
28
+ {
29
+ $this->_blockGroup = 'lanot_scheduler';
30
+ $this->_controller = 'adminhtml_queue';
31
+ $this->_headerText = Mage::helper('lanot_scheduler')->__('View Cron Queue');
32
+
33
+ parent::__construct();
34
+ $this->_removeButton('add');
35
+ }
36
+ }
37
+
app/code/community/Lanot/Scheduler/Block/Adminhtml/Queue/Grid.php ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Scheduler
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Lanot_Scheduler_Block_Adminhtml_Queue_Grid
22
+ extends Lanot_Core_Block_Adminhtml_Grid_Abstract
23
+ {
24
+ protected $_gridId = 'queueGrid';
25
+ protected $_entityIdField = 'schedule_id';
26
+ protected $_itemParam = 'schedule_id';
27
+ protected $_formFieldName = 'queue';
28
+ protected $_eventPrefix = 'queue_';
29
+
30
+ /**
31
+ * Checks when this block is readonly
32
+ *
33
+ * @return boolean
34
+ */
35
+ public function isReadonly()
36
+ {
37
+ return !$this->_getAclHelper()->isActionAllowed('view_queue');
38
+ }
39
+
40
+ /**
41
+ * @return Mage_Cron_Model_Schedule
42
+ */
43
+ protected function _getItemModel()
44
+ {
45
+ return Mage::getModel('cron/schedule');
46
+ }
47
+
48
+ /**
49
+ * @return $this
50
+ */
51
+ protected function _prepareCollection()
52
+ {
53
+ parent::_prepareCollection();
54
+
55
+ $options = Mage::getSingleton('lanot_scheduler/job')->getTypeOptions();
56
+
57
+ /** @var $item Mage_Cron_Model_Schedule */
58
+ foreach($this->getCollection() as $item) {
59
+
60
+ $type= (strpos($item->getJobCode(), 'lanot_scheduler_job_id_') === 0) ?
61
+ Lanot_Scheduler_Model_Job::TYPE_CUSTOM : Lanot_Scheduler_Model_Job::TYPE_SYSTEM;
62
+
63
+ $item->setTypeLabel($options[$type]);
64
+ }
65
+ return $this;
66
+ }
67
+
68
+ /**
69
+ * Prepare Grid columns
70
+ *
71
+ * @return Lanot_Scheduler_Block_Adminhtml_Queue_Grid
72
+ */
73
+ protected function _prepareColumns()
74
+ {
75
+ Mage::dispatchEvent($this->_eventPrefix . 'lanot_grid_prepare_columns_before', array('grid' => $this));
76
+
77
+ $this->addColumn($this->_entityIdField, array(
78
+ 'header' => $this->_getHelper()->__('ID'),
79
+ 'index' => $this->_entityIdField,
80
+ 'type' => 'number',
81
+ 'width' => '50px',
82
+ ));
83
+
84
+ $this->addColumn('status', array(
85
+ 'header' => $this->_getHelper()->__('Status'),
86
+ 'index' => 'status',
87
+ 'frame_callback' => array($this, 'decorateStatus'),
88
+ 'width' => '90',
89
+ ));
90
+
91
+ $this->addColumn('type_label', array(
92
+ 'header' => $this->_getHelper()->__('Job Type'),
93
+ 'index' => 'type_label',
94
+ 'width' => '50px',
95
+ 'filter' => false,
96
+ 'align' => 'center',
97
+ ));
98
+
99
+ $this->addColumn('job_code', array(
100
+ 'header' => $this->_getHelper()->__('Job Code'),
101
+ 'index' => 'job_code',
102
+ ));
103
+
104
+ $this->addColumn('messages', array(
105
+ 'header' => $this->_getHelper()->__('Messages'),
106
+ 'index' => 'messages',
107
+ 'frame_callback' => array($this, 'decorateMessages'),
108
+ 'width' => '30%',
109
+ ));
110
+
111
+ $this->addColumn('scheduled_at', array(
112
+ 'header' => $this->_getHelper()->__('Scheduled At'),
113
+ 'index' => 'scheduled_at',
114
+ 'width' => '150px',
115
+ 'align' => 'center',
116
+ ));
117
+
118
+ $this->addColumn('executed_at', array(
119
+ 'header' => $this->_getHelper()->__('Executed At'),
120
+ 'index' => 'executed_at',
121
+ 'width' => '150px',
122
+ 'align' => 'center',
123
+ ));
124
+
125
+ $this->addColumn('finished_at', array(
126
+ 'header' => $this->_getHelper()->__('Finished At'),
127
+ 'index' => 'finished_at',
128
+ 'width' => '150px',
129
+ 'align' => 'center',
130
+ ));
131
+
132
+ $this->addColumn('action',
133
+ array(
134
+ 'header' => $this->_getHelper()->__('Action'),
135
+ 'width' => '70px',
136
+ 'align' => 'center',
137
+ 'type' => 'action',
138
+ 'getter' => 'getId',
139
+ 'actions' => array(
140
+ array(
141
+ 'caption' => $this->_getHelper()->__('View'),
142
+ 'url' => array('base' => '*/*/view'),
143
+ 'field' => 'job_code'
144
+ )
145
+ ),
146
+ 'filter' => false,
147
+ 'sortable' => false,
148
+ 'index' => 'banner',
149
+ ));
150
+
151
+ Mage::dispatchEvent($this->_eventPrefix . 'lanot_grid_prepare_columns', array('grid' => $this));
152
+
153
+ return Mage_Adminhtml_Block_Widget_Grid::_prepareColumns();
154
+ }
155
+
156
+ /**
157
+ * @return Lanot_Scheduler_Helper_Data
158
+ */
159
+ protected function _getHelper()
160
+ {
161
+ return Mage::helper('lanot_scheduler');
162
+ }
163
+
164
+ /**
165
+ * @return Lanot_Scheduler_Helper_Admin
166
+ */
167
+ protected function _getAclHelper()
168
+ {
169
+ return Mage::helper('lanot_scheduler/admin');
170
+ }
171
+
172
+ /**
173
+ * Checks when this block is not available
174
+ *
175
+ * @return boolean
176
+ */
177
+ public function isMassActionAllowed()
178
+ {
179
+ return false;
180
+ }
181
+
182
+ /**
183
+ * Decorate status column values
184
+ *
185
+ * @param string $value
186
+ * @param $row
187
+ * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
188
+ * @param bool $isExport
189
+ * @return string
190
+ */
191
+ public function decorateStatus($value, $row, $column, $isExport)
192
+ {
193
+ $class = '';
194
+ switch ($row->getStatus()) {
195
+ case Mage_Cron_Model_Schedule::STATUS_PENDING:
196
+ $class = 'grid-severity-minor';
197
+ break;
198
+ case Mage_Cron_Model_Schedule::STATUS_RUNNING:
199
+ $class = 'grid-severity-major';
200
+ break;
201
+ case Mage_Cron_Model_Schedule::STATUS_ERROR:
202
+ case Mage_Cron_Model_Schedule::STATUS_MISSED:
203
+ $class = 'grid-severity-critical';
204
+ break;
205
+ case Mage_Cron_Model_Schedule::STATUS_SUCCESS:
206
+ $class = 'grid-severity-notice';
207
+ break;
208
+ }
209
+ return '<span class="'.$class.'"><span>'.$value.'</span></span>';
210
+ }
211
+
212
+ /**
213
+ * Decorate status column values
214
+ *
215
+ * @param string $value
216
+ * @param $row
217
+ * @param Mage_Adminhtml_Block_Widget_Grid_Column $column
218
+ * @param bool $isExport
219
+ * @return string
220
+ */
221
+ public function decorateMessages($value, $row, $column, $isExport)
222
+ {
223
+ return nl2br($row->getMessages());
224
+ }
225
+
226
+ /**
227
+ * @param $row
228
+ * @return string
229
+ */
230
+ public function getRowUrl($row)
231
+ {
232
+ return $this->getUrl('*/*/view', array('job_code' => $row->getJobCode()));
233
+ }
234
+ }
app/code/community/Lanot/Scheduler/Block/Adminhtml/Queue/View.php ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Scheduler
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Lanot_Scheduler_Block_Adminhtml_Queue_View
22
+ extends Mage_Adminhtml_Block_Widget_Form
23
+ {
24
+ /**
25
+ * Prepare form elements for tab
26
+ *
27
+ * @return Mage_Adminhtml_Block_Widget_Form
28
+ */
29
+ protected function _prepareForm()
30
+ {
31
+ $data = Mage::registry('cron.job.item.data');
32
+
33
+ $form = new Varien_Data_Form(array(
34
+ 'id' => 'view_form',
35
+ 'action' => '#',
36
+ 'method' => 'post',
37
+ ));
38
+ $form->setUseContainer(false);
39
+
40
+ //prepare fieldsets
41
+ $fieldset = $form->addFieldset('main_fieldset', array(
42
+ 'legend' => $this->_getHelper()->__('Cron Job Info')
43
+ ));
44
+
45
+ $fieldset->addField('job_code', 'label', array(
46
+ 'name' => 'job_code',
47
+ 'label' => $this->_getHelper()->__('Job Code'),
48
+ 'bold' => true,
49
+ ));
50
+
51
+ if (isset($data['job_id'])) {
52
+ $fieldset->addField('job_id', 'note', array(
53
+ 'name' => 'job_id',
54
+ 'label' => '',
55
+ 'bold' => true,
56
+ 'after_element_html' => sprintf('<a href="%s">%s</a>',
57
+ $this->getUrl('*/adminhtml_job/edit', array('id' => $data['job_id'])),
58
+ $this->_getHelper()->__('Edit custom cron job')
59
+ ),
60
+ ));
61
+ }
62
+
63
+ $fieldset->addField('type_label', 'label', array(
64
+ 'name' => 'type_label',
65
+ 'label' => $this->_getHelper()->__('Type'),
66
+ ));
67
+
68
+ $fieldset->addField('cron_expr', 'label', array(
69
+ 'name' => 'cron_expr',
70
+ 'label' => $this->_getHelper()->__('Cron schedule'),
71
+ ));
72
+
73
+ $fieldset->addField('model', 'label', array(
74
+ 'name' => 'model',
75
+ 'label' => $this->_getHelper()->__('Model'),
76
+ ));
77
+
78
+ Mage::dispatchEvent('adminhtml_lanot_scheduler_queue_view_form', array('form' => $form));
79
+
80
+ $form->setValues($data);
81
+ $this->setForm($form);
82
+
83
+ return parent::_prepareForm();
84
+ }
85
+
86
+ /**
87
+ * @return Lanot_Scheduler_Helper_Data
88
+ */
89
+ protected function _getHelper()
90
+ {
91
+ return Mage::helper('lanot_scheduler');
92
+ }
93
+ }
app/code/community/Lanot/Scheduler/Block/Adminhtml/Systemjob.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Scheduler
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Lanot_Scheduler_Block_Adminhtml_Systemjob
22
+ extends Mage_Adminhtml_Block_Widget_Grid_Container
23
+ {
24
+ /**
25
+ * Block constructor
26
+ */
27
+ public function __construct()
28
+ {
29
+ $this->_blockGroup = 'lanot_scheduler';
30
+ $this->_controller = 'adminhtml_systemjob';
31
+ $this->_headerText = Mage::helper('lanot_scheduler')->__('View System Cron Jobs');
32
+
33
+ parent::__construct();
34
+
35
+ $this->_removeButton('add');
36
+ }
37
+ }
38
+
app/code/community/Lanot/Scheduler/Block/Adminhtml/Systemjob/Grid.php ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Scheduler
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Lanot_Scheduler_Block_Adminhtml_Systemjob_Grid
22
+ extends Lanot_Scheduler_Block_Adminhtml_Job_Grid
23
+ {
24
+ protected $_eventPrefix = 'systemjob_';
25
+ protected $_filterVisibility = false;
26
+ protected $_pagerVisibility = false;
27
+
28
+ protected function _construct()
29
+ {
30
+ parent::_construct();
31
+ $this->setDefaultLimit(1000);//@todo: fix
32
+ }
33
+
34
+ /**
35
+ * @return Lanot_Core_Block_Adminhtml_Grid_Abstract
36
+ */
37
+ protected function _prepareCollection()
38
+ {
39
+ $collection = new Varien_Data_Collection();
40
+ Mage::dispatchEvent($this->_eventPrefix . 'lanot_grid_prepare_collection', array(
41
+ 'grid' => $this,
42
+ 'collection' => $collection
43
+ ));
44
+ $this->setCollection($collection);
45
+ return Mage_Adminhtml_Block_Widget_Grid::_prepareCollection();
46
+ }
47
+
48
+ /**
49
+ * Prepare Grid columns
50
+ *
51
+ * @return Lanot_Scheduler_Block_Adminhtml_Job_Grid
52
+ */
53
+ protected function _prepareColumns()
54
+ {
55
+ parent::_prepareColumns();
56
+
57
+ $this->removeColumn('updated_at');
58
+ $this->removeColumn('action');
59
+ $this->removeColumn('title');
60
+ $this->removeColumn('job_id');
61
+ }
62
+
63
+ /**
64
+ * Checks when this block is readonly
65
+ *
66
+ * @return boolean
67
+ */
68
+ public function isReadonly()
69
+ {
70
+ return true;
71
+ }
72
+
73
+ /**
74
+ * Checks when this block is not available
75
+ *
76
+ * @return boolean
77
+ */
78
+ public function isMassActionAllowed()
79
+ {
80
+ return false;
81
+ }
82
+
83
+ /**
84
+ * @param $row
85
+ * @return string
86
+ */
87
+ public function getRowUrl($row)
88
+ {
89
+ return '#';
90
+ }
91
+ }
app/code/community/Lanot/Scheduler/Helper/Admin.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Scheduler
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+ class Lanot_Scheduler_Helper_Admin
21
+ extends Mage_Core_Helper_Abstract
22
+ {
23
+ /**
24
+ * Check permission
25
+ *
26
+ * @return bool
27
+ */
28
+ public function isActionAllowed($section)
29
+ {
30
+ return Mage::getSingleton('admin/session')->isAllowed('lanot/lanot_scheduler/' . $section);
31
+ }
32
+ }
app/code/community/Lanot/Scheduler/Helper/Data.php ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Scheduler
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Lanot_Scheduler_Helper_Data extends Mage_Core_Helper_Abstract
22
+ {
23
+ const SCHEDULE_DELIMITER = ',';
24
+ const XPATH_PATTERN_MODEL = 'crontab/jobs/lanot_scheduler_job_id_%d/run/model';
25
+ const XPATH_PATTERN_EXPR = 'crontab/jobs/lanot_scheduler_job_id_%d/schedule/cron_expr';
26
+ const XPATH_PATTERN_JOB_CODE = 'lanot_scheduler_job_id_%d';
27
+ const XPATH_CLEAN_CACHE_NODE = 'lanot_scheduler/settings/enabled_cache_clean';
28
+ const XPATH_CLEAN_QUEUE_NODE = 'lanot_scheduler/settings/enabled_queue_clean';
29
+ const XPATH_GENERATE_QUEUE_NODE = 'lanot_scheduler/settings/enabled_queue_generation';
30
+ const DATETIME_PHP_FORMAT = 'Y-m-d H:i:s';
31
+
32
+ protected $_translatedLimits = array(
33
+ 'day_of_week' => array(
34
+ '0' => 'Sunday',
35
+ '1' => 'Monday',
36
+ '2' => 'Tuesday',
37
+ '3' => 'Wednesday',
38
+ '4' => 'Thursday',
39
+ '5' => 'Friday',
40
+ '6' => 'Saturday',
41
+ ),
42
+ 'month' => array(
43
+ '1' => 'January',
44
+ '2' => 'February',
45
+ '3' => 'March',
46
+ '4' => 'April',
47
+ '5' => 'May',
48
+ '6' => 'June',
49
+ '7' => 'July',
50
+ '8' => 'August',
51
+ '9' => 'September',
52
+ '10' => 'October',
53
+ '11' => 'November',
54
+ '12' => 'December',
55
+ ),
56
+ );
57
+
58
+ /**
59
+ * @return array
60
+ */
61
+ public function getScheduleDescription()
62
+ {
63
+ return array(
64
+ 'min' => $this->__('Minute'),
65
+ 'hour' => $this->__('Hour'),
66
+ 'day_of_month' => $this->__('Day Of Month'),
67
+ 'month' => $this->__('Month'),
68
+ 'day_of_week' => $this->__('Day Of Week'),
69
+ );
70
+ }
71
+
72
+ /**
73
+ * @return array
74
+ */
75
+ public function getScheduleLimits()
76
+ {
77
+ return array(
78
+ 'min' => array('min' => 0, 'max' => 59),
79
+ 'hour' => array('min' => 0, 'max' => 23),
80
+ 'day_of_month' => array('min' => 1, 'max' => 31),
81
+ 'month' => array('min' => 1, 'max' => 12),
82
+ 'day_of_week' => array('min' => 0, 'max' => 6),
83
+ );
84
+ }
85
+
86
+ /**
87
+ * @param $name
88
+ * @param $value
89
+ * @return mixed
90
+ */
91
+ public function getScheduleTranslatedLimits($name, $value)
92
+ {
93
+ return isset($this->_translatedLimits[$name][$value]) ? $this->_translatedLimits[$name][$value] : $value;
94
+ }
95
+
96
+ /**
97
+ * @return string
98
+ */
99
+ public function getCronJobExamples()
100
+ {
101
+ return '<br />Run once a year - 0 0 1 1 *' .
102
+ '<br />Run once a month - 0 0 1 * *' .
103
+ '<br />Run once a week - 0 0 * * 0' .
104
+ '<br />Run once a day - 0 0 * * *' .
105
+ '<br />Run once an hour - 0 * * * *'.
106
+ '<br />Run each 6 hours - 0 0,6,12,18 * * *'.
107
+ '<br />Run each 10 minutes - 0,10,20,30,40,50 * * * *';
108
+ }
109
+
110
+ /**
111
+ * @param $key
112
+ * @param bool $each
113
+ * @return array
114
+ */
115
+ public function prepareCronJobOptions($key, $each = false)
116
+ {
117
+ $options = array();
118
+ if ($each) {
119
+ $schedules = $this->getScheduleDescription();
120
+ $options['*'] = array('value' => '*', 'label' => $this->__('Every %s', $schedules[$key]));
121
+ }
122
+ $limits = $this->getScheduleLimits();
123
+ for($i = $limits[$key]['min']; $i <= $limits[$key]['max'];$i++) {
124
+ $options["$i"] = array('value' => $i, 'label' => $this->getScheduleTranslatedLimits($key, $i));
125
+ }
126
+ return $options;
127
+ }
128
+
129
+ /**
130
+ * @return Lanot_Scheduler_Model_job
131
+ */
132
+ public function getJobItemInstance()
133
+ {
134
+ $item = Mage::registry('lanot.cron.job.item');
135
+ if (!$item->getId()) {
136
+ foreach($this->getScheduleDescription() as $key => $label) {
137
+ if (!$item->hasData($key)) {
138
+ $item->setData($key, $key == 'min' ? '0' : '*');
139
+ }
140
+ }
141
+ }
142
+ return $item;
143
+ }
144
+
145
+ /**
146
+ * @return bool
147
+ */
148
+ public function isAutoCacheCleanEnabled()
149
+ {
150
+ return (bool) Mage::app()->getStore()->getConfig(self::XPATH_CLEAN_CACHE_NODE);
151
+ }
152
+
153
+ /**
154
+ * @return bool
155
+ */
156
+ public function isAutoQueueCleanEnabled()
157
+ {
158
+ return (bool) Mage::app()->getStore()->getConfig(self::XPATH_CLEAN_QUEUE_NODE);
159
+ }
160
+
161
+ /**
162
+ * @return bool
163
+ */
164
+ public function isAutoQueueGenerationEnabled()
165
+ {
166
+ return (bool) Mage::app()->getStore()->getConfig(self::XPATH_GENERATE_QUEUE_NODE);
167
+ }
168
+
169
+ /**
170
+ * Retrieve current date in internal format
171
+ * @return string
172
+ */
173
+ public static function now()
174
+ {
175
+ return date(self::DATETIME_PHP_FORMAT);
176
+ }
177
+
178
+ /**
179
+ * @param $jobCode
180
+ * @return array|bool|string
181
+ */
182
+ public function getCronData($jobCode)
183
+ {
184
+ $node = Mage::getConfig()->getNode('crontab/jobs/' . $jobCode);
185
+ if (!$node) {
186
+ $node = Mage::getConfig()->getNode('default/crontab/jobs/' . $jobCode);
187
+ }
188
+ $data = array();
189
+ if ($node) {
190
+ $options = Mage::getSingleton('lanot_scheduler/job')->getTypeOptions();
191
+ $data = $node->asArray();
192
+
193
+ $data['job_code'] = $jobCode;
194
+ $data['cron_expr'] = $data['schedule']['cron_expr'];
195
+ $data['model'] = $data['run']['model'];
196
+
197
+ $data['type'] = (strpos($jobCode, 'lanot_scheduler_job_id_') === 0) ?
198
+ Lanot_Scheduler_Model_Job::TYPE_CUSTOM : Lanot_Scheduler_Model_Job::TYPE_SYSTEM;
199
+ $data['type_label'] = $options[$data['type']];
200
+
201
+ if ($data['type'] == Lanot_Scheduler_Model_Job::TYPE_CUSTOM) {
202
+ $data['job_id'] = (int) str_replace('lanot_scheduler_job_id_', '', $jobCode);
203
+ }
204
+ }
205
+ return $data;
206
+ }
207
+ }
app/code/community/Lanot/Scheduler/Model/Job.php ADDED
@@ -0,0 +1,254 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Scheduler
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ /**
22
+ * job item model
23
+ *
24
+ * @author Lanot
25
+ */
26
+ class Lanot_Scheduler_Model_Job extends Mage_Core_Model_Abstract
27
+ {
28
+ const TYPE_SYSTEM = 0;
29
+ const TYPE_CUSTOM = 1;
30
+
31
+ protected function _construct()
32
+ {
33
+ $this->_init('lanot_scheduler/job');
34
+ }
35
+
36
+ /**
37
+ * @return $this
38
+ */
39
+ protected function _beforeSave()
40
+ {
41
+ $this->validateData();
42
+ $this->validateSchedule();
43
+ $this->prepareScheduleFromArray($this);
44
+ $this->setData('updated_at', Lanot_Scheduler_Helper_Data::now());
45
+ if ($this->isObjectNew()) {
46
+ $this->setData('created_at', Lanot_Scheduler_Helper_Data::now());
47
+ }
48
+ return parent::_beforeSave();
49
+ }
50
+
51
+ /**
52
+ * @return $this
53
+ */
54
+ protected function _afterLoad()
55
+ {
56
+ parent::_afterLoad();
57
+ $this->prepareScheduleToArray($this);
58
+ $this->setJobCode($this->_getJobCode());
59
+ return $this;
60
+ }
61
+
62
+ /**
63
+ * @return $this
64
+ */
65
+ protected function _afterSaveCommit()
66
+ {
67
+ parent::_afterSaveCommit();
68
+ $this->cacheClean();
69
+ $this->cleanObsoleteSchedules();
70
+ $this->generateNewSchedules();
71
+ return $this;
72
+ }
73
+
74
+ /**
75
+ * @return $this
76
+ */
77
+ protected function _afterDeleteCommit()
78
+ {
79
+ parent::_afterDeleteCommit();
80
+ $this->cleanObsoleteSchedules();
81
+ $this->cacheClean();
82
+ return $this;
83
+ }
84
+
85
+ /**
86
+ * @return string
87
+ */
88
+ public function getSchedule()
89
+ {
90
+ return $this->prepareScheduleFromObject($this);
91
+ }
92
+
93
+ /**
94
+ * @param Lanot_Scheduler_Model_Job $object
95
+ * @return string
96
+ */
97
+ public function prepareScheduleFromObject($object)
98
+ {
99
+ $schedule = array();
100
+ foreach($this->_getHelper()->getScheduleDescription() as $k => $v) {
101
+ $schedule[] = $object->hasData($k) ? $object->getData($k) : '*';
102
+ }
103
+ return implode(' ', $schedule);
104
+ }
105
+
106
+ /**
107
+ * @param Lanot_Scheduler_Model_Job $object
108
+ * @return $this
109
+ */
110
+ public function prepareScheduleFromArray($object)
111
+ {
112
+ foreach($this->_getHelper()->getScheduleDescription() as $k => $description) {
113
+ $val = $object->hasData($k) ? $object->getData($k) : '*';
114
+ $val = is_array($val) ? implode(Lanot_Scheduler_Helper_Data::SCHEDULE_DELIMITER, $val) : $val;
115
+ $this->setData($k, $val);
116
+ }
117
+ return $this;
118
+ }
119
+
120
+ /**
121
+ * @param Lanot_Scheduler_Model_Job $object
122
+ * @return $this
123
+ */
124
+ public function prepareScheduleToArray($object)
125
+ {
126
+ foreach($this->_getHelper()->getScheduleDescription() as $k => $description) {
127
+ $val = $object->hasData($k) ? $object->getData($k) : '*';
128
+ $val = !is_array($val) ? explode(Lanot_Scheduler_Helper_Data::SCHEDULE_DELIMITER, $val) : $val;
129
+ $this->setData($k, $val);
130
+ }
131
+ return $this;
132
+ }
133
+
134
+ /**
135
+ * @return Lanot_Scheduler_Helper_Data
136
+ */
137
+ protected function _getHelper()
138
+ {
139
+ return Mage::helper('lanot_scheduler');
140
+ }
141
+
142
+ /**
143
+ * @return $this
144
+ * @throws Mage_Core_Exception
145
+ */
146
+ public function validateSchedule()
147
+ {
148
+ $description = $this->_getHelper()->getScheduleDescription();
149
+ foreach($this->_getHelper()->getScheduleLimits() as $key => $limit) {
150
+ if (!$this->hasData($key) || !is_array($this->getData($key))) {
151
+ Mage::throwException($this->_getHelper()->__('Please, fill the "%s" field', $description[$key]));
152
+ }
153
+
154
+ $cnt = count($this->getData($key));
155
+ foreach($this->getData($key) as $value) {
156
+ if ($value == '*' && $cnt > 1) {
157
+ Mage::throwException($this->_getHelper()->__('Please, unselect other values which are different from the "Every %s" field', $description[$key]));
158
+ } elseif($value != '*' && $value > $limit['max']) {
159
+ Mage::throwException($this->_getHelper()->__('Value of the "%s" field if bigger than it is allowed. Max. value is "%s"', $description[$key], $limit['max']));
160
+ } elseif($value != '*' && $value < $limit['min']) {
161
+ Mage::throwException($this->_getHelper()->__('Value of the "%s" field if smaller than it is allowed. Min. value is "%s"', $description[$key], $limit['min']));
162
+ }
163
+ }
164
+ }
165
+ return $this;
166
+ }
167
+
168
+ /**
169
+ * @return $this
170
+ * @throws Mage_Core_Exception
171
+ */
172
+ public function validateData()
173
+ {
174
+ if (!preg_match(Mage_Cron_Model_Observer::REGEX_RUN_MODEL, $this->getModel(), $run)) {
175
+ Mage::throwException(Mage::helper('cron')->__('Invalid model/method definition, expecting "model/class::method".'));
176
+ }
177
+
178
+ if (!($model = Mage::getModel($run[1])) || !method_exists($model, $run[2])) {
179
+ Mage::throwException(Mage::helper('cron')->__('Invalid callback: %s::%s does not exist', $run[1], $run[2]));
180
+ }
181
+ return $this;
182
+ }
183
+
184
+ /**
185
+ * @return string
186
+ */
187
+ protected function _getJobCode()
188
+ {
189
+ return sprintf(Lanot_Scheduler_Helper_Data::XPATH_PATTERN_JOB_CODE, $this->getId());
190
+ }
191
+
192
+ /**
193
+ * @return $this
194
+ */
195
+ public function cacheClean()
196
+ {
197
+ if (!$this->_getHelper()->isAutoCacheCleanEnabled()) {
198
+ return $this;
199
+ }
200
+ Mage::app()->getCacheInstance()->cleanType('config');
201
+ return $this;
202
+ }
203
+
204
+ /**
205
+ * @return $this
206
+ */
207
+ public function cleanObsoleteSchedules()
208
+ {
209
+ if (!$this->_getHelper()->isAutoQueueCleanEnabled()) {
210
+ return $this;
211
+ }
212
+ $obsoleteRecords = Mage::getModel('cron/schedule')->getCollection()
213
+ ->addFieldToFilter('job_code', $this->getJobCode());
214
+ foreach ($obsoleteRecords as $record) {
215
+ $record->delete();
216
+ }
217
+ return $this;
218
+ }
219
+
220
+ /**
221
+ * @return $this
222
+ */
223
+ public function generateNewSchedules()
224
+ {
225
+ if (!$this->_getHelper()->isAutoQueueGenerationEnabled()) {
226
+ return $this;
227
+ }
228
+ Mage::app()->saveCache(0,Mage_Cron_Model_Observer::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT, array('crontab'), null);
229
+ Mage::getSingleton('cron/observer')->generate();
230
+ return $this;
231
+ }
232
+
233
+ /**
234
+ * @return array
235
+ */
236
+ public function getTypeOptions()
237
+ {
238
+ return array(
239
+ self::TYPE_SYSTEM => $this->_getHelper()->__('System'),
240
+ self::TYPE_CUSTOM => $this->_getHelper()->__('Custom'),
241
+ );
242
+ }
243
+
244
+ /**
245
+ * @return mixed
246
+ */
247
+ public function getJobCode()
248
+ {
249
+ if (!$this->hasData('job_code')) {
250
+ $this->setJobCode($this->_getJobCode());
251
+ }
252
+ return $this->getData('job_code');
253
+ }
254
+ }
app/code/community/Lanot/Scheduler/Model/Mysql4/Job.php ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Scheduler
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ /**
22
+ * Job resource model
23
+ *
24
+ * @author Lanot
25
+ */
26
+ class Lanot_Scheduler_Model_Mysql4_Job extends Mage_Core_Model_Mysql4_Abstract
27
+ {
28
+ /**
29
+ * Initialize connection and define main table and primary key
30
+ */
31
+ protected function _construct()
32
+ {
33
+ $this->_init('lanot_scheduler/job', 'job_id');
34
+ }
35
+
36
+ /**
37
+ * @param Mage_Core_Model_Abstract $object
38
+ * @return $this
39
+ */
40
+ protected function _afterSave(Mage_Core_Model_Abstract $object)
41
+ {
42
+ parent::_afterSave($object);
43
+ $this->_saveConfigRelations($object);
44
+ return $this;
45
+ }
46
+
47
+ /**
48
+ * @param Mage_Core_Model_Abstract $object
49
+ * @return $this
50
+ */
51
+ protected function _afterDelete(Mage_Core_Model_Abstract $object)
52
+ {
53
+ $this->_removeConfigRelations($object);
54
+ return parent::_afterDelete($object);
55
+ }
56
+
57
+ /**
58
+ * @param Mage_Core_Model_Abstract $object
59
+ * @return $this
60
+ */
61
+ protected function _saveConfigRelations(Mage_Core_Model_Abstract $object)
62
+ {
63
+ $data = array(
64
+ array(
65
+ 'scope' => 'default',
66
+ 'scope_id' => '0',
67
+ 'path' => sprintf(Lanot_Scheduler_Helper_Data::XPATH_PATTERN_MODEL, $object->getId()),
68
+ 'value' => $object->getModel(),
69
+ ),
70
+ array(
71
+ 'scope' => 'default',
72
+ 'scope_id' => '0',
73
+ 'path' => sprintf(Lanot_Scheduler_Helper_Data::XPATH_PATTERN_EXPR, $object->getId()),
74
+ 'value' => $object->getSchedule(),
75
+ ),
76
+ );
77
+
78
+ $this->_getWriteAdapter()->insertOnDuplicate(
79
+ $this->getTable('core/config_data'),
80
+ $data,
81
+ array('value')
82
+ );
83
+ return $this;
84
+ }
85
+
86
+ /**
87
+ * @param Mage_Core_Model_Abstract $object
88
+ * @return $this
89
+ */
90
+ protected function _removeConfigRelations(Mage_Core_Model_Abstract $object)
91
+ {
92
+ $paths = array(
93
+ sprintf(Lanot_Scheduler_Helper_Data::XPATH_PATTERN_MODEL, $object->getId()),
94
+ sprintf(Lanot_Scheduler_Helper_Data::XPATH_PATTERN_EXPR, $object->getId())
95
+ );
96
+ $this->_getWriteAdapter()->delete(
97
+ $this->getTable('core/config_data'),
98
+ $this->_getWriteAdapter()->quoteInto('`path` IN (?)', $paths)
99
+ );
100
+ return $this;
101
+ }
102
+ }
app/code/community/Lanot/Scheduler/Model/Mysql4/Job/Collection.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Scheduler
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ /**
22
+ * Job collection
23
+ *
24
+ * @author Lanot
25
+ */
26
+ class Lanot_Scheduler_Model_Mysql4_Job_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
27
+ {
28
+ /**
29
+ * Define collection model
30
+ */
31
+ protected function _construct()
32
+ {
33
+ $this->_init('lanot_scheduler/job');
34
+ }
35
+ }
app/code/community/Lanot/Scheduler/Model/Observer.php ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Scheduler
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ /**
22
+ * Observer model
23
+ *
24
+ * @author Lanot
25
+ */
26
+ class Lanot_Scheduler_Model_Observer
27
+ {
28
+ /**
29
+ * @param $observer
30
+ * @return $this
31
+ */
32
+ public function prepareSystemJobsCollection($observer)
33
+ {
34
+ /** @var Mage_Core_Model_Config_Element $jobsRoot */
35
+ $jobsRoot = Mage::getConfig()->getNode('crontab/jobs');
36
+ if (!$jobsRoot) {
37
+ return $this;
38
+ }
39
+
40
+ /** @var Mage_Core_Model_Config_Element $defaultJobsRoot */
41
+ $defaultJobsRoot = Mage::getConfig()->getNode('default/crontab/jobs');
42
+ $defaultJobsRoot = $defaultJobsRoot? $defaultJobsRoot->asArray() : array();
43
+
44
+ /** @var Varien_Data_Collection $collection */
45
+ $collection = $observer->getEvent()->getCollection();
46
+
47
+ foreach($jobsRoot->asArray() as $jobCode => $data) {
48
+ $expr = isset($data['schedule']['cron_expr']) ?
49
+ $data['schedule']['cron_expr'] : Mage::helper('lanot_scheduler')->__('Not scheduled');
50
+
51
+ if (isset($defaultJobsRoot[$jobCode]['schedule']['cron_expr']) &&
52
+ !empty($defaultJobsRoot[$jobCode]['schedule']['cron_expr'])
53
+ ) {
54
+ $expr = $defaultJobsRoot[$jobCode]['schedule']['cron_expr'];
55
+ }
56
+
57
+ $collection->addItem(
58
+ new Varien_Object(array(
59
+ 'job_code' => $jobCode,
60
+ 'model' => $data['run']['model'],
61
+ 'schedule' => $expr,
62
+ ))
63
+ );
64
+ }
65
+ return $this;
66
+ }
67
+ }
app/code/community/Lanot/Scheduler/controllers/Adminhtml/JobController.php ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Scheduler
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Lanot_Scheduler_Adminhtml_JobController
22
+ extends Lanot_Core_Controller_Adminhtml_AbstractController
23
+ {
24
+ protected $_msgTitle = 'Jobs';
25
+ protected $_msgHeader = 'Manage Jobs';
26
+ protected $_msgItemDoesNotExist = 'The job item does not exist.';
27
+ protected $_msgItemNotFound = 'Unable to find the job item #%s.';
28
+ protected $_msgItemEdit = 'Edit Job Type Item';
29
+ protected $_msgItemNew = 'New Job Type Item';
30
+ protected $_msgItemSaved = 'The job item has been saved.';
31
+ protected $_msgItemDeleted = 'The job item has been deleted.';
32
+ protected $_msgError = 'An error occurred while edit the job item.';
33
+ protected $_msgErrorItems = 'An error occurred while edit the job items %s.';
34
+ protected $_msgItems = 'The job items (#%s) has been';
35
+
36
+ protected $_menuActive = 'lanot/lanot_scheduler';
37
+ protected $_aclSection = 'manage_jobs';
38
+
39
+ /**
40
+ * @return Lanot_Scheduler_Model_Job
41
+ */
42
+ protected function _getItemModel()
43
+ {
44
+ return Mage::getModel('lanot_scheduler/job');
45
+ }
46
+
47
+ /**
48
+ * @param Lanot_Scheduler_Model_Job $model
49
+ * @return $this
50
+ */
51
+ protected function _registerItem(Mage_Core_Model_Abstract $model)
52
+ {
53
+ Mage::register('lanot.cron.job.item', $model);
54
+ return $this;
55
+ }
56
+
57
+ /**
58
+ * @return Lanot_Scheduler_Helper_Data
59
+ */
60
+ protected function _getHelper()
61
+ {
62
+ return Mage::helper('lanot_scheduler');
63
+ }
64
+
65
+ /**
66
+ * @return Lanot_Scheduler_Helper_Admin
67
+ */
68
+ protected function _getAclHelper()
69
+ {
70
+ return Mage::helper('lanot_scheduler/admin');
71
+ }
72
+
73
+ /**
74
+ * Check the permission to run it
75
+ *
76
+ * @return boolean
77
+ */
78
+ protected function _isAllowed()
79
+ {
80
+ return $this->_getAclHelper()->isActionAllowed($this->_aclSection);
81
+ }
82
+ }
app/code/community/Lanot/Scheduler/controllers/Adminhtml/QueueController.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Scheduler
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ class Lanot_Scheduler_Adminhtml_QueueController
22
+ extends Lanot_Core_Controller_Adminhtml_AbstractController
23
+ {
24
+ protected $_msgTitle = 'Queue';
25
+ protected $_msgHeader = 'Manage Queue';
26
+ protected $_msgItemDoesNotExist = 'The queue item does not exist.';
27
+ protected $_msgItemNotFound = 'Unable to find the queue item #%s.';
28
+ protected $_msgItemEdit = 'Edit Queue Type Item';
29
+ protected $_msgItemNew = 'New Queue Type Item';
30
+ protected $_msgItemSaved = 'The queue item has been saved.';
31
+ protected $_msgItemDeleted = 'The queue item has been deleted.';
32
+ protected $_msgError = 'An error occurred while edit the queue item.';
33
+ protected $_msgErrorItems = 'An error occurred while edit the queue items %s.';
34
+ protected $_msgItems = 'The queue items (#%s) has been';
35
+
36
+ protected $_menuActive = 'lanot/lanot_scheduler';
37
+ protected $_aclSection = 'view_queue';
38
+
39
+ public function viewAction()
40
+ {
41
+ $jobCode = $this->getRequest()->getParam('job_code');
42
+ if (!$jobCode) {
43
+ return $this->_forward('noRoute');
44
+ }
45
+ $data = $this->_getHelper()->getCronData($jobCode);
46
+ if (empty($data)) {
47
+ return $this->_forward('noRoute');
48
+ }
49
+ Mage::register('cron.job.item.data', $data);
50
+ $this->_loadLayouts();
51
+ }
52
+
53
+ /**
54
+ * @return Mage_Cron_Model_Schedule
55
+ */
56
+ protected function _getItemModel()
57
+ {
58
+ return Mage::getModel('cron/schedule');
59
+ }
60
+
61
+ /**
62
+ * @param Mage_Cron_Model_Schedule $model
63
+ * @return $this
64
+ */
65
+ protected function _registerItem(Mage_Core_Model_Abstract $model)
66
+ {
67
+ Mage::register('lanot.cron.queue.item', $model);
68
+ return $this;
69
+ }
70
+
71
+ /**
72
+ * @return Lanot_Scheduler_Helper_Data
73
+ */
74
+ protected function _getHelper()
75
+ {
76
+ return Mage::helper('lanot_scheduler');
77
+ }
78
+
79
+ /**
80
+ * @return Lanot_Scheduler_Helper_Admin
81
+ */
82
+ protected function _getAclHelper()
83
+ {
84
+ return Mage::helper('lanot_scheduler/admin');
85
+ }
86
+
87
+ /**
88
+ * Check the permission to run it
89
+ *
90
+ * @return boolean
91
+ */
92
+ protected function _isAllowed()
93
+ {
94
+ return $this->_getAclHelper()->isActionAllowed($this->_aclSection);
95
+ }
96
+ }
app/code/community/Lanot/Scheduler/controllers/Adminhtml/SystemjobController.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Scheduler
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+ require_once('Lanot/Scheduler/controllers/Adminhtml/JobController.php');
21
+
22
+ class Lanot_Scheduler_Adminhtml_SystemjobController
23
+ extends Lanot_Scheduler_Adminhtml_JobController
24
+ {
25
+ protected $_msgTitle = 'System Jobs';
26
+ protected $_msgHeader = 'View System Jobs';
27
+ protected $_aclSection = 'view_systemjobs';
28
+ }
app/code/community/Lanot/Scheduler/etc/adminhtml.xml ADDED
@@ -0,0 +1,83 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <!--/MENU -->
4
+ <menu>
5
+ <lanot translate="title">
6
+ <title>Lanot</title>
7
+ <sort_order>65</sort_order>
8
+ <children>
9
+ <lanot_scheduler translate="title" module="lanot_scheduler">
10
+ <title>Scheduler</title>
11
+ <sort_order>150</sort_order>
12
+ <children>
13
+ <manage_jobs translate="title" module="lanot_scheduler">
14
+ <title>Manage Custom Cron Jobs</title>
15
+ <action>lanot_scheduler/adminhtml_job</action>
16
+ <sort_order>10</sort_order>
17
+ </manage_jobs>
18
+ <view_systemjobs translate="title" module="lanot_scheduler">
19
+ <title>View System Cron Jobs</title>
20
+ <action>lanot_scheduler/adminhtml_systemjob</action>
21
+ <sort_order>20</sort_order>
22
+ </view_systemjobs>
23
+ <view_queue translate="title" module="lanot_scheduler">
24
+ <title>View Cron Queue</title>
25
+ <action>lanot_scheduler/adminhtml_queue</action>
26
+ <sort_order>30</sort_order>
27
+ </view_queue>
28
+ </children>
29
+ </lanot_scheduler>
30
+ </children>
31
+ </lanot>
32
+ </menu>
33
+ <!--/MENU -->
34
+
35
+ <!--ACL -->
36
+ <acl>
37
+ <resources>
38
+ <admin>
39
+ <children>
40
+
41
+ <lanot>
42
+ <title>Lanot</title>
43
+ <sort_order>65</sort_order>
44
+ <children>
45
+ <lanot_scheduler translate="title" module="lanot_scheduler">
46
+ <title>Scheduler</title>
47
+ <sort_order>150</sort_order>
48
+ <children>
49
+ <manage_jobs translate="title" module="lanot_scheduler">
50
+ <title>Manage Custom Cron Jobs</title>
51
+ <sort_order>10</sort_order>
52
+ </manage_jobs>
53
+ <view_systemjobs translate="title" module="lanot_scheduler">
54
+ <title>View System Cron Jobs</title>
55
+ <sort_order>20</sort_order>
56
+ </view_systemjobs>
57
+ <view_queue translate="title" module="lanot_scheduler">
58
+ <title>Manage Cron Queue</title>
59
+ <sort_order>30</sort_order>
60
+ </view_queue>
61
+ </children>
62
+ </lanot_scheduler>
63
+ </children>
64
+ </lanot>
65
+
66
+ <system>
67
+ <children>
68
+ <config>
69
+ <children>
70
+ <lanot_scheduler translate="title" module="lanot_scheduler">
71
+ <title>Lanot Scheduler Configuration</title>
72
+ </lanot_scheduler>
73
+ </children>
74
+ </config>
75
+ </children>
76
+ </system>
77
+
78
+ </children>
79
+ </admin>
80
+ </resources>
81
+ </acl>
82
+ <!--/ACL -->
83
+ </config>
app/code/community/Lanot/Scheduler/etc/config.xml ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+
4
+ <modules>
5
+ <Lanot_Scheduler>
6
+ <version>1.0.0</version>
7
+ </Lanot_Scheduler>
8
+ </modules>
9
+
10
+ <global>
11
+ <helpers>
12
+ <lanot_scheduler>
13
+ <class>Lanot_Scheduler_Helper</class>
14
+ </lanot_scheduler>
15
+ </helpers>
16
+
17
+ <blocks>
18
+ <lanot_scheduler>
19
+ <class>Lanot_Scheduler_Block</class>
20
+ </lanot_scheduler>
21
+ </blocks>
22
+
23
+ <models>
24
+ <lanot_scheduler>
25
+ <class>Lanot_Scheduler_Model</class>
26
+ <resourceModel>lanot_scheduler_resource</resourceModel>
27
+ </lanot_scheduler>
28
+ <lanot_scheduler_resource>
29
+ <class>Lanot_Scheduler_Model_Mysql4</class>
30
+ <entities>
31
+ <job><table>lanot_scheduler_job</table></job>
32
+ <type><table>lanot_scheduler_job_type</table></type>
33
+ </entities>
34
+ </lanot_scheduler_resource>
35
+ </models>
36
+
37
+ <resources>
38
+ <lanot_scheduler_setup>
39
+ <setup>
40
+ <module>Lanot_Scheduler</module>
41
+ </setup>
42
+ </lanot_scheduler_setup>
43
+ </resources>
44
+ </global>
45
+
46
+ <adminhtml>
47
+ <layout>
48
+ <updates>
49
+ <lanot_scheduler>
50
+ <file>lanot_scheduler.xml</file>
51
+ </lanot_scheduler>
52
+ </updates>
53
+ </layout>
54
+
55
+ <events>
56
+ <systemjob_lanot_grid_prepare_collection>
57
+ <observers>
58
+ <lanot_scheduler>
59
+ <class>lanot_scheduler/observer</class>
60
+ <method>prepareSystemJobsCollection</method>
61
+ </lanot_scheduler>
62
+ </observers>
63
+ </systemjob_lanot_grid_prepare_collection>
64
+ </events>
65
+
66
+ <!-- translations -->
67
+ <translate>
68
+ <modules>
69
+ <Lanot_Scheduler>
70
+ <files>
71
+ <default>Lanot_Scheduler.csv</default>
72
+ </files>
73
+ </Lanot_Scheduler>
74
+ </modules>
75
+ </translate>
76
+ <!-- translations -->
77
+ </adminhtml>
78
+
79
+ <admin>
80
+ <routers>
81
+ <lanot_scheduler>
82
+ <use>admin</use>
83
+ <args>
84
+ <module>Lanot_Scheduler</module>
85
+ <frontName>lanot_scheduler</frontName>
86
+ </args>
87
+ </lanot_scheduler>
88
+ </routers>
89
+ </admin>
90
+
91
+ <default>
92
+ <lanot_scheduler>
93
+ <settings>
94
+ <enabled_cache_clean>1</enabled_cache_clean>
95
+ <enabled_queue_clean>1</enabled_queue_clean>
96
+ <enabled_queue_generation>1</enabled_queue_generation>
97
+ </settings>
98
+ </lanot_scheduler>
99
+ </default>
100
+ </config>
app/code/community/Lanot/Scheduler/etc/system.xml ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <tabs>
4
+ <lanot translate="label">
5
+ <label>Lanot Extensions</label>
6
+ <sort_order>200</sort_order>
7
+ </lanot>
8
+ </tabs>
9
+ <sections>
10
+ <lanot_scheduler>
11
+ <class>separator-top</class>
12
+ <label>Scheduler</label>
13
+ <tab>lanot</tab>
14
+ <frontend_type>text</frontend_type>
15
+ <sort_order>1000</sort_order>
16
+ <show_in_default>1</show_in_default>
17
+ <show_in_website>1</show_in_website>
18
+ <show_in_store>1</show_in_store>
19
+ <groups>
20
+ <settings translate="label">
21
+ <label>Scheduler Settings</label>
22
+ <frontend_type>text</frontend_type>
23
+ <sort_order>10</sort_order>
24
+ <show_in_default>1</show_in_default>
25
+ <show_in_website>0</show_in_website>
26
+ <show_in_store>0</show_in_store>
27
+ <fields>
28
+ <enabled_cache_clean translate="label comment">
29
+ <label>Enable Automated Cache Cleaning</label>
30
+ <comment>Works when a cron job is added/updated/removed</comment>
31
+ <frontend_type>select</frontend_type>
32
+ <source_model>adminhtml/system_config_source_yesno</source_model>
33
+ <sort_order>10</sort_order>
34
+ <show_in_default>1</show_in_default>
35
+ <show_in_website>0</show_in_website>
36
+ <show_in_store>0</show_in_store>
37
+ </enabled_cache_clean>
38
+ <enabled_queue_clean translate="label comment">
39
+ <label>Enable Automated Queue Cleaning</label>
40
+ <comment>Works when a cron job is added/updated/removed</comment>
41
+ <frontend_type>select</frontend_type>
42
+ <source_model>adminhtml/system_config_source_yesno</source_model>
43
+ <sort_order>10</sort_order>
44
+ <show_in_default>1</show_in_default>
45
+ <show_in_website>0</show_in_website>
46
+ <show_in_store>0</show_in_store>
47
+ </enabled_queue_clean>
48
+ <enabled_queue_generation translate="label comment">
49
+ <label>Enable Automated Queue Pre-generation</label>
50
+ <comment>Works when a cron job is added/updated/removed</comment>
51
+ <frontend_type>select</frontend_type>
52
+ <source_model>adminhtml/system_config_source_yesno</source_model>
53
+ <sort_order>10</sort_order>
54
+ <show_in_default>1</show_in_default>
55
+ <show_in_website>0</show_in_website>
56
+ <show_in_store>0</show_in_store>
57
+ </enabled_queue_generation>
58
+ </fields>
59
+ </settings>
60
+ </groups>
61
+ </lanot_scheduler>
62
+ </sections>
63
+ </config>
app/code/community/Lanot/Scheduler/sql/lanot_scheduler_setup/mysql4-install-1.0.0.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Open Software License (OSL 3.0)
8
+ * that is bundled with this package in the file LICENSE.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/osl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * @category Lanot
16
+ * @package Lanot_Core
17
+ * @copyright Copyright (c) 2012 Lanot
18
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
19
+ */
20
+
21
+ /* @var $installer Mage_Core_Model_Resource_Setup */
22
+ $installer = $this;
23
+ $installer->startSetup();
24
+
25
+ //tables definition
26
+ $jobTable = $this->getTable('lanot_scheduler/job');
27
+
28
+ //create table for jobs
29
+ $this->run("
30
+ DROP TABLE IF EXISTS `{$jobTable}`;
31
+ CREATE TABLE `{$jobTable}` (
32
+ `job_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Cron Job ID',
33
+ `model` varchar(255) DEFAULT NULL,
34
+ `title` varchar(255) DEFAULT NULL,
35
+ `min` varchar(255) DEFAULT NULL,
36
+ `hour` varchar(255) DEFAULT NULL,
37
+ `day_of_month` varchar(255) DEFAULT NULL,
38
+ `month` varchar(255) DEFAULT NULL,
39
+ `day_of_week` varchar(255) DEFAULT NULL,
40
+
41
+ `created_at` timestamp NULL DEFAULT NULL COMMENT 'Creation Time',
42
+ `updated_at` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT 'Update Time',
43
+
44
+ PRIMARY KEY (`job_id`)
45
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Cron Job Table';
46
+ ");
47
+
48
+ $installer->endSetup();
app/design/adminhtml/default/default/layout/lanot_scheduler.xml ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento backend layout
5
+ *
6
+ * @author Lanot
7
+ */
8
+ -->
9
+ <layout>
10
+ <lanot_scheduler_adminhtml_job_index>
11
+ <reference name="content">
12
+ <block type="lanot_scheduler/adminhtml_job" name="lanot_scheduler_job" />
13
+ </reference>
14
+ </lanot_scheduler_adminhtml_job_index>
15
+
16
+ <lanot_scheduler_adminhtml_job_grid>
17
+ <block type="lanot_scheduler/adminhtml_job_grid" name="root"/>
18
+ </lanot_scheduler_adminhtml_job_grid>
19
+
20
+ <lanot_scheduler_adminhtml_systemjob_index>
21
+ <reference name="content">
22
+ <block type="lanot_scheduler/adminhtml_systemjob" name="lanot_scheduler_systemjob" />
23
+ </reference>
24
+ </lanot_scheduler_adminhtml_systemjob_index>
25
+
26
+ <lanot_scheduler_adminhtml_systemjob_grid>
27
+ <block type="lanot_scheduler/adminhtml_systemjob_grid" name="root"/>
28
+ </lanot_scheduler_adminhtml_systemjob_grid>
29
+
30
+ <!-- CRON JOB EDIT PAGE -->
31
+ <lanot_scheduler_adminhtml_job_edit>
32
+ <update handle="lanot_lightbox"/>
33
+ <reference name="content">
34
+ <block type="lanot_scheduler/adminhtml_job_edit" name="lanot_scheduler_job_edit" />
35
+ </reference>
36
+ <reference name="left">
37
+ <block type="lanot_scheduler/adminhtml_job_edit_tabs" name="job_edit_tabs">
38
+ <action method="addTab">
39
+ <name>job_main_info</name>
40
+ <block>lanot_scheduler/adminhtml_job_edit_tab_main</block>
41
+ </action>
42
+ </block>
43
+ </reference>
44
+ </lanot_scheduler_adminhtml_job_edit>
45
+ <!-- /CRON JOB EDIT PAGE -->
46
+
47
+ <lanot_scheduler_adminhtml_queue_index>
48
+ <reference name="content">
49
+ <block type="lanot_scheduler/adminhtml_queue" name="lanot_scheduler_queue" />
50
+ </reference>
51
+ </lanot_scheduler_adminhtml_queue_index>
52
+
53
+ <lanot_scheduler_adminhtml_queue_grid>
54
+ <block type="lanot_scheduler/adminhtml_queue_grid" name="root"/>
55
+ </lanot_scheduler_adminhtml_queue_grid>
56
+
57
+ <lanot_scheduler_adminhtml_queue_view>
58
+ <reference name="content">
59
+ <block type="lanot_scheduler/adminhtml_queue_view" name="job_edit_main"/>
60
+ </reference>
61
+ </lanot_scheduler_adminhtml_queue_view>
62
+ </layout>
app/design/adminhtml/default/default/template/lanot/scheduler/widget/form/renderer/fieldset.phtml ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package default_default
23
+ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php $_element = $this->getElement() ?>
28
+ <?php if ($_element->getFieldsetContainerId()): ?>
29
+ <div id="<?php echo $_element->getFieldsetContainerId(); ?>">
30
+ <?php endif; ?>
31
+ <?php if ($_element->getLegend()): ?>
32
+ <div class="entry-edit-head">
33
+ <h4 class="icon-head head-edit-form fieldset-legend"><?php echo $_element->getLegend() ?></h4>
34
+ <div class="form-buttons"><?php echo $_element->getHeaderBar() ?></div>
35
+ </div>
36
+ <?php endif; ?>
37
+ <?php if (!$_element->getNoContainer()): ?>
38
+ <div class="fieldset <?php echo $_element->getClass() ?>" id="<?php echo $_element->getHtmlId() ?>">
39
+ <?php endif; ?>
40
+ <div class="hor-scroll">
41
+ <?php if ($_element->getComment()): ?>
42
+ <p class="comment"><?php echo $this->escapeHtml($_element->getComment()) ?></p>
43
+ <?php endif; ?>
44
+ <?php if ($_element->hasHtmlContent()): ?>
45
+ <?php echo $_element->getHtmlContent(); ?>
46
+ <?php else: ?>
47
+ <table cellspacing="10" class="<?php echo $_element->hasTableClass() ? $_element->getTableClass() : 'form-list'?>">
48
+ <tbody>
49
+ <tr>
50
+ <?php echo $_element->getChildrenHtml(); ?>
51
+ </tr>
52
+ </tbody>
53
+ </table>
54
+ <?php endif; ?>
55
+ <?php if ($_element->getAfterElementHtml()): ?>
56
+ <?php echo $_element->getAfterElementHtml(); ?>
57
+ <?php endif; ?>
58
+ </div>
59
+ <?php echo $_element->getSubFieldsetHtml() ?>
60
+ <?php if (!$_element->getNoContainer()): ?>
61
+ </div>
62
+ <?php endif; ?>
63
+ <?php if ($_element->getFieldsetContainerId()): ?>
64
+ </div>
65
+ <?php endif; ?>
app/design/adminhtml/default/default/template/lanot/scheduler/widget/form/renderer/fieldset/element.phtml ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Magento
4
+ *
5
+ * NOTICE OF LICENSE
6
+ *
7
+ * This source file is subject to the Academic Free License (AFL 3.0)
8
+ * that is bundled with this package in the file LICENSE_AFL.txt.
9
+ * It is also available through the world-wide-web at this URL:
10
+ * http://opensource.org/licenses/afl-3.0.php
11
+ * If you did not receive a copy of the license and are unable to
12
+ * obtain it through the world-wide-web, please send an email
13
+ * to license@magentocommerce.com so we can send you a copy immediately.
14
+ *
15
+ * DISCLAIMER
16
+ *
17
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
18
+ * versions in the future. If you wish to customize Magento for your
19
+ * needs please refer to http://www.magentocommerce.com for more information.
20
+ *
21
+ * @category design
22
+ * @package default_default
23
+ * @copyright Copyright (c) 2011 Magento Inc. (http://www.magentocommerce.com)
24
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
25
+ */
26
+ ?>
27
+ <?php
28
+ $_element = $this->getElement();
29
+ $_note = $_element->getNote();
30
+ $_trId = $_element->getHtmlContainerId();
31
+ $_class = $_element->getFieldsetHtmlClass();
32
+ ?>
33
+ <?php if (!$_element->getNoDisplay()): ?>
34
+ <?php if ($_element->getType()=='hidden'): ?>
35
+ <td class="hidden" <?php if($_trId): ?> id="<?php echo $_trId ?>"<?php endif; ?>><?php echo trim($_element->getElementHtml()) ?></td>
36
+ <?php else: ?>
37
+ <td class="<?php echo $_element->hasValueClass() ? $_element->getValueClass() : 'value' ?><?php echo $_class ? " {$_class}-value" : ''?>" id="<?php echo $_trId ?>">
38
+ <div class="label<?php echo $_class ? " {$_class}-label" : ''?>"><?php echo trim($_element->getLabelHtml()) ?></div>
39
+ <?php echo trim($_element->getElementHtml()) ?>
40
+ <?php if ($_note): ?>
41
+ <p class="note<?php echo $_class ? " {$_class}-note" : ''?>" id="note_<?php echo $_element->getId()?>"><span><?php echo $_note ?></span></p>
42
+ <?php endif ?>
43
+ </td>
44
+ <?php endif; ?>
45
+ <?php endif; ?>
app/etc/modules/Lanot_Core.xml ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Lanot_Core>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <depends>
8
+ <Mage_Adminhtml />
9
+ </depends>
10
+ </Lanot_Core>
11
+ </modules>
12
+ </config>
app/etc/modules/Lanot_Scheduler.xml ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Lanot_Scheduler>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ <depends>
8
+ <Mage_Cron />
9
+ <Mage_Adminhtml />
10
+ </depends>
11
+ </Lanot_Scheduler>
12
+ </modules>
13
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Lanot_Scheduler</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>OSL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Allows to manage custom cron jobs</summary>
10
+ <description>Allows to manage custom cron jobs</description>
11
+ <notes>The first release with necessary features</notes>
12
+ <authors><author><name>Lanot</name><user>Lanot</user><email>lanot.biz@gmail.com</email></author></authors>
13
+ <date>2014-06-15</date>
14
+ <time>16:07:13</time>
15
+ <contents><target name="mageetc"><dir name="modules"><file name="Lanot_Scheduler.xml" hash="f32431a4b4fe9dcbbc5cdbbb3f2d9522"/><file name="Lanot_Core.xml" hash="5cbd19e87f40b23df5b1cae5c7ac1078"/></dir></target><target name="magecommunity"><dir name="Lanot"><dir name="Scheduler"><dir name="Block"><dir name="Adminhtml"><dir name="Job"><dir name="Edit"><file name="Form.php" hash="21ce80a7ffbb6025746de2160d6212d1"/><dir name="Tab"><file name="Main.php" hash="bb39a3b4837bb52c4964c833997cfbac"/></dir><file name="Tabs.php" hash="3520d19fe1388ec65f981b7781d33937"/></dir><file name="Edit.php" hash="06885174b6b6fa98f4c90ab25dfe80a1"/><file name="Grid.php" hash="dbe861fa9c0e7592bce47d4f50f0aa69"/></dir><file name="Job.php" hash="e4811f5faac5f897f4fd0c2834f32d3b"/><dir name="Queue"><file name="Grid.php" hash="793d2c4f6e5a31554d6d3433db09183e"/><file name="View.php" hash="ceece8da3e0d169079ac5e703a86a295"/></dir><file name="Queue.php" hash="c8d550a94fc6b6b867ea6f1c6d0d318c"/><dir name="Systemjob"><file name="Grid.php" hash="addacfc18084b0c817d29887b005f34e"/></dir><file name="Systemjob.php" hash="75a4f0f212397bcb7fd12a93165bc379"/></dir></dir><dir name="Helper"><file name="Admin.php" hash="7a09531aaceffe8ae56db97c03744c1f"/><file name="Data.php" hash="1a640e19537877b742d65dcfb46df497"/></dir><dir name="Model"><file name="Job.php" hash="aae2070ef18e36c45efdf4677fd46c33"/><dir name="Mysql4"><dir name="Job"><file name="Collection.php" hash="607ed2af1e32b348f949730801044d9e"/></dir><file name="Job.php" hash="3e6f0cb87fdce3b8504e810fc7392ebc"/></dir><file name="Observer.php" hash="dbe7bbfb9e70521c09be68346bd8e666"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="JobController.php" hash="ed91bca983eb5056dc0eccdc128fb3db"/><file name="QueueController.php" hash="0bfb7356a333b10a27f2fa8dd5ce28b1"/><file name="SystemjobController.php" hash="e5cc46a4056e447ce411660ca0f946ff"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="f3040dbb07e6b56fa7628ac7a8faffa9"/><file name="config.xml" hash="53708598a42acd57e42f9e31bce07f19"/><file name="system.xml" hash="30d26eea6886ac55ffc5c8b3cbe0e8ec"/></dir><dir name="sql"><dir name="lanot_scheduler_setup"><file name="mysql4-install-1.0.0.php" hash="6788859132df251d3ed70bf5fa384761"/></dir></dir></dir><dir name="Core"><dir name="Block"><dir name="Adminhtml"><dir name="Grid"><file name="Abstract.php" hash="7435e7fb99be238abc5a92a2fb2b031a"/></dir><dir name="System"><dir name="Config"><dir name="Form"><file name="Field.php" hash="0103ddfc1ac7f6a6c10b62b650e8e561"/></dir></dir><file name="Extension.php" hash="9412b06c2b993cd0e6f15df8177d01bb"/></dir></dir></dir><dir name="Controller"><dir name="Adminhtml"><file name="AbstractController.php" hash="166d2b371c96f96902b82a67d43f330b"/></dir></dir><dir name="Helper"><file name="Data.php" hash="c8b87c7644ccc315fdb2274b4052a1ae"/></dir><dir name="Model"><file name="Extension.php" hash="496f44598e8e84393f2d03b1d48021c9"/><dir name="Item"><file name="Interface.php" hash="990948919c42cd88c317fdadcd45e895"/></dir></dir><dir name="controllers"><dir name="System"><file name="ConfigController.php" hash="20e3f72ab3517174f2386d49933f9e6c"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="4f7e7da0b613580e9e7159c9cb5bd75d"/><file name="config.xml" hash="7f4b65a7be6b882385b6a03b393496ea"/><file name="system.xml" hash="76460a51c3ae79917ade87c38c0c765a"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="lanot_scheduler.xml" hash="b317ca0d55118811a06e854ce6222518"/></dir><dir name="template"><dir name="lanot"><dir name="scheduler"><dir name="widget"><dir name="form"><dir name="renderer"><dir name="fieldset"><file name="element.phtml" hash="fdde4030298ad019151b682daf9b8ec4"/></dir><file name="fieldset.phtml" hash="d72e901c66049419ed808025a242c623"/></dir></dir></dir></dir></dir></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>