summaryrefslogtreecommitdiffstats
path: root/includes/admin/views/giglog_import_gigs.php
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2022-03-09 21:41:54 +0100
committerHarald Eilertsen <haraldei@anduin.net>2022-03-09 21:41:54 +0100
commit4ceb50835b38f74b68a4d1d1e0d3a32baeeb8b89 (patch)
tree1cf0a87c65b9b3970a775e51848dae1affb90f34 /includes/admin/views/giglog_import_gigs.php
parent82a3901a6d68f088aff335a1bc88b9878e17e990 (diff)
parente1ac66aade5c2d5d2d9f6c6db501fccd9db9be0a (diff)
downloadgigologadmin-4ceb50835b38f74b68a4d1d1e0d3a32baeeb8b89.tar.gz
gigologadmin-4ceb50835b38f74b68a4d1d1e0d3a32baeeb8b89.tar.bz2
gigologadmin-4ceb50835b38f74b68a4d1d1e0d3a32baeeb8b89.zip
Merge remote-tracking branch 'andrea/andreaschanges' into dev
And fixup most whitespace issues while at it.
Diffstat (limited to 'includes/admin/views/giglog_import_gigs.php')
-rw-r--r--includes/admin/views/giglog_import_gigs.php79
1 files changed, 65 insertions, 14 deletions
diff --git a/includes/admin/views/giglog_import_gigs.php b/includes/admin/views/giglog_import_gigs.php
index 62717c6..ed6f978 100644
--- a/includes/admin/views/giglog_import_gigs.php
+++ b/includes/admin/views/giglog_import_gigs.php
@@ -56,32 +56,83 @@ if ( !class_exists( 'GiglogAdmin_ImportGigsPage' ) ) {
* @param array<mixed>
*/
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 (is_numeric($venue)) {
- $venue = GiglogAdmin_Venue::get($venue);
- }
- else {
- $venue = GiglogAdmin_Venue::find_or_create($venue,'Oslo');
+ //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!'."<br>";
+ 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]."<br>";
- $condate = date('Y-m-d', strtotime($resultArray[2]));
- $ticketlink = trim($resultArray[3]);
- $eventlink = trim($resultArray[4]);
+ continue;
+ }
+ else {
+ if (empty(trim($resultArray[0]))) {
+ $importerrors.= 'Row '.$rid.' is missing concert name!'."<br>";
+ continue;
+ }
+ elseif (empty(trim($resultArray[1]))) {
+ $importerrors.= 'Row '.$rid.' is missing venue name!'."<br>";
+ continue;
+ }
+ elseif (empty(trim($resultArray[2]))) {
+ $importerrors.= 'Row '.$rid.' is missing city name!' ."<br>";
+ continue;
+ }
+ else {
+ $condate = date('Y-m-d', strtotime($resultArray[3]));
+ if ($condate<date("Y-m-d")) {
+ $importerrors.= 'Row '.$rid.' has date in the past!' .$resultArray[3]."<br>";
+ continue;
+ }
+ else {
+ $cname = trim($resultArray[0]);
+ $venue = trim($resultArray[1]);
- 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)!'."<br>";
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (!empty($importerrors)) {
+ echo ($importerrors);
+ }
+ else {
+ echo ('All rows imported ok');
}
}
}