Merge pull request #18069 from civicrm/5.28
[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
18 require_once '../civicrm.config.php';
19
20 require_once 'CRM/Core/Config.php';
21 require_once 'CRM/Core/Error.php';
22 require_once 'CRM/Core/I18n.php';
23
24 require_once 'CRM/Mailing/BAO/Mailing.php';
25 require_once 'CRM/Mailing/BAO/Job.php';
26 require_once 'CRM/Mailing/DAO/Group.php';
27
28 $config = CRM_Core_Config::singleton();
29
30 $tables = array(
31 'civicrm_mailing_event_delivered',
32 'civicrm_mailing_event_queue',
33 'civicrm_mailing_job',
34 'civicrm_mailing_group',
35 'civicrm_mailing',
36 );
37 foreach ($tables as $t) {
38 $query = "DELETE FROM $t";
39 CRM_Core_DAO::executeQuery($query);
40 }
41
42 $prefix = 'Automated Mailing Gen: ';
43 $numGroups = 153;
44
45 $status = array('Scheduled', 'Running', 'Complete', 'Paused', 'Canceled', 'Testing');
46
47 for ($i = 1; $i <= $numGroups; $i++) {
48 $mailing = new CRM_Mailing_BAO_Mailing();
49
50 $alphabet = mt_rand(97, 122);
51
52 $cnt = sprintf('%05d', $i);
53 $mailing->name = chr($alphabet) . ": $prefix $cnt";
54 $mailing->header_id = $mailing->footer_id = $mailing->reply_id = $mailing->unsubscribe_id = $mailing->optout_id = 1;
55 $mailing->is_completed = 1;
56 $mailing->save();
57
58 $job = new CRM_Mailing_BAO_MailingJob();
59 $job->mailing_id = $mailing->id;
60 $job->scheduled_date = generateRandomDate();
61 $job->start_date = generateRandomDate();
62 $job->end_date = generateRandomDate();
63 $job->status = 'Complete';
64 $job->save();
65
66 $group = new CRM_Mailing_DAO_MailingGroup();
67 $group->mailing_id = $mailing->id;
68 $group->group_type = 'Include';
69 $group->entity_table = 'civicrm_group';
70 $group->entity_id = 1;
71 $group->save();
72 }
73
74 /**
75 * @return string
76 */
77 function generateRandomDate() {
78 $year = 2006 + mt_rand(0, 2);
79 $month = 1 + mt_rand(0, 11);
80 $day = 1 + mt_rand(0, 27);
81
82 $date = sprintf("%4d%02d%02d", $year, $month, $day) . '000000';
83 return $date;
84
85 }