]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - scripts/createsim.php
Merge branch 'master' of gitorious.org:statusnet/mainline
[quix0rs-gnu-social.git] / scripts / createsim.php
index e3677e1564bda25293619f7acb4b2299b61aefd7..21ed38fd56341d76fde20bc0449ff128397eceb0 100644 (file)
 
 define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
 
-$shortoptions = 'u:n:b:g:j:t:x:z:';
-$longoptions = array('users=', 'notices=', 'subscriptions=', 'groups=', 'joins=', 'tags=', 'prefix=');
+$shortoptions = 'b:g:j:n:t:u:w:x:z:';
+$longoptions = array(
+    'subscriptions=',
+    'groups=',
+    'joins=',
+    'notices=',
+    'tags=',
+    'users=',
+    'words=',
+    'prefix=',
+    'groupprefix'
+);
 
 $helptext = <<<END_OF_CREATESIM_HELP
 Creates a lot of test users and notices to (loosely) simulate a real server.
 
-    -u --users         Number of users (default 100)
-    -n --notices       Average notices per user (default 100)
     -b --subscriptions Average subscriptions per user (default no. users/20)
     -g --groups        Number of groups (default 20)
     -j --joins         Number of groups per user (default 5)
+    -n --notices       Average notices per user (default 100)
     -t --tags          Number of distinct hash tags (default 10000)
-    -x --prefix        User name prefix (default 'testuser')
+    -u --users         Number of users (default 100)
     -w --words         Words file (default '/usr/share/dict/words')
+    -x --prefix        User name prefix (default 'testuser')
+    -z --groupprefix   Group name prefix (default 'testgroup')
 
 END_OF_CREATESIM_HELP;
 
@@ -138,7 +149,7 @@ function newNotice($i, $tagmax)
         $options['scope'] |= Notice::SITE_SCOPE;
     }
 
-    $notice = Notice::saveNew($user->id, $content, 'system', $options);
+    $notice = Notice::saveNew($user->id, $content, 'createsim', $options);
 }
 
 function newSub($i)
@@ -210,7 +221,7 @@ function newJoin($u, $g)
 function testNoticeContent()
 {
     global $words;
-    
+
     if (is_null($words)) {
         return "test notice content";
     }
@@ -224,11 +235,11 @@ function testNoticeContent()
     }
 
     $text = implode(' ', $parts);
-    
+
     if (mb_strlen($text) > 80) {
         $text = substr($text, 0, 77) . "...";
     }
-    
+
     return $text;
 }
 
@@ -300,6 +311,8 @@ function main($usercount, $groupcount, $noticeavg, $subsavg, $joinsavg, $tagmax)
     }
 }
 
+$defaultWordsfile = '/usr/share/dict/words';
+
 $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;
@@ -308,11 +321,15 @@ $joinsavg    = (have_option('j', 'joins')) ? get_option_value('j', 'joins') : 5;
 $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';
-$wordsfile   = (have_option('w', 'words')) ? get_option_value('w', 'words') : '/usr/share/dict/words';
+$wordsfile   = (have_option('w', 'words')) ? get_option_value('w', 'words') : $defaultWordsfile;
 
 if (is_readable($wordsfile)) {
     $words = file($wordsfile);
 } else {
+   if ($wordsfile != $defaultWordsfile) {
+      // user specified words file couldn't be read
+      throw new Exception("Couldn't read words file: {$wordsfile}.");
+    }
     $words = null;
 }