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