// SPDX-FileCopyrightText: 2021 Harald Eilertsen // // SPDX-License-Identifier: AGPL-3.0-or-later if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) { require_once __DIR__ . '/../../concert.php'; require_once __DIR__ . '/../../venue.php'; class GiglogAdmin_ImportGigsPage { static function render_html(): void { ?>

Import gigs

Import gig data from a tab separated data file.

*/ static function process_upload(array $file): void { global $wpdb; $newconcert= []; $fo = new SplFileObject($file['tmp_name']); $importerrors = ''; $rid=0; foreach ($fo as $line) { $rid++; $line = trim( $line ); if ( empty($line) ) { // Skip empty lines continue; } $resultArray = explode("\t", $line); if (empty(trim($resultArray[0]))) { $importerrors.= 'Row '.$rid.' is missing concert name!'."
"; continue; } else if (empty(trim($resultArray[1]))) { $importerrors.= 'Row '.$rid.' is missing venue name!'."
"; continue; } else if (empty(trim($resultArray[2]))) { $importerrors.= 'Row '.$rid.' is missing city name!' ."
"; continue; } else { $condate = date('Y-m-d', strtotime($resultArray[3])); if ($condate"; continue; } else { $cname = trim($resultArray[0]); $venue = trim($resultArray[1]); if (is_numeric($venue)) { $venue = GiglogAdmin_Venue::get($venue); } else { $venue = GiglogAdmin_Venue::find_or_create($venue,trim($resultArray[2])); } $ticketlink = trim($resultArray[4]); $eventlink = trim($resultArray[5]); try { GiglogAdmin_Concert::create($cname, $venue->id(), $condate, $ticketlink, $eventlink); } catch(Exception $e) { $importerrors.= 'Row '.$rid.' is duplicate (or failed due unknown error)!'."
"; } } } } if (!empty($importerrors)) echo ($importerrors); else echo ('All rows imported ok'); } } }