Revision da6a187a
Von Moritz Bunkus vor etwa 9 Jahren hinzugefügt
SL/DB/CsvImportProfile.pm | ||
---|---|---|
use List::Util qw(first);
|
||
|
||
require SL::DB::MetaSetup::CsvImportProfile;
|
||
use Rose::DB::Object::Helpers qw(clone_and_reset);
|
||
|
||
__PACKAGE__->meta->add_relationship(
|
||
settings => {
|
SL/DB/DeliveryOrder.pm | ||
---|---|---|
sub _clone_orderitem_cvar {
|
||
my ($cvar) = @_;
|
||
|
||
my $cloned = Rose::DB::Object::Helpers::clone_and_reset($_);
|
||
my $cloned = $_->clone_and_reset;
|
||
$cloned->sub_module('delivery_order_items');
|
||
|
||
return $cloned;
|
SL/DB/Invoice.pm | ||
---|---|---|
sub _clone_orderitem_delivery_order_item_cvar {
|
||
my ($cvar) = @_;
|
||
|
||
my $cloned = Rose::DB::Object::Helpers::clone_and_reset($_);
|
||
my $cloned = $_->clone_and_reset;
|
||
$cloned->sub_module('invoice');
|
||
|
||
return $cloned;
|
SL/DB/Object.pm | ||
---|---|---|
use Carp;
|
||
use English qw(-no_match_vars);
|
||
use Rose::DB::Object;
|
||
use List::MoreUtils qw(any);
|
||
use Rose::DB::Object::Constants qw();
|
||
use List::MoreUtils qw(any pairwise);
|
||
|
||
use SL::DB;
|
||
use SL::DB::Helper::Attr;
|
||
... | ... | |
return $class_or_self;
|
||
}
|
||
|
||
my %_skip_fields_when_cloning = map { ($_ => 1) } qw(itime mtime);
|
||
|
||
sub clone_and_reset {
|
||
my($self) = shift;
|
||
my $class = ref $self;
|
||
my $cloning = Rose::DB::Object::Constants::STATE_CLONING();
|
||
local $self->{$cloning} = 1;
|
||
|
||
my $meta = $class->meta;
|
||
my @accessors = $meta->column_accessor_method_names;
|
||
my @mutators = $meta->column_mutator_method_names;
|
||
my @column_names =
|
||
grep { $_->[0] && $_->[1] && !$_skip_fields_when_cloning{ $_->[0] } }
|
||
pairwise { [ $a, $b] } @accessors, @mutators;
|
||
|
||
my $clone = $class->new(map { my $method = $_->[0]; ($_->[1] => $self->$method) } @column_names);
|
||
|
||
# Blank all primary and unique key columns
|
||
my @keys = (
|
||
$meta->primary_key_column_mutator_names,
|
||
map { my $uk = $_; map { $meta->column_mutator_method_name($_) } ($uk->columns) } ($meta->unique_keys)
|
||
);
|
||
|
||
$clone->$_(undef) for @keys;
|
||
|
||
# Also copy db object, if any
|
||
$clone->db($self->{db}) if $self->{db};
|
||
|
||
return $clone;
|
||
}
|
||
|
||
1;
|
||
|
||
__END__
|
||
... | ... | |
|
||
Returns the object/class it was called on.
|
||
|
||
=item C<clone_and_reset>
|
||
|
||
This works similar to L<Rose::DB::Object::Helpers/clone_and_reset>: it
|
||
returns a cloned instance of C<$self>. All primary and unique key
|
||
fields have been reset.
|
||
|
||
The difference between Rose's and this function is that this function
|
||
will also skip setting the following fields if such columns exist for
|
||
C<$self>: C<itime>, C<mtime>.
|
||
|
||
=back
|
||
|
||
=head1 AUTHOR
|
SL/DB/PriceRule.pm | ||
---|---|---|
|
||
use SL::DB::MetaSetup::PriceRule;
|
||
use SL::DB::Manager::PriceRule;
|
||
use Rose::DB::Object::Helpers qw(clone_and_reset);
|
||
use SL::Locale::String qw(t8);
|
||
|
||
__PACKAGE__->meta->add_relationship(
|
SL/DB/PriceRuleItem.pm | ||
---|---|---|
|
||
use SL::DB::MetaSetup::PriceRuleItem;
|
||
use SL::DB::Manager::PriceRuleItem;
|
||
use Rose::DB::Object::Helpers qw(clone_and_reset);
|
||
use SL::Locale::String qw(t8);
|
||
|
||
__PACKAGE__->meta->initialize;
|
SL/DB/RequirementSpec.pm | ||
---|---|---|
sub _create_copy {
|
||
my ($self, %params) = @_;
|
||
|
||
my $copy = Rose::DB::Object::Helpers::clone_and_reset($self);
|
||
my $copy = $self->clone_and_reset;
|
||
$copy->copy_from($self, %params);
|
||
|
||
return $copy;
|
||
... | ... | |
# Clone text blocks and pictures.
|
||
my $clone_and_reset_position = sub {
|
||
my ($src_obj) = @_;
|
||
my $cloned = Rose::DB::Object::Helpers::clone_and_reset($src_obj);
|
||
my $cloned = $src_obj->clone_and_reset;
|
||
$cloned->position(undef);
|
||
return $cloned;
|
||
};
|
||
|
||
my $clone_text_block = sub {
|
||
my ($text_block) = @_;
|
||
my $cloned = Rose::DB::Object::Helpers::clone_and_reset($text_block);
|
||
my $cloned = $text_block->clone_and_reset;
|
||
$cloned->position(undef);
|
||
$cloned->pictures([ map { $clone_and_reset_position->($_) } @{ $text_block->pictures_sorted } ]);
|
||
return $cloned;
|
||
... | ... | |
my $clone_item;
|
||
$clone_item = sub {
|
||
my ($item) = @_;
|
||
my $cloned = Rose::DB::Object::Helpers::clone_and_reset($item);
|
||
my $cloned = $item->clone_and_reset;
|
||
$cloned->requirement_spec_id($self->id);
|
||
$cloned->position(undef);
|
||
$cloned->fb_number(undef) if $params->{paste_template};
|
Auch abrufbar als: Unified diff
SL::DB::Object: clone_and_reset unter Umgehung von itime, mtime