-
Notifications
You must be signed in to change notification settings - Fork 3
/
simplenews.drush.inc
91 lines (77 loc) · 2.56 KB
/
simplenews.drush.inc
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
90
91
<?php
/**
* @file
*
* Drush commands for administer Simplenews.
*/
/**
* Implements hook_drush_command().
*/
function simplenews_drush_command() {
$items = array();
$items['simplenews-spool-count'] = array(
'description' => 'Print the current simplenews mail spool count',
'aliases' => array('sn-sc'),
'backdrop dependencies' => array('simplenews'),
'options' => array(
'pipe' => dt('Just print the count value to allow parsing'),
),
);
$items['simplenews-spool-send'] = array(
'description' => 'Send the defined amount of mail spool entries.',
'examples' => array(
'drush sn-ss' => dt('Send the default amount of mails, as defined by the simplenews_throttle variable.'),
'drush sn-ss 0' => dt('Send all mails.'),
'drush sn-ss 100' => dt('Send 100 mails'),
),
'options' => array(
'pipe' => dt('Just print the sent and remaining count on separate lines to allow parsing'),
),
'aliases' => array('sn-ss'),
'backdrop dependencies' => array('simplenews'),
);
return $items;
}
/**
* Drush command to count the mail spool queue.
*/
function drush_simplenews_spool_count() {
module_load_include('inc', 'simplenews', 'includes/simplenews.mail');
$count = simplenews_count_spool();
$no_description = drush_get_option(array('p', 'pipe'));
if ($no_description) {
drush_print_pipe($count);
}
else {
drush_log(dt('Current simplenews mail spool count: @count', array('@count' => $count)), 'status');
}
}
/**
* Drush command to send the mail spool queue.
*/
function drush_simplenews_spool_send($limit = FALSE) {
module_load_include('inc', 'simplenews', 'includes/simplenews.mail');
if ($limit === FALSE) {
$limit = config_get('simplenews.settings', 'simplenews_throttle');
}
elseif ($limit == 0) {
$limit = SIMPLENEWS_UNLIMITED;
}
$start_time = microtime(TRUE);
$sent = simplenews_mail_spool($limit);
simplenews_clear_spool();
simplenews_send_status_update();
$durance = round(microtime(TRUE) - $start_time, 2);
// Report the number of sent mails.
if ($sent > 0) {
$remaining = simplenews_count_spool();
if (drush_get_option(array('p', 'pipe'))) {
// For pipe, print the sent first and then the remaining count, separated by a space.
drush_print_pipe($sent . " " . $remaining);
}
else {
drush_log(dt('Sent @count mails from the queue in @sec seconds.', array('@count' => $sent, '@sec' => $durance)), 'status');
drush_log(dt('Remaining simplenews mail spool count: @count', array('@count' => $remaining)), 'status');
}
}
}