Skip to content

Commit

Permalink
quickfix lonnieezell#324: conversion int/bool for PostgreSQL and othe…
Browse files Browse the repository at this point in the history
…r strict DB
  • Loading branch information
xlii-chl committed Feb 19, 2022
1 parent a8f45cc commit 13ab6e4
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/Entities/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,32 @@ public function setPassword(string $password)
$this->attributes['reset_expires'] = null;
}

/**
* Explicitly convert false and true to 0 and 1
*
* Some BDD (PostgreSQL for example) can be picky about data types and
* if 'active' or 'force_pass_reset' are set to (bool)true/false, the method
* CodeIgniter\Database\Postgre\Connection::escape() will translate it
* to a literal TRUE/FALSE. Since the database fields are defined as integer,
* an error will be emitted.
*
* @param int|bool $active
*/
public function setActive($active)
{
$this->attributes['active'] = $active ? 1 : 0;
}

/**
* Explicitly convert false and true to 0 and 1
*
* @param int|bool $active
*/
public function setForcePassReset($force_pass_reset)
{
$this->attributes['force_pass_reset'] = $force_pass_reset ? 1 : 0;
}

/**
* Force a user to reset their password on next page refresh
* or login. Checked in the LocalAuthenticator's check() method.
Expand Down

0 comments on commit 13ab6e4

Please sign in to comment.