GenerateMailing.php 2.39 KB
Newer Older
totten's avatar
totten committed
1 2 3
<?php
/*
 +--------------------------------------------------------------------+
4
 | Copyright CiviCRM LLC. All rights reserved.                        |
totten's avatar
totten committed
5
 |                                                                    |
6 7 8
 | This work is published under the GNU AGPLv3 license with some      |
 | permitted exceptions and without any warranty. For full license    |
 | and copyright information, see https://civicrm.org/licensing       |
totten's avatar
totten committed
9
 +--------------------------------------------------------------------+
yashodha's avatar
yashodha committed
10
 */
totten's avatar
totten committed
11 12 13 14

/**
 *
 * @package CRM
15
 * @copyright CiviCRM LLC https://civicrm.org/licensing
totten's avatar
totten committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
 */

require_once '../civicrm.config.php';

require_once 'CRM/Core/Config.php';
require_once 'CRM/Core/Error.php';
require_once 'CRM/Core/I18n.php';

require_once 'CRM/Mailing/BAO/Mailing.php';
require_once 'CRM/Mailing/BAO/Job.php';
require_once 'CRM/Mailing/DAO/Group.php';

$config = CRM_Core_Config::singleton();

$tables = array(
  'civicrm_mailing_event_delivered',
  'civicrm_mailing_event_queue',
  'civicrm_mailing_job',
  'civicrm_mailing_group',
  'civicrm_mailing',
);
foreach ($tables as $t) {
  $query = "DELETE FROM $t";
eileen's avatar
eileen committed
39
  CRM_Core_DAO::executeQuery($query);
totten's avatar
totten committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
}

$prefix = 'Automated Mailing Gen: ';
$numGroups = 153;

$status = array('Scheduled', 'Running', 'Complete', 'Paused', 'Canceled', 'Testing');

for ($i = 1; $i <= $numGroups; $i++) {
  $mailing = new CRM_Mailing_BAO_Mailing();

  $alphabet = mt_rand(97, 122);

  $cnt = sprintf('%05d', $i);
  $mailing->name = chr($alphabet) . ": $prefix $cnt";
  $mailing->header_id = $mailing->footer_id = $mailing->reply_id = $mailing->unsubscribe_id = $mailing->optout_id = 1;
  $mailing->is_completed = 1;
  $mailing->save();

58
  $job                 = new CRM_Mailing_BAO_MailingJob();
totten's avatar
totten committed
59 60 61 62 63 64 65
  $job->mailing_id     = $mailing->id;
  $job->scheduled_date = generateRandomDate();
  $job->start_date     = generateRandomDate();
  $job->end_date       = generateRandomDate();
  $job->status         = 'Complete';
  $job->save();

66
  $group               = new CRM_Mailing_DAO_MailingGroup();
totten's avatar
totten committed
67 68 69 70 71 72 73
  $group->mailing_id   = $mailing->id;
  $group->group_type   = 'Include';
  $group->entity_table = 'civicrm_group';
  $group->entity_id    = 1;
  $group->save();
}

74 75 76
/**
 * @return string
 */
totten's avatar
totten committed
77 78 79 80 81 82 83
function generateRandomDate() {
  $year  = 2006 + mt_rand(0, 2);
  $month = 1 + mt_rand(0, 11);
  $day   = 1 + mt_rand(0, 27);

  $date = sprintf("%4d%02d%02d", $year, $month, $day) . '000000';
  return $date;
yashodha's avatar
yashodha committed
84

totten's avatar
totten committed
85
}