Browse Source

* CMTD::Helpers : sid_by_name -> site_by_name

master
Alex 'AdUser' Z 7 years ago
parent
commit
8b9fd894d7
  1. 4
      lib/CMTD/Helpers.pm
  2. 15
      lib/CMTD/Main.pm

4
lib/CMTD/Helpers.pm

@ -66,9 +66,9 @@ sub register {
return; return;
}); });
$app->helper(sid_by_name => sub { $app->helper(site_by_name => sub {
my ($c, $site) = @_; 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 { $app->helper(pid_by_hash => sub {

15
lib/CMTD/Main.pm

@ -43,9 +43,10 @@ sub c_list {
} }
eval { 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 = (); 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); my @tm = $self->app->comments_by_pid($pid);
# TODO: processing # TODO: processing
@cm = @tm; @cm = @tm;
@ -86,8 +87,8 @@ sub c_add {
$self->app->client_reply(400, "empty message"); $self->app->client_reply(400, "empty message");
last; last;
} }
my $sid = $self->app->sid_by_name($ref->{site}); my $site = $self->app->site_by_name($ref->{site});
unless ($sid) { unless ($site and ref($site) eq 'HASH') {
$self->app->client_reply(400, "no such site"); $self->app->client_reply(400, "no such site");
last; last;
} }
@ -106,10 +107,10 @@ sub c_add {
last; last;
} }
} }
my $pid = $self->app->pid_by_hash($sid, $ref->{hash}); my $pid = $self->app->pid_by_hash($site->{id}, $ref->{hash});
unless ($pid) { unless ($pid) {
$self->app->add_page($sid, $ref); $self->app->add_page($site->{id}, $ref);
$pid = $self->app->pid_by_hash($sid, $ref->{hash}); $pid = $self->app->pid_by_hash($site->{id}, $ref->{hash});
} }
$self->add_comment($pid, \%msg); $self->add_comment($pid, \%msg);
}} while (0); 1; }} while (0); 1;

Loading…
Cancel
Save