Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions Source/MantisSourceGitBasePlugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ abstract class MantisSourceGitBasePlugin extends MantisSourcePlugin
* Error constants
*/
const ERROR_INVALID_BRANCH = 'invalid_branch';
const ERROR_INVALID_DATE = 'invalid_date';

/**
* Define plugin's Error strings
Expand All @@ -54,6 +55,7 @@ abstract class MantisSourceGitBasePlugin extends MantisSourcePlugin
public function errors() {
$t_errors_list = array(
self::ERROR_INVALID_BRANCH,
self::ERROR_INVALID_DATE,
);

foreach( $t_errors_list as $t_error ) {
Expand All @@ -73,6 +75,19 @@ protected function is_branch_valid( $p_branch )
return (bool)preg_match( $this->valid_branch_regex, $p_branch );
}

/**
* Determines if given string name is a valid regex.
* @param string $p_regex regex to validate
* @return bool True if valid
*/
protected function is_regex_branch_valid( $p_regex )
{
# Trick to compile the regex
# see ReturnValues of the official doc https://www.php.net/manual/en/function.preg-match.php
return (0 === preg_match( $p_regex, "" ));
}


/**
* Triggers an error if the branch is invalid
* @param string $p_branch Branch name to validate
Expand All @@ -89,15 +104,20 @@ protected function ensure_branch_valid( $p_branch )
/**
* Validates a comma-delimited list of git branches.
* Triggers an ERROR_INVALID_BRANCH if one of the branches is invalid
* @param string $p_list Comma-delimited list of branch names (or '*')
* @param string $p_list Comma-delimited list of branch names, or a regex, or '*'
* @return void
*/
protected function validate_branch_list( $p_list )
{
#Case '*'
if( $p_list == '*' ) {
return;
}

#Case regex
if( preg_match( "/^\/.+\/[a-z]*$/i", $p_list ) ) {
return;
}
#Case list of validi git branches
foreach( explode( ',', $p_list ) as $t_branch ) {
$this->ensure_branch_valid( trim( $t_branch ) );
}
Expand All @@ -114,6 +134,21 @@ protected function get_default_primary_branches() {
return $t_value;
}

/**
* Validates a date
* Triggers an ERROR_INVALID_DATE if date is not valid
* @return void
*/
protected function validate_date($p_date) {
if (empty($p_date)) {
return;
}
if (! (bool)strtotime($p_date)) {
error_parameters( $p_date );
plugin_error( self::ERROR_INVALID_DATE );
}
}

/**
* Output form elements for configuration options.
*/
Expand Down
3 changes: 3 additions & 0 deletions Source/lang/strings_english.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ $s_plugin_Source_changeset_removed = 'Changeset removed';

$s_plugin_Source_ensure_delete = 'Do you really want to delete the "%s" repository and all of its history?';
$s_plugin_Source_ensure_import_full = 'This will import to a new copy of your repository, and then destroy the old repository data, and may require use of shell access. Do you wish to continue?';
$s_plugin_Source_ensure_import__full_since = 'This will import to a new copy of your repository since "%s", and then destroy the old repository data, and may require use of shell access. Do you wish to continue?';
$s_plugin_Source_ensure_import_latest = 'This will attempt to import recent data for your repository, and may require use of shell access. Do you wish to continue?';
$s_plugin_Source_ensure_import_latest_since = 'This will attempt to import since "%s" for yout repository, and may require use of shell access. Do you wish to continue?';
$s_plugin_Source_import_results = 'Import Results';
$s_plugin_Source_import_stats = 'Imported %s changesets, %s files, and %s bug references.';
$s_plugin_Source_import_repo_error = 'Import process produced an error.';
Expand All @@ -150,6 +152,7 @@ $s_plugin_Source_invalid_changeset = 'Changeset information could not be loaded'

$s_plugin_Source_import_latest_failed = 'Repository latest data importing failed.';
$s_plugin_Source_import_full_failed = 'Full repository data importing failed.';
$s_plugin_Source_import_since_failed = 'Repository "since date" importing failed.';

$s_plugin_Source_changeset_column_title = 'C';

Expand Down
3 changes: 3 additions & 0 deletions Source/lang/strings_french.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ $s_plugin_Source_back_repo = 'Retour au dépôt';
$s_plugin_Source_back_changeset = 'Retour au jeu de changements';
$s_plugin_Source_import_full = 'Tout importer';
$s_plugin_Source_import_latest = 'Importer les dernières données';
$s_plugin_Source_import_since = 'Importer depuis le...';
$s_plugin_Source_related_changesets = 'Jeux de changements liés';
$s_plugin_Source_affected_issues = 'Demandes affectées';
$s_plugin_Source_attach_to_issue = 'Attacher des demandes :';
Expand Down Expand Up @@ -134,7 +135,9 @@ $s_plugin_Source_changeset_removed = 'Jeu de changement détaché';

$s_plugin_Source_ensure_delete = 'Voulez-vous vraiment supprimer le dépôt "%s" et tout son historique ?';
$s_plugin_Source_ensure_import_full = 'Ceci va importer une nouvelle copie de votre dépôt, puis détruira les vieilles données de dépôt et pourrait avoir besoin d\'un accès au shell. Voulez-vous continuer ?';
$s_plugin_Source_ensure_import_full_since = 'Ceci va importer une nouvelle copie de votre dépôt depuis le "%s", puis détruira les vieilles données de dépôt et pourrait avoir besoin d\'un accès au shell. Voulez-vous continuer ?';
$s_plugin_Source_ensure_import_latest = 'Ceci va tenter d\'importer les données récentes dans votre dépôt et pourrait avoir besoin d\'un accès au shell. Voulez-vous continuer ?';
$s_plugin_Source_ensure_import_latest_since = 'Cevi va tenter d\'importer les données depuis le "%s" dans votre dépôt et pourrait avoir besoin d\'un accès au shell. Voulez-vous continuer ?';
$s_plugin_Source_import_results = 'Résultats de l\'import';
$s_plugin_Source_import_stats = '%s jeux de changements importés, %s fichiers, et %s références de demande.';
$s_plugin_Source_import_repo_error = 'Le processus d\'import a rencontré une erreur.';
Expand Down
10 changes: 8 additions & 2 deletions Source/pages/repo_import_full.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@
form_security_validate( 'plugin_Source_repo_import_full' );
access_ensure_global_level( plugin_config_get( 'manage_threshold' ) );

$f_repo_id = gpc_get_string( 'id' );
$f_repo_id = gpc_get_int( 'id' );

$t_repo = SourceRepo::load( $f_repo_id );
$t_vcs = SourceVCS::repo( $t_repo );

helper_ensure_confirmed( plugin_lang_get( 'ensure_import_full' ), plugin_lang_get( 'import_full' ) );
if (empty( $t_repo->info['hub_oldest_commit_date'])){
helper_ensure_confirmed( plugin_lang_get( 'ensure_import_full' ), plugin_lang_get( 'import_full' ) );
}else{
$t_date_since = $t_repo->info['hub_oldest_commit_date'];
helper_ensure_confirmed( sprintf( plugin_lang_get( 'ensure_import_full_since' ), $t_date_since), plugin_lang_get( 'import_full' ) );
}

helper_begin_long_process();

layout_page_header( plugin_lang_get( 'title' ) );
Expand Down
30 changes: 18 additions & 12 deletions Source/pages/repo_import_latest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@

form_security_validate( 'plugin_Source_repo_import_latest' );
access_ensure_global_level( plugin_config_get( 'manage_threshold' ) );
helper_ensure_confirmed( plugin_lang_get( 'ensure_import_latest' ), plugin_lang_get( 'import_latest' ) );

$f_repo_id = strtolower( gpc_get_string( 'id' ) );
$f_repo_id = gpc_get_int( 'id' );

$t_repo_id = (int) $f_repo_id;
$t_repos = array( SourceRepo::load( $t_repo_id ) );

$t_repo = array_shift( $t_repos );
$t_vcs = SourceVCS::repo( $t_repo );

$t_repo->pre_stats = $t_repo->stats();
$t_pre_stats = $t_repo->stats();

if ( empty( $t_repo->info['hub_oldest_commit_date'] ) ) {
helper_ensure_confirmed( plugin_lang_get( 'ensure_import_latest' ), plugin_lang_get( 'import_latest' ) );
}else{
$t_date_since = $t_repo->info['hub_oldest_commit_date'];
helper_ensure_confirmed( sprintf(plugin_lang_get( 'ensure_import_latest_since' ), $t_date_since), plugin_lang_get( 'import_latest' ) );
}


layout_page_header( plugin_lang_get( 'title' ) );
layout_page_begin();
Expand All @@ -39,15 +45,15 @@

<?php
# keep checking for more changesets to import
$t_repo->import_error = false;
$t_import_error = false;
while( true ) {

# import the next batch of changesets
$t_changesets = $t_vcs->import_latest( $t_repo );

# check for errors
if ( !is_array( $t_changesets ) ) {
$t_repo->import_error = true;
$t_import_error = true;
break;
}

Expand All @@ -59,21 +65,21 @@
Source_Process_Changesets( $t_changesets );
}

$t_repo->post_stats = $t_repo->stats();
$t_post_stats = $t_repo->stats();
?>

<tr>
<td class="category"><?php echo string_display_line( $t_repo->name ) ?></td>
<td>
<?php
if ( $t_repo->import_error ) {
if ( $t_import_error) {
echo plugin_lang_get( 'import_latest_failed' ), '<br/>';
}

$t_stats = $t_repo->post_stats;
$t_stats['changesets'] -= $t_repo->pre_stats['changesets'];
$t_stats['files'] -= $t_repo->pre_stats['files'];
$t_stats['bugs'] -= $t_repo->pre_stats['bugs'];
$t_stats = $t_post_stats;
$t_stats['changesets'] -= $t_pre_stats['changesets'];
$t_stats['files'] -= $t_pre_stats['files'];
$t_stats['bugs'] -= $t_pre_stats['bugs'];

echo sprintf( plugin_lang_get( 'import_stats' ), $t_stats['changesets'], $t_stats['files'], $t_stats['bugs'] );
?>
Expand Down
4 changes: 2 additions & 2 deletions Source/pages/repo_manage_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ function convert_to_key_value( $p_array ) {
<form action="<?php echo plugin_page( 'repo_import_latest' ) . '&amp;id=' . $t_repo->id ?>" method="post" class="pull-right">
<?php echo form_security_field( 'plugin_Source_repo_import_latest' ) ?>
<input type="submit" class="btn btn-primary btn-white btn-sm btn-round " value="<?php echo plugin_lang_get( 'import_latest' ) ?>"/>
</form>
</form>
</div>
</div>
</div>
</div>

<div class="space-10"></div>


Expand Down
Loading