📄 topic.pm
字号:
################################################################################ Codestriker: Copyright (c) 2001, 2002 David Sitsky. All rights reserved.# sits@users.sourceforge.net## This program is free software; you can redistribute it and modify it under# the terms of the GPL.# Model object for handling topic data.package Codestriker::Model::Topic;use strict;use Encode qw(decode_utf8);use Codestriker::DB::DBI;use Codestriker::Model::File;use Codestriker::Model::Metrics;sub new { my ($class, $topicid) = @_; my $self = {}; $self->{topicid} = 0; $self->{author} = ""; $self->{title} = ""; $self->{bug_ids} = ""; $self->{reviewers} = ""; $self->{cc} = ""; $self->{description} = ""; $self->{document} = ""; $self->{creation_ts} = ""; $self->{modified_ts} = ""; $self->{topic_state} = ""; $self->{topic_state_id} = 0; $self->{version} = 0; $self->{start_tag} = ""; $self->{end_tag} = ""; $self->{module} = ""; $self->{repository} = ""; $self->{project_id} = ""; $self->{project_name} = ""; $self->{obsoleted_topics} = []; $self->{obsoleted_by} = []; $self->{comments} = []; $self->{metrics} = Codestriker::Model::Metrics->new($topicid); bless $self, $class; if (defined($topicid)) { $self->read($topicid); } return $self;}# Delete the specified participant type from the topic.sub _delete_participants($$$) { my ($self, $dbh, $type) = @_; my $delete_participants = $dbh->prepare_cached('DELETE FROM participant ' . 'WHERE topicid = ? AND type = ?'); my $success = defined $delete_participants; $success &&= $delete_participants->execute($self->{topicid}, $type); return $success;}# Insert the specified participants into the topic.sub _insert_participants($$$$$) { my ($self, $dbh, $type, $participants, $timestamp) = @_; my $insert_participant = $dbh->prepare_cached('INSERT INTO participant (email, topicid, type,' . 'state, modified_ts, version) ' . 'VALUES (?, ?, ?, ?, ?, ?)'); my $success = defined $insert_participant; my @participants = split /, /, $participants; for (my $i = 0; $i <= $#participants; $i++) { $success &&= $insert_participant->execute($participants[$i], $self->{topicid}, $type, 0, $timestamp, 0); } return $success;}# Delete the bugids associated with a particular topic.sub _delete_bug_ids($$) { my ($self, $dbh) = @_; my $delete_topicbug = $dbh->prepare_cached('DELETE FROM topicbug WHERE topicid = ?'); my $success = defined $delete_topicbug; $success &&= $delete_topicbug->execute($self->{topicid}); return $success;}# Insert the comma-separated list of bug_ids into the topic.sub _insert_bug_ids($$$) { my ($self, $dbh, $bug_ids) = @_; my $insert_bugs = $dbh->prepare_cached('INSERT INTO topicbug (topicid, bugid) ' . 'VALUES (?, ?)'); my $success = defined $insert_bugs; my @bug_ids = split /, /, $bug_ids; for (my $i = 0; $i <= $#bug_ids; $i++) { $success &&= $insert_bugs->execute($self->{topicid}, $bug_ids[$i]); } return $success;}# Create a new topic with all of the specified properties.sub create($$$$$$$$$$$$) { my ($self, $topicid, $author, $title, $state, $bug_ids, $reviewers, $cc, $description, $document, $start_tag, $end_tag, $module, $repository, $projectid, $deltas_ref, $obsoleted_topics) = @_; my $timestamp = Codestriker->get_timestamp(time); # Map the state to its number. my $stateid; for ($stateid = 0; $stateid <= $#Codestriker::topic_states; $stateid++) { last if ($Codestriker::topic_states[$stateid] eq $state); } if ($stateid > $#Codestriker::topic_states) { die "Unable to create topic to invalid state: \"$state\""; } $self->{topicid} = $topicid; $self->{author} = $author; $self->{title} = $title; $self->{bug_ids} = $bug_ids; $self->{reviewers} = $reviewers; $self->{cc} = $cc; $self->{description} = $description; $self->{document} = $document; $self->{creation_ts} = $timestamp; $self->{modified_ts} = $timestamp; $self->{topic_state} = $state; $self->{topic_state_id} = $stateid; $self->{project_id} = $projectid; $self->{version} = 0; $self->{start_tag} = $start_tag; $self->{end_tag} = $end_tag; $self->{module} = $module; $self->{repository} = $repository; $self->{metrics} = Codestriker::Model::Metrics->new($topicid); $self->{obsoleted_topics} = []; $self->{obsoleted_by} = []; # Obtain a database connection. my $dbh = Codestriker::DB::DBI->get_connection(); # Create the prepared statements. my $insert_topic = $dbh->prepare_cached('INSERT INTO topic (id, author, title, ' . 'description, document, state, creation_ts, ' . 'modified_ts, version, start_tag, end_tag, ' . 'module, repository, projectid) ' . 'VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'); my $success = defined $insert_topic; # Create all of the necessary rows. $success &&= $insert_topic->execute($topicid, $author, $title, $description, $document, $stateid, $timestamp, $timestamp, 0, $start_tag, $end_tag, $module, $repository, $projectid); # Insert the associated bug records. $success &&= $self->_insert_bug_ids($dbh, $bug_ids); # Insert the reviewers and cc participants. $success &&= $self->_insert_participants($dbh, $Codestriker::PARTICIPANT_REVIEWER, $reviewers, $timestamp); $success &&= $self->_insert_participants($dbh, $Codestriker::PARTICIPANT_CC, $cc, $timestamp); # Create the appropriate delta rows. $success &&= Codestriker::Model::File->create($dbh, $topicid, $deltas_ref); # Create any obsolete records, if any. if (defined $obsoleted_topics && $obsoleted_topics ne '') { my $insert_obsolete_topic = $dbh->prepare_cached('INSERT INTO topicobsolete ' . '(topicid, obsoleted_by) ' . 'VALUES (?, ?)'); my $success = defined $insert_obsolete_topic; my @data = split ',', $obsoleted_topics; my @obsoleted = (); for (my $i = 0; $success && $i <= $#data; $i+=2) { my $obsolete_topic_id = $data[$i]; my $obsolete_topic_version = $data[$i+1]; $success &&= $insert_obsolete_topic->execute($obsolete_topic_id, $topicid); push @obsoleted, $obsolete_topic_id if $success; } $self->{obsoleted_topics} = \@obsoleted; } Codestriker::DB::DBI->release_connection($dbh, $success); die $dbh->errstr unless $success;}# Read the contents of a specific topic, and return the results in the# provided reference variables.sub read($$) { my ($self, $topicid) = @_; $self->{topicid} = $topicid; # Obtain a database connection. my $dbh = Codestriker::DB::DBI->get_connection(); # Setup the prepared statements. my $select_topic = $dbh->prepare_cached('SELECT topic.id, topic.author, ' . 'topic.title, ' . 'topic.description, ' . 'topic.document, topic.state, ' . 'topic.creation_ts, ' . 'topic.modified_ts, ' . 'topic.version, ' . 'topic.start_tag, ' . 'topic.end_tag, ' . 'topic.module, ' . 'topic.repository, ' . 'project.id, project.name ' . 'FROM topic, project ' . 'WHERE topic.id = ? AND ' . 'topic.projectid = project.id'); my $select_bugs = $dbh->prepare_cached('SELECT bugid FROM topicbug WHERE topicid = ?'); my $select_participants = $dbh->prepare_cached('SELECT type, email FROM participant ' . 'WHERE topicid = ?'); my $select_obsoleted_by = $dbh->prepare_cached('SELECT obsoleted_by FROM topicobsolete ' . 'WHERE topicid = ?'); my $select_topics_obsoleted = $dbh->prepare_cached('SELECT topicid FROM topicobsolete ' . 'WHERE obsoleted_by = ?'); my $success = defined $select_topic && defined $select_bugs && defined $select_participants && defined $select_obsoleted_by && defined $select_topics_obsoleted; my $rc = $Codestriker::OK; # Retrieve the topic information. $success &&= $select_topic->execute($topicid); my ($id, $author, $title, $description, $document, $state, $creationtime, $modifiedtime, $version, $start_tag, $end_tag, $module, $repository, $projectid, $projectname); if ($success) { ($id, $author, $title, $description, $document, $state, $creationtime, $modifiedtime, $version, $start_tag, $end_tag, $module, $repository, $projectid, $projectname) = $select_topic->fetchrow_array(); $select_topic->finish(); if (!defined $id) { $success = 0; $rc = $Codestriker::INVALID_TOPIC; } } # Retrieve the bug ids relating to this topic. my @bugs = (); $success &&= $select_bugs->execute($topicid); if ($success) { my @data; while (@data = $select_bugs->fetchrow_array()) { push @bugs, $data[0]; } $select_bugs->finish(); } # Retrieve the participants in this review. my @reviewers = (); my @cc = (); $success &&= $select_participants->execute($topicid); if ($success) { while (my @data = $select_participants->fetchrow_array()) { if ($data[0] == 0) { push @reviewers, $data[1]; } else { push @cc, $data[1]; } } $select_participants->finish(); } # Retrieve the topics obsoleted by this topic. $success &&= $select_topics_obsoleted->execute($topicid); my @obsoleted_topics = (); if ($success) { while (my ($id) = $select_topics_obsoleted->fetchrow_array()) { push @obsoleted_topics, $id; } $select_topics_obsoleted->finish(); } # Retrieve the topics that have obsoleted this topic. $success &&= $select_obsoleted_by->execute($topicid); my @obsoleted_by = (); if ($success) { while (my ($id) = $select_obsoleted_by->fetchrow_array()) { push @obsoleted_by, $id; } $select_obsoleted_by->finish(); } # Close the connection, and check for any database errors. Codestriker::DB::DBI->release_connection($dbh, $success); # Store the data into the referenced variables if the operation was # successful. if ($success) { $self->{author} = $author; $self->{title} = decode_utf8($title); $self->{bug_ids} = join ', ', @bugs; $self->{reviewers} = join ', ', @reviewers; $self->{cc} = join ', ', @cc; $self->{description} = decode_utf8($description); $self->{document} = decode_utf8($document); $self->{creation_ts} = $creationtime; $self->{modified_ts} = $modifiedtime; $self->{topic_state} = $Codestriker::topic_states[$state]; $self->{topic_state_id} = $state; $self->{project_id} = $projectid; $self->{project_name} = decode_utf8($projectname); $self->{start_tag} = $start_tag; $self->{end_tag} = $end_tag; $self->{module} = $module; $self->{version} = $version; $self->{metrics} = Codestriker::Model::Metrics->new($topicid); $self->{obsoleted_topics} = \@obsoleted_topics;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -