Disable recipient estimation on mailings
[civicrm-core.git] / sql / GenerateMailing.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17 if (!(php_sapi_name() == 'cli' || (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0))) {
18 header("HTTP/1.0 404 Not Found");
19
20 return;
21 }
22
23 require_once '../civicrm.config.php';
24
25 require_once 'CRM/Core/Config.php';
26 require_once 'CRM/Core/Error.php';
27 require_once 'CRM/Core/I18n.php';
28
29 require_once 'CRM/Mailing/BAO/Mailing.php';
30 require_once 'CRM/Mailing/BAO/Job.php';
31 require_once 'CRM/Mailing/DAO/Group.php';
32
33 $config = CRM_Core_Config::singleton();
34
35 $tables = array(
36 'civicrm_mailing_event_delivered',
37 'civicrm_mailing_event_queue',
38 'civicrm_mailing_job',
39 'civicrm_mailing_group',
40 'civicrm_mailing',
41 );
42 foreach ($tables as $t) {
43 $query = "DELETE FROM $t";
44 CRM_Core_DAO::executeQuery($query);
45 }
46
47 $prefix = 'Automated Mailing Gen: ';
48 $numGroups = 153;
49
50 $status = array('Scheduled', 'Running', 'Complete', 'Paused', 'Canceled', 'Testing');
51
52 for ($i = 1; $i <= $numGroups; $i++) {
53 $mailing = new CRM_Mailing_BAO_Mailing();
54
55 $alphabet = mt_rand(97, 122);
56
57 $cnt = sprintf('%05d', $i);
58 $mailing->name = chr($alphabet) . ": $prefix $cnt";
59 $mailing->header_id = $mailing->footer_id = $mailing->reply_id = $mailing->unsubscribe_id = $mailing->optout_id = 1;
60 $mailing->is_completed = 1;
61 $mailing->save();
62
63 $job = new CRM_Mailing_BAO_MailingJob();
64 $job->mailing_id = $mailing->id;
65 $job->scheduled_date = generateRandomDate();
66 $job->start_date = generateRandomDate();
67 $job->end_date = generateRandomDate();
68 $job->status = 'Complete';
69 $job->save();
70
71 $group = new CRM_Mailing_DAO_MailingGroup();
72 $group->mailing_id = $mailing->id;
73 $group->group_type = 'Include';
74 $group->entity_table = 'civicrm_group';
75 $group->entity_id = 1;
76 $group->save();
77 }
78
79 /**
80 * @return string
81 */
82 function generateRandomDate() {
83 $year = 2006 + mt_rand(0, 2);
84 $month = 1 + mt_rand(0, 11);
85 $day = 1 + mt_rand(0, 27);
86
87 $date = sprintf("%4d%02d%02d", $year, $month, $day) . '000000';
88 return $date;
89
90 }