create_account_anon boolean DEFAULT true NOT NULL,
theme_css text,
feedback_email text,
- mailing_list boolean DEFAULT false NOT NULL
+ mailing_list boolean DEFAULT false NOT NULL,
+ is_template boolean DEFAULT false NOT NULL
);
can_manage_users boolean DEFAULT false NOT NULL,
can_manage_contacts boolean DEFAULT false NOT NULL,
can_manage_site boolean DEFAULT false NOT NULL,
- can_edit_global_css boolean DEFAULT false NOT NULL
+ can_edit_global_css boolean DEFAULT false NOT NULL,
+ force_password_change boolean DEFAULT false NOT NULL
);
--
--- TOC entry 62 (OID 542626)
+-- TOC entry 63 (OID 542626)
-- Name: contact_emails_uq; Type: INDEX; Schema: public; Owner: rich
--
--
--- TOC entry 63 (OID 543505)
+-- TOC entry 64 (OID 543505)
-- Name: themes_theme_css_uq; Type: INDEX; Schema: public; Owner: rich
--
--
--- TOC entry 64 (OID 543763)
+-- TOC entry 65 (OID 543763)
-- Name: page_emails_email_uq; Type: INDEX; Schema: public; Owner: rich
--
--
--- TOC entry 65 (OID 543795)
+-- TOC entry 66 (OID 543795)
-- Name: mailing_lists_email_uq; Type: INDEX; Schema: public; Owner: rich
--
--
+-- TOC entry 61 (OID 543880)
+-- Name: contacts_name_uq; Type: INDEX; Schema: public; Owner: rich
+--
+
+CREATE UNIQUE INDEX contacts_name_uq ON contacts USING btree (hostid, name);
+
+
+--
-- TOC entry 45 (OID 536012)
-- Name: pages_pkey; Type: CONSTRAINT; Schema: public; Owner: rich
--
--
--- TOC entry 61 (OID 542611)
+-- TOC entry 62 (OID 542611)
-- Name: contacts_pkey; Type: CONSTRAINT; Schema: public; Owner: rich
--
--
--- TOC entry 70 (OID 536029)
+-- TOC entry 71 (OID 536029)
-- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
--
--
--- TOC entry 73 (OID 536384)
+-- TOC entry 74 (OID 536384)
-- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
--
--
--- TOC entry 71 (OID 536394)
+-- TOC entry 72 (OID 536394)
-- Name: hosts_hostname_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
--
--
--- TOC entry 66 (OID 536404)
+-- TOC entry 67 (OID 536404)
-- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
--
--
--- TOC entry 74 (OID 536920)
+-- TOC entry 75 (OID 536920)
-- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
--
--
--- TOC entry 75 (OID 537160)
+-- TOC entry 76 (OID 537160)
-- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
--
--
--- TOC entry 76 (OID 537175)
+-- TOC entry 77 (OID 537175)
-- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
--
--
--- TOC entry 67 (OID 539155)
+-- TOC entry 68 (OID 539155)
-- Name: pages_redirect_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
--
--
--- TOC entry 77 (OID 540827)
+-- TOC entry 78 (OID 540827)
-- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
--
--
--- TOC entry 78 (OID 540837)
+-- TOC entry 79 (OID 540837)
-- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
--
--
--- TOC entry 68 (OID 540942)
+-- TOC entry 69 (OID 540942)
-- Name: $2; Type: FK CONSTRAINT; Schema: public; Owner: rich
--
--
--- TOC entry 69 (OID 540947)
+-- TOC entry 70 (OID 540947)
-- Name: pages_user_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
--
--
--- TOC entry 79 (OID 540966)
+-- TOC entry 80 (OID 540966)
-- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
--
--
--- TOC entry 80 (OID 540972)
+-- TOC entry 81 (OID 540972)
-- Name: sitemenu_url_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
--
--
--- TOC entry 81 (OID 542613)
+-- TOC entry 82 (OID 542613)
-- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
--
--
--- TOC entry 82 (OID 542622)
+-- TOC entry 83 (OID 542622)
-- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
--
--
--- TOC entry 72 (OID 543506)
+-- TOC entry 73 (OID 543506)
-- Name: hosts_theme_css_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
--
--
--- TOC entry 83 (OID 543759)
+-- TOC entry 84 (OID 543759)
-- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
--
--
--- TOC entry 84 (OID 543764)
+-- TOC entry 85 (OID 543764)
-- Name: page_emails_url_cn; Type: FK CONSTRAINT; Schema: public; Owner: rich
--
--
--- TOC entry 85 (OID 543791)
+-- TOC entry 86 (OID 543791)
-- Name: $1; Type: FK CONSTRAINT; Schema: public; Owner: rich
--
(* COCANWIKI - a wiki written in Objective CAML.
* Written by Richard W.M. Jones <rich@merjis.com>.
* Copyright (C) 2004 Merjis Ltd.
- * $Id: create_host.ml,v 1.3 2004/09/09 12:21:22 rich Exp $
+ * $Id: create_host.ml,v 1.4 2004/09/25 11:45:59 rich Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
let hostnames = List.map check_hostname hostnames in
let hostnames = List.filter ((<>) "") hostnames in
- (* Update the database. *)
- let sth = dbh#prepare_cached
- "set constraints \"hosts_hostname_cn\" deferred" in
+ let sth =
+ dbh#prepare_cached "set constraints hosts_hostname_cn deferred" in
sth#execute [];
let sth = dbh#prepare_cached "insert into hosts (canonical_hostname)
- values (?)" in
+ values (?)" in
sth#execute [`String canonical_hostname];
let hostid = sth#serial "hosts_id_seq" in
let sth = dbh#prepare_cached "insert into hostnames (hostid, name)
- values (?, ?)" in
+ values (?, ?)" in
sth#execute [`Int hostid; `String canonical_hostname];
List.iter (fun name ->
sth#execute [`Int hostid; `String name]) hostnames;
- let sth = dbh#prepare_cached "insert into pages (hostid, url, title,
+ (* Are we creating a blank site or copying a template? *)
+ if not (q#param_true "template") then (
+ (* Blank site. *)
+
+ let sth = dbh#prepare_cached "insert into pages (hostid, url, title,
description) values (?, 'index', ?, ?)" in
- sth#execute [`Int hostid; `String title; `String title];
+ sth#execute [`Int hostid; `String title; `String title];
+
+ ) else (
+ (* Copy from template. *)
+ let template = int_of_string (q#param "template") in
+
+ (*dbh#set_debug true;*)
+
+ let sth = dbh#prepare_cached "select * from hosts where id = ?" in
+ sth#execute [`Int template];
+
+ let names = sth#names in
+ let row = sth#fetch1 () in
+ sth#finish ();
+
+ List.iter
+ (fun (name, field) ->
+ if name <> "id" && name <> "canonical_hostname" then (
+ let sql = "update hosts set " ^ name ^ " = ? where id = ?" in
+ let sth = dbh#prepare_cached sql in
+ sth#execute [field; `Int hostid]
+ )
+ ) (List.combine names row);
+
+ (* Copy pages. *)
+ let sth =
+ dbh#prepare_cached
+ "insert into pages (hostid, url, title, description, redirect, css)
+ select ?, url, title, description, redirect, css
+ from pages
+ where hostid = ? and url is not null" in
+ sth#execute [`Int hostid; `Int template];
+
+ (* Copy page contents. *)
+ let sth =
+ dbh#prepare_cached
+ "insert into contents (pageid, ordering, sectionname, content,
+ divname)
+ select (select id from pages where hostid = ? and url = p.url),
+ c.ordering, c.sectionname, c.content, c.divname
+ from contents c, pages p
+ where c.pageid = p.id and p.hostid = ? and p.url is not null" in
+ sth#execute [`Int hostid; `Int template];
+
+ (* Copy files and images. *)
+ let sth =
+ dbh#prepare_cached
+ "insert into files (hostid, name, content, title, mime_type)
+ select ?, name, content, title, mime_type
+ from files
+ where hostid = ? and name is not null" in
+ sth#execute [`Int hostid; `Int template];
+
+ let sth =
+ dbh#prepare_cached
+ "insert into images (hostid, name, image, width, height, alt, title,
+ longdesc, class, mime_type, thumbnail,
+ tn_width, tn_height, tn_mime_type)
+ select ?, name, image, width, height, alt, title, longdesc, class,
+ mime_type, thumbnail, tn_width, tn_height, tn_mime_type
+ from images
+ where hostid = ? and name is not null" in
+ sth#execute [`Int hostid; `Int template];
+
+ (* Copy sitemenu. *)
+ let sth =
+ dbh#prepare_cached
+ "insert into sitemenu (hostid, url, label, ordering)
+ select ?, url, label, ordering from sitemenu where hostid = ?" in
+ sth#execute [`Int hostid; `Int template];
+
+ (* Copy contacts. *)
+ let sth =
+ dbh#prepare_cached
+ "insert into contacts (hostid, name, subject)
+ select ?, name, subject from contacts where hostid = ?" in
+ sth#execute [`Int hostid; `Int template];
+
+ let sth =
+ dbh#prepare_cached
+ "insert into contact_emails (contactid, email)
+ select (select contactid from contacts
+ where hostid = ? and name = c.name), ce.email
+ from contact_emails ce, contacts c
+ where ce.contactid = c.id and c.hostid = ?" in
+ sth#execute [`Int hostid; `Int template];
+
+ (* Set the title of the index page. *)
+ let sth = dbh#prepare_cached "update pages set title = ?
+ where hostid = ? and url = 'index'" in
+ sth#execute [`String title; `Int hostid]
+ );
+
+ (* Create the administrator user. *)
+ let sth = dbh#prepare_cached "insert into users (hostid, name, password,
+ force_password_change, can_manage_users)
+ values (?, 'Administrator', '123456', true,
+ true)" in
+ sth#execute [`Int hostid];
(* Commit to the database. *)
dbh#commit ();