CommunityID/utilities/generateRandomHistory.php

66 lines
1.8 KiB
PHP
Raw Normal View History

2019-07-17 20:08:50 +00:00
<?php
/*
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
* @license http://creativecommons.org/licenses/BSD/ BSD License
* @author Keyboard Monkey Ltd
* @since CommunityID 0.9
* @package CommunityID
* @packager Keyboard Monkeys
*/
/**
* This scripts creates fake entries in the history table
*/
define('APP_DIR', dirname(__FILE__) . '/..');
/**
* Number of entries to create
*/
define('NUM_ENTRIES', 3000);
2019-07-17 20:16:19 +00:00
require APP_DIR . '/Application.php';
2019-07-17 20:08:50 +00:00
2019-07-17 20:16:19 +00:00
Application::setIncludePath();
Application::setAutoLoader();
Application::setConfig();
Application::setLogger();
Application::setDatabase();
2019-07-17 20:08:50 +00:00
class GenerateRandomHistory
{
private $_names;
private $_numNames;
public function __construct()
{
$this->_words = file(dirname(__FILE__).'/../libs/Monkeys/tests/words.txt');
$this->_numWords= count($this->_words);
}
public function generate()
{
2019-07-17 20:16:19 +00:00
$histories = new Model_Histories();
2019-07-17 20:08:50 +00:00
2019-07-17 20:16:19 +00:00
$stats = new Stats_Model_Stats();
2019-07-17 20:08:50 +00:00
$userIds = $stats->getAllTestUsersIds();
$numUsers = count($userIds);
for ($i = 0; $i < NUM_ENTRIES; $i++) {
$history = $histories->createRow();
$history->user_id = $userIds[rand(0, $numUsers - 1)]['id'];
$history->date = date('Y-m-d H:i:s', time() - rand(0, 365) * 24 * 60 * 60);
$history->site = 'http://' . strtolower(trim($this->_words[rand(0, $this->_numWords)])) . '.com/'
. strtolower(trim($this->_words[rand(0, $this->_numWords)]));
$history->ip = rand(1, 255) . '.' . rand(1, 255) . '.' . rand(1, 255) . '.' . rand(1, 255);
2019-07-17 20:16:19 +00:00
$history->result = Model_History::AUTHORIZED;
2019-07-17 20:08:50 +00:00
$history->save();
}
}
}
$generate = new GenerateRandomHistory();
$generate->generate();