From 7140963e49af5783ca76308f78f96f3a53622f6d Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Sun, 15 Jan 2012 20:44:10 +1300 Subject: [PATCH] Allow user_no, created and modified to be set on create. --- dba/views/dav_principal.sql | 4 ++-- inc/Principal.php | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/dba/views/dav_principal.sql b/dba/views/dav_principal.sql index bd32df3b..1950c084 100644 --- a/dba/views/dav_principal.sql +++ b/dba/views/dav_principal.sql @@ -23,8 +23,8 @@ DO INSTEAD VALUES( COALESCE( NEW.user_no, nextval('usr_user_no_seq')), COALESCE( NEW.user_active, TRUE), - current_timestamp, - current_timestamp, + COALESCE( NEW.created, current_timestamp), + COALESCE( NEW.modified, current_timestamp), NEW.username, NEW.password, COALESCE( NEW.fullname, NEW.displayname ), NEW.email, NEW.email_ok, diff --git a/inc/Principal.php b/inc/Principal.php index deff90e8..c7c5a298 100644 --- a/inc/Principal.php +++ b/inc/Principal.php @@ -553,6 +553,16 @@ class Principal { throw new Exception( get_class($this).'::Create: Mandatory field "'.$k.'" is not set.'); } } + if ( isset($this->user_no) ) { + $param_names[] = ':user_no'; + $insert_fields[] = 'user_no'; + $sql_params[':user_no'] = $this->user_no; + } + if ( isset($this->created) ) { + $param_names[] = ':created'; + $insert_fields[] = 'created'; + $sql_params[':created'] = $this->created; + } $sql = 'INSERT INTO '.self::$db_tablename.' ('.implode(',',$insert_fields).') VALUES('.implode(',',$param_names).')'; } else {