diff options
Diffstat (limited to 'includes/admin/views/giglog_import_gigs.php')
-rw-r--r-- | includes/admin/views/giglog_import_gigs.php | 40 |
1 files changed, 17 insertions, 23 deletions
diff --git a/includes/admin/views/giglog_import_gigs.php b/includes/admin/views/giglog_import_gigs.php index 053f505..a8daa3f 100644 --- a/includes/admin/views/giglog_import_gigs.php +++ b/includes/admin/views/giglog_import_gigs.php @@ -12,7 +12,7 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) { require_once __DIR__ . '/../../venue.php'; class GiglogAdmin_ImportGigsPage { - static function render_html() { + static function render_html(): void { ?> <div class="wrap"> <h1>Import gigs</h1> @@ -27,7 +27,7 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) { <?php } - static function submit_form() { + static function submit_form(): void { if ('POST' === $_SERVER['REQUEST_METHOD'] && current_user_can('upload_files') && !empty($_FILES['giglog_import_file']['tmp_name'])) { $nonce = $_POST['giglog_import_nonce']; $valid_nonce = isset($nonce) && wp_verify_nonce($nonce); @@ -42,14 +42,18 @@ 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 * * Empty lines are ignored. + * + * @return void + * + * @param ArrayAccess|array $file */ - static function process_upload($file) { + static function process_upload(array $file): void { $newconcert= []; $fo = new SplFileObject($file['tmp_name']); @@ -61,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); } } } |