Added the EditUserPresenceCommand. Tested
[breadcrumbs.git] / src / lib / Bcd / Commands / MoveAdsUserPresenceCommand.pm
blob55a86fb44a23e2e3f5bd940e1c63b1a08b459357
1 package Bcd::Commands::MoveAdsUserPresenceCommand;
3 # This file is part of the breadcrumbs daemon (bcd).
4 # Copyright (C) 2007 Pasqualino Ferrentino
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 # 02110-1301, USA.
21 # Contact: lino.ferrentino@yahoo.it (in Italian, English or German).
23 use strict;
24 use warnings;
26 #My base class is the create user command
27 use Bcd::Commands::PresencesCommand;
28 use base(qq/Bcd::Commands::PresencesCommand/);
29 use Bcd::Data::Users;
30 use Data::Dumper;
31 use Bcd::Constants::PublicSitesConstants;
33 use constant NAME => "ws.move_ads_user_presence";
35 sub get_name{
36 return NAME;
39 use constant PARAM_TABLE =>
41 ["id_locus_to_move", "id_locus_new"],
43 id_locus_to_move => ["id_type", "required"],
44 id_locus_new => ["id_type", "required"],
46 [Bcd::Commands::SessionCommand::PARAM_TABLE],
50 sub get_param_table{
51 return PARAM_TABLE;
54 sub new {
55 my $class = shift;
56 my $self = $class->SUPER::new(@_);
58 $self->{privilege_required} = Bcd::Data::Users::ANT_ROLE;
60 bless ($self, $class);
61 return $self;
64 sub _exec{
65 #I should get the name and password of the user.
66 my ($self, $stash) = @_;
68 my $input = $self->{_in}->get_input();
69 my $my_id = $stash->get_session_id($input->{session_id});
71 my $id_locus_to_move = $input->{id_locus_to_move};
72 my $id_locus_new = $input->{id_locus_new};
74 my ($ans, $presence_old) =
75 $self->_check_owner_and_free_state_of_presence_fail($stash, $id_locus_to_move);
77 if ($ans == 1){
78 return;
81 my $presence_new;
82 ($ans, $presence_new) = $self->_check_owner_fail($stash, $id_locus_new);
84 if ($ans == 1){
85 return;
88 #the new presence should be compatible: (the same rel type!)
89 if ($presence_old->{id_rel_type} != $presence_new->{id_rel_type}){
90 $self->{exit_code} = Bcd::Errors::ErrorCodes::BEC_INCOMPATIBLE_PRESENCE_TYPE;
91 return;
94 #ok, now I should check that no invoice exists for the ads which
95 #insist on the old locus...
96 $ans = Bcd::Data::Invoices->are_there_active_invoices_in_this_locus
97 ($stash, $id_locus_to_move);
99 if ($ans == 1){
100 $self->{exit_code} = Bcd::Errors::ErrorCodes::BEC_CANNOT_EDIT_ACTIVE_PRESENCE;
101 return;
104 #Ok, I can move the invoice
105 Bcd::Data::Ads->change_locus_for_ads($stash, $id_locus_new, $id_locus_to_move);
107 #last, if the presence is not used any more, I can delete it.
108 my $count = Bcd::Data::Invoices->get_invoices_count_for_this_locus($stash, $id_locus_to_move);
110 if ($count == 0){
111 #ok, this locus can be deleted...
112 Bcd::Data::PublicSites->delete_presence($stash, $id_locus_to_move);
115 #ok, it should be all ok
116 $self->{exit_code} = Bcd::Errors::ErrorCodes::BEC_OK;
119 #No output, only the exit code is sufficient.