コード例 #1
0
/**
 * Get the custom field id given an object ref.  The id is set based on the following algorithm:
 * - id from objectref (if not zero).
 * - id corresponding to name in object ref.
 * - 0, if object ref doesn't contain an id or a name.
 *
 * @param ObjectRef  $p_object_ref   An associate array with "id" and "name" keys.
 */
function mci_get_custom_field_id_from_objectref($p_object_ref)
{
    $p_object_ref = SoapObjectsFactory::unwrapObject($p_object_ref);
    if ((int) $p_object_ref['id'] != 0) {
        $t_id = (int) $p_object_ref['id'];
    } else {
        if (!is_blank($p_object_ref['name'])) {
            $t_id = custom_field_get_id_from_name($p_object_ref['name']);
        } else {
            $t_id = 0;
        }
    }
    return $t_id;
}
コード例 #2
0
ファイル: mc_api.php プロジェクト: elmarculino/mantisbt
/**
 * Return user id
 * @param stdClass $p_user User.
 * @return integer user id
 */
function mci_get_user_id(stdClass $p_user)
{
    $p_user = SoapObjectsFactory::unwrapObject($p_user);
    $t_user_id = 0;
    if (isset($p_user['id']) && (int) $p_user['id'] != 0) {
        $t_user_id = (int) $p_user['id'];
    } elseif (isset($p_user['name'])) {
        $t_user_id = user_get_id_by_name($p_user['name']);
    } elseif (isset($p_user['email'])) {
        $t_user_id = user_get_id_by_email($p_user['email']);
    }
    return $t_user_id;
}
コード例 #3
0
ファイル: mc_tag_api.php プロジェクト: fur81/zofaxiopeu
function mci_tag_set_for_issue($p_issue_id, $p_tags, $p_user_id)
{
    $t_tag_ids_to_attach = array();
    $t_tag_ids_to_detach = array();
    $t_submitted_tag_ids = array();
    $t_attached_tags = tag_bug_get_attached($p_issue_id);
    $t_attached_tag_ids = array();
    foreach ($t_attached_tags as $t_attached_tag) {
        $t_attached_tag_ids[] = $t_attached_tag['id'];
    }
    foreach ($p_tags as $t_tag) {
        $t_tag = SoapObjectsFactory::unwrapObject($t_tag);
        $t_submitted_tag_ids[] = $t_tag['id'];
        if (in_array($t_tag['id'], $t_attached_tag_ids)) {
            continue;
        } else {
            $t_tag_ids_to_attach[] = $t_tag['id'];
        }
    }
    foreach ($t_attached_tag_ids as $t_attached_tag_id) {
        if (in_array($t_attached_tag_id, $t_submitted_tag_ids)) {
            continue;
        } else {
            $t_tag_ids_to_detach[] = $t_attached_tag_id;
        }
    }
    foreach ($t_tag_ids_to_detach as $t_tag_id) {
        if (access_has_bug_level(config_get('tag_detach_threshold'), $p_issue_id, $p_user_id)) {
            tag_bug_detach($t_tag_id, $p_issue_id);
        }
    }
    foreach ($t_tag_ids_to_attach as $t_tag_id) {
        if (access_has_bug_level(config_get('tag_attach_threshold'), $p_issue_id, $p_user_id)) {
            tag_bug_attach($t_tag_id, $p_issue_id);
        }
    }
}
コード例 #4
0
/**
 * Get the enumeration id given an object ref.  The id is set based on the following algorithm:
 * - id from objectref.
 * - id corresponding to name in object ref.
 * - default value for the specified enumeration, if exists in configuration.
 * - first id, if object ref doesn't contain an id or a name.
 *
 * @param string     $p_enum         The name of the enumeration as in the MantisBT configuration file
 * @param ObjectRef  $p_object_ref   An associate array with "id" and "name" keys.
 * @return enum id
 */
function mci_get_enum_id_from_objectref($p_enum, $p_object_ref)
{
    $p_object_ref = SoapObjectsFactory::unwrapObject($p_object_ref);
    if (!is_null($p_object_ref) && isset($p_object_ref['id']) && (int) $p_object_ref['id'] != 0) {
        $t_id = (int) $p_object_ref['id'];
    } else {
        $t_enum = config_get($p_enum . '_enum_string');
        if (!is_null($p_object_ref) && isset($p_object_ref['name']) && !is_blank($p_object_ref['name'])) {
            $t_id = mci_get_enum_value_from_label($t_enum, $p_object_ref['name']);
            if ($t_id == 0) {
                $t_id = config_get('mc_' . $p_enum . '_enum_default_when_not_found');
            }
        } else {
            $t_default_id = config_get('default_bug_' . $p_enum, 0);
            if ($t_default_id == 0) {
                $t_array = mci_explode_to_objectref($p_enum);
                $t_id = (int) $t_array[0]['id'];
            } else {
                $t_id = $t_default_id;
            }
        }
    }
    return $t_id;
}
コード例 #5
0
ファイル: mc_issue_api.php プロジェクト: elmarculino/mantisbt
/**
 * Submit a new relationship.
 *
 * @param string   $p_username     The name of the user trying to add a note to an issue.
 * @param string   $p_password     The password of the user.
 * @param integer  $p_issue_id     The id of the issue of the source issue.
 * @param stdClass $p_relationship The relationship to add (RelationshipData SOAP object).
 * @return integer The id of the added relationship.
 */
