/** * Check if the specified bug can be closed * @param BugData $p_bug Bug to check access against * @param int|null $p_user_id integer representing user id, defaults to null to use current user * @return bool true if user can close the bug * @access public */ function access_can_close_bug($p_bug, $p_user_id = null) { if (bug_is_closed($p_bug->id)) { # Can't close a bug that's already closed return false; } if (null === $p_user_id) { $p_user_id = auth_get_current_user_id(); } # If allow_reporter_close is enabled, then reporters can close their own bugs # if they are in resolved status if (ON == config_get('allow_reporter_close', null, null, $p_bug->project_id) && bug_is_user_reporter($p_bug->id, $p_user_id) && bug_is_resolved($p_bug->id)) { return true; } $t_closed_status = config_get('bug_closed_status_threshold', null, null, $p_bug->project_id); $t_closed_status_threshold = access_get_status_threshold($t_closed_status, $p_bug->project_id); return access_has_bug_level($t_closed_status_threshold, $p_bug->id, $p_user_id); }
function save_acra_issue($p_project_id, $packages) { $begin_ts = microtime(true); set_time_limit(0); $pid = "pid:" . getmypid() . "-" . substr(md5(microtime()), 8, 16) . " "; error_log($pid . "save_acra_issue enter"); $t_app_version = gpc_get_string('APP_VERSION_NAME', ''); $t_project_id = $p_project_id; $t_fingerprint = $this->build_acra_issue_fingerprint(gpc_get_string('STACK_TRACE'), $packages, $pid); $t_bug_id = acra_get_bug_id_by_fingerprint($t_fingerprint, $t_app_version); if ($t_bug_id != false && $t_bug_id != '0' && $t_bug_id != '-1') { //the bug id is valid if (bug_is_closed($t_bug_id)) { error_log($pid . "the bug " . $t_bug_id . " is closed"); error_log($pid . "save_acra_issue quit2 " . (microtime(true) - $begin_ts) . 'ms'); return; } } //save acra issue extionsion $acra_ext = new BugDataAcraExt(); $acra_ext->project_id = $t_project_id; $acra_ext->issue_id = 0; $acra_ext->report_id = gpc_get_string('REPORT_ID', ''); $acra_ext->report_fingerprint = $t_fingerprint; $acra_ext->file_path = gpc_get_string('FILE_PATH', ''); $acra_ext->phone_model = gpc_get_string('PHONE_MODEL', ''); $acra_ext->phone_build = gpc_get_string('BUILD', ''); $acra_ext->phone_brand = gpc_get_string('BRAND', ''); $acra_ext->product_name = gpc_get_string('PRODUCT', ''); $acra_ext->total_mem_size = gpc_get_string('TOTAL_MEM_SIZE', ''); $acra_ext->available_mem_size = gpc_get_string('AVAILABLE_MEM_SIZE', ''); $acra_ext->custom_data = gpc_get_string('CUSTOM_DATA', ''); $acra_ext->initial_configuration = gpc_get_string('INITIAL_CONFIGURATION', ''); $acra_ext->crash_configuration = gpc_get_string('CRASH_CONFIGURATION', ''); $acra_ext->display = gpc_get_string('DISPLAY', ''); $acra_ext->user_comment = gpc_get_string('USER_COMMENT', ''); $acra_ext->dumpsys_meminfo = gpc_get_string('DUMPSYS_MEMINFO', ''); $acra_ext->dropbox = gpc_get_string('DROPBOX', ''); //NOT EXITS, need check with acra, later $acra_ext->eventslog = gpc_get_string('EVENTSLOG', ''); //NOT EXITS, need check with acra, later $acra_ext->radiolog = gpc_get_string('RADIOLOG', ''); //NOT EXITS, need check with acra, later $acra_ext->is_silent = gpc_get_string('IS_SILENT', ''); $acra_ext->device_id = gpc_get_string('INSTALLATION_ID', ''); //NOT EXITS, need check with acra, later $acra_ext->installation_id = gpc_get_string('INSTALLATION_ID', ''); $acra_ext->user_email = gpc_get_string('USER_EMAIL', ''); $acra_ext->device_features = gpc_get_string('DEVICE_FEATURES', ''); $acra_ext->environment = gpc_get_string('ENVIRONMENT', ''); $acra_ext->settings_system = gpc_get_string('SETTINGS_SYSTEM', ''); $acra_ext->settings_secure = gpc_get_string('SETTINGS_SECURE', ''); $acra_ext->shared_preferences = gpc_get_string('SHARED_PREFERENCES', ''); $acra_ext->android_version = gpc_get_string('ANDROID_VERSION', ''); $acra_ext->app_version = $t_app_version; $acra_ext->crash_date = $this->covertTimeString(gpc_get_string('USER_CRASH_DATE', '')); $acra_ext->install_date = $this->covertTimeString(gpc_get_string('USER_APP_START_DATE', '')); $t_result = $acra_ext->create(); if ($t_result === false) { error_log($pid . "dumplicated report id"); return; } error_log($pid . "save fingerprint " . $acra_ext->report_fingerprint . " to acra issue:" . $acra_ext->id); $t_duplicated_bug_id = '0'; $tries = 0; while ($tries < 30) { sleep(1); //wait one second $t_duplicated_bug_id = acra_get_bug_id_by_fingerprint($t_fingerprint, $t_app_version); $tries = $tries + 1; if ($t_duplicated_bug_id == "-1") { $id = acra_get_first_issue_id_by_fingerprint($t_fingerprint, 0); if ($id == $acra_ext->id) { $t_duplicated_bug_id = '0'; break; } continue; } if ($t_duplicated_bug_id == '0') { break; } break; } if (tries >= 30) { $t_duplicated_bug_id = '0'; } $t_user_id = $this->get_user_id(); if ($t_duplicated_bug_id == '0') { //new crash report, save a bug record $t_duplicated_bug_id = $this->save_bug($t_project_id, $t_user_id); error_log($pid . "create bug " . $t_duplicated_bug_id . ' for acra issue:' . $acra_ext->id . ' fp:' . $t_fingerprint); //create version if possible $t_version_id = version_get_id($t_app_version, $t_project_id); if ($t_version_id === false) { version_add($t_project_id, $t_app_version, VERSION_RELEASED); event_signal('EVENT_MANAGE_VERSION_CREATE', array($t_version_id)); } } else { error_log($pid . "exists bug " . $t_duplicated_bug_id); if (!bug_is_closed($t_duplicated_bug_id)) { //the bug is open $t_notes = bugnote_get_all_bugnotes($t_duplicated_bug_id); if (count($t_notes) < 20) { //we only accepts 20 crash records as notes for the reason of the speed of viewing bug detail page. error_log($pid . "acra issue is:" . $acra_ext->id); $note_id = bugnote_add($t_duplicated_bug_id, gpc_get_string('STACK_TRACE'), '0:00', false, BUGNOTE, $acra_ext->id, $t_user_id, false, false); error_log($pid . "add note " . $note_id . " to bug" . $t_duplicated_bug_id); } else { bug_update_date($t_duplicated_bug_id); error_log($pid . "update bug" . $t_duplicated_bug_id . " time, not add note"); } } else { //the bug is closed, do not accept crash report any more acra_delete_bug_ext_by_id($acra_ext->id); error_log($pid . "delete the acra issue because the bug" . $t_duplicated_bug_id . " is closed"); error_log($pid . "save_acra_issue quit1 " . (microtime(true) - $begin_ts) . 'ms'); return; } /* if( !($t_bug->status == RESOLVED || $t_bug->status == CLOSED || $t_bug->resolution == FIXED || $t_bug->resolution == DUPLICATE || $t_bug->resolution == NOT_FIXABLE) ){ //refresh bug update time bug_update_date($t_duplicated_bug_id); } */ } error_log($pid . "update bug id of acra issues which fingerprint is " . $t_fingerprint); acra_update_bug_id_by_fingerprint($t_fingerprint, $t_duplicated_bug_id); error_log($pid . "save_acra_issue quit0 " . (microtime(true) - $begin_ts) . 'ms'); }