Skip to content

Commit

Permalink
fix write sql audit log on database error; add unique indexes for suser
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey Loktionov committed Nov 18, 2020
1 parent 95d5f6d commit 2d615c1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions etc/sql/pgsql-basesystem.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ CREATE TABLE suser (
status BOOL
) WITH OIDS;

CREATE UNIQUE INDEX suser_title_uniq_idx ON suser(title);
CREATE UNIQUE INDEX suser_email_uniq_idx ON suser(lower(email)) WHERE email IS NOT NULL;

CREATE TABLE sgroup (
id SERIAL PRIMARY KEY,
sys_owner INT4 DEFAULT NULL REFERENCES suser ON DELETE SET NULL ON UPDATE CASCADE,
Expand Down
7 changes: 4 additions & 3 deletions lib/Database/database.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -781,8 +781,8 @@ class PXDatabase extends DatabaseAdapter implements DatabaseInterface
$newId = $this->InsertObject($format->id, $dbFields, $dbValues, false);
if ($newId < 0) {
$errString = $this->GetError();
$audit->error($errString, $format->id . '/' . getFromArray($object, 'parent'));
$this->transactionRollback();
$audit->error($errString, $format->id . '/' . getFromArray($object, 'parent'));
$this->FatalError($errString);
}

Expand Down Expand Up @@ -1095,9 +1095,10 @@ class PXDatabase extends DatabaseAdapter implements DatabaseInterface
$result = $this->UpdateObjectById($format->id, $object['id'], $dbFields, $dbValues, false);

if ($result < 0) {
$audit->error($this->GetError(), $format->id . '/' . $object['id']);
$errString = $this->GetError();
$this->transactionRollback();
$this->FatalError($this->GetError());
$audit->error($errString, $format->id . '/' . $object['id']);
$this->FatalError($errString);
}
if ($format->struct == 'tree' && isset($objectInDB['parent']) && $objectInDB['parent'] != $object['parent']) {
$childs = $this->getObjectsByParent($format, NULL, $objectInDB['parent'], DB_SELECT_TREE);
Expand Down
1 change: 1 addition & 0 deletions lib/Logger/nllogger.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ class FileAppender extends Appender
*/
class SQLAppender extends Appender
{
/** @var PXDatabase */
public $db;

public function __construct($name)
Expand Down

0 comments on commit 2d615c1

Please sign in to comment.