⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 topic.pm

📁 codestriker is a develop useful tool to review code on web user interface.
💻 PM
📖 第 1 页 / 共 3 页
字号:
          $self->_insert_participants($dbh, $Codestriker::PARTICIPANT_CC,                                      $new_cc, $modified_ts);        $self->{cc} = $new_cc;    }    Codestriker::DB::DBI->release_connection($dbh, $success);    if ($success == 0 && $rc == $Codestriker::OK) {        # Unexpected DB error.        die $dbh->errstr;    }    return $rc;}# Return back the list of topics which match the specified parameters.sub query($$$$$$$$$$$$$$\@\@\@) {    my ($type, $sauthor, $sreviewer, $scc, $sbugid, $sstate, $sproject, $stext,        $stitle, $sdescription, $scomments, $sbody, $sfilename, $sort_order) = @_;    # Obtain a database connection.    my $database = Codestriker::DB::Database->get_database();    my $dbh = $database->get_connection();    # If there are wildcards in the author, reviewer, or CC fields,    # replace them with the appropriate SQL wildcards.    $sauthor =~ s/\*/%/g if $sauthor ne "";    $sreviewer =~ s/\*/%/g if $sreviewer ne "";    $scc =~ s/\*/%/g if $scc ne "";    # Automatically surround the search term term in wildcards, and replace    # any wildcards appropriately.    if ($stext ne "") {        $stext =~ s/\*/%/g;        if (! ($stext =~ /^%/o) ) {            $stext = "%${stext}";        }        if (! ($stext =~ /%$/o) ) {            $stext = "${stext}%";        }    }    # Build up the query conditions.    my $author_part = $sauthor eq "" ? "" :      $database->case_insensitive_like("topic.author", $sauthor);    my $reviewer_part = $sreviewer eq "" ? "" :      ($database->case_insensitive_like("participant.email", $sreviewer) .       " AND type = $Codestriker::PARTICIPANT_REVIEWER");    my $cc_part = $scc eq "" ? "" :      ($database->case_insensitive_like("participant.email", $scc) .       " AND type = $Codestriker::PARTICIPANT_CC");    my $bugid_part = $sbugid eq "" ? "" :      ("topicbug.bugid = " . $dbh->quote($sbugid));    # Build up the state condition.    my $state_part = "";    if ($sstate ne "") {        $state_part = "topic.state IN ($sstate)";    }    # Build up the project condition.    my $project_part = "";    if (defined $sproject && $sproject ne "") {        $project_part = "topic.projectid IN ($sproject)";    }    my $text_title_part =      $database->case_insensitive_like("topic.title", $stext);    my $text_description_part =      $database->case_insensitive_like("topic.description", $stext);    my $text_body_part =      $database->case_insensitive_like("topic.document", $stext);    my $text_filename_part =      $database->case_insensitive_like("topicfile.filename", $stext);    my $text_comment_part =      $database->case_insensitive_like("commentdata.commentfield", $stext);    # Build up the base query.    my $query =      "SELECT topic.id, topic.title, topic.description, " .        "topic.author, topic.creation_ts, " .          "topic.state, topicbug.bugid, participant.email, participant.type, " .            "topic.version ";    # Since Oracle < 9i can't handle LEFT OUTER JOIN, determine what tables    # are required in this query and add them in.    my $using_oracle = $Codestriker::db =~ /^DBI:Oracle/i;    if ($using_oracle) {        my @fromlist = ("topic", "topicbug", "participant");        if ($stext ne "" && $scomments) {            push @fromlist, "commentstate";            push @fromlist, "commentdata";        }        if ($stext ne "" && $sfilename) {            push @fromlist, "topicfile";        }        $query .= "FROM " . (join ', ', @fromlist) . " WHERE ";    } else {        $query .= "FROM topic ";    }    # Add the join to topicbug and participant.    if ($using_oracle) {        $query .= "topic.id = topicbug.topicid(+) AND " .          "topic.id = participant.topicid(+) ";    } else {        $query .= "LEFT OUTER JOIN topicbug ON topic.id = topicbug.topicid " .          "LEFT OUTER JOIN participant ON topic.id = participant.topicid ";    }    # Join with the comment table if required - GACK!    if ($stext ne "" && $scomments) {        if ($using_oracle) {            $query .=              ' AND topic.id = commentstate.topicid(+) AND '.                'commentstate.id = commentdata.commentstateid(+) ';        } else {            $query .=              'LEFT OUTER JOIN commentstate ON ' .                'topic.id = commentstate.topicid '.                  'LEFT OUTER JOIN commentdata ON ' .                    'commentstate.id = commentdata.commentstateid ';        }    }    # Join with the file table if required.    if ($stext ne "" && $sfilename) {        if ($using_oracle) {            $query .= ' AND topic.id = topicfile.topicid(+) ';        } else {            $query .= 'LEFT OUTER JOIN topicfile ON ' .              'topicfile.topicid = topic.id ';        }    }    # Combine the "AND" conditions together.  Note for Oracle, the 'WHERE'    # keyword has already been used.    my $first_condition = $using_oracle ? 0 : 1;    $query = _add_condition($query, $author_part, \$first_condition);    $query = _add_condition($query, $reviewer_part, \$first_condition);    $query = _add_condition($query, $cc_part, \$first_condition);    $query = _add_condition($query, $bugid_part, \$first_condition);    # Handle the state set.    if ($state_part ne "") {        $query = _add_condition($query, $state_part, \$first_condition);    }    # Handle the project set.    if ($project_part ne "") {        $query = _add_condition($query, $project_part, \$first_condition);    }    # Handle the text searching part, which is a series of ORs.    if ($stext ne "") {        my @text_cond = ();        push @text_cond, $text_title_part if $stitle;        push @text_cond, $text_description_part if $sdescription;        push @text_cond, $text_body_part if $sbody;        push @text_cond, $text_filename_part if $sfilename;        push @text_cond, $text_comment_part if $scomments;        if ($#text_cond >= 0) {            my $cond = join  ' OR ', @text_cond;            $query = _add_condition($query, $cond, \$first_condition);        }    }    # Order the result by the creation date field.    if (scalar( @$sort_order ) == 0) {        # no sort order, defaults to topic creation.        $query .= " ORDER BY topic.creation_ts ";    } else {        my @sort_terms;        foreach my $sortItem (@$sort_order) {            if ($sortItem eq "+title") {                push @sort_terms, "topic.title";            } elsif ($sortItem eq "-title") {                push @sort_terms, "topic.title DESC";            } elsif ($sortItem eq "+author") {                push @sort_terms, "topic.author ";            } elsif ($sortItem eq "-author") {                push @sort_terms, "topic.author DESC";            } elsif ($sortItem eq "+created") {                push @sort_terms, "topic.creation_ts ";            } elsif ($sortItem eq "-created") {                push @sort_terms, "topic.creation_ts DESC";            } elsif ($sortItem eq "+state") {                push @sort_terms, "topic.state ";            } elsif ($sortItem eq "-state") {                push @sort_terms, "topic.state DESC";            } else {                die "unknown sort key $sortItem";            }        }        $query .= " ORDER BY " . join(',',@sort_terms) . " ";    }    my $select_topic = $dbh->prepare_cached($query);    my $success = defined $select_topic;    $success &&= $select_topic->execute();    my $lastid;    my @topic_list;    if ($success) {        my ($id, $title, $author, $description, $creation_ts, $state, $bugid,            $email, $type, $version);        while (($id, $title, $description, $author, $creation_ts, $state,                $bugid, $email, $type, $version) =               $select_topic->fetchrow_array()) {            # This is a bit heavy, but the search screen does need much            # of the information in the topic object, it is much cleaner            # to just return a fully formed topic object, rather than a            # array tunned. If performace is an issue, then the topic            # object should use lazy instatation to don't pull data from            # the database unless it is needed.            if ( !defined($lastid) || $id ne $lastid ) {                my $new_topic = Codestriker::Model::Topic->new($id);                push @topic_list,$new_topic;            }            $lastid = $id;        }        $select_topic->finish();    }    $database->release_connection();    die $dbh->errstr unless $success;    return @topic_list;}# Add the condition to the specified query string, returning the new query.sub _add_condition($$\$) {    my ($query, $condition, $first_cond_ref) = @_;    return $query if ($condition eq ""); # Nothing to do.    if ($$first_cond_ref) {        $$first_cond_ref = 0;        $query .= " WHERE (" . $condition . ") ";    } else {        $query .= " AND (" . $condition . ") ";    }    return $query;}# Delete the specified topic.sub delete($) {    my ($self) = @_;    # Obtain a database connection.    my $dbh = Codestriker::DB::DBI->get_connection();    # Create the prepared statements.    my $delete_topic = $dbh->prepare_cached('DELETE FROM topic WHERE id = ?');    my $select = $dbh->prepare_cached('SELECT id FROM commentstate ' .                                      'WHERE topicid = ?');    my $delete_comments =      $dbh->prepare_cached('DELETE FROM commentdata ' .                           'WHERE commentstateid = ?');    my $delete_commentstate_metric =      $dbh->prepare_cached('DELETE FROM commentstatemetric ' .                           'WHERE id = ?');    my $delete_commentstate =      $dbh->prepare_cached('DELETE FROM commentstate ' .                           'WHERE topicid = ?');    my $delete_file =      $dbh->prepare_cached('DELETE FROM topicfile WHERE topicid = ?');    my $delete_delta =      $dbh->prepare_cached('DELETE FROM delta WHERE topicid = ?');    my $topic_metrics =      $dbh->prepare_cached('DELETE FROM topicmetric WHERE topicid = ?');    my $user_metrics =      $dbh->prepare_cached('DELETE FROM topicusermetric WHERE topicid = ?');    my $topic_history =      $dbh->prepare_cached('DELETE FROM topichistory WHERE topicid = ?');    my $topic_view_history =      $dbh->prepare_cached('DELETE FROM topicviewhistory WHERE topicid = ?');    my $commentstate_history =      $dbh->prepare_cached('DELETE FROM commentstatehistory WHERE id = ?');    my $obsolete_records =      $dbh->prepare_cached('DELETE FROM topicobsolete WHERE ' .                           'topicid = ? OR obsoleted_by = ?');    my $success = defined $delete_topic && defined $delete_comments &&      defined $delete_commentstate && defined $select &&        defined $delete_file && defined $delete_delta &&          defined $topic_metrics && defined $user_metrics &&            defined $topic_history && defined $topic_view_history &&              defined $commentstate_history && $delete_commentstate_metric &&                defined $obsolete_records;    # Now do the deed.    $success &&= $select->execute($self->{topicid});    if ($success) {        foreach my $commentstate (@{$select->fetchall_arrayref()}) {            my $commentstateid = $commentstate->[0];            $success &&= $delete_comments->execute($commentstateid);            $success &&= $commentstate_history->execute($commentstateid);            $success &&= $delete_commentstate_metric->execute($commentstateid);        }    }    $success &&= $delete_commentstate->execute($self->{topicid});    $success &&= $delete_topic->execute($self->{topicid});    $success &&= $delete_comments->execute($self->{topicid});    $success &&= $delete_file->execute($self->{topicid});    $success &&= $delete_delta->execute($self->{topicid});    $success &&= $topic_metrics->execute($self->{topicid});    $success &&= $user_metrics->execute($self->{topicid});    $success &&= $self->_delete_bug_ids($dbh);    $success &&=      $self->_delete_participants($dbh, $Codestriker::PARTICIPANT_REVIEWER);    $success &&=      $self->_delete_participants($dbh, $Codestriker::PARTICIPANT_CC);    $success &&= $topic_history->execute($self->{topicid});    $success &&= $topic_view_history->execute($self->{topicid});    $success &&= $obsolete_records->execute($self->{topicid},                                            $self->{topicid});    Codestriker::DB::DBI->release_connection($dbh, $success);    # Update the topic state to deleted    $self->{topic_state} = "Deleted";    # Indicate the success of the operation.    return $success ? $Codestriker::OK : $Codestriker::INVALID_TOPIC;}1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -