[Rt-commit] rt branch, 4.0/disabled-articles, created. rt-4.0.22-18-gd875239
? sunnavy
sunnavy at bestpractical.com
Mon Oct 20 12:10:28 EDT 2014
The branch, 4.0/disabled-articles has been created
at d87523984b397ed7ce6f2ba21dee74cc1799d47a (commit)
- Log -----------------------------------------------------------------
commit d87523984b397ed7ce6f2ba21dee74cc1799d47a
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Oct 21 00:03:37 2014 +0800
don't delete articles, just disable them.
Fixes: #19323
diff --git a/etc/schema.Oracle b/etc/schema.Oracle
index 4bcae6c..fe98996 100755
--- a/etc/schema.Oracle
+++ b/etc/schema.Oracle
@@ -439,6 +439,7 @@ SortOrder NUMBER(11,0) DEFAULT 0 NOT NULL,
Class NUMBER(11,0) DEFAULT 0 NOT NULL,
Parent NUMBER(11,0) DEFAULT 0 NOT NULL,
URI varchar2(255),
+Disabled NUMBER(11,0) DEFAULT 0 NOT NULL,
Creator NUMBER(11,0) DEFAULT 0 NOT NULL,
Created DATE,
LastUpdatedBy NUMBER(11,0) DEFAULT 0 NOT NULL,
diff --git a/etc/schema.Pg b/etc/schema.Pg
index 565f76b..17f13df 100755
--- a/etc/schema.Pg
+++ b/etc/schema.Pg
@@ -673,6 +673,7 @@ SortOrder integer NOT NULL DEFAULT 0,
Class integer NOT NULL DEFAULT 0,
Parent integer NOT NULL DEFAULT 0,
URI varchar(255),
+Disabled smallint NOT NULL DEFAULT 0,
Creator integer NOT NULL DEFAULT 0,
Created TIMESTAMP NULL,
LastUpdatedBy integer NOT NULL DEFAULT 0,
diff --git a/etc/schema.SQLite b/etc/schema.SQLite
index 6897be2..6c57d18 100755
--- a/etc/schema.SQLite
+++ b/etc/schema.SQLite
@@ -470,6 +470,7 @@ SortOrder integer NOT NULL DEFAULT 0,
Class integer NOT NULL DEFAULT 0,
Parent integer NOT NULL DEFAULT 0,
URI varchar(255),
+Disabled smallint NOT NULL DEFAULT 0,
Creator integer NOT NULL DEFAULT 0,
Created TIMESTAMP NULL,
LastUpdatedBy integer NOT NULL DEFAULT 0,
diff --git a/etc/schema.mysql b/etc/schema.mysql
index e0ccecb..f89daa6 100755
--- a/etc/schema.mysql
+++ b/etc/schema.mysql
@@ -461,6 +461,7 @@ CREATE TABLE Articles (
Class int(11) NOT NULL default '0',
Parent int(11) NOT NULL default '0',
URI varchar(255) character set ascii default NULL,
+ Disabled int(2) NOT NULL default '0',
Creator int(11) NOT NULL default '0',
Created datetime default NULL,
LastUpdatedBy int(11) NOT NULL default '0',
diff --git a/lib/RT/Article.pm b/lib/RT/Article.pm
index e9f3d43..e8311ac 100644
--- a/lib/RT/Article.pm
+++ b/lib/RT/Article.pm
@@ -251,81 +251,21 @@ sub ValidateName {
# {{{ Delete
-=head2 Delete
-
-Delete all its transactions
-Delete all its custom field values
-Delete all its relationships
-Delete this article.
+sub Delete {
+ my $self = shift;
+ return $self->SetDisabled(1);
+}
-=cut
+# }}}
-sub Delete {
+sub SetDisabled {
my $self = shift;
unless ( $self->CurrentUserHasRight('DeleteArticle') ) {
return ( 0, $self->loc("Permission Denied") );
}
-
- $RT::Handle->BeginTransaction();
- my $linksto = $self->_Links( 'Target' );
- my $linksfrom = $self->_Links( 'Base' );
- my $cfvalues = $self->CustomFieldValues;
- my $txns = $self->Transactions;
- my $topics = $self->Topics;
-
- while ( my $item = $linksto->Next ) {
- my ( $val, $msg ) = $item->Delete();
- unless ($val) {
- $RT::Logger->crit( ref($item) . ": $msg" );
- $RT::Handle->Rollback();
- return ( 0, $self->loc('Internal Error') );
- }
- }
-
- while ( my $item = $linksfrom->Next ) {
- my ( $val, $msg ) = $item->Delete();
- unless ($val) {
- $RT::Logger->crit( ref($item) . ": $msg" );
- $RT::Handle->Rollback();
- return ( 0, $self->loc('Internal Error') );
- }
- }
-
- while ( my $item = $txns->Next ) {
- my ( $val, $msg ) = $item->Delete();
- unless ($val) {
- $RT::Logger->crit( ref($item) . ": $msg" );
- $RT::Handle->Rollback();
- return ( 0, $self->loc('Internal Error') );
- }
- }
-
- while ( my $item = $cfvalues->Next ) {
- my ( $val, $msg ) = $item->Delete();
- unless ($val) {
- $RT::Logger->crit( ref($item) . ": $msg" );
- $RT::Handle->Rollback();
- return ( 0, $self->loc('Internal Error') );
- }
- }
-
- while ( my $item = $topics->Next ) {
- my ( $val, $msg ) = $item->Delete();
- unless ($val) {
- $RT::Logger->crit( ref($item) . ": $msg" );
- $RT::Handle->Rollback();
- return ( 0, $self->loc('Internal Error') );
- }
- }
-
- $self->SUPER::Delete();
- $RT::Handle->Commit();
- return ( 1, $self->loc('Article Deleted') );
-
+ return $self->SUPER::SetDisabled(@_);
}
-# }}}
-
# {{{ Children
=head2 Children
@@ -796,6 +736,21 @@ Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
=cut
+=head2 Disabled
+
+Returns the current value of Disabled.
+(In the database, Disabled is stored as int(2).)
+
+
+
+=head2 SetDisabled VALUE
+
+
+Set Disabled to VALUE.
+Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
+(In the database, Disabled will be stored as a int(2).)
+
+
=head2 Creator
@@ -851,6 +806,8 @@ sub _CoreAccessible {
{read => 1, write => 1, type => 'int(11)', default => '0'},
URI =>
{read => 1, write => 1, type => 'varchar(255)', default => ''},
+ Disabled =>
+ {read => 1, write => 1, type => 'int(2)', default => '0'},
Creator =>
{read => 1, auto => 1, type => 'int(11)', default => '0'},
Created =>
diff --git a/lib/RT/Articles.pm b/lib/RT/Articles.pm
index 9bee844..0b429ae 100644
--- a/lib/RT/Articles.pm
+++ b/lib/RT/Articles.pm
@@ -57,6 +57,7 @@ sub Table {'Articles'}
sub _Init {
my $self = shift;
+ $self->{'with_disabled_column'} = 1;
$self->OrderByCols(
{ FIELD => 'SortOrder', ORDER => 'ASC' },
{ FIELD => 'Name', ORDER => 'ASC' },
diff --git a/share/html/Articles/Article/Edit.html b/share/html/Articles/Article/Edit.html
index dd8f945..3894498 100644
--- a/share/html/Articles/Article/Edit.html
+++ b/share/html/Articles/Article/Edit.html
@@ -198,6 +198,7 @@ elsif ( $id eq 'new' ) {
Name => $ARGS{'Name'},
Class => $ARGS{'Class'},
Topics => $ARGS{'Topics'},
+ Disabled => $ARGS{'Disabled'},
%create_args
);
push( @results, $msg );
@@ -239,7 +240,7 @@ else {
Why => loc("Unable to load article") );
}
- my @attribs = qw(Name Summary Class);
+ my @attribs = qw(Name Summary Class Disabled);
@results = UpdateRecordObject(
AttributesRef => \@attribs,
diff --git a/share/html/Articles/Article/Elements/EditBasics b/share/html/Articles/Article/Elements/EditBasics
index 705cb0d..d567223 100644
--- a/share/html/Articles/Article/Elements/EditBasics
+++ b/share/html/Articles/Article/Elements/EditBasics
@@ -64,6 +64,17 @@
% }
</td>
</tr>
+% if ($ARGS{'id'} eq 'new' || $ArticleObj->CurrentUserHasRight('DeleteArticle')) {
+<tr>
+<td class="label"><&|/l&>Disabled</&></td>
+<td>
+ <select name="Disabled">
+ <option <% ( $ArticleObj->id && $ArticleObj->Disabled || $ARGS{'Disabled'} ) ? 'selected="selected"' : '' |n %> value="1"><&|/l&>Yes</&></option>
+ <option <% ( $ArticleObj->id && $ArticleObj->Disabled || $ARGS{'Disabled'} ) ? '' : 'selected="selected"' |n %> value="0"><&|/l&>No</&></option>
+ </select>
+</td>
+</tr>
+% }
<%INIT>
</%INIT>
<%ARGS>
diff --git a/share/html/Elements/EditLinks b/share/html/Elements/EditLinks
index 7dfdfa7..07595d7 100644
--- a/share/html/Elements/EditLinks
+++ b/share/html/Elements/EditLinks
@@ -55,6 +55,7 @@
<td class="labeltop"><& ShowRelationLabel, id => $id, Label => loc('Depends on'), Relation => 'DependsOn' &>:</td>
<td class="value">
% while (my $link = $Object->DependsOn->Next) {
+% next if (UNIVERSAL::isa($link->TargetObj, 'RT::Article')) && $link->TargetObj->Disabled;
<input type="checkbox" class="checkbox" name="DeleteLink--<%$link->Type%>-<%$link->Target%>" value="1" />
<& ShowLink, URI => $link->TargetURI &><br />
% }
@@ -64,6 +65,7 @@
<td class="labeltop"><& ShowRelationLabel, id => $id, Label => loc('Depended on by'), Relation => 'DependedOnBy' &>:</td>
<td class="value">
% while (my $link = $Object->DependedOnBy->Next) {
+% next if (UNIVERSAL::isa($link->BaseObj, 'RT::Article')) && $link->BaseObj->Disabled;
<input type="checkbox" class="checkbox" name="DeleteLink-<%$link->Base%>-<%$link->Type%>-" value="1" />
<& ShowLink, URI => $link->BaseURI &><br />
% }
@@ -73,6 +75,7 @@
<td class="labeltop"><& ShowRelationLabel, id => $id, Label => loc('Parents'), Relation => 'Parents' &>:</td>
<td class="value">
% while (my $link = $Object->MemberOf->Next) {
+% next if (UNIVERSAL::isa($link->TargetObj, 'RT::Article')) && $link->TargetObj->Disabled;
<input type="checkbox" class="checkbox" name="DeleteLink--<%$link->Type%>-<%$link->Target%>" value="1" />
<& ShowLink, URI => $link->TargetURI &><br />
% }
@@ -82,6 +85,7 @@
<td class="labeltop"><& ShowRelationLabel, id => $id, Label => loc('Children'), Relation => 'Children' &>:</td>
<td class="value">
% while (my $link = $Object->Members->Next) {
+% next if (UNIVERSAL::isa($link->BaseObj, 'RT::Article')) && $link->BaseObj->Disabled;
<input type="checkbox" class="checkbox" name="DeleteLink-<%$link->Base%>-<%$link->Type%>-" value="1" />
<& ShowLink, URI => $link->BaseURI &><br />
% }
@@ -91,6 +95,7 @@
<td class="labeltop"><& ShowRelationLabel, id => $id, Label => loc('Refers to'), Relation => 'RefersTo' &>:</td>
<td class="value">
% while (my $link = $Object->RefersTo->Next) {
+% next if (UNIVERSAL::isa($link->TargetObj, 'RT::Article')) && $link->TargetObj->Disabled;
<input type="checkbox" class="checkbox" name="DeleteLink--<%$link->Type%>-<%$link->Target%>" value="1" />
<& ShowLink, URI => $link->TargetURI &><br />
%}
@@ -101,6 +106,7 @@
<td class="value">
% while (my $link = $Object->ReferredToBy->Next) {
% # Skip reminders
+% next if (UNIVERSAL::isa($link->BaseObj, 'RT::Article')) && $link->BaseObj->Disabled;
% next if (UNIVERSAL::isa($link->BaseObj, 'RT::Ticket') && $link->BaseObj->Type eq 'reminder');
<input type="checkbox" class="checkbox" name="DeleteLink-<%$link->Base%>-<%$link->Type%>-" value="1" />
<& ShowLink, URI => $link->BaseURI &><br />
diff --git a/share/html/Elements/ShowLinks b/share/html/Elements/ShowLinks
index 16fc56d..5c3ef3a 100644
--- a/share/html/Elements/ShowLinks
+++ b/share/html/Elements/ShowLinks
@@ -59,6 +59,7 @@ $depends_on = $Ticket->DependsOn;
while ( my $link = $depends_on->Next ) {
my $target = $link->TargetObj;
+ next if $target->isa('RT::Article') && $target->Disabled;
if ( $target && $target->isa('RT::Ticket') ) {
if ( $target->QueueObj->IsInactiveStatus( $target->Status ) ) {
push( @inactive, $link->TargetURI );
@@ -88,6 +89,7 @@ while ( my $link = $depends_on->Next ) {
<td class="value">
<ul>
% while (my $Link = $Ticket->DependedOnBy->Next) {
+% next if (UNIVERSAL::isa($Link->BaseObj, 'RT::Article')) && $Link->BaseObj->Disabled;
<li><& ShowLink, URI => $Link->BaseURI &></li>
% }
</ul>
@@ -118,6 +120,7 @@ while ( my $link = $depends_on->Next ) {
<td class="value">
<ul>
% while (my $Link = $Ticket->RefersTo->Next) {
+% next if (UNIVERSAL::isa($Link->TargetObj, 'RT::Article')) && $Link->TargetObj->Disabled;
<li><& ShowLink, URI => $Link->TargetURI &></li>
% }
</ul>
@@ -132,6 +135,7 @@ while ( my $link = $depends_on->Next ) {
<td class="value">
<ul>
% while (my $Link = $Ticket->ReferredToBy->Next) {
+% next if (UNIVERSAL::isa($Link->BaseObj, 'RT::Article')) && $Link->BaseObj->Disabled;
% next if (UNIVERSAL::isa($Link->BaseObj, 'RT::Ticket') && $Link->BaseObj->Type eq 'reminder');
<li><& ShowLink, URI => $Link->BaseURI &></li>
% }
diff --git a/share/html/Elements/Tabs b/share/html/Elements/Tabs
index 7e19bd3..b51d62f 100644
--- a/share/html/Elements/Tabs
+++ b/share/html/Elements/Tabs
@@ -798,7 +798,6 @@ my $build_main_nav = sub {
$tabs->child( display => title => loc('Display'), path => "/Articles/Article/Display.html?id=".$id );
$tabs->child( history => title => loc('History'), path => "/Articles/Article/History.html?id=".$id );
$tabs->child( modify => title => loc('Modify'), path => "/Articles/Article/Edit.html?id=".$id );
- $tabs->child( delete => title => loc('Delete'), path => "/Articles/Article/Delete.html?id=".$id );
}
}
@@ -822,9 +821,6 @@ my $build_main_nav = sub {
if ( $obj->CurrentUserHasRight('ModifyArticle') ) {
$tabs->child(modify => title => loc('Modify'), path => '/Articles/Article/Edit.html?id=' . $id );
}
- if ( $obj->CurrentUserHasRight('DeleteArticle') ) {
- $tabs->child(delete => title => loc('Delete'), path => '/Articles/Article/Delete.html?id=' . $id );
- }
}
}
diff --git a/share/html/Ticket/Elements/ShowMembers b/share/html/Ticket/Elements/ShowMembers
index 3f805ef..8b0edec 100644
--- a/share/html/Ticket/Elements/ShowMembers
+++ b/share/html/Ticket/Elements/ShowMembers
@@ -47,6 +47,7 @@
%# END BPS TAGGED BLOCK }}}
<ul>
% while (my $link = $members->Next) {
+% next if (UNIVERSAL::isa($link->BaseObj, 'RT::Article')) && $link->BaseObj->Disabled;
<li><& /Elements/ShowLink, URI => $link->BaseURI &><br />
% next if $link->BaseObj and $checked->{$link->BaseObj->id};
% if ($depth < 8) {
diff --git a/share/html/Ticket/Elements/ShowParents b/share/html/Ticket/Elements/ShowParents
index 17c7bdf..c58f5c3 100644
--- a/share/html/Ticket/Elements/ShowParents
+++ b/share/html/Ticket/Elements/ShowParents
@@ -47,6 +47,7 @@
%# END BPS TAGGED BLOCK }}}
<ul>
% while (my $link = $member_of->Next) {
+% next if (UNIVERSAL::isa($link->TargetObj, 'RT::Article')) && $link->TargetObj->Disabled;
<li><& /Elements/ShowLink, URI => $link->TargetURI &><br />
% }
</ul>
diff --git a/t/articles/article.t b/t/articles/article.t
index 7a3474f..5c7fe06 100644
--- a/t/articles/article.t
+++ b/t/articles/article.t
@@ -80,7 +80,7 @@ ok ($val, "Article Deleted: $msg");
$a2 = RT::Article->new($RT::SystemUser);
$a2->Load($id);
-ok (!$a2->Id, "Did not find the article");
+ok ($a2->Disabled, "the article is disabled");
# NOT OK
#$RT::Handle->SimpleQuery("DELETE FROM Links");
-----------------------------------------------------------------------
More information about the rt-commit
mailing list