| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.5 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
| 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 |
| 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
| 32 | * $Id$ |
| 33 | * |
| 34 | */ |
| 35 | |
| 36 | require_once '../civicrm.config.php'; |
| 37 | |
| 38 | require_once 'CRM/Core/Config.php'; |
| 39 | require_once 'CRM/Core/Error.php'; |
| 40 | require_once 'CRM/Core/I18n.php'; |
| 41 | |
| 42 | require_once 'CRM/Mailing/BAO/Mailing.php'; |
| 43 | require_once 'CRM/Mailing/BAO/Job.php'; |
| 44 | require_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 | ); |
| 55 | foreach ($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 | |
| 65 | for ($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 | |
| 76 | $job = new CRM_Mailing_BAO_MailingJob(); |
| 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 | |
| 84 | $group = new CRM_Mailing_DAO_MailingGroup(); |
| 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 | |
| 92 | function generateRandomDate() { |
| 93 | $year = 2006 + mt_rand(0, 2); |
| 94 | $month = 1 + mt_rand(0, 11); |
| 95 | $day = 1 + mt_rand(0, 27); |
| 96 | |
| 97 | $date = sprintf("%4d%02d%02d", $year, $month, $day) . '000000'; |
| 98 | return $date; |
| 99 | } |
| 100 | |