-
Notifications
You must be signed in to change notification settings - Fork 4
/
commerce_order_cleanup.module
89 lines (80 loc) · 2.17 KB
/
commerce_order_cleanup.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* @file
* Contains commerce order cleanup implementation.
*/
/**
* Implements hook_menu()
*/
function commerce_order_cleanup_menu() {
$items = array();
$items['admin/commerce/config/order-cleanup'] = array(
'title' => 'Commerce order cleanup',
'description' => 'Configure order cleanup.',
'page callback' => 'drupal_get_form',
'page arguments' => array('commerce_order_cleanup_settings'),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM,
'weight' => 30,
'file' => 'commerce_order_cleanup.admin.inc',
);
return $items;
}
/**
* Providers available order status.
*
* @param string $type
* A string of type. Allowed value is status for now.
*
* @return array
*/
function _commerce_order_cleanup_get_options($type) {
switch ($type) {
case 'status':
if (empty($status_list)) {
$result = db_query("SELECT status FROM {commerce_order} GROUP BY status");
foreach ($result as $row) {
$status_list[] = array($row->status);
}
if (!empty($status_list)) {
array_unshift($status_list, array('Available status'));
}
}
return $status_list;
}
}
/**
* Helper to calculate changed timestamp.
*
* @param int|string $changed
* A integer timestamp or date string.
*
* @return int|null
* timestamp if valid, NULL otherwise.
*/
function _commerce_order_cleanup_calculate_changed($changed) {
if (is_int($changed) && _commerce_order_cleanup_is_valid_date($changed)) {
return $changed;
}
elseif (is_string($changed) && _commerce_order_cleanup_is_valid_date(strtotime($changed))) {
return strtotime($changed);
}
return NULL;
}
/**
* Validates given date range is valid.
*
* @param $timestamp
*
* @return bool
*/
function _commerce_order_cleanup_is_valid_date($timestamp) {
// if it is timestamp, make sure it is in a range.
// Start of commerce module in drupal.org
$start_date = strtotime('October 15, 2009 9:41pm');
$end_date = strtotime('-' . variable_get('commerce_order_cleanup_max_date', '1 year'));
if ($timestamp < $start_date || $timestamp > $end_date) {
return FALSE;
}
return TRUE;
}