Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 1af50c02

Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt

  • ID 1af50c02794dc8b5e495de1e5b8c739bb94f7dc5
  • Vorgänger b4fc4933
  • Nachfolger c96c4bb2

SL::DB::RequirementSpec-Refactoring: create_copy in create_copy+copy_from aufgesplittet

Unterschiede anzeigen:

SL/DB/RequirementSpec.pm
87 87
  my ($self, %params) = @_;
88 88

  
89 89
  my $copy = Rose::DB::Object::Helpers::clone_and_reset($self);
90
  $copy->assign_attributes(%params);
90
  $copy->copy_from($self, %params);
91

  
92
  return $copy;
93
}
94

  
95
sub copy_from {
96
  my ($self, $source, %attributes) = @_;
97

  
98
  croak "Missing parameter 'source'" unless $source;
99

  
100
  # Copy attributes.
101
  $self->assign_attributes(map({ ($_ => $source->$_) } qw(type_id status_id customer_id project_id title hourly_rate net_sum previous_section_number previous_fb_number is_template)),
102
                           %attributes);
91 103

  
92 104
  # Clone text blocks.
93
  $copy->text_blocks(map { Rose::DB::Object::Helpers::clone_and_reset($_) } @{ $self->text_blocks });
105
  $self->text_blocks(map { Rose::DB::Object::Helpers::clone_and_reset($_) } @{ $source->text_blocks });
94 106

  
95 107
  # Save new object -- we need its ID for the items.
96
  $copy->save;
108
  $self->save;
97 109

  
98 110
  my %id_to_clone;
99 111

  
......
102 114
  $clone_item = sub {
103 115
    my ($item) = @_;
104 116
    my $cloned = Rose::DB::Object::Helpers::clone_and_reset($item);
105
    $cloned->requirement_spec_id($copy->id);
117
    $cloned->requirement_spec_id($self->id);
106 118
    $cloned->children(map { $clone_item->($_) } @{ $item->children });
107 119

  
108 120
    $id_to_clone{ $item->id } = $cloned;
......
110 122
    return $cloned;
111 123
  };
112 124

  
113
  $copy->items(map { $clone_item->($_) } @{ $self->sections });
125
  $self->items(map { $clone_item->($_) } @{ $source->sections });
114 126

  
115 127
  # Save the items -- need to do that before setting dependencies.
116
  $copy->save;
128
  $self->save;
117 129

  
118 130
  # Set dependencies.
119
  foreach my $item (@{ $self->items }) {
131
  foreach my $item (@{ $source->items }) {
120 132
    next unless @{ $item->dependencies };
121 133
    $id_to_clone{ $item->id }->update_attributes(dependencies => [ map { $id_to_clone{$_->id} } @{ $item->dependencies } ]);
122 134
  }
123 135

  
124
  return $copy;
136
  return $self;
125 137
}
126 138

  
127 139
sub previous_version {

Auch abrufbar als: Unified diff