summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2023-05-17 12:09:34 +0200
committerHarald Eilertsen <haraldei@anduin.net>2023-05-17 12:09:34 +0200
commit76184e83fa18e92fd6b86fd012335ec7c7bbbd53 (patch)
treea58af12c8547bbc587328ccb2586aaa6f88f3dbe
parent13cf5c871008b65ff695a967c88260f1d815139d (diff)
downloadgigologadmin-76184e83fa18e92fd6b86fd012335ec7c7bbbd53.tar.gz
gigologadmin-76184e83fa18e92fd6b86fd012335ec7c7bbbd53.tar.bz2
gigologadmin-76184e83fa18e92fd6b86fd012335ec7c7bbbd53.zip
bugfix: Return null if gig is not found by id.
Also add some error logging if more than one concert is returned for the same id. Should never happen, but in case it will be logged.
-rw-r--r--includes/class-giglogadmin-concert.php15
1 files changed, 14 insertions, 1 deletions
diff --git a/includes/class-giglogadmin-concert.php b/includes/class-giglogadmin-concert.php
index c6223cb..a4513db 100644
--- a/includes/class-giglogadmin-concert.php
+++ b/includes/class-giglogadmin-concert.php
@@ -82,7 +82,20 @@ if ( ! class_exists( 'GiglogAdmin_Concert' ) ) {
* @return null|self
*/
public static function get( int $id ) : ?self {
- return self::find_concerts( array( 'id' => $id ) )[0];
+ $gigs = self::find_concerts( array( 'id' => $id ) );
+ $count = count( $gigs );
+
+ if ( $count > 1 ) {
+ error_log(
+ "Found more than one concert with the same id ({$id})."
+ . ' This should not happen!'
+ );
+ wp_die( 'Oops! Something went wrong', 500 );
+ } else if ( $count != 1 ) {
+ return null;
+ } else {
+ return array_shift( $gigs );
+ }
}
/**