Merge pull request #18315 from eileenmcnaughton/ordergo
[civicrm-core.git] / sql / GenerateGroups.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
6b7eb9df 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
6b7eb9df
TO
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 |
6a488035 9 +--------------------------------------------------------------------+
d631cdc8 10 */
6a488035
TO
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
18require_once '../civicrm.config.php';
19
20require_once 'CRM/Core/Config.php';
21require_once 'CRM/Core/Error.php';
22require_once 'CRM/Core/I18n.php';
23
24require_once 'CRM/Contact/BAO/Group.php';
25
26$config = CRM_Core_Config::singleton();
27
28$prefix = 'Automated Generated Group: ';
29$query = "DELETE FROM civicrm_group where name like '%{$prefix}%'";
33621c4f 30CRM_Core_DAO::executeQuery($query);
6a488035
TO
31
32$numGroups = 100;
33
34$visibility = array('User and User Admin Only', 'Public Pages');
35$groupType = array(NULL, '\ 11\ 1', '\ 12\ 1', '\ 11\ 12\ 1');
36
37for ($i = 1; $i <= $numGroups; $i++) {
38 $group = new CRM_Contact_BAO_Group();
39 $cnt = sprintf('%05d', $i);
40 $alphabet = mt_rand(97, 122);
41 $group->name = $group->title = chr($alphabet) . ": $prefix $cnt";
42 $group->is_active = 1;
43
44 $v = mt_rand(0, 1);
45 $group->visibility = $visibility[$v];
46
47 $t = mt_rand(0, 3);
48 $group->group_type = $groupType[$t];
49
50 $group->save();
d631cdc8 51
6a488035 52}