Merge pull request #3846 from totten/master-phpunit-indiv-restore
[civicrm-core.git] / sql / GenerateMailing.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
f5721b07 4 | CiviCRM version 4.5 |
6a488035 5 +--------------------------------------------------------------------+
f5721b07 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 * @package CRM
f5721b07 31 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
32 * $Id$
33 *
34 */
35
36require_once '../civicrm.config.php';
37
38require_once 'CRM/Core/Config.php';
39require_once 'CRM/Core/Error.php';
40require_once 'CRM/Core/I18n.php';
41
42require_once 'CRM/Mailing/BAO/Mailing.php';
43require_once 'CRM/Mailing/BAO/Job.php';
44require_once 'CRM/Mailing/DAO/Group.php';
45
46$config = CRM_Core_Config::singleton();
47
48$tables = array(
49 'civicrm_mailing_event_delivered',
50 'civicrm_mailing_event_queue',
51 'civicrm_mailing_job',
52 'civicrm_mailing_group',
53 'civicrm_mailing',
54);
55foreach ($tables as $t) {
56 $query = "DELETE FROM $t";
57 CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
58}
59
60$prefix = 'Automated Mailing Gen: ';
61$numGroups = 153;
62
63$status = array('Scheduled', 'Running', 'Complete', 'Paused', 'Canceled', 'Testing');
64
65for ($i = 1; $i <= $numGroups; $i++) {
66 $mailing = new CRM_Mailing_BAO_Mailing();
67
68 $alphabet = mt_rand(97, 122);
69
70 $cnt = sprintf('%05d', $i);
71 $mailing->name = chr($alphabet) . ": $prefix $cnt";
72 $mailing->header_id = $mailing->footer_id = $mailing->reply_id = $mailing->unsubscribe_id = $mailing->optout_id = 1;
73 $mailing->is_completed = 1;
74 $mailing->save();
75
9da8dc8c 76 $job = new CRM_Mailing_BAO_MailingJob();
6a488035
TO
77 $job->mailing_id = $mailing->id;
78 $job->scheduled_date = generateRandomDate();
79 $job->start_date = generateRandomDate();
80 $job->end_date = generateRandomDate();
81 $job->status = 'Complete';
82 $job->save();
83
04124b30 84 $group = new CRM_Mailing_DAO_MailingGroup();
6a488035
TO
85 $group->mailing_id = $mailing->id;
86 $group->group_type = 'Include';
87 $group->entity_table = 'civicrm_group';
88 $group->entity_id = 1;
89 $group->save();
90}
91
627456b5
EM
92/**
93 * @return string
94 */
6a488035
TO
95function generateRandomDate() {
96 $year = 2006 + mt_rand(0, 2);
97 $month = 1 + mt_rand(0, 11);
98 $day = 1 + mt_rand(0, 27);
99
100 $date = sprintf("%4d%02d%02d", $year, $month, $day) . '000000';
101 return $date;
102}
103