Example #1
0
/**
 * Update a category of a project
 * @param string $p_username  The name of the user trying to access the categories.
 * @param string $p_password  The password of the user.
 * @param integer $p_project_id  The id of the project to retrieve the categories for.
 * @param string $p_category_name The name of the category to rename
 * @param string $p_category_name_new The new name of the category to rename
 * @param int $p_assigned_to User ID that category is assigned to
 * @return bool returns true or false depending on the success of the update action
 */
function mc_project_rename_category_by_name($p_username, $p_password, $p_project_id, $p_category_name, $p_category_name_new, $p_assigned_to)
{
    $t_user_id = mci_check_login($p_username, $p_password);
    if (null === $p_assigned_to) {
        return new soap_fault('Client', '', 'p_assigned_to needed');
    }
    if ($t_user_id === false) {
        return new soap_fault('Client', '', 'Access Denied');
    }
    if (!project_exists($p_project_id)) {
        return new soap_fault('Client', '', "Project '{$p_project_id}' does not exist.");
    }
    if (!mci_has_access(config_get('manage_project_threshold'), $t_user_id, $p_project_id)) {
        return new soap_fault('Client', '', 'Access Denied');
    }
    // find the id of the category
    $p_category_id = category_get_id_by_name($p_category_name, $p_project_id);
    // update the category
    return category_update($p_category_id, $p_category_name_new, $p_assigned_to);
}
Example #2
0
 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";
 }
Example #3
0
 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);
        }
    }
}
/**
 * Update a category of a project
 * @param string  $p_username          The name of the user trying to access the categories.
 * @param string  $p_password          The password of the user.
 * @param integer $p_project_id        The id of the project to retrieve the categories for.
 * @param string  $p_category_name     The name of the category to rename.
 * @param string  $p_category_name_new The new name of the category to rename.
 * @param integer $p_assigned_to       User ID that category is assigned to.
 * @return boolean returns true or false depending on the success of the update action
 */
function mc_project_rename_category_by_name($p_username, $p_password, $p_project_id, $p_category_name, $p_category_name_new, $p_assigned_to)
{
    global $g_project_override;
    $t_user_id = mci_check_login($p_username, $p_password);
    if (null === $p_assigned_to) {
        return SoapObjectsFactory::newSoapFault('Client', 'p_assigned_to needed');
    }
    if ($t_user_id === false) {
        return mci_soap_fault_access_denied();
    }
    if (!project_exists($p_project_id)) {
        return SoapObjectsFactory::newSoapFault('Client', 'Project \'' . $p_project_id . '\' does not exist.');
    }
    $g_project_override = $p_project_id;
    if (!mci_has_access(config_get('manage_project_threshold'), $t_user_id, $p_project_id)) {
        return mci_soap_fault_access_denied();
    }
    # find the id of the category
    $p_category_id = category_get_id_by_name($p_category_name, $p_project_id);
    # update the category
    return category_update($p_category_id, $p_category_name_new, $p_assigned_to);
}
Example #6
0
/**
 * 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 );

	// Check if the category for the issue is global or not.
	$t_category_id = bug_get_field( $p_bug_id, 'category_id' );
	$t_category_project_id = category_get_field( $t_category_id, 'project_id' );

	// If not global, then attempt mapping it to the new project.
	if ( $t_category_project_id != ALL_PROJECTS && !project_hierarchy_inherit_parent( $p_target_project_id, $t_category_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, /* triggerErrors */ 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 );
	}
}
Example #7
0
 function get_category_id($p_project_id)
 {
     $t_cat_name = 'acra report';
     $t_cat_id = category_get_id_by_name($t_cat_name, $p_project_id, false);
     if ($t_cat_id === false) {
         category_add($p_project_id, $t_cat_name);
         $t_cat_id = category_get_id_by_name($t_cat_name, $p_project_id);
     }
     return $t_cat_id;
 }