function mc_issue_relationship_add($p_username, $p_password, $p_issue_id, stdClass $p_relationship)
{
    global $g_project_override;
    $t_user_id = mci_check_login($p_username, $p_password);
    $p_relationship = SoapObjectsFactory::unwrapObject($p_relationship);
    $t_dest_issue_id = $p_relationship['target_id'];
    $t_rel_type = SoapObjectsFactory::unwrapObject($p_relationship['type']);
    if ($t_user_id === false) {
        return mci_soap_fault_login_failed();
    }
    $t_project_id = bug_get_field($p_issue_id, 'project_id');
    $g_project_override = $t_project_id;
    if (!mci_has_readwrite_access($t_user_id, $t_project_id)) {
        return mci_soap_fault_access_denied($t_user_id);
    }
    # user has access to update the bug...
    if (!access_has_bug_level(config_get('update_bug_threshold'), $p_issue_id, $t_user_id)) {
        return mci_soap_fault_access_denied($t_user_id, 'Active user does not have access level required to add a relationship to this issue');
    }
    # source and destination bugs are the same bug...
    if ($p_issue_id == $t_dest_issue_id) {
        return SoapObjectsFactory::newSoapFault('Client', 'An issue can\'t be related to itself.');
    }
    # the related bug exists...
    if (!bug_exists($t_dest_issue_id)) {
        return SoapObjectsFactory::newSoapFault('Client', 'Issue \'' . $t_dest_issue_id . '\' not found.');
    }
    # bug is not read-only...
    if (bug_is_readonly($p_issue_id)) {
        return mci_soap_fault_access_denied($t_user_id, 'Issue \'' . $p_issue_id . '\' is readonly');
    }
    # user can access to the related bug at least as viewer...
    if (!access_has_bug_level(config_get('view_bug_threshold', null, null, $t_project_id), $t_dest_issue_id, $t_user_id)) {
        return mci_soap_fault_access_denied($t_user_id, 'The issue \'' . $t_dest_issue_id . '\' requires higher access level');
    }
    $t_old_id_relationship = relationship_same_type_exists($p_issue_id, $t_dest_issue_id, $t_rel_type['id']);
    if ($t_old_id_relationship == 0) {
        log_event(LOG_WEBSERVICE, 'adding relationship type \'' . $t_rel_type['id'] . '\' between \'' . $p_issue_id . '\' and \'' . $t_dest_issue_id . '\'');
        relationship_add($p_issue_id, $t_dest_issue_id, $t_rel_type['id']);
        # The above function call into MantisBT does not seem to return a valid BugRelationshipData object.
        # So we call db_insert_id in order to find the id of the created relationship.
        $t_relationship_id = db_insert_id(db_get_table('bug_relationship'));
        # Add log line to the history (both bugs)
        history_log_event_special($p_issue_id, BUG_ADD_RELATIONSHIP, $t_rel_type['id'], $t_dest_issue_id);
        history_log_event_special($t_dest_issue_id, BUG_ADD_RELATIONSHIP, relationship_get_complementary_type($t_rel_type['id']), $p_issue_id);
        # update bug last updated for both bugs
        bug_update_date($p_issue_id);
        bug_update_date($t_dest_issue_id);
        # send email notification to the users addressed by both the bugs
        email_relationship_added($p_issue_id, $t_dest_issue_id, $t_rel_type['id']);
        email_relationship_added($t_dest_issue_id, $p_issue_id, relationship_get_complementary_type($t_rel_type['id']));
        return $t_relationship_id;
    } else {
        return SoapObjectsFactory::newSoapFault('Client', 'Relationship already exists.');
    }
}
コード例 #6
0
/**
 * Update a project
 *
 * @param string   $p_username   The name of the user.
 * @param string   $p_password   The password of the user.
 * @param integer  $p_project_id A project's identifier.
 * @param stdClass $p_project    A new ProjectData structure.
 * @return boolean returns true or false depending on the success of the update action
 */
function mc_project_update($p_username, $p_password, $p_project_id, stdClass $p_project)
{
    global $g_project_override;
    $t_user_id = mci_check_login($p_username, $p_password);
    if ($t_user_id === false) {
        return mci_soap_fault_access_denied();
    }
    if (!mci_has_administrator_access($t_user_id, $p_project_id)) {
        return mci_soap_fault_access_denied($t_user_id);
    }
    if (!project_exists($p_project_id)) {
        return SoapObjectsFactory::newSoapFault('Client', 'Project \'' . $p_project_id . '\' does not exist.');
    }
    $g_project_override = $p_project_id;
    $p_project = SoapObjectsFactory::unwrapObject($p_project);
    if (!isset($p_project['name'])) {
        return SoapObjectsFactory::newSoapFault('Client', 'Missing required field \'name\'.');
    } else {
        $t_name = $p_project['name'];
    }
    # check to make sure project doesn't already exist
    if ($t_name != project_get_name($p_project_id)) {
        if (!project_is_name_unique($t_name)) {
            return SoapObjectsFactory::newSoapFault('Client', 'Project name exists');
        }
    }
    if (!isset($p_project['description'])) {
        $t_description = project_get_field($p_project_id, 'description');
    } else {
        $t_description = $p_project['description'];
    }
    if (!isset($p_project['status'])) {
        $t_status = project_get_field($p_project_id, 'status');
    } else {
        $t_status = $p_project['status'];
    }
    if (!isset($p_project['view_state'])) {
        $t_view_state = project_get_field($p_project_id, 'view_state');
    } else {
        $t_view_state = $p_project['view_state'];
    }
    if (!isset($p_project['file_path'])) {
        $t_file_path = project_get_field($p_project_id, 'file_path');
    } else {
        $t_file_path = $p_project['file_path'];
    }
    if (!isset($p_project['enabled'])) {
        $t_enabled = project_get_field($p_project_id, 'enabled');
    } else {
        $t_enabled = $p_project['enabled'];
    }
    if (!isset($p_project['inherit_global'])) {
        $t_inherit_global = project_get_field($p_project_id, 'inherit_global');
    } else {
        $t_inherit_global = $p_project['inherit_global'];
    }
    $t_project_status = mci_get_project_status_id($t_status);
    $t_project_view_state = mci_get_project_view_state_id($t_view_state);
    project_update($p_project_id, $t_name, $t_description, $t_project_status, $t_project_view_state, $t_file_path, $t_enabled, $t_inherit_global);
    return true;
}
コード例 #7
0
ファイル: mc_tag_api.php プロジェクト: gtn/mantisbt
/**
 * Set tag(s) for a given issue id
 * @param integer $p_issue_id Issue id.
 * @param array   $p_tags     Array of tags.
 * @param integer $p_user_id  User id.
 * @return void
 */
function mci_tag_set_for_issue($p_issue_id, array $p_tags, $p_user_id)
{
    $t_tag_ids_to_attach = array();
    $t_tag_ids_to_detach = array();
    $t_submitted_tag_ids = array();
    $t_attached_tags = tag_bug_get_attached($p_issue_id);
    $t_attached_tag_ids = array();
    foreach ($t_attached_tags as $t_attached_tag) {
        $t_attached_tag_ids[] = $t_attached_tag['id'];
    }
    foreach ($p_tags as $t_tag) {
        $t_tag = SoapObjectsFactory::unwrapObject($t_tag);
        $t_submitted_tag_ids[] = $t_tag['id'];
        if (in_array($t_tag['id'], $t_attached_tag_ids)) {
            continue;
        } else {
            $t_tag_ids_to_attach[] = $t_tag['id'];
        }
    }
    foreach ($t_attached_tag_ids as $t_attached_tag_id) {
        if (in_array($t_attached_tag_id, $t_submitted_tag_ids)) {
            continue;
        } else {
            $t_tag_ids_to_detach[] = $t_attached_tag_id;
        }
    }
    foreach ($t_tag_ids_to_detach as $t_tag_id) {
        if (access_has_bug_level(config_get('tag_detach_threshold'), $p_issue_id, $p_user_id)) {
            log_event(LOG_WEBSERVICE, 'detaching tag id \'' . $t_tag_id . '\' from issue \'' . $p_issue_id . '\'');
            tag_bug_detach($t_tag_id, $p_issue_id);
        }
    }
    foreach ($t_tag_ids_to_attach as $t_tag_id) {
        if (access_has_bug_level(config_get('tag_attach_threshold'), $p_issue_id, $p_user_id)) {
            log_event(LOG_WEBSERVICE, 'attaching tag id \'' . $t_tag_id . '\' to issue \'' . $p_issue_id . '\'');
            tag_bug_attach($t_tag_id, $p_issue_id);
        }
    }
}