Merge pull request #14227 from civicrm/5.14
[civicrm-core.git] / tools / scripts / civimail-spooler / civimail-spooler.php
1 <?php
2 $options = getopt('bc:ht:');
3 if (isset($options['h'])) {
4 print ("\nUsage: php civimail-spooler.php [-bh] [-c <config>] [-t <period>]\n");
5 print (" -b Run this process continuously\n");
6 print (" -c Path to CiviCRM civicrm.settings.php\n");
7 print (" -h Print this help message\n");
8 print (" -t In continuous mode, the period (in seconds) to wait between queue events\n\n");
9 exit();
10 }
11
12 if (isset($options['c'])) {
13 $config_file = $options['c'];
14 }
15
16 eval('
17 require_once "$config_file";
18 require_once "CRM/Core/Config.php";
19 ');
20
21 $config = CRM_Core_Config::singleton();
22
23 /* Temporary permissioning hack for now */
24
25
26 CRM_Utils_System_Soap::swapUF();
27
28 if (isset($options['t']) && is_int($options['t']) && $options['t'] > 0) {
29 $config->mailerPeriod = $options['t'];
30 }
31
32 if (isset($options['b'])) {
33 while (TRUE) {
34 /* TODO: put some syslog calls in here. Also, we may want to fork the
35 * process into the background and provide init.d scripts */
36
37
38 CRM_Mailing_BAO_MailingJob::runJobs();
39 sleep($config->mailerPeriod);
40 }
41 }
42 else {
43 CRM_Mailing_BAO_MailingJob::runJobs();
44 }
45