From 4977a733b6f614de868fc405b820d5c66e5bf9b7 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 8 May 2021 19:18:38 +0200 Subject: Auto fixup missing return types by Psalm --- includes/admin/helpfiles/instr_photog.php | 2 +- includes/admin/helpfiles/instr_reviewers.php | 2 +- includes/admin/helpfiles/instrunctions.php | 2 +- includes/admin/register_db_tables.php | 5 ++++- includes/admin/views/giglog_admin_page.php | 26 +++++++++++++--------- includes/admin/views/giglog_import_gigs.php | 8 ++++--- includes/band.php | 9 ++++++-- includes/concert.php | 7 ++++-- includes/concertlogs.php | 4 +++- includes/public/shortcodes/giglog_bands.php | 4 ++-- .../shortcodes/giglog_display_unprocessed.php | 6 ++--- .../public/shortcodes/giglog_photographers.php | 16 ++++++++----- .../public/shortcodes/giglog_process_files.php | 2 +- includes/venue.php | 20 ++++++++++++----- 14 files changed, 75 insertions(+), 38 deletions(-) (limited to 'includes') diff --git a/includes/admin/helpfiles/instr_photog.php b/includes/admin/helpfiles/instr_photog.php index 0750557..f661c5f 100644 --- a/includes/admin/helpfiles/instr_photog.php +++ b/includes/admin/helpfiles/instr_photog.php @@ -13,7 +13,7 @@ if ( !class_exists( 'Instructions_Photogs' ) ) { - static function render_instr_photo_html() { + static function render_instr_photo_html(): void { diff --git a/includes/admin/helpfiles/instr_reviewers.php b/includes/admin/helpfiles/instr_reviewers.php index e00a432..3632980 100644 --- a/includes/admin/helpfiles/instr_reviewers.php +++ b/includes/admin/helpfiles/instr_reviewers.php @@ -9,7 +9,7 @@ if ( !class_exists( 'Instructions_Reviewers' ) ) { class Instructions_Reviewers { - static function render_instr_rev_html() { + static function render_instr_rev_html(): void { ?> diff --git a/includes/admin/helpfiles/instrunctions.php b/includes/admin/helpfiles/instrunctions.php index 49b77fe..b9c4d89 100644 --- a/includes/admin/helpfiles/instrunctions.php +++ b/includes/admin/helpfiles/instrunctions.php @@ -9,7 +9,7 @@ if ( !class_exists( 'Instructions_Page' ) ) { class Instructions_Page { - static function render_instr_html() { + static function render_instr_html(): void { ?> diff --git a/includes/admin/register_db_tables.php b/includes/admin/register_db_tables.php index 947be22..11223b3 100644 --- a/includes/admin/register_db_tables.php +++ b/includes/admin/register_db_tables.php @@ -5,7 +5,7 @@ // SPDX-License-Identifier: AGPL-3.0-or-later if (!function_exists('giglogadmin_populate_countries')) { - function giglogadmin_populate_countries() + function giglogadmin_populate_countries(): void { global $wpdb; $wpdb->query( @@ -254,6 +254,9 @@ if (!function_exists('giglogadmin_populate_countries')) { if ( !function_exists( "giglog_register_db_tables") ) { + /** + * @return void + */ function giglog_register_db_tables() { $db_version = get_option('giglogadmin_db_version'); diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php index 72a34eb..f2b6edd 100644 --- a/includes/admin/views/giglog_admin_page.php +++ b/includes/admin/views/giglog_admin_page.php @@ -9,7 +9,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { require_once __DIR__ . '/../../venue.php'; class GiglogAdmin_AdminPage { - static function render_html() { + static function render_html(): void { ?>

Giglog Admin

@@ -36,7 +36,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { echo(GiglogAdmin_AdminPage::editforms()); //not sure why it doesn't show without the echo? } - static function get_allvenues($invenue) + static function get_allvenues($invenue): string { $select = ''; diff --git a/includes/public/shortcodes/giglog_photographers.php b/includes/public/shortcodes/giglog_photographers.php index 500445a..829c53e 100644 --- a/includes/public/shortcodes/giglog_photographers.php +++ b/includes/public/shortcodes/giglog_photographers.php @@ -10,7 +10,7 @@ * Admin users also control concert statuses here */ -function giglogadmin_assignconcert($p1, $c) +function giglogadmin_assignconcert($p1, $c): void { global $wpdb; @@ -40,7 +40,7 @@ function giglogadmin_assignconcert($p1, $c) } -function giglogadmin_unassignconcert($p1, $c) +function giglogadmin_unassignconcert($p1, $c): void { global $wpdb; @@ -71,6 +71,9 @@ function giglogadmin_unassignconcert($p1, $c) } +/** + * @return null|string + */ function giglogadmin_getpublishstatus ($c) { global $wpdb; @@ -88,6 +91,9 @@ function giglogadmin_getpublishstatus ($c) } +/** + * @return null|string + */ function giglogadmin_returnuser($p1, $c) { global $wpdb; @@ -164,7 +170,7 @@ function giglogadmin_returnuser($p1, $c) } -function giglogadmin_getfiltersphotog() { +function giglogadmin_getfiltersphotog(): string { global $wpdb; //echo (var_dump($_POST["selectvenue"])); @@ -211,7 +217,7 @@ function giglogadmin_getfiltersphotog() { } -function giglogadmin_getconcertsphotog ( ) { +function giglogadmin_getconcertsphotog ( ): string { $hf_user = wp_get_current_user(); $hf_username = $hf_user->user_login; $roles = ( array ) $hf_user->roles; @@ -370,7 +376,7 @@ function giglogadmin_getconcertsphotog ( ) { return $content; } -function giglogadmin_photographers() +function giglogadmin_photographers(): string { $output = giglogadmin_getfiltersphotog(); $output .= giglogadmin_getconcertsphotog(); diff --git a/includes/public/shortcodes/giglog_process_files.php b/includes/public/shortcodes/giglog_process_files.php index 9dc2ec0..9443cda 100644 --- a/includes/public/shortcodes/giglog_process_files.php +++ b/includes/public/shortcodes/giglog_process_files.php @@ -9,7 +9,7 @@ * Band Venue Date TicketLink Eventlink. The form is at the end of this snippet */ -function giglogadmin_upload_files() { +function giglogadmin_upload_files(): string { global $wpdb; $output = ""; $dir = wp_upload_dir()['basedir'].'/concertlists/'; //the basedir is from file uploader plugin, namely the uploads folder in which I created a concertlist folder diff --git a/includes/venue.php b/includes/venue.php index f6f46b2..ddd3d4a 100644 --- a/includes/venue.php +++ b/includes/venue.php @@ -28,7 +28,7 @@ if ( !class_exists('GiglogAdmin_Venue') ) { $this->webpage = isset($attrs->wpgvenue_webpage) ? $attrs->wpgvenue_webpage : NULL; } - static function create($name, $city = 'Oslo') + static function create($name, $city = 'Oslo'): self { $venue = new GiglogAdmin_Venue((object) [ 'wpgvenue_name' => $name, @@ -61,7 +61,7 @@ if ( !class_exists('GiglogAdmin_Venue') ) { } } - static function all_cities() + static function all_cities(): array { global $wpdb; $results = $wpdb->get_results('select distinct wpgvenue_city from wpg_venues'); @@ -69,7 +69,12 @@ if ( !class_exists('GiglogAdmin_Venue') ) { return array_map(function ($r) { return $r->wpgvenue_city; }, $results); } - static function all_venues() + /** + * @return self[] + * + * @psalm-return array + */ + static function all_venues(): array { global $wpdb; @@ -79,7 +84,12 @@ if ( !class_exists('GiglogAdmin_Venue') ) { } - static function venues_in_city($city) + /** + * @return self[] + * + * @psalm-return array + */ + static function venues_in_city($city): array { global $wpdb; $q = $wpdb->prepare( @@ -89,7 +99,7 @@ if ( !class_exists('GiglogAdmin_Venue') ) { return array_map(function ($r) { return new GiglogAdmin_Venue($r); }, $results); } - public function save() + public function save(): void { global $wpdb; -- cgit v1.2.3 From 88de0f55d7499009f0f316262757e70385d43ce5 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 8 May 2021 20:28:00 +0200 Subject: Psalm fixes --- includes/admin/views/giglog_admin_page.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'includes') diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php index f2b6edd..85c4193 100644 --- a/includes/admin/views/giglog_admin_page.php +++ b/includes/admin/views/giglog_admin_page.php @@ -36,7 +36,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { echo(GiglogAdmin_AdminPage::editforms()); //not sure why it doesn't show without the echo? } - static function get_allvenues($invenue): string + static function get_allvenues(int $invenue): string { $select = ''; - foreach ( $venues AS $venue ) { + foreach ( $venue_list as $venue ) { $select .= ''; } @@ -167,7 +167,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { return $content; } - static function adminactions($concert_id): string + static function adminactions( int $concert_id ) : string { global $wpdb; $query = "SELECT id,wpgs_name from wpg_pressstatus" ; @@ -195,7 +195,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { /** * @return null|string */ - static function getpublishstatus($concert_id) + static function getpublishstatus(int $concert_id) { global $wpdb; $date1 = new DateTime("now"); @@ -216,7 +216,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { { $hf_user = wp_get_current_user(); $hf_username = $hf_user->user_login; - $roles = ( array ) $hf_user->roles; + $roles = $hf_user->roles; global $wpdb; $content = ''; -- cgit v1.2.3 From 30f12e61317d9b181efb46382a4db98d73f65954 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 8 May 2021 20:50:39 +0200 Subject: Autofixes by Psalm --- includes/admin/views/giglog_admin_page.php | 6 +++--- includes/admin/views/giglog_import_gigs.php | 4 +++- includes/band.php | 2 +- includes/concert.php | 2 +- includes/venue.php | 4 ++-- 5 files changed, 10 insertions(+), 8 deletions(-) (limited to 'includes') diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php index 85c4193..624566f 100644 --- a/includes/admin/views/giglog_admin_page.php +++ b/includes/admin/views/giglog_admin_page.php @@ -36,7 +36,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { echo(GiglogAdmin_AdminPage::editforms()); //not sure why it doesn't show without the echo? } - static function get_allvenues(int $invenue): string + static function get_allvenues( ?int $invenue ): string { $select = ''; $select .= ''; foreach ( GiglogAdmin_Venue::all_venues() AS $venue ) { - if($invenue==$venue ->id() ) $select .= ''; } $select .= ''; @@ -131,7 +135,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { $editing = filter_input(INPUT_POST, "edit") == "EDIT"; if ($editing && !empty($cid)) //A bit overdoing with the checks if concert ID is empty both here and in find_cid. But based on that, things are NULL or not. Better ideas? - $c = GiglogAdmin_Concert::find_cid($cid); + $c = GiglogAdmin_Concert::get($cid); else $c = new GiglogAdmin_Concert(); @@ -140,7 +144,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { .'
CONCERT DETAILS

' .'' .'
' - .''.GiglogAdmin_AdminPage::get_allvenues($c->venue()).'
' + .'' . GiglogAdmin_AdminPage::get_allvenues($c->venue()) . '
' .'
' .'
' .'
' diff --git a/includes/concert.php b/includes/concert.php index 5c17933..8c99c42 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -25,33 +25,41 @@ if ( !class_exists('GiglogAdmin_Concert') ) { { $this->id = isset($attrs->id) ? $attrs->id : NULL; $this->cname = isset($attrs->wpgconcert_name) ? $attrs->wpgconcert_name : NULL; - $this->venue = isset($attrs->venue) ? $attrs->venue : NULL; $this->cdate = isset($attrs->wpgconcert_date) ? $attrs->wpgconcert_date : NULL; $this->tickets = isset($attrs->wpgconcert_tickets) ? $attrs->wpgconcert_tickets : NULL; $this->eventlink = isset($attrs->wpgconcert_event) ? $attrs->wpgconcert_event : NULL; + + + if ( isset( $attrs->venue ) ) { + $venue_attrs = (object) [ + "id" => $attrs->venue, + "wpgvenue_name" => $attrs->wpgvenue_name, + "wpgvenue_city" => $attrs->wpgvenue_city, + ]; + + $this->venue = new GiglogAdmin_Venue($venue_attrs); + } } /** - * @return null|self + * Get concert with given id. + * + * @param int $id. + * @return null|self. */ - static function find_cid($id) + static function get( int $id ) : ?self { global $wpdb; - if(!empty($id)) - { - $csql = 'SELECT * FROM wpg_concerts WHERE id="' . $id . '"'; - $results = $wpdb->get_results($csql); - if ($results) - { - return new GiglogAdmin_Concert($results[0]); - } - } - else - { - return new GiglogAdmin_Concert(); - } + $query = 'SELECT wpg_concerts.*, wpg_venues.wpgvenue_name, wpg_venues.wpgvenue_city ' + . 'FROM wpg_concerts ' + . 'LEFT JOIN wpg_venues ON wpg_concerts.venue = wpg_venues.id ' + . 'WHERE ' . $wpdb->prepare('wpg_concerts.id = %d', $id); + + $results = $wpdb->get_results($query); + + return $results ? new GiglogAdmin_Concert($results[0]) : NULL; } public static function create(string $name, $venue, string $date, string $ticketlink, string $eventlink): ?self @@ -154,7 +162,6 @@ if ( !class_exists('GiglogAdmin_Concert') ) { . ' and venue = ' . $venue . ' and wpgconcert_date ="' . $date . '"'; - error_log(__CLASS__ . '::' . __FUNCTION__ . ": {$sql}"); return $wpdb->get_results($sql); } @@ -165,7 +172,7 @@ if ( !class_exists('GiglogAdmin_Concert') ) { $wpdb->insert('wpg_concerts', array( 'id' => '', 'wpgconcert_name' => $this->cname, - 'venue' => $this->venue, + 'venue' => $this->venue->id(), 'wpgconcert_date' => $this->cdate, 'wpgconcert_tickets' => $this->tickets, 'wpgconcert_event' => $this->eventlink -- cgit v1.2.3 From b58211e3617f4125567c313736f5ed0bcea7313c Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sun, 9 May 2021 15:51:37 +0200 Subject: Rename strangely named function. GoglogAdmin_AdminPage::get_allvenues did not get all venues, but presented a selection control for selecting a venue. Renamed it as get_venue_selector instead. --- includes/admin/views/giglog_admin_page.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'includes') diff --git a/includes/admin/views/giglog_admin_page.php b/includes/admin/views/giglog_admin_page.php index 2971a22..9d9d759 100644 --- a/includes/admin/views/giglog_admin_page.php +++ b/includes/admin/views/giglog_admin_page.php @@ -36,7 +36,7 @@ if ( !class_exists( 'GiglogAdmin_AdminPage' ) ) { echo(GiglogAdmin_AdminPage::editforms()); //not sure why it doesn't show without the echo? } - static function get_allvenues( ?GiglogAdmin_Venue $invenue ): string + static function get_venue_selector( ?GiglogAdmin_Venue $invenue ): string { $select = '' .'
' - .'' . GiglogAdmin_AdminPage::get_allvenues($c->venue()) . '
' + .'' . GiglogAdmin_AdminPage::get_venue_selector($c->venue()) . '
' .'
' .'
' .'
' -- cgit v1.2.3 From df7c0a5dbf772a535c383f31fab578b5f82cb337 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sun, 9 May 2021 17:18:46 +0200 Subject: New method Venue::get to get venue by id --- includes/venue.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'includes') diff --git a/includes/venue.php b/includes/venue.php index aaf51d0..f9f7e4f 100644 --- a/includes/venue.php +++ b/includes/venue.php @@ -28,6 +28,22 @@ if ( !class_exists('GiglogAdmin_Venue') ) { $this->webpage = isset($attrs->wpgvenue_webpage) ? $attrs->wpgvenue_webpage : NULL; } + /** + * Get venue by given id. + * + * @param int $id. + * @return null|self. + */ + static function get(int $id) : ?self + { + global $wpdb; + + $query = $wpdb->prepare('SELECT * from wpg_venues WHERE id = %d', $id); + $results = $wpdb->get_results($query); + + return $results ? new GiglogAdmin_Venue($results[0]) : NULL; + } + static function create($name, $city = 'Oslo'): self { $venue = new GiglogAdmin_Venue((object) [ -- cgit v1.2.3 From 8045b78bc2032f772e35d1bf484541332336c7e0 Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sun, 9 May 2021 17:19:22 +0200 Subject: Fix constructing concerts if only venue id passed. The previous changes required the full venue data to be included in the constructor. This patch ensures that we handle the old case, where only the venue id was passed in. We still should get the full concert object including the venue name and city back. --- includes/concert.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'includes') diff --git a/includes/concert.php b/includes/concert.php index 8c99c42..e3c32e8 100644 --- a/includes/concert.php +++ b/includes/concert.php @@ -31,13 +31,18 @@ if ( !class_exists('GiglogAdmin_Concert') ) { if ( isset( $attrs->venue ) ) { - $venue_attrs = (object) [ - "id" => $attrs->venue, - "wpgvenue_name" => $attrs->wpgvenue_name, - "wpgvenue_city" => $attrs->wpgvenue_city, - ]; - - $this->venue = new GiglogAdmin_Venue($venue_attrs); + if (isset($attrs->wpgvenue_name) && isset($attrs->wpgvenue_city)) { + $venue_attrs = (object) [ + "id" => $attrs->venue, + "wpgvenue_name" => $attrs->wpgvenue_name, + "wpgvenue_city" => $attrs->wpgvenue_city, + ]; + + $this->venue = new GiglogAdmin_Venue($venue_attrs); + } + else { + $this->venue = GiglogAdmin_Venue::get($attrs->venue); + } } } -- cgit v1.2.3 From 142ff436282844677b8b4e7d8ececd44440ec96d Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sun, 9 May 2021 17:24:12 +0200 Subject: Fix importing gigs after changes to the concert class. --- includes/admin/views/giglog_import_gigs.php | 30 ++++++++++------------------- 1 file changed, 10 insertions(+), 20 deletions(-) (limited to 'includes') diff --git a/includes/admin/views/giglog_import_gigs.php b/includes/admin/views/giglog_import_gigs.php index 0e7406f..a8daa3f 100644 --- a/includes/admin/views/giglog_import_gigs.php +++ b/includes/admin/views/giglog_import_gigs.php @@ -42,7 +42,7 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) { * tab character: * * 1. Concertname - * 2. Venuename + * 2. Venuename or numeric venue id * 3. Concert date * 4. Ticket link * 5. Event info link @@ -65,31 +65,21 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) { } $resultArray = explode("\t", $line); - $cname = trim($resultArray[0]); + $cname = trim($resultArray[0]); $venue = trim($resultArray[1]); - $condate = date('Y-m-d', strtotime($resultArray[2])); - $ticketlink = trim($resultArray[3]); - $eventlink = trim($resultArray[4]); - //first item in the row should be concert name $resultArray[0]; second should be venue $resultArray[1]; third should be concert date $resultArray[2]; - //fourth item is ticketlink $resultArray[3]; fifth item is eventlink $resultArray[4]; - - - if (is_numeric($venue)) - $newconcert[1] = $venue; + if (is_numeric($venue)) { + $venue = GiglogAdmin_Venue::get($venue); + } else { - $v = GiglogAdmin_Venue::find_or_create($venue,'Oslo'); //phase 666 of the project should maybe consider both city and band country when creating concerts/importing files - $newconcert[1] = $v->id(); + $venue = GiglogAdmin_Venue::find_or_create($venue,'Oslo'); } - //not sure how to check dates, hopefully manual verification of files will take care of it + $condate = date('Y-m-d', strtotime($resultArray[2])); + $ticketlink = trim($resultArray[3]); + $eventlink = trim($resultArray[4]); - GiglogAdmin_Concert::create( - $cname, - $newconcert[1], - $condate, - $ticketlink, - $eventlink); + GiglogAdmin_Concert::create($cname, $venue->id(), $condate, $ticketlink, $eventlink); } } } -- cgit v1.2.3