-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugs/seeder #1
base: master
Are you sure you want to change the base?
Bugs/seeder #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,131 @@ | ||
<?php | ||
/************************************************************************** | ||
MantisBT Seeder Plugin | ||
Copyright (c) MantisHub - Victor Boctor | ||
All rights reserved. | ||
MIT License | ||
**************************************************************************/ | ||
* MantisBT Seeder Plugin | ||
* Copyright (c) MantisHub - Victor Boctor | ||
* All rights reserved. | ||
* MIT License | ||
**************************************************************************/ | ||
|
||
require_once( dirname( __FILE__ ) . '/MantisPhpClient.php' ); | ||
require_once(dirname(__FILE__) . '/MantisPhpClient.php'); | ||
|
||
define( 'MANTIS_SEEDER_ISSUES_COUNT', 100 ); | ||
define('MANTIS_SEEDER_ISSUES_COUNT', 100); | ||
|
||
/** | ||
* Seeder | ||
*/ | ||
* Seeder | ||
*/ | ||
class Seeder | ||
{ | ||
/** | ||
* Seed the database with test projects. | ||
* | ||
* return array Array of created project ids. | ||
*/ | ||
function createProjects() { | ||
$t_project_ids = array(); | ||
$t_project_ids[] = $this->ensure_project_exists( 'MantisBT', 'Mantis Bug Tracker' ); | ||
$t_project_ids[] = $this->ensure_project_exists( 'MantisHub', 'MantisBT as a Service' ); | ||
return $t_project_ids; | ||
} | ||
|
||
/** | ||
* Seed the database with test issues. | ||
* | ||
* @param integer $p_project_ids The projects to use for test issues. | ||
* @param integer $p_issues_count The number of issues to seed. | ||
*/ | ||
function createIssues( $p_project_ids, $p_issues_count = MANTIS_SEEDER_ISSUES_COUNT ) { | ||
$t_client = new MantisPhpClient( 'https://www.mantisbt.org/bugs/', '', '' ); | ||
|
||
$t_issues_count = 0; | ||
$t_ids_tested = array(); | ||
|
||
while (true) { | ||
$t_issue_id = rand( 19000, 20500 ); | ||
if ( !isset( $t_ids_tested[$t_issue_id] ) ) { | ||
$t_ids_tested[$t_issue_id] = true; | ||
} | ||
|
||
try { | ||
$t_issue = $t_client->getIssue( $t_issue_id ); | ||
$t_issues_count++; | ||
} catch ( SoapFault $e ) { | ||
if ( strstr( $e->getMessage(), 'Issue does not exist' ) ) { | ||
continue; | ||
} | ||
} | ||
|
||
$this->ensure_user_exists( $t_issue->reporter ); | ||
|
||
$t_handler_id = 0; | ||
|
||
if ( isset( $t_issue->handler ) ) { | ||
$this->ensure_user_exists( $t_issue->handler ); | ||
$t_handler_id = user_get_id_by_name( $t_issue->handler->name ); | ||
} | ||
|
||
$t_bug_data = new BugData; | ||
$t_bug_data->project_id = $p_project_ids[rand(0, 1)]; | ||
$t_bug_data->reporter_id = user_get_id_by_name( $t_issue->reporter->name ); | ||
$t_bug_data->handler_id = $t_handler_id; | ||
$t_bug_data->view_state = $t_issue->view_state->id; | ||
$t_bug_data->category_id = 1; | ||
$t_bug_data->reproducibility = $t_issue->reproducibility->id; | ||
$t_bug_data->severity = $t_issue->severity->id; | ||
$t_bug_data->priority = $t_issue->priority->id; | ||
$t_bug_data->projection = $t_issue->projection->id; | ||
$t_bug_data->eta = $t_issue->eta->id; | ||
$t_bug_data->resolution = $t_issue->resolution->id; | ||
$t_bug_data->status = $t_issue->status->id; | ||
$t_bug_data->summary = $t_issue->summary; | ||
$t_bug_data->description = $t_issue->description; | ||
|
||
$t_bug_id = $t_bug_data->create(); | ||
|
||
if ( $t_issues_count == $p_issues_count ) { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
function ensure_project_exists( $p_name, $p_description ) { | ||
$t_project_id = project_get_id_by_name( $p_name ); | ||
if ( $t_project_id !== false ) { | ||
return $t_project_id; | ||
} | ||
|
||
return project_create( 'MantisBT', 'Mantis Bug Tracker', /* status: stable */ 50 ); | ||
} | ||
|
||
function ensure_user_exists( $p_account_info ) { | ||
if ( $p_account_info === null ) { | ||
return; | ||
} | ||
|
||
$t_user_id = user_get_id_by_name( $p_account_info->name ); | ||
|
||
if ( $t_user_id === false ) { | ||
user_create( $p_account_info->name, '', '', DEVELOPER ); | ||
|
||
} | ||
|
||
return $t_user_id; | ||
} | ||
/** | ||
* Seed the database with test projects. | ||
* | ||
* return array Array of created project ids. | ||
*/ | ||
function createProjects(): array | ||
{ | ||
$t_project_ids = array(); | ||
|
||
$projects = [ | ||
[ | ||
'p_name' => 'MantisBT', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
'p_description' => 'Mantis Bug Tracker', | ||
], | ||
[ | ||
'p_name' => 'MantisHub', | ||
'p_description' => 'MantisBT as a Service', | ||
] | ||
]; | ||
|
||
foreach ($projects as $project){ | ||
$t_project_ids[] = $this->ensure_project_exists($project['p_name'], $project['p_description']); | ||
} | ||
|
||
return $t_project_ids; | ||
} | ||
|
||
/** | ||
* Seed the database with test issues. | ||
* | ||
* @param array $p_project_ids The projects to use for test issues. | ||
* @param integer $p_issues_count The number of issues to seed. | ||
*/ | ||
function createIssues($p_project_ids, $p_issues_count = MANTIS_SEEDER_ISSUES_COUNT) | ||
{ | ||
$t_client = new MantisPhpClient('https://www.mantisbt.org/bugs/', '', ''); | ||
|
||
$t_issues_count = 0; | ||
$t_ids_tested = array(); | ||
|
||
while (true) { | ||
$t_issue_id = rand(19000, 20500); | ||
if (!isset($t_ids_tested[$t_issue_id])) { | ||
$t_ids_tested[$t_issue_id] = true; | ||
} | ||
|
||
try { | ||
$t_issue = $t_client->getIssue($t_issue_id); | ||
$t_issues_count++; | ||
} catch (SoapFault $e) { | ||
if (strstr($e->getMessage(), 'Issue does not exist')) { | ||
continue; | ||
} | ||
} | ||
|
||
$this->ensure_user_exists($t_issue->reporter); | ||
|
||
$t_handler_id = 0; | ||
|
||
if (isset($t_issue->handler)) { | ||
$this->ensure_user_exists($t_issue->handler); | ||
$t_handler_id = user_get_id_by_name($t_issue->handler->name); | ||
} | ||
|
||
$t_bug_data = new BugData; | ||
$t_bug_data->project_id = $p_project_ids[rand(0, 1)]; | ||
$t_bug_data->reporter_id = user_get_id_by_name($t_issue->reporter->name); | ||
$t_bug_data->handler_id = $t_handler_id; | ||
$t_bug_data->view_state = rand(1, 10); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are two valid values for view_state --- VS_PRIVATE and VS_PUBLIC. It shouldn't be set to other values. |
||
$t_bug_data->category_id = 1; | ||
$t_bug_data->reproducibility = $t_issue->reproducibility->id; | ||
$t_bug_data->severity = $t_issue->severity->id; | ||
$t_bug_data->priority = $t_issue->priority->id; | ||
$t_bug_data->projection = $t_issue->projection->id; | ||
$t_bug_data->eta = $t_issue->eta->id; | ||
$t_bug_data->resolution = $t_issue->resolution->id; | ||
$t_bug_data->status = $t_issue->status->id; | ||
$t_bug_data->summary = "Test"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you overwriting the summary to 'Test'? |
||
$t_bug_data->description = "Test"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you overwriting the description to 'Test'? |
||
|
||
$t_bug_id = $t_bug_data->create(); | ||
|
||
if ($t_issues_count == $p_issues_count) { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
function ensure_project_exists($p_name, $p_description) | ||
{ | ||
$t_project_id = project_get_id_by_name($p_name); | ||
if ($t_project_id) { | ||
return $t_project_id; | ||
} | ||
|
||
return project_create($p_name, $p_description, /* status: stable */ 50); | ||
} | ||
|
||
function ensure_user_exists($p_account_info) | ||
{ | ||
if ($p_account_info === null) { | ||
return; | ||
} | ||
|
||
$t_user_id = user_get_id_by_name($p_account_info->name); | ||
|
||
if ($t_user_id === false) { | ||
user_create($p_account_info->name, '', '', DEVELOPER); | ||
|
||
} | ||
|
||
return $t_user_id; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,46 @@ | ||
<?php | ||
/************************************************************************** | ||
MantisBT Seeder Plugin | ||
Copyright (c) MantisHub - Victor Boctor | ||
All rights reserved. | ||
MIT License | ||
**************************************************************************/ | ||
MantisBT Seeder Plugin | ||
Copyright (c) MantisHub - Victor Boctor | ||
All rights reserved. | ||
MIT License | ||
**************************************************************************/ | ||
|
||
access_ensure_global_level( config_get( 'manage_plugin_threshold' ) ); | ||
|
||
require_once( dirname( dirname( __FILE__ ) ) . '/core/Seeder.php' ); | ||
layout_page_header_begin( lang_get( 'my_view_link' ) ); | ||
layout_page_header_end(); | ||
|
||
html_page_top(); | ||
layout_page_begin( __FILE__ ); | ||
?> | ||
|
||
<br /> | ||
<div class="form-container"> | ||
<form action="<?php echo plugin_page( 'seed' ) ?>" method="post"> | ||
<fieldset> | ||
<legend> | ||
<?php echo plugin_lang_get( 'title' ) ?> | ||
</legend> | ||
|
||
<?php echo form_security_field( 'plugin_MantisSeeder_config' ) ?> | ||
|
||
<!-- Import Access Level --> | ||
<div class="field-container"> | ||
<label for="create_issues"> | ||
<span><?php echo plugin_lang_get( 'create_issues' ) ?></span> | ||
</label> | ||
<span class="select"> | ||
<br /> | ||
<div class="form-container"> | ||
<form action="<?php echo plugin_page( 'seed' ) ?>" method="post"> | ||
<fieldset> | ||
<legend> | ||
<?php echo plugin_lang_get( 'title' ) ?> | ||
</legend> | ||
<?php echo form_security_field( 'plugin_MantisSeeder_config' ) ?> | ||
|
||
<!-- Import Access Level --> | ||
<div class="field-container"> | ||
<label for="create_issues"> | ||
<span><?php echo plugin_lang_get( 'create_issues' ) ?></span> | ||
</label> | ||
<span class="select"> | ||
<?php echo sprintf( plugin_lang_get( 'create_issues_desc' ), MANTIS_SEEDER_ISSUES_COUNT ); ?> | ||
<br /><br /> | ||
<input type="submit" id="create_issues" value="<?php echo plugin_lang_get( 'create_issues' ) ?>"/> | ||
</span> | ||
<span class="label-style"></span> | ||
</div> | ||
<span class="label-style"></span> | ||
</div> | ||
|
||
</fieldset> | ||
</form> | ||
</div> | ||
</fieldset> | ||
</form> | ||
</div> | ||
|
||
<?php | ||
html_page_bottom(); | ||
layout_page_end(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,33 @@ | ||
<?php | ||
/************************************************************************** | ||
MantisBT Seeder Plugin | ||
Copyright (c) MantisHub - Victor Boctor | ||
All rights reserved. | ||
MIT License | ||
**************************************************************************/ | ||
MantisBT Seeder Plugin | ||
Copyright (c) MantisHub - Victor Boctor | ||
All rights reserved. | ||
MIT License | ||
**************************************************************************/ | ||
|
||
access_ensure_global_level( ADMINISTRATOR ); | ||
|
||
require_once( dirname( dirname( __FILE__ ) ) . '/core/Seeder.php' ); | ||
|
||
html_page_top1(); | ||
html_meta_redirect( plugin_page( 'config_page') ); | ||
html_page_top2(); | ||
layout_page_header_begin( lang_get( 'my_view_link' ) ); | ||
layout_page_header_end(); | ||
|
||
layout_page_begin( __FILE__ ); | ||
|
||
$f_create_issues = gpc_isset( 'create_issues' ); | ||
|
||
$g_enable_email_notification = OFF; | ||
$t_seeder = new Seeder(); | ||
|
||
if( $f_create_issues !== OFF ) { | ||
$t_project_ids = $t_seeder->createProjects(); | ||
$t_seeder->createIssues( $t_project_ids ); | ||
$t_project_ids = $t_seeder->createProjects(); | ||
$t_seeder->createIssues( $t_project_ids ); | ||
} | ||
|
||
echo '<div class="success-msg">'; | ||
echo lang_get( 'operation_successful' ); | ||
echo '</div>'; | ||
|
||
html_page_bottom(); | ||
|
||
layout_page_end(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a lot of noise in the indentation, can you please update it to follow the convention of the original code of the plugin to remove the noise and be consistent.