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;
});
$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 {

15
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;

Loading…
Cancel
Save