From 277fedffc624f55c6ecc8bd80ed8db370134e47e Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Fri, 20 Jan 2023 20:22:06 +0100 Subject: Rename and reorganize more source files. --- includes/admin/views/giglog_import_gigs.php | 133 ---------------------------- 1 file changed, 133 deletions(-) delete mode 100644 includes/admin/views/giglog_import_gigs.php (limited to 'includes/admin/views/giglog_import_gigs.php') diff --git a/includes/admin/views/giglog_import_gigs.php b/includes/admin/views/giglog_import_gigs.php deleted file mode 100644 index 758981e..0000000 --- a/includes/admin/views/giglog_import_gigs.php +++ /dev/null @@ -1,133 +0,0 @@ - -// SPDX-FileCopyrightText: 2021 Harald Eilertsen -// -// SPDX-License-Identifier: AGPL-3.0-or-later - -if ( ! class_exists( 'GiglogAdmin_ImportGigsPage' ) ) { - require_once __DIR__ . '/../../class-giglogadmin-concert.php'; - require_once __DIR__ . '/../../class-giglogadmin-venue.php'; - - class GiglogAdmin_ImportGigsPage { - static function render_html(): void { - ?> -
-

Import gigs

-

Import gig data from a tab separated data file.

-
- - - - -
-
- $file - */ - static function process_upload( array $file ): void { - $fo = new SplFileObject( $file['tmp_name'] ); - $importerrors = array(); - $rid = 0; - - foreach ( $fo as $line ) { - $rid++; - $line = trim( $line ); - if ( ! empty( $line ) ) { - try { - self::process_line( $line ); - } catch ( Exception $e ) { - $importerrors[] = "Error importing line {$rid}: {$e->getMessage()}"; - } - } - } - - if ( ! empty( $importerrors ) ) { - echo implode( '
', $importerrors ); - } else { - echo ( 'All rows imported ok' ); - } - } - - static function process_line( string $line ) : void { - $resultArray = explode( "\t", $line ); - - // unsure if this is needed, considering we are also checking if - // each individual important field is missing. But if they are not - // replaced by tabs, then everything gets shifted so probably best - // to check if a value is empty and NOT replaced by tab - - if ( count( $resultArray ) < 6 ) { - throw new Exception( 'missing a field' ); - } - - if ( ! preg_match( '/\d{4}\-\d{2}-\d{2}/', $resultArray[3] ) ) { - throw new Exception( 'invalid date: ' . esc_html( $resultArray[3] ) ); - } - - if ( empty( trim( $resultArray[0] ) ) ) { - throw new Exception( 'missing concert name' ); - } - - if ( empty( trim( $resultArray[1] ) ) ) { - throw new Exception( 'missing venue' ); - } - - if ( empty( trim( $resultArray[2] ) ) ) { - throw new Exception( 'missing city' ); - } - - $condate = date( 'Y-m-d', strtotime( $resultArray[3] ) ); - - if ( $condate < date( 'Y-m-d' ) ) { - throw new Exception( 'has date in the past: ' . esc_html( $resultArray[3] ) ); - } - - $cname = trim( $resultArray[0] ); - $venue = trim( $resultArray[1] ); - - if ( is_numeric( $venue ) ) { - $venue = GiglogAdmin_Venue::get( intval( $venue ) ); - if ( ! $venue ) { - throw new Exception( "invalid venue id: {$venue}" ); - } - } else { - $venue = GiglogAdmin_Venue::find_or_create( $venue, trim( $resultArray[2] ) ); - } - - $ticketlink = trim( $resultArray[4] ); - $eventlink = trim( $resultArray[5] ); - - GiglogAdmin_Concert::create( $cname, $venue->id(), $condate, $ticketlink, $eventlink ); - } - } -} -- cgit v1.2.3