PageRenderTime 34ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/MantisBT/scripts/checkin.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 97 lines | 57 code | 15 blank | 25 comment | 15 complexity | a1b4ecfe3afe650f52bb4fe371a13eb7 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0
  1. #!/usr/bin/php -q
  2. <?php
  3. # MantisBT - a php based bugtracking system
  4. # Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
  5. # Copyright (C) 2002 - 2011 MantisBT Team - mantisbt-dev@lists.sourceforge.net
  6. # MantisBT is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # MantisBT is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
  18. # See the README and LICENSE files for details
  19. global $g_bypass_headers;
  20. $g_bypass_headers = 1;
  21. require_once( dirname( dirname( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'core.php' );
  22. # Make sure this script doesn't run via the webserver
  23. if( php_sapi_name() != 'cli' ) {
  24. echo "checkin.php is not allowed to run through the webserver.\n";
  25. exit( 1 );
  26. }
  27. # Check that the username is set and exists
  28. $t_username = config_get( 'source_control_account' );
  29. if( is_blank( $t_username ) || ( user_get_id_by_name( $t_username ) === false ) ) {
  30. echo "Invalid source control account ('$t_username').\n";
  31. exit( 1 );
  32. }
  33. if( !defined( "STDIN" ) ) {
  34. define( "STDIN", fopen( 'php://stdin', 'r' ) );
  35. }
  36. # Detect references to issues + concat all lines to have the comment log.
  37. $t_commit_regexp = config_get( 'source_control_regexp' );
  38. $t_commit_fixed_regexp = config_get( 'source_control_fixed_regexp' );
  39. $t_comment = '';
  40. $t_issues = array();
  41. $t_fixed_issues = array();
  42. while(( $t_line = fgets( STDIN, 1024 ) ) ) {
  43. $t_comment .= $t_line;
  44. if( preg_match_all( $t_commit_regexp, $t_line, $t_matches ) ) {
  45. $t_count = count( $t_matches[0] );
  46. for( $i = 0;$i < $t_count;++$i ) {
  47. $t_issues[] = $t_matches[1][$i];
  48. }
  49. }
  50. if( preg_match_all( $t_commit_fixed_regexp, $t_line, $t_matches ) ) {
  51. $t_count = count( $t_matches[0] );
  52. for( $i = 0;$i < $t_count;++$i ) {
  53. $t_fixed_issues[] = $t_matches[1][$i];
  54. }
  55. }
  56. }
  57. # If no issues found, then no work to do.
  58. if(( count( $t_issues ) == 0 ) && ( count( $t_fixed_issues ) == 0 ) ) {
  59. echo "Comment does not reference any issues.\n";
  60. exit( 0 );
  61. }
  62. # Login as source control user
  63. if( !auth_attempt_script_login( $t_username ) ) {
  64. echo "Unable to login\n";
  65. exit( 1 );
  66. }
  67. # history parameters are reserved for future use.
  68. $t_history_old_value = '';
  69. $t_history_new_value = '';
  70. # add note to each bug only once
  71. $t_issues = array_unique( $t_issues );
  72. $t_fixed_issues = array_unique( $t_fixed_issues );
  73. # Call the custom function to register the checkin on each issue.
  74. foreach( $t_issues as $t_issue_id ) {
  75. if( !in_array( $t_issue_id, $t_fixed_issues ) ) {
  76. helper_call_custom_function( 'checkin', array( $t_issue_id, $t_comment, $t_history_old_value, $t_history_new_value, false ) );
  77. }
  78. }
  79. foreach( $t_fixed_issues as $t_issue_id ) {
  80. helper_call_custom_function( 'checkin', array( $t_issue_id, $t_comment, $t_history_old_value, $t_history_new_value, true ) );
  81. }
  82. exit( 0 );