diff --git a/lib/CMTD/Helpers.pm b/lib/CMTD/Helpers.pm index fa515fb..fc42432 100644 --- a/lib/CMTD/Helpers.pm +++ b/lib/CMTD/Helpers.pm @@ -66,9 +66,9 @@ sub register { return; }); - $app->helper(sid_by_name => sub { + $app->helper(site_by_name => sub { my ($c, $site) = @_; - return $self->app->db->select('sites', 'id', {site => $site})->list; + return $self->app->db->select('sites', '*', {site => $site})->hash; }); $app->helper(pid_by_hash => sub { diff --git a/lib/CMTD/Main.pm b/lib/CMTD/Main.pm index 926ec93..4a29c58 100644 --- a/lib/CMTD/Main.pm +++ b/lib/CMTD/Main.pm @@ -43,9 +43,10 @@ sub c_list { } eval { - if (my $sid = $self->app->sid_by_name($ref->{site})) { + my $site = $self->app->site_by_name($ref->{site}); + if ($site and ref($site) eq 'HASH') { my @cm = (); - if (my $pid = $self->app->pid_by_hash($sid, $ref->{hash})) { + if (my $pid = $self->app->pid_by_hash($site->{id}, $ref->{hash})) { my @tm = $self->app->comments_by_pid($pid); # TODO: processing @cm = @tm; @@ -86,8 +87,8 @@ sub c_add { $self->app->client_reply(400, "empty message"); last; } - my $sid = $self->app->sid_by_name($ref->{site}); - unless ($sid) { + my $site = $self->app->site_by_name($ref->{site}); + unless ($site and ref($site) eq 'HASH') { $self->app->client_reply(400, "no such site"); last; } @@ -106,10 +107,10 @@ sub c_add { last; } } - my $pid = $self->app->pid_by_hash($sid, $ref->{hash}); + my $pid = $self->app->pid_by_hash($site->{id}, $ref->{hash}); unless ($pid) { - $self->app->add_page($sid, $ref); - $pid = $self->app->pid_by_hash($sid, $ref->{hash}); + $self->app->add_page($site->{id}, $ref); + $pid = $self->app->pid_by_hash($site->{id}, $ref->{hash}); } $self->add_comment($pid, \%msg); }} while (0); 1;