[Rt-commit] [svn] r1246 - in rt: . branches/3.2-RELEASE/lib/RT
autrijus at pallas.eruditorum.org
autrijus at pallas.eruditorum.org
Wed Jul 14 15:24:16 EDT 2004
Author: autrijus
Date: Wed Jul 14 15:24:16 2004
New Revision: 1246
Modified:
rt/ (props changed)
rt/branches/3.2-RELEASE/lib/RT/Attributes_Overlay.pm
rt/branches/3.2-RELEASE/lib/RT/Record.pm
Log:
----------------------------------------------------------------------
r6049 at not: autrijus | 2004-07-14T19:18:50.831922Z
* Implement singular-attribute APIs: FirstAttribute, DeleteAttribute
and SetAttribute.
* Attributes->DeleteEntry can now unconditionally delete all attributes
with the matching name.
----------------------------------------------------------------------
Modified: rt/branches/3.2-RELEASE/lib/RT/Attributes_Overlay.pm
==============================================================================
--- rt/branches/3.2-RELEASE/lib/RT/Attributes_Overlay.pm (original)
+++ rt/branches/3.2-RELEASE/lib/RT/Attributes_Overlay.pm Wed Jul 14 15:24:16 2004
@@ -137,9 +137,13 @@
=head2 DeleteEntry { Name => Content => , id => }
-Deletes the attribute with
- the matching name
+Deletes attributes with
+ the matching name
and the matching content or id
+
+If Content and id are both undefined, delete all attributes with
+the matching name.
+
=cut
@@ -151,8 +155,10 @@
@_);
foreach my $attr ($self->Named($args{'Name'})){
- $attr->Delete if ($attr->Content eq $args{'Content'});
- $attr->Delete if ($attr->id eq $args{'id'});
+ $attr->Delete
+ if (!defined $args{'id'} and !defined $args{'Content'})
+ or (defined $args{'id'} and $attr->id eq $args{'id'})
+ or (defined $args{'Content'} and $attr->Content eq $args{'Content'});
}
$self->_DoSearch();
return (1, $self->loc('Attribute Deleted'));
Modified: rt/branches/3.2-RELEASE/lib/RT/Record.pm
==============================================================================
--- rt/branches/3.2-RELEASE/lib/RT/Record.pm (original)
+++ rt/branches/3.2-RELEASE/lib/RT/Record.pm Wed Jul 14 15:24:16 2004
@@ -129,6 +129,58 @@
}
+=head2 SetAttribute { Name, Description, Content }
+
+Like AddAttribute, but replaces all existing attributes with the same Name.
+
+=cut
+
+sub SetAttribute {
+ my $self = shift;
+ my %args = ( Name => undef,
+ Description => undef,
+ Content => undef,
+ @_ );
+
+ my @AttributeObjs = $self->Attributes->Named( $args{'Name'} )
+ or return $self->AddAttribute( %args );
+
+ my $AttributeObj = pop( @AttributeObjs );
+ $_->Delete foreach @AttributeObjs;
+
+ $AttributeObj->SetDescription( $args{'Description'} );
+ $AttributeObj->SetContent( $args{'Content'} );
+
+ $self->Attributes->RedoSearch;
+ return 1;
+}
+
+=head2 DeleteAttribute NAME
+
+Deletes all attributes with the matching name for this object.
+
+=cut
+
+sub DeleteAttribute {
+ my $self = shift;
+ my $name = shift;
+ return $self->Attributes->DeleteEntry( Name => $name );
+}
+
+=head2 FirstAttribute NAME
+
+Returns the value of the first attribute with the matching name
+for this object, or C<undef> if no such attributes exist.
+
+=cut
+
+sub FirstAttribute {
+ my $self = shift;
+ my $name = shift;
+ return ($self->Attributes->Named( $name ))[0];
+}
+
+
# {{{ sub _Handle
sub _Handle {
my $self = shift;
More information about the Rt-commit
mailing list