From c5d786a1c72911e4352a6e40ea19aff98711d353 Mon Sep 17 00:00:00 2001 From: AndreaChirulescu Date: Sun, 27 Feb 2022 13:35:59 +0100 Subject: iCal file download fixes to generate one file per concert giglog import fixes to catch errors and ignore old concerts --- includes/admin/views/giglog_import_gigs.php | 102 ++++++++++++++++++++-------- 1 file changed, 72 insertions(+), 30 deletions(-) (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 index 1a72fe1..e523dee 100644 --- a/includes/admin/views/giglog_import_gigs.php +++ b/includes/admin/views/giglog_import_gigs.php @@ -38,51 +38,93 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) { } /** - * Imports concert data from a file with tab separated values. - * - * The file must contain the following columns each separated by _one_ - * tab character: - * - * 1. Concertname - * 2. Venuename or numeric venue id - * 3. Concert date - * 4. Ticket link - * 5. Event info link - * - * Empty lines are ignored. - * - * @return void - * - * @param array - */ + * Imports concert data from a file with tab separated values. + * + * The file must contain the following columns each separated by _one_ + * tab character: + * + * 1. Concertname + * 2. Venuename or numeric venue id + * 3. Concert date + * 4. Ticket link + * 5. Event info link + * + * Empty lines are ignored. + * + * @return void + * + * @param array + */ 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); - $cname = trim($resultArray[0]); - $venue = trim($resultArray[1]); + 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; + } - if (is_numeric($venue)) { - $venue = GiglogAdmin_Venue::get($venue); + else if (empty(trim($resultArray[2]))) + { $importerrors.= 'Row '.$rid.' is missing city name!' ."
"; + continue; } + else { - $venue = GiglogAdmin_Venue::find_or_create($venue,'Oslo'); - } + $condate = date('Y-m-d', strtotime($resultArray[3])); + if ($condate"; + continue; } + + else { + + + $cname = trim($resultArray[0]); + $venue = trim($resultArray[1]); - $condate = date('Y-m-d', strtotime($resultArray[2])); - $ticketlink = trim($resultArray[3]); - $eventlink = trim($resultArray[4]); - GiglogAdmin_Concert::create($cname, $venue->id(), $condate, $ticketlink, $eventlink); + 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'); } } } -} -- cgit v1.2.3 From e1ac66aade5c2d5d2d9f6c6db501fccd9db9be0a Mon Sep 17 00:00:00 2001 From: AndreaChirulescu Date: Tue, 1 Mar 2022 21:49:09 +0100 Subject: import giglog checks for empty values and ivnalid date --- includes/admin/views/giglog_import_gigs.php | 85 ++++++++++++++++++----------- 1 file changed, 53 insertions(+), 32 deletions(-) (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 index e523dee..7cf4009 100644 --- a/includes/admin/views/giglog_import_gigs.php +++ b/includes/admin/views/giglog_import_gigs.php @@ -55,6 +55,9 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) { * * @param array */ + + + static function process_upload(array $file): void { global $wpdb; $newconcert= []; @@ -69,59 +72,77 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) { 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!'."
"; + //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) + { + $importerrors.= 'Row '.$rid.' is missing a field!'."
"; continue; } + else{ + //Below only checks if the date field is made of 4-2-2 digits, irregardless of their values. Actual date check is lower + if( ! preg_match("/\d{4}\-\d{2}-\d{2}/",$resultArray[3])) + { + $importerrors.= 'Row '.$rid.' has invalid date!'.$resultArray[3]."
"; - else if (empty(trim($resultArray[2]))) - { $importerrors.= 'Row '.$rid.' is missing city name!' ."
"; - continue; - } + continue; + } - else { - $condate = date('Y-m-d', strtotime($resultArray[3])); - if ($condate"; - continue; } - else { + else { + 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; + } - $cname = trim($resultArray[0]); - $venue = trim($resultArray[1]); + else { + $condate = date('Y-m-d', strtotime($resultArray[3])); + if ($condate"; + continue; } + else { - if (is_numeric($venue)) { - $venue = GiglogAdmin_Venue::get($venue); - } - else { - $venue = GiglogAdmin_Venue::find_or_create($venue,trim($resultArray[2])); - } + $cname = trim($resultArray[0]); + $venue = trim($resultArray[1]); - $ticketlink = trim($resultArray[4]); - $eventlink = trim($resultArray[5]); + 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); + try { + GiglogAdmin_Concert::create($cname, $venue->id(), $condate, $ticketlink, $eventlink); - } + } - catch(Exception $e) { - $importerrors.= 'Row '.$rid.' is duplicate (or failed due unknown error)!'."
"; + catch(Exception $e) { + $importerrors.= 'Row '.$rid.' is duplicate (or failed due unknown error)!'."
"; + } + } } + } - } + + } } if (!empty($importerrors)) echo ($importerrors); else echo ('All rows imported ok'); -- cgit v1.2.3