OSDN Git Service

Model: fix Stories, Submissions, SlashDB to implement Stories::create
authorhylom <hylom@users.sourceforge.jp>
Mon, 24 Oct 2016 12:43:39 +0000 (21:43 +0900)
committerhylom <hylom@users.sourceforge.jp>
Mon, 24 Oct 2016 12:43:39 +0000 (21:43 +0900)
src/newslash_web/lib/Newslash/Model/SlashDB.pm [moved from src/newslash_web/lib/Newslash/Model/Slash.pm with 99% similarity]
src/newslash_web/lib/Newslash/Model/Stories.pm
src/newslash_web/lib/Newslash/Model/Submissions.pm
src/newslash_web/t/comment.t

@@ -2,9 +2,12 @@
 # Copyright 1997-2009 by Geeknet, Inc. See README
 # and COPYING for more information, or see http://slashcode.com/.
 
-package Slash::DB::MySQL;
+#package Slash::DB::MySQL;
+package Newslash::Model::SlashDB;
+use base Newslash::Model::LegacyDB;
+#use Newslash::Model::Base -base;
 
-use strict;
+#use strict;
 
 use Socket;
 use Digest::MD5 'md5_hex';
@@ -17,16 +20,17 @@ use Data::Dumper;
 use Storable qw(thaw nfreeze);
 use URI ();
 
-use Slash::Utility;
-use Slash::Custom::ParUserAgent;
-use Slash::Constants ':messages';
+#use Slash::Utility;
+#use Slash::Custom::ParUserAgent;
+#use Slash::Constants ':messages';
 
-use vars qw($_proxy_port);
+#use vars qw($_proxy_port);
 
-use base 'Slash::DB';
-use base 'Slash::DB::Utility';
+#use base 'Slash::DB';
+#use base 'Slash::DB::Utility';
 
-our $VERSION = $Slash::Constants::VERSION;
+
+#our $VERSION = $Slash::Constants::VERSION;
 
 # Fry: How can I live my life if I can't tell good from evil?
 
index 1dc4b5e..987f47a 100644 (file)
@@ -1,6 +1,8 @@
 package Newslash::Model::Stories;
 use Newslash::Model::Base -base;
 
+use Newslash::Model::SlashDB;
+
 use Data::Dumper;
 
 #========================================================================
@@ -219,6 +221,11 @@ sub create {
     my ($self, $params, $uid) = @_;
     #createStory
 
+    #my $slash_db = $self->new_instance_of('Newslash::Model::SlashDB');
+    my $slash_db = Newslash::Model::SlashDB->new($self->{options});
+    #my $slash_db = $self->new_instance_of('SlashDB');
+    my $story = $slash_db->createStory($params);
+    return $story;
 }
 
 sub createSid {
@@ -256,6 +263,8 @@ sub createSid {
     return sprintf($sidformat, @lt[reverse 0..5]);
 }
 
+=pod
+
 sub grantStorySubmissionKarma {
     my($self, $story) = @_;
     #my $constants = getCurrentStatic();
@@ -317,7 +326,13 @@ sub grantStorySubmissionKarma {
                                subid => $story->{subid});
 }
 
+
+=cut
+
 ########################################################
+
+=pod
+
 sub createStory {
     my($self, $story) = @_;
 
@@ -375,15 +390,16 @@ sub createStory {
         $self->grantStorySubmissionKarma($story);
     }
 
-       if (!$error) {
-               if (! $self->sqlInsert('story_text', { stoid => $stoid })) {
-                       $error = "sqlInsert failed for story_text: " . $self->sqlError();
-               }
-       }
+    if (!$error) {
+        #if (! $self->sqlInsert('story_text', { stoid => $stoid })) {
+        if (! $db->sqlInsert('story_text', { stoid => $stoid })) {
+            $error = "sqlInsert failed for story_text: " . $self->sqlError();
+        }
+    }
 
-       # Write the chosen topics into story_topics_chosen.  We do this
-       # here because it returns the primaryskid and we will write that
-       # into the stories table with setStory in just a moment.
+    # Write the chosen topics into story_topics_chosen.  We do this
+    # here because it returns the primaryskid and we will write that
+    # into the stories table with setStory in just a moment.
        my($primaryskid, $tids);
        if (!$error) {
                my $success = $self->setStoryTopicsChosen($stoid, $story->{topics_chosen});
@@ -531,7 +547,6 @@ sub createStory {
        return $story->{sid};
 }
 
-
 sub editCreateStory {
     my($self, $preview, $fhitem) = @_;
     my $constants = getCurrentStatic();
@@ -638,7 +653,7 @@ sub editCreateStory {
 
 
 
-
+=cut
 
 
 
index b9b3994..389edb0 100644 (file)
@@ -452,9 +452,9 @@ sub upsert_param {
     my $self = shift;
     my %params = @_;
 
-    my $subid = %params{subid};
-    my $values = %params{params};
-    if (!$subid || !params) {
+    my $subid = $params{subid};
+    my $values = $params{params};
+    if (!$subid || !%params) {
         return;
     }
 
@@ -465,7 +465,7 @@ INSERT INTO submission_param (subid, name, value) VALUES (?, ?, ?)
 EOSQL
     my $sth = $dbh->prepare($sql);
 
-    for my $k (keys $values) {
+    for my $k (keys %$values) {
         my $rs = $sth->execute($subid, $k, $values->{$k}, $values->{$k});
         if (!$rs) {
             # TODO
@@ -479,7 +479,7 @@ sub update {
     my $self = shift;
     my %params = @_;
 
-    my $subid = %params{subid};
+    my $subid = $params{subid};
     return if !$subid;
 
     my $sql = "UPDATE submissions SET ? = ? WHERE subid = ?";
index e8bcdd6..6443bab 100644 (file)
@@ -9,11 +9,20 @@ my $t = Test::Mojo->new('Newslash::Web');
 
 SKIP: {
     skip "mode is not 'test'", 1 if ($t->app->mode ne 'test');
-    my $comments = $t->app->model('comments');
-    my $params = {};
-    my $user = "";
-    my $cid = $comments->create($params, $user);
-    ok($cid);
+    #my $comments = $t->app->model('comments');
+    my $stories = $t->app->model('stories');
+    my $params = {
+                  uid => 1,
+                  title => "Test Story",
+                  bodytext => '',
+                  introtext => 'Test Story body',
+                  topics_chosen => {},
+                  commentstatus => '',
+                  #subid => '',
+                 };
+    my $uid = 1;
+    my $sid = $stories->create($params, $uid);
+    ok($sid);
 }
 
 done_testing();