Skip to content

Commit

Permalink
Merge pull request #15148 from marcusmoore/fixes/dates-in-user-import
Browse files Browse the repository at this point in the history
Fixed start_date and end_date in user importer
  • Loading branch information
snipe committed Jul 23, 2024
2 parents 1f4118a + f4a3823 commit 57b5b12
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions app/Importer/UserImporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function createUserIfNotExists(array $row)
$this->item['vip'] = ($this->fetchHumanBoolean(trim($this->findCsvMatch($row, 'vip'))) ==1 ) ? '1' : 0;
$this->item['autoassign_licenses'] = ($this->fetchHumanBoolean(trim($this->findCsvMatch($row, 'autoassign_licenses'))) ==1 ) ? '1' : 0;

$this->handleEmptyStringsForDates();

$user_department = trim($this->findCsvMatch($row, 'department'));
if ($this->shouldUpdateField($user_department)) {
Expand Down Expand Up @@ -179,4 +180,22 @@ public function sendWelcome($send = true)
{
$this->send_welcome = $send;
}

/**
* Since the findCsvMatch() method will set '' for columns that are present but empty,
* we need to set those empty strings to null to avoid passing bad data to the database
* (ie ending up with 0000-00-00 instead of the intended null).
*
* @return void
*/
private function handleEmptyStringsForDates(): void
{
if ($this->item['start_date'] === '') {
$this->item['start_date'] = null;
}

if ($this->item['end_date'] === '') {
$this->item['end_date'] = null;
}
}
}

0 comments on commit 57b5b12

Please sign in to comment.