From 735e99ac1cbf71733ba8b106ab13954fccf2f1d3 Mon Sep 17 00:00:00 2001 From: leosw Date: Tue, 30 Oct 2018 21:54:41 +0100 Subject: [PATCH] Store wikie page editor id in contributors table --- models/d.wiki.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/models/d.wiki.php b/models/d.wiki.php index ccb7fce..cc74ecc 100755 --- a/models/d.wiki.php +++ b/models/d.wiki.php @@ -98,15 +98,24 @@ class WikiPage $result = pg_execute($con, "prepare1", array($this->permalink)) or die ("Cannot execute statement\n"); - $query = "INSERT INTO contents (permalink, version, locale, creation_date, update_date, author, is_public, is_archive, is_commentable, type, name, content) VALUES - ($1, $2, $3, $4, $5, $6, TRUE, FALSE, FALSE, 'wiki', $7, $8)"; + ($1, $2, $3, $4, $5, $6, TRUE, FALSE, FALSE, 'wiki', $7, $8) RETURNING id"; pg_prepare($con, "prepare2", $query) or die ("Cannot prepare statement\n"); $result = pg_execute($con, "prepare2", array($this->permalink, $this->version, $this->locale, $this->creation_date, date('r'), $this->author, $this->name, $this->content)) or die ("Cannot execute statement\n"); + $this->id = pg_fetch_assoc($result)['id']; + + $query = "INSERT INTO content_contributors (content, contributor) VALUES + ($1, $2)"; + + pg_prepare($con, "prepare3", $query) + or die ("Cannot prepare statement\n"); + $result = pg_execute($con, "prepare3", array($this->id, $user->id)) + or die ("Cannot execute statement\n"); + pg_close($con); error_log( @@ -176,13 +185,15 @@ class WikiPage or die ("Could not connect to server\n"); $query = "INSERT INTO contents (permalink, version, locale, creation_date, update_date, author, is_public, is_archive, is_commentable, type, name, content) VALUES - ($1, '0', $2, $3, $4, $5, TRUE, FALSE, FALSE, 'wiki', $6, $7)"; + ($1, '0', $2, $3, $4, $5, TRUE, FALSE, FALSE, 'wiki', $6, $7) RETURNING id"; pg_prepare($con, "prepare1", $query) or die ("Cannot prepare statement\n"); $result = pg_execute($con, "prepare1", array($this->permalink, $this->locale, date('r'), date('r'), $user->id, $this->name, $this->content)) or die ("Cannot execute statement\n"); + $this->id = pg_fetch_assoc($result)['id']; + pg_close($con); error_log(