| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  | #!/usr/bin/env php
 | 
					
						
							|  |  |  | <?php | 
					
						
							|  |  |  | /* | 
					
						
							| 
									
										
										
										
											2009-08-25 18:14:12 -04:00
										 |  |  |  * StatusNet - the distributed open-source microblogging tool | 
					
						
							| 
									
										
										
										
											2009-08-25 18:12:20 -04:00
										 |  |  |  * Copyright (C) 2008, 2009, StatusNet, Inc. | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This program is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU Affero General Public License as published by | 
					
						
							|  |  |  |  * the Free Software Foundation, either version 3 of the License, or | 
					
						
							|  |  |  |  * (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU Affero General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Affero General Public License | 
					
						
							|  |  |  |  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-03 09:46:29 +00:00
										 |  |  | $shortoptions = 'b:g:j:n:t:u:w:x:z:'; | 
					
						
							|  |  |  | $longoptions = array( | 
					
						
							|  |  |  |     'subscriptions=', | 
					
						
							|  |  |  |     'groups=', | 
					
						
							|  |  |  |     'joins=', | 
					
						
							|  |  |  |     'notices=', | 
					
						
							|  |  |  |     'tags=', | 
					
						
							|  |  |  |     'users=', | 
					
						
							|  |  |  |     'words=', | 
					
						
							|  |  |  |     'prefix=', | 
					
						
							| 
									
										
										
										
											2013-06-16 02:18:19 +00:00
										 |  |  |     'groupprefix=', | 
					
						
							|  |  |  |     'faves=' | 
					
						
							| 
									
										
										
										
											2011-08-03 09:46:29 +00:00
										 |  |  | ); | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | $helptext = <<<END_OF_CREATESIM_HELP | 
					
						
							|  |  |  | Creates a lot of test users and notices to (loosely) simulate a real server. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     -b --subscriptions Average subscriptions per user (default no. users/20) | 
					
						
							| 
									
										
										
										
											2011-03-25 17:39:14 -04:00
										 |  |  |     -g --groups        Number of groups (default 20) | 
					
						
							|  |  |  |     -j --joins         Number of groups per user (default 5) | 
					
						
							| 
									
										
										
										
											2013-06-16 02:18:19 +00:00
										 |  |  |     -f --faves         Number of faves per user (default notices/10) | 
					
						
							| 
									
										
										
										
											2011-08-03 09:46:29 +00:00
										 |  |  |     -n --notices       Average notices per user (default 100) | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  |     -t --tags          Number of distinct hash tags (default 10000) | 
					
						
							| 
									
										
										
										
											2011-08-03 09:46:29 +00:00
										 |  |  |     -u --users         Number of users (default 100) | 
					
						
							| 
									
										
										
										
											2011-04-12 14:27:48 -04:00
										 |  |  |     -w --words         Words file (default '/usr/share/dict/words') | 
					
						
							| 
									
										
										
										
											2011-08-03 09:46:29 +00:00
										 |  |  |     -x --prefix        User name prefix (default 'testuser') | 
					
						
							|  |  |  |     -z --groupprefix   Group name prefix (default 'testgroup') | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | END_OF_CREATESIM_HELP; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require_once INSTALLDIR.'/scripts/commandline.inc'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // XXX: make these command-line options
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function newUser($i) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     global $userprefix; | 
					
						
							| 
									
										
										
										
											2010-01-04 22:49:09 -10:00
										 |  |  |     $user = User::register(array('nickname' => sprintf('%s%d', $userprefix, $i), | 
					
						
							|  |  |  |                                  'password' => sprintf('password%d', $i), | 
					
						
							|  |  |  |                                  'fullname' => sprintf('Test User %d', $i))); | 
					
						
							|  |  |  |     if (!empty($user)) { | 
					
						
							|  |  |  |         $user->free(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-26 15:16:04 -04:00
										 |  |  | function newGroup($i, $j) | 
					
						
							| 
									
										
										
										
											2011-03-25 17:39:14 -04:00
										 |  |  | { | 
					
						
							|  |  |  |     global $groupprefix; | 
					
						
							| 
									
										
										
										
											2011-03-26 15:16:04 -04:00
										 |  |  |     global $userprefix; | 
					
						
							| 
									
										
										
										
											2011-03-25 17:39:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-26 15:16:04 -04:00
										 |  |  |     // Pick a random user to be the admin
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $n = rand(0, max($j - 1, 0)); | 
					
						
							| 
									
										
										
										
											2013-08-18 13:04:58 +02:00
										 |  |  |     $user = User::getKV('nickname', sprintf('%s%d', $userprefix, $n)); | 
					
						
							| 
									
										
										
										
											2011-03-26 15:16:04 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $group = User_group::register(array('nickname' => sprintf('%s%d', $groupprefix, $i), | 
					
						
							|  |  |  |                                         'local'    => true, | 
					
						
							|  |  |  |                                         'userid'   => $user->id, | 
					
						
							|  |  |  |                                         'fullname' => sprintf('Test Group %d', $i))); | 
					
						
							| 
									
										
										
										
											2011-03-25 17:39:14 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  | function newNotice($i, $tagmax) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     global $userprefix; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-01 21:50:04 -04:00
										 |  |  |     $options = array('scope' => Notice::defaultScope()); | 
					
						
							| 
									
										
										
										
											2011-03-26 14:58:11 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  |     $n = rand(0, $i - 1); | 
					
						
							| 
									
										
										
										
											2013-08-18 13:04:58 +02:00
										 |  |  |     $user = User::getKV('nickname', sprintf('%s%d', $userprefix, $n)); | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-26 15:36:47 -04:00
										 |  |  |     $is_reply = rand(0, 1); | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-12 14:27:48 -04:00
										 |  |  |     $content = testNoticeContent(); | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if ($is_reply == 0) { | 
					
						
							| 
									
										
										
										
											2014-03-06 03:43:48 +01:00
										 |  |  |         $stream = new InboxNoticeStream($user->getProfile(), $user->getProfile()); | 
					
						
							| 
									
										
										
										
											2011-04-11 12:38:12 -04:00
										 |  |  |         $notices = $stream->getNotices(0, 20); | 
					
						
							| 
									
										
										
										
											2011-03-26 14:58:11 -04:00
										 |  |  |         if ($notices->N > 0) { | 
					
						
							| 
									
										
										
										
											2011-03-26 15:36:47 -04:00
										 |  |  |             $nval = rand(0, $notices->N - 1); | 
					
						
							| 
									
										
										
										
											2011-03-26 14:58:11 -04:00
										 |  |  |             $notices->fetch(); // go to 0th
 | 
					
						
							|  |  |  |             for ($i = 0; $i < $nval; $i++) { | 
					
						
							|  |  |  |                 $notices->fetch(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             $options['reply_to'] = $notices->id; | 
					
						
							| 
									
										
										
										
											2011-03-26 15:36:47 -04:00
										 |  |  |             $dont_use_nickname = rand(0, 2); | 
					
						
							|  |  |  |             if ($dont_use_nickname != 0) { | 
					
						
							|  |  |  |                 $rprofile = $notices->getProfile(); | 
					
						
							|  |  |  |                 $content = "@".$rprofile->nickname." ".$content; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-03-26 16:06:17 -04:00
										 |  |  |             $private_to_addressees = rand(0, 4); | 
					
						
							|  |  |  |             if ($private_to_addressees == 0) { | 
					
						
							|  |  |  |                 $options['scope'] |= Notice::ADDRESSEE_SCOPE; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-03-26 14:58:11 -04:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2013-06-17 20:16:49 -07:00
										 |  |  |     } else { | 
					
						
							|  |  |  |         $is_directed = rand(0, 4); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ($is_directed == 0) { | 
					
						
							| 
									
										
										
										
											2013-09-21 18:26:58 +02:00
										 |  |  |             $subs = $user->getSubscribed(0, 100)->fetchAll(); | 
					
						
							| 
									
										
										
										
											2013-06-17 20:16:49 -07:00
										 |  |  |             if (count($subs) > 0) { | 
					
						
							|  |  |  |                 $seen = array(); | 
					
						
							|  |  |  |                 $f = rand(0, 9); | 
					
						
							|  |  |  |                 if ($f <= 6) { | 
					
						
							|  |  |  |                     $addrs = 1; | 
					
						
							|  |  |  |                 } else if ($f <= 8) { | 
					
						
							|  |  |  |                     $addrs = 2; | 
					
						
							|  |  |  |                 } else { | 
					
						
							|  |  |  |                     $addrs = 3; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 for ($m = 0; $m < $addrs; $m++) { | 
					
						
							|  |  |  |                     $x = rand(0, count($subs) - 1); | 
					
						
							|  |  |  |                     if ($seen[$x]) { | 
					
						
							|  |  |  |                         continue; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     if ($subs[$x]->id == $user->id) { | 
					
						
							|  |  |  |                         continue; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     $seen[$x] = true; | 
					
						
							|  |  |  |                     $rprofile = $subs[$x]; | 
					
						
							|  |  |  |                     $content = "@".$rprofile->nickname." ".$content; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |                 $private_to_addressees = rand(0, 4); | 
					
						
							|  |  |  |                 if ($private_to_addressees == 0) { | 
					
						
							|  |  |  |                     $options['scope'] |= Notice::ADDRESSEE_SCOPE; | 
					
						
							|  |  |  |                 } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $has_hash = rand(0, 2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ($has_hash == 0) { | 
					
						
							|  |  |  |         $hashcount = rand(0, 2); | 
					
						
							|  |  |  |         for ($j = 0; $j < $hashcount; $j++) { | 
					
						
							|  |  |  |             $h = rand(0, $tagmax); | 
					
						
							|  |  |  |             $content .= " #tag{$h}"; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-26 15:08:27 -04:00
										 |  |  |     $in_group = rand(0, 5); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ($in_group == 0) { | 
					
						
							|  |  |  |         $groups = $user->getGroups(); | 
					
						
							| 
									
										
										
										
											2013-10-29 11:27:26 +01:00
										 |  |  |         if ($groups instanceof User_group) { | 
					
						
							| 
									
										
										
										
											2011-06-27 17:29:33 -04:00
										 |  |  |             $gval = rand(0, $groups->N - 1); | 
					
						
							| 
									
										
										
										
											2011-03-26 15:08:27 -04:00
										 |  |  |             $groups->fetch(); // go to 0th
 | 
					
						
							|  |  |  |             for ($i = 0; $i < $gval; $i++) { | 
					
						
							|  |  |  |                 $groups->fetch(); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             $options['groups'] = array($groups->id); | 
					
						
							|  |  |  |             $content = "!".$groups->nickname." ".$content; | 
					
						
							| 
									
										
										
										
											2011-03-26 16:06:17 -04:00
										 |  |  |             $private_to_group = rand(0, 2); | 
					
						
							|  |  |  |             if ($private_to_group == 0) { | 
					
						
							|  |  |  |                 $options['scope'] |= Notice::GROUP_SCOPE; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2011-03-26 15:08:27 -04:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-26 16:06:17 -04:00
										 |  |  |     $private_to_site = rand(0, 4); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ($private_to_site == 0) { | 
					
						
							|  |  |  |         $options['scope'] |= Notice::SITE_SCOPE; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-09-18 12:37:14 -04:00
										 |  |  |     $notice = Notice::saveNew($user->id, $content, 'createsim', $options); | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-17 20:16:49 -07:00
										 |  |  | function newMessage($i) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     global $userprefix; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $n = rand(0, $i - 1); | 
					
						
							| 
									
										
										
										
											2013-08-18 13:04:58 +02:00
										 |  |  |     $user = User::getKV('nickname', sprintf('%s%d', $userprefix, $n)); | 
					
						
							| 
									
										
										
										
											2013-06-17 20:16:49 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $content = testNoticeContent(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $friends = $user->mutuallySubscribedUsers()->fetchAll(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (count($friends) == 0) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $j = rand(0, count($friends) - 1); | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     $other = $friends[$j]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $message = Message::saveNew($user->id, $other->id, $content, 'createsim'); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  | function newSub($i) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     global $userprefix; | 
					
						
							|  |  |  |     $f = rand(0, $i - 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $fromnick = sprintf('%s%d', $userprefix, $f); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-18 13:04:58 +02:00
										 |  |  |     $from = User::getKV('nickname', $fromnick); | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (empty($from)) { | 
					
						
							|  |  |  |         throw new Exception("Can't find user '$fromnick'."); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $t = rand(0, $i - 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ($t == $f) { | 
					
						
							|  |  |  |         $t++; | 
					
						
							|  |  |  |         if ($t > $i - 1) { | 
					
						
							|  |  |  |             $t = 0; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $tunic = sprintf('%s%d', $userprefix, $t); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-18 13:04:58 +02:00
										 |  |  |     $to = User::getKV('nickname', $tunic); | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-19 17:20:44 +02:00
										 |  |  |     if (!($to instanceof User)) { | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  |         throw new Exception("Can't find user '$tunic'."); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-19 17:20:44 +02:00
										 |  |  |     Subscription::start($from->getProfile(), $to->getProfile()); | 
					
						
							| 
									
										
										
										
											2010-01-04 22:49:09 -10:00
										 |  |  | 
 | 
					
						
							|  |  |  |     $from->free(); | 
					
						
							|  |  |  |     $to->free(); | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-25 17:39:14 -04:00
										 |  |  | function newJoin($u, $g) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     global $userprefix; | 
					
						
							|  |  |  |     global $groupprefix; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $userNumber = rand(0, $u - 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $userNick = sprintf('%s%d', $userprefix, $userNumber); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-18 13:04:58 +02:00
										 |  |  |     $user = User::getKV('nickname', $userNick); | 
					
						
							| 
									
										
										
										
											2011-03-25 17:39:14 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (empty($user)) { | 
					
						
							|  |  |  |         throw new Exception("Can't find user '$fromnick'."); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $groupNumber = rand(0, $g - 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $groupNick = sprintf('%s%d', $groupprefix, $groupNumber); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-18 13:04:58 +02:00
										 |  |  |     $group = User_group::getKV('nickname', $groupNick); | 
					
						
							| 
									
										
										
										
											2011-03-25 17:39:14 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (empty($group)) { | 
					
						
							|  |  |  |         throw new Exception("Can't find group '$groupNick'."); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!$user->isMember($group)) { | 
					
						
							|  |  |  |         $user->joinGroup($group); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-16 02:18:19 +00:00
										 |  |  | function newFave($u) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     global $userprefix; | 
					
						
							|  |  |  |     global $groupprefix; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $userNumber = rand(0, $u - 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $userNick = sprintf('%s%d', $userprefix, $userNumber); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-18 13:04:58 +02:00
										 |  |  |     $user = User::getKV('nickname', $userNick); | 
					
						
							| 
									
										
										
										
											2013-06-16 02:18:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (empty($user)) { | 
					
						
							|  |  |  |         throw new Exception("Can't find user '$userNick'."); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // NB: it's OK to like your own stuff!
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $otherNumber = rand(0, $u - 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $otherNick = sprintf('%s%d', $userprefix, $otherNumber); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-18 13:04:58 +02:00
										 |  |  |     $other = User::getKV('nickname', $otherNick); | 
					
						
							| 
									
										
										
										
											2013-06-16 02:18:19 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (empty($other)) { | 
					
						
							|  |  |  |         throw new Exception("Can't find user '$otherNick'."); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $notices = $other->getNotices()->fetchAll(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (count($notices) == 0) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $idx = rand(0, count($notices) - 1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $notice = $notices[$idx]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ($user->hasFave($notice)) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Fave::addNew($user->getProfile(), $notice); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-12 14:27:48 -04:00
										 |  |  | function testNoticeContent() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     global $words; | 
					
						
							| 
									
										
										
										
											2011-08-04 12:06:57 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-12 14:27:48 -04:00
										 |  |  |     if (is_null($words)) { | 
					
						
							|  |  |  |         return "test notice content"; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $cnt = rand(3, 8); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $ids = array_rand($words, $cnt); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     foreach ($ids as $id) { | 
					
						
							|  |  |  |         $parts[] = $words[$id]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $text = implode(' ', $parts); | 
					
						
							| 
									
										
										
										
											2011-08-04 12:06:57 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-12 14:27:48 -04:00
										 |  |  |     if (mb_strlen($text) > 80) { | 
					
						
							|  |  |  |         $text = substr($text, 0, 77) . "..."; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-08-04 12:06:57 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-12 14:27:48 -04:00
										 |  |  |     return $text; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-17 20:16:49 -07:00
										 |  |  | function main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $favesavg, $messageavg, $tagmax) | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2010-02-26 12:19:33 -05:00
										 |  |  |     global $config; | 
					
						
							|  |  |  |     $config['site']['dupelimit'] = -1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-11 12:38:12 -04:00
										 |  |  |     $n = 0; | 
					
						
							|  |  |  |     $g = 0; | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-11 12:38:12 -04:00
										 |  |  |     // Make users first
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $preuser = min($usercount, 5); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for ($j = 0; $j < $preuser; $j++) { | 
					
						
							|  |  |  |         printfv("$i Creating user $n\n"); | 
					
						
							|  |  |  |         newUser($n); | 
					
						
							|  |  |  |         $n++; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     $pregroup = min($groupcount, 3); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for ($k = 0; $k < $pregroup; $k++) { | 
					
						
							|  |  |  |         printfv("$i Creating group $g\n"); | 
					
						
							|  |  |  |         newGroup($g, $n); | 
					
						
							|  |  |  |         $g++; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // # registrations + # notices + # subs
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-17 20:16:49 -07:00
										 |  |  |     $events = $usercount + $groupcount + ($usercount * ($noticeavg + $subsavg + $joinsavg + $favesavg + $messageavg)); | 
					
						
							| 
									
										
										
										
											2011-03-25 17:39:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-11 12:38:12 -04:00
										 |  |  |     $events -= $preuser; | 
					
						
							|  |  |  |     $events -= $pregroup; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-25 17:39:14 -04:00
										 |  |  |     $ut = $usercount; | 
					
						
							|  |  |  |     $gt = $ut + $groupcount; | 
					
						
							|  |  |  |     $nt = $gt + ($usercount * $noticeavg); | 
					
						
							|  |  |  |     $st = $nt + ($usercount * $subsavg); | 
					
						
							|  |  |  |     $jt = $st + ($usercount * $joinsavg); | 
					
						
							| 
									
										
										
										
											2013-06-16 02:18:19 +00:00
										 |  |  |     $ft = $jt + ($usercount * $favesavg); | 
					
						
							| 
									
										
										
										
											2013-06-17 20:16:49 -07:00
										 |  |  |     $mt = $ft + ($usercount * $messageavg); | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-17 20:16:49 -07:00
										 |  |  |     printfv("$events events ($ut, $gt, $nt, $st, $jt, $ft, $mt)\n"); | 
					
						
							| 
									
										
										
										
											2011-03-26 14:58:11 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  |     for ($i = 0; $i < $events; $i++) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2011-03-25 17:39:14 -04:00
										 |  |  |         $e = rand(0, $events); | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-26 15:16:04 -04:00
										 |  |  |         if ($e >= 0 && $e <= $ut) { | 
					
						
							| 
									
										
										
										
											2011-03-26 14:58:11 -04:00
										 |  |  |             printfv("$i Creating user $n\n"); | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  |             newUser($n); | 
					
						
							|  |  |  |             $n++; | 
					
						
							| 
									
										
										
										
											2011-03-25 17:39:14 -04:00
										 |  |  |         } else if ($e > $ut && $e <= $gt) { | 
					
						
							| 
									
										
										
										
											2011-03-26 14:58:11 -04:00
										 |  |  |             printfv("$i Creating group $g\n"); | 
					
						
							| 
									
										
										
										
											2011-03-26 15:16:04 -04:00
										 |  |  |             newGroup($g, $n); | 
					
						
							| 
									
										
										
										
											2011-03-25 17:39:14 -04:00
										 |  |  |             $g++; | 
					
						
							|  |  |  |         } else if ($e > $gt && $e <= $nt) { | 
					
						
							| 
									
										
										
										
											2011-03-26 14:58:11 -04:00
										 |  |  |             printfv("$i Making a new notice\n"); | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  |             newNotice($n, $tagmax); | 
					
						
							| 
									
										
										
										
											2011-03-25 17:39:14 -04:00
										 |  |  |         } else if ($e > $nt && $e <= $st) { | 
					
						
							| 
									
										
										
										
											2011-03-26 14:58:11 -04:00
										 |  |  |             printfv("$i Making a new subscription\n"); | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  |             newSub($n); | 
					
						
							| 
									
										
										
										
											2011-03-25 17:39:14 -04:00
										 |  |  |         } else if ($e > $st && $e <= $jt) { | 
					
						
							| 
									
										
										
										
											2011-03-26 14:58:11 -04:00
										 |  |  |             printfv("$i Making a new group join\n"); | 
					
						
							| 
									
										
										
										
											2011-03-25 17:39:14 -04:00
										 |  |  |             newJoin($n, $g); | 
					
						
							| 
									
										
										
										
											2013-06-16 02:18:19 +00:00
										 |  |  |         } else if ($e > $jt && $e <= $ft) { | 
					
						
							|  |  |  |             printfv("$i Making a new fave\n"); | 
					
						
							|  |  |  |             newFave($n); | 
					
						
							| 
									
										
										
										
											2013-06-17 20:16:49 -07:00
										 |  |  |         } else if ($e > $ft && $e <= $mt) { | 
					
						
							|  |  |  |             printfv("$i Making a new message\n"); | 
					
						
							|  |  |  |             newMessage($n); | 
					
						
							| 
									
										
										
										
											2011-03-26 14:58:11 -04:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             printfv("No event for $i!"); | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-08-04 12:06:57 -07:00
										 |  |  | $defaultWordsfile = '/usr/share/dict/words'; | 
					
						
							| 
									
										
										
										
											2011-08-03 09:46:29 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-25 17:39:14 -04:00
										 |  |  | $usercount   = (have_option('u', 'users')) ? get_option_value('u', 'users') : 100; | 
					
						
							|  |  |  | $groupcount  = (have_option('g', 'groups')) ? get_option_value('g', 'groups') : 20; | 
					
						
							|  |  |  | $noticeavg   = (have_option('n', 'notices')) ? get_option_value('n', 'notices') : 100; | 
					
						
							|  |  |  | $subsavg     = (have_option('b', 'subscriptions')) ? get_option_value('b', 'subscriptions') : max($usercount/20, 10); | 
					
						
							|  |  |  | $joinsavg    = (have_option('j', 'joins')) ? get_option_value('j', 'joins') : 5; | 
					
						
							| 
									
										
										
										
											2013-06-16 02:18:19 +00:00
										 |  |  | $favesavg    = (have_option('f', 'faves')) ? get_option_value('f', 'faves') : max($noticeavg/10, 5); | 
					
						
							| 
									
										
										
										
											2013-06-17 20:16:49 -07:00
										 |  |  | $messageavg  = (have_option('m', 'messages')) ? get_option_value('m', 'messages') : max($noticeavg/10, 5); | 
					
						
							| 
									
										
										
										
											2011-03-25 17:39:14 -04:00
										 |  |  | $tagmax      = (have_option('t', 'tags')) ? get_option_value('t', 'tags') : 10000; | 
					
						
							|  |  |  | $userprefix  = (have_option('x', 'prefix')) ? get_option_value('x', 'prefix') : 'testuser'; | 
					
						
							|  |  |  | $groupprefix = (have_option('z', 'groupprefix')) ? get_option_value('z', 'groupprefix') : 'testgroup'; | 
					
						
							| 
									
										
										
										
											2011-08-04 12:06:57 -07:00
										 |  |  | $wordsfile   = (have_option('w', 'words')) ? get_option_value('w', 'words') : $defaultWordsfile; | 
					
						
							| 
									
										
										
										
											2011-04-12 14:27:48 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | if (is_readable($wordsfile)) { | 
					
						
							|  |  |  |     $words = file($wordsfile); | 
					
						
							|  |  |  | } else { | 
					
						
							| 
									
										
										
										
											2011-08-04 12:06:57 -07:00
										 |  |  |    if ($wordsfile != $defaultWordsfile) { | 
					
						
							| 
									
										
										
										
											2011-08-03 09:46:29 +00:00
										 |  |  |       // user specified words file couldn't be read
 | 
					
						
							| 
									
										
										
										
											2011-08-04 12:06:57 -07:00
										 |  |  |       throw new Exception("Couldn't read words file: {$wordsfile}."); | 
					
						
							| 
									
										
										
										
											2011-08-03 09:46:29 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-04-12 14:27:48 -04:00
										 |  |  |     $words = null; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-07-27 13:11:46 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-26 14:58:11 -04:00
										 |  |  | try { | 
					
						
							| 
									
										
										
										
											2013-06-17 20:16:49 -07:00
										 |  |  |     main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $favesavg, $messageavg, $tagmax); | 
					
						
							| 
									
										
										
										
											2011-03-26 14:58:11 -04:00
										 |  |  | } catch (Exception $e) { | 
					
						
							|  |  |  |     printfv("Got an exception: ".$e->getMessage()); | 
					
						
							|  |  |  | } |