From a5ea57f20c1beb80f327fea5233605400462156c Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Thu, 22 Apr 2021 23:15:22 +0200 Subject: Concert::create return NULL if concert already exist. We probably need some better error handling here. There's a myriad of reasons why this call could fail, and we might need to communicate the failure reason somewhere. --- includes/admin/views/giglog_admin_page.php | 19 +++++++++++-------- includes/concert.php | 8 +++++--- tests/ConcertTest.php | 2 +- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php index 92d97dd..b48fa77 100644 --- a/includes/admin/views/giglog_admin_page.php +++ b/includes/admin/views/giglog_admin_page.php @@ -329,17 +329,20 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { //header("Refresh: 1; URL=$url2"); //reload page } - if(isset($_POST['newconcert'])) - { - IF (empty($_POST['cname']) || empty($_POST['selectvenueadmin']) || empty($_POST['cdate']) || empty($_POST['ticket']) || empty($_POST['eventurl'])) + if(isset($_POST['newconcert'])) { + if (empty($_POST['cname']) || empty($_POST['selectvenueadmin']) || empty($_POST['cdate']) || empty($_POST['ticket']) || empty($_POST['eventurl'])) { echo ''; - else - { - $ret = GiglogAdmin_Concert::create($_POST['cname'], $_POST['selectvenueadmin'], $_POST['cdate'], $_POST['ticket'], $_POST['eventurl']); - if ($ret!='dup') echo ''; - else echo ''; + } + else { + if (GiglogAdmin_Concert::create($_POST['cname'], $_POST['selectvenueadmin'], $_POST['cdate'], $_POST['ticket'], $_POST['eventurl'])) { + echo ''; + } + else { + echo ''; + } } } + if(isset($_POST['editconcert'])) { IF (empty($_POST['cname']) || empty($_POST['selectvenueadmin']) || empty($_POST['cdate']) || empty($_POST['ticket']) || empty($_POST['eventurl'])) diff --git a/includes/concert.php b/includes/concert.php index 37e8fe3..22fc13d 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -51,7 +51,7 @@ if ( !class_exists('GiglogAdmin_Concert') ) { } } - static function check_duplicate($cname, $venue, $cdate, $ticketlink, $eventlink) + private static function check_duplicate($cname, $venue, $cdate, $ticketlink, $eventlink) { global $wpdb; @@ -62,8 +62,10 @@ if ( !class_exists('GiglogAdmin_Concert') ) { return ('new'); } + public static function create($cname, $venue, $cdate, $ticketlink, $eventlink) - { $c = GiglogAdmin_Concert::check_duplicate($cname, $venue, $cdate, $ticketlink, $eventlink); + { + $c = GiglogAdmin_Concert::check_duplicate($cname, $venue, $cdate, $ticketlink, $eventlink); if ($c=='new') { $attrs = new stdClass(); @@ -102,7 +104,7 @@ if ( !class_exists('GiglogAdmin_Concert') ) { . ' CONCERT NAME ' . $cname . ', VENUE ID ' . $venue . ', CONCERTDATE ' . $cdate); - return('dup'); + return NULL; } } diff --git a/tests/ConcertTest.php b/tests/ConcertTest.php index 19267ee..82bdc9a 100644 --- a/tests/ConcertTest.php +++ b/tests/ConcertTest.php @@ -44,6 +44,6 @@ final class ConcertTest extends WP_UnitTestCase "https://example.com/tickets/42", "https://example.com/events/93"); - $this->assertEquals("dup", $new); + $this->assertNull($new); } } -- cgit v1.2.3