1 package SL::BackgroundJob::ShopPartMassUpload;
 
   6 use parent qw(SL::BackgroundJob::Base);
 
  12 use constant WAITING_FOR_EXECUTION        => 0;
 
  13 use constant UPLOAD_TO_WEBSHOP            => 1;
 
  14 use constant DONE                         => 2;
 
  18 #     shop_part_record_ids         => [ 603, 604, 605 ],
 
  19 #     todo                         => $::form->{upload_todo},
 
  20 #     status                       => SL::BackgroundJob::ShopPartMassUpload->WAITING_FOR_EXECUTION(),
 
  22 #     conversation                 => [ { id => 603 , number => 2, message => "Ok" or $@ }, ],
 
  25 sub update_webarticles {
 
  28   my $job_obj = $self->{job_obj};
 
  29   my $db      = $job_obj->db;
 
  31   $job_obj->set_data(UPLOAD_TO_WEBSHOP())->save;
 
  33   foreach my $shop_part_id (@{ $job_obj->data_as_hash->{shop_part_record_ids} }) {
 
  34     my $data  = $job_obj->data_as_hash;
 
  36       my $shop_part = SL::DB::Manager::ShopPart->find_by(id => $shop_part_id);
 
  38         push @{ $data->{conversion} }, { id => $shop_part_id, number => '', message => 'Shoppart not found' };
 
  41       my $shop = SL::Shop->new( config => $shop_part->shop );
 
  43       my $return    = $shop->connector->update_part($shop_part, $data->{todo});
 
  45         my $now = DateTime->now;
 
  46         my $attributes->{last_update} = $now;
 
  47         $shop_part->assign_attributes(%{ $attributes });
 
  49         $data->{num_uploaded} = $num_uploaded++;
 
  50         push @{ $data->{conversion} }, { id => $shop_part_id, number => $shop_part->part->partnumber, message => 'uploaded' };
 
  52       push @{ $data->{conversion} }, { id => $shop_part_id, number => $shop_part->part->partnumber, message => $return };
 
  56       push @{ $data->{conversion} }, { id => $shop_part_id, number => '', message => $@ };
 
  59     $job_obj->update_attributes(data_as_hash => $data);
 
  64   my ($self, $job_obj) = @_;
 
  66   $self->{job_obj}         = $job_obj;
 
  67   $self->update_webarticles;
 
  69   $job_obj->set_data(status => DONE())->save;