/** * Gets the where clause to use for retrieving versions. * * @param integer $p_project_id The project id to use. * @param bool $p_inherit Include versions from parent projects? true: yes, false: no, null: use default configuration. * @return string The where clause not including WHERE. */ function version_get_project_where_clause($p_project_id, $p_inherit) { if ($p_project_id == ALL_PROJECTS) { $t_inherit = false; } else { if ($p_inherit === null) { $t_inherit = ON == config_get('subprojects_inherit_versions'); } else { $t_inherit = $p_inherit; } } $c_project_id = db_prepare_int($p_project_id); if ($t_inherit) { $t_project_ids = project_hierarchy_inheritance($p_project_id); $t_project_where = ' project_id IN ( ' . implode(', ', $t_project_ids) . ' ) '; } else { $t_project_where = ' project_id=' . $c_project_id . ' '; } return $t_project_where; }
public function process(XMLreader $reader) { //print "\nImportIssue process()\n"; $t_project_id = helper_get_current_project(); // TODO: category_get_id_by_name could work by default on current project $userId = auth_get_current_user_id(); $t_custom_fields = array(); $t_bugnotes = array(); $t_attachments = array(); $depth = $reader->depth; while ($reader->read() && ($reader->depth > $depth || $reader->nodeType != XMLReader::END_ELEMENT)) { if ($reader->nodeType == XMLReader::ELEMENT) { switch ($reader->localName) { case 'reporter': $t_old_id = $reader->getAttribute('id'); $reader->read(); $this->newbug_->reporter_id = $this->get_user_id($reader->value, $userId); //echo "reporter: old id = $t_old_id - new id = {$this->newbug_->reporter_id}\n"; break; case 'handler': $t_old_id = $reader->getAttribute('id'); $reader->read(); $this->newbug_->handler_id = $this->get_user_id($reader->value, $userId); //echo "handler: old id = $t_old_id - new id = {$this->newbug_->handler_id}\n"; break; case 'category': $this->newbug_->category_id = $this->defaultCategory_; if (version_compare(MANTIS_VERSION, '1.2', '>') === true) { $reader->read(); if ($this->keepCategory_) { # Check for the category's existence in the current project # well as its parents (if any) $t_projects_hierarchy = project_hierarchy_inheritance($t_project_id); foreach ($t_projects_hierarchy as $t_project) { $t_category_id = category_get_id_by_name($reader->value, $t_project, false); if ($t_category_id !== false) { $this->newbug_->category_id = $t_category_id; break; } } } // echo "new id = {$this->newbug_->category_id}\n"; } break; case 'eta': case 'priority': case 'projection': case 'reproducibility': case 'resolution': case 'severity': case 'status': case 'view_state': $t_field = $reader->localName; $t_id = $reader->getAttribute('id'); $reader->read(); $t_value = $reader->value; // Here we assume ids have the same meaning in both installations // TODO add a check for customized values $this->newbug_->{$t_field} = $t_id; break; case 'id': $reader->read(); $this->old_id_ = $reader->value; break; case 'project': // ignore original value, use current project $this->newbug_->project_id = $t_project_id; break; case 'custom_fields': // store custom fields $i = -1; $depth_cf = $reader->depth; while ($reader->read() && ($reader->depth > $depth_cf || $reader->nodeType != XMLReader::END_ELEMENT)) { if ($reader->nodeType == XMLReader::ELEMENT) { if ($reader->localName == 'custom_field') { $t_custom_fields[++$i] = new stdClass(); } switch ($reader->localName) { default: $field = $reader->localName; $reader->read(); $t_custom_fields[$i]->{$field} = $reader->value; } } } break; case 'bugnotes': // store bug notes $i = -1; $depth_bn = $reader->depth; while ($reader->read() && ($reader->depth > $depth_bn || $reader->nodeType != XMLReader::END_ELEMENT)) { if ($reader->nodeType == XMLReader::ELEMENT) { if ($reader->localName == 'bugnote') { $t_bugnotes[++$i] = new stdClass(); } switch ($reader->localName) { case 'reporter': $t_old_id = $reader->getAttribute('id'); $reader->read(); $t_bugnotes[$i]->reporter_id = $this->get_user_id($reader->value, $userId); break; case 'view_state': $t_old_id = $reader->getAttribute('id'); $reader->read(); $t_bugnotes[$i]->private = $reader->value == VS_PRIVATE ? true : false; break; default: $field = $reader->localName; $reader->read(); $t_bugnotes[$i]->{$field} = $reader->value; } } } break; case 'attachments': // store attachments $i = -1; $depth_att = $reader->depth; while ($reader->read() && ($reader->depth > $depth_att || $reader->nodeType != XMLReader::END_ELEMENT)) { if ($reader->nodeType == XMLReader::ELEMENT) { if ($reader->localName == 'attachment') { $t_attachments[++$i] = new stdClass(); } switch ($reader->localName) { default: $field = $reader->localName; $reader->read(); $t_attachments[$i]->{$field} = $reader->value; } } } break; default: $field = $reader->localName; //echo "using default handler for field: $field\n"; $reader->read(); $this->newbug_->{$field} = $reader->value; } } } // now save the new bug $this->new_id_ = $this->newbug_->create(); // add custom fields if ($this->new_id_ > 0 && is_array($t_custom_fields) && count($t_custom_fields) > 0) { foreach ($t_custom_fields as $t_custom_field) { $t_custom_field_id = custom_field_get_id_from_name($t_custom_field->name); if (custom_field_ensure_exists($t_custom_field_id) && custom_field_is_linked($t_custom_field_id, $t_project_id)) { custom_field_set_value($t_custom_field->id, $this->new_id_, $t_custom_field->value); } else { error_parameters($t_custom_field->name, $t_custom_field_id); trigger_error(ERROR_CUSTOM_FIELD_NOT_LINKED_TO_PROJECT, ERROR); } } } // add bugnotes if ($this->new_id_ > 0 && is_array($t_bugnotes) && count($t_bugnotes) > 0) { foreach ($t_bugnotes as $t_bugnote) { bugnote_add($this->new_id_, $t_bugnote->note, $t_bugnote->time_tracking, $t_bugnote->private, $t_bugnote->note_type, $t_bugnote->note_attr, $t_bugnote->reporter_id, false, $t_bugnote->date_submitted, $t_bugnote->last_modified, true); } } // add attachments if ($this->new_id_ > 0 && is_array($t_attachments) && count($t_attachments) > 0) { foreach ($t_attachments as $t_attachment) { // Create a temporary file in the temporary files directory using sys_get_temp_dir() $temp_file_name = tempnam(sys_get_temp_dir(), 'MantisImport'); file_put_contents($temp_file_name, base64_decode($t_attachment->content)); $file_data = array('name' => $t_attachment->filename, 'type' => $t_attachment->file_type, 'tmp_name' => $temp_file_name, 'size' => filesize($temp_file_name), 'error' => UPLOAD_ERR_OK); // unfortunately we have no clue who has added the attachment (this could only be fetched from history -> feel free to implement this) // also I have no clue where description should come from... file_add($this->new_id_, $file_data, 'bug', $t_attachment->title, $p_desc = '', $p_user_id = null, $t_attachment->date_added, true); unlink($temp_file_name); } } //echo "\nnew bug: $this->new_id_\n"; }
public function process(XMLreader $reader) { //print "\nImportIssue process()\n"; $t_project_id = helper_get_current_project(); // TODO: category_get_id_by_name could work by default on current project $userId = auth_get_current_user_id(); $depth = $reader->depth; while ($reader->read() && ($reader->depth > $depth || $reader->nodeType != XMLReader::END_ELEMENT)) { if ($reader->nodeType == XMLReader::ELEMENT) { switch ($reader->localName) { case 'reporter': $t_old_id = $reader->getAttribute('id'); $reader->read(); $this->newbug_->reporter_id = $this->get_user_id($reader->value, $userId); //echo "reporter: old id = $t_old_id - new id = {$this->newbug_->reporter_id}\n"; break; case 'handler': $t_old_id = $reader->getAttribute('id'); $reader->read(); $this->newbug_->handler_id = $this->get_user_id($reader->value, $userId); //echo "handler: old id = $t_old_id - new id = {$this->newbug_->handler_id}\n"; break; case 'category': $this->newbug_->category_id = $this->defaultCategory_; if (version_compare(MANTIS_VERSION, '1.2', '>') === true) { $reader->read(); if ($this->keepCategory_) { # Check for the category's existence in the current project # well as its parents (if any) $t_projects_hierarchy = project_hierarchy_inheritance($t_project_id); foreach ($t_projects_hierarchy as $t_project) { $t_category_id = category_get_id_by_name($reader->value, $t_project, false); if ($t_category_id !== false) { $this->newbug_->category_id = $t_category_id; break; } } } // echo "new id = {$this->newbug_->category_id}\n"; } break; case 'eta': case 'priority': case 'projection': case 'reproducibility': case 'resolution': case 'severity': case 'status': case 'view_state': $t_field = $reader->localName; $t_id = $reader->getAttribute('id'); $reader->read(); $t_value = $reader->value; // Here we assume ids have the same meaning in both installations // TODO add a check for customized values $this->newbug_->{$t_field} = $t_id; break; case 'id': $reader->read(); $this->old_id_ = $reader->value; break; case 'project': // ignore original value, use current project $this->newbug_->project_id = $t_project_id; break; default: $field = $reader->localName; //echo "using default handler for field: $field\n"; $reader->read(); $this->newbug_->{$field} = $reader->value; } } } // now save the new bug $this->new_id_ = $this->newbug_->create(); //echo "\nnew bug: $this->new_id_\n"; }
/** * Moves an issue from a project to another. * * @todo Validate with sub-project / category inheritance scenarios. * @param int p_bug_id The bug to be moved. * @param int p_target_project_id The target project to move the bug to. * @access public */ function bug_move($p_bug_id, $p_target_project_id) { // Attempt to move disk based attachments to new project file directory. file_move_bug_attachments($p_bug_id, $p_target_project_id); // Move the issue to the new project. bug_set_field($p_bug_id, 'project_id', $p_target_project_id); // Update the category if needed $t_category_id = bug_get_field($p_bug_id, 'category_id'); // Bug has no category if ($t_category_id == 0) { // Category is required in target project, set it to default if (ON != config_get('allow_no_category', null, null, $p_target_project_id)) { bug_set_field($p_bug_id, 'category_id', config_get('default_category_for_moves')); } } else { $t_category_project_id = category_get_field($t_category_id, 'project_id'); if ($t_category_project_id != ALL_PROJECTS && !in_array($t_category_project_id, project_hierarchy_inheritance($p_target_project_id))) { // Map by name $t_category_name = category_get_field($t_category_id, 'name'); $t_target_project_category_id = category_get_id_by_name($t_category_name, $p_target_project_id, false); if ($t_target_project_category_id === false) { // Use default category after moves, since there is no match by name. $t_target_project_category_id = config_get('default_category_for_moves'); } bug_set_field($p_bug_id, 'category_id', $t_target_project_category_id); } } }
/** * Return all categories for the specified project id. * Obeys project hierarchies and such. * @param int $p_project_id Project id * @param bool $p_inherit indicates whether to inherit categories from parent projects, or null to use configuration default. * @param bool $p_sort_by_project * @return array array of categories * @access public */ function category_get_all_rows( $p_project_id, $p_inherit = null, $p_sort_by_project = false ) { global $g_category_cache, $g_cache_category_project; if( isset( $g_cache_category_project[ (int)$p_project_id ] ) ) { if( !empty( $g_cache_category_project[ (int)$p_project_id ]) ) { foreach( $g_cache_category_project[ (int)$p_project_id ] as $t_id ) { $t_categories[] = category_get_row( $t_id ); } if( $p_sort_by_project ) { category_sort_rows_by_project( $p_project_id ); usort( $t_categories, 'category_sort_rows_by_project' ); category_sort_rows_by_project( null ); } return $t_categories; } else { return array(); } } $c_project_id = db_prepare_int( $p_project_id ); $t_category_table = db_get_table( 'category' ); $t_project_table = db_get_table( 'project' ); if ( $c_project_id == ALL_PROJECTS ) { $t_inherit = false; } else { if ( $p_inherit === null ) { $t_inherit = config_get( 'subprojects_inherit_categories' ); } else { $t_inherit = $p_inherit; } } if ( $t_inherit ) { $t_project_ids = project_hierarchy_inheritance( $p_project_id ); $t_project_where = ' project_id IN ( ' . implode( ', ', $t_project_ids ) . ' ) '; } else { $t_project_where = ' project_id=' . $p_project_id . ' '; } $query = "SELECT c.*, p.name AS project_name FROM $t_category_table c LEFT JOIN $t_project_table p ON c.project_id=p.id WHERE $t_project_where ORDER BY c.name "; $result = db_query_bound( $query ); $count = db_num_rows( $result ); $rows = array(); for( $i = 0;$i < $count;$i++ ) { $row = db_fetch_array( $result ); $rows[] = $row; $g_category_cache[(int) $row['id']] = $row; } if( $p_sort_by_project ) { category_sort_rows_by_project( $p_project_id ); usort( $rows, 'category_sort_rows_by_project' ); category_sort_rows_by_project( null ); } return $rows; }
/** * Return all categories for the specified project id. * Obeys project hierarchies and such. * @param integer $p_project_id A Project identifier. * @param boolean $p_inherit Indicates whether to inherit categories from parent projects, or null to use configuration default. * @param boolean $p_sort_by_project Whether to sort by project. * @return array array of categories * @access public */ function category_get_all_rows($p_project_id, $p_inherit = null, $p_sort_by_project = false) { global $g_category_cache, $g_cache_category_project; if (isset($g_cache_category_project[(int) $p_project_id])) { if (!empty($g_cache_category_project[(int) $p_project_id])) { foreach ($g_cache_category_project[(int) $p_project_id] as $t_id) { $t_categories[] = category_get_row($t_id); } if ($p_sort_by_project) { category_sort_rows_by_project($p_project_id); usort($t_categories, 'category_sort_rows_by_project'); category_sort_rows_by_project(null); } return $t_categories; } else { return array(); } } $c_project_id = (int) $p_project_id; if ($c_project_id == ALL_PROJECTS) { $t_inherit = false; } else { if ($p_inherit === null) { $t_inherit = config_get('subprojects_inherit_categories'); } else { $t_inherit = $p_inherit; } } if ($t_inherit) { $t_project_ids = project_hierarchy_inheritance($p_project_id); $t_project_where = ' project_id IN ( ' . implode(', ', $t_project_ids) . ' ) '; } else { $t_project_where = ' project_id=' . $p_project_id . ' '; } $t_query = 'SELECT c.*, p.name AS project_name FROM {category} c LEFT JOIN {project} p ON c.project_id=p.id WHERE ' . $t_project_where . ' ORDER BY c.name'; $t_result = db_query($t_query); $t_rows = array(); while ($t_row = db_fetch_array($t_result)) { $t_rows[] = $t_row; $g_category_cache[(int) $t_row['id']] = $t_row; } if ($p_sort_by_project) { category_sort_rows_by_project($p_project_id); usort($t_rows, 'category_sort_rows_by_project'); category_sort_rows_by_project(null); } return $t_rows; }
function print_category_filter_option_list($p_category_name = '', $p_project_id = null) { $t_category_table = db_get_table('category'); $t_project_table = db_get_table('project'); if (null === $p_project_id) { $c_project_id = helper_get_current_project(); } else { $c_project_id = db_prepare_int($p_project_id); } $t_project_ids = project_hierarchy_inheritance($c_project_id); $t_subproject_ids = array(); foreach ($t_project_ids as $t_project_id) { $t_subproject_ids = array_merge($t_subproject_ids, current_user_get_all_accessible_subprojects($t_project_id)); } $t_project_ids = array_merge($t_project_ids, $t_subproject_ids); $t_project_where = ' project_id IN ( ' . implode(', ', $t_project_ids) . ' ) '; # grab all categories in the project category table $cat_arr = array(); $query = "SELECT DISTINCT name FROM {$t_category_table}\n\t\t\t\tWHERE {$t_project_where}\n\t\t\t\tORDER BY name"; $result = db_query($query); while ($row = db_fetch_array($result)) { $cat_arr[] = $row['name']; } sort($cat_arr); foreach ($cat_arr as $t_name) { $t_name = string_attribute($t_name); echo '<option value="' . $t_name . '"'; check_selected(string_attribute($p_category_name), $t_name); echo '>' . $t_name . '</option>'; } }