Mercurial > hg > fapweb
annotate createdb.php @ 32:36392d1d6b5f
Moar work.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 10 Dec 2012 11:14:05 +0200 |
parents | 4b5a176805e2 |
children | ace577c92a32 |
rev | line source |
---|---|
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 #!/usr/bin/php |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 <? |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 require "mconfig.inc.php"; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 require "msite.inc.php"; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 // We don't want to be run from anywhere else than commandline |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 stCheckCLIOrDie(); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 // The defaults we put in |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 $siteDefaults = array( |
11
c10bf196390f
Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
12 "maxAttendees" => array(VT_INT, 30, "Maximum attendees (soft limit)"), |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 |
32 | 14 "userTimeout" => array(VT_INT, 120, "User pages (voting, entry submission) timeout in minutes"), |
15 "admTimeout" => array(VT_INT, 15, "Administration interface timeout in minutes"), | |
27
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
16 |
17 | 17 "showAdmin" => array(VT_BOOL, false, "Show administration interface link on the menu"), |
18 "showAttendees" => array(VT_BOOL, false, "Show attendees list"), | |
11
c10bf196390f
Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
19 "allowRegister" => array(VT_BOOL, false, "Enable event registration"), |
27
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
20 "allowSubmit" => array(VT_BOOL, false, "Enable compo entry submission"), |
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
21 "allowVoting" => array(VT_BOOL, false, "Enable voting (individual compos must be enabled as well)"), |
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
22 |
11
c10bf196390f
Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
23 "showResults" => array(VT_BOOL, false, "Enable results page"), |
c10bf196390f
Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
24 "showResAuthors" => array(VT_BOOL, false, "Show entry authors on results page"), |
c10bf196390f
Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
25 "showVoteAuthors" => array(VT_BOOL, false, "Show entry authors on voting page"), |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 |
16 | 27 "requireEMail" => array(VT_BOOL, false, "Require e-mail address in registrations"), |
28 | |
29 "registerInfoText" => array(VT_TEXT, "<p> | |
30 Only your <b>handle</b> and the answer to the botcheck are strictly required. | |
31 If you plan on joining the IRC channel | |
32 (<a href=\"irc://#fap2022@ircnet\">#fap2022 @ IRCNet</a>) or staying up to date by other means, | |
33 <b>e-mail</b> is not required either. | |
34 </p>", "Registration page info text"), | |
35 | |
36 "registerPostText" => array(VT_TEXT, "<p>Now go make a demo about it!</p>", "Successful post-registration note text"), | |
37 | |
38 "registerPostNoEmail" => array(VT_TEXT, " | |
39 <h2>By the way ...</h2> | |
40 <p>As you did not specify an e-mail contact address, you'll have to get updates | |
41 and information about the location (if you don't already know it) by | |
42 some other means (IRC, for example.)</p> | |
43 ", "No e-mail address registration note"), | |
44 | |
45 "eventDescription" => array(VT_TEXT, " | |
46 <h1>Event program & schedule</h1> | |
47 <ul> | |
48 <li><b>Aegis</b> of DSS and FAG will be performing a DJ gig.</li> | |
49 <li>.. and possible additional live acts. More info to come.</li> | |
50 </ul> | |
51 | |
52 <h2>Friday 30.11.</h2> | |
53 <ul> | |
54 <li><b>18:00</b> - <i>Doors open</i>.</li> | |
55 <li><b>22:00</b> - DJ set by Aegis.</li> | |
56 </ul> | |
57 | |
58 <h2>Saturday 1.12.</h2> | |
59 <ul> | |
60 <li><b>14:00</b> - Deadline for remote entries.</li> | |
61 <li><b>18:00</b> - Deadline for the entries delivered on location.</li> | |
62 <li><b>20:00</b> - Competitions start.</li> | |
63 </ul> | |
64 | |
65 Competition schedule and voting deadline will depend on number of entries. | |
66 | |
67 <h2>Sunday 2.12.</h2> | |
68 <ul> | |
69 <li><b>12:00</b> - Party over?</li> | |
70 </ul> | |
71 ", "Event general description / timetables etc."), | |
72 | |
73 | |
14
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
74 "compoDescription" => array(VT_TEXT, " |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
75 <h1>General</h1> |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
76 <p class=\"notice\"> |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
77 YOU <b>MUST</b> HAVE AT LEAST ONE ENTRY TO COMPETITIONS IF YOU COME TO THE PARTY. |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
78 </p> |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
79 |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
80 <p class=\"note\"> |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
81 If there are enough entries, then AGA/OCS/ECS demos will be run in separate compos. |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
82 <br /> |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
83 Remote entries are welcome! |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
84 </p> |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
85 |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
86 <p> |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
87 The compo machine will be an <b>A1200 with an 060/50 and lots of |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
88 RAM</b>. An <b>A500 1.3 512k/512k</b> will also be available if your |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
89 prod is not AGA compatible. |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
90 </p> |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
91 |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
92 <h1>Compos</h1> |
e36c4d2b09c4
Fix settings to work, clean up the code, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
93 ", "Compo general description"), |
16 | 94 |
95 | |
96 "siteInfoText" => array(VT_TEXT, " | |
97 <a href=\"news\"> | |
98 <img src=\"img/fapsm.png\" alt=\"Finnish Amiga Party 2012\" class=\"logo\" /></a> | |
99 <div id=\"date\"> | |
100 30.11. - 2.12.2012<br /> | |
101 Helsinki, Finland<br /> | |
102 @ old location<br /> | |
103 Entry 15 EUR + prod | |
104 </div>", "Site header text"), | |
105 | |
106 | |
9
fa9b66f596bb
More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
107 "newsDescription" => array(VT_TEXT, " |
fa9b66f596bb
More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
108 <div style=\"text-align: center;\"> |
fa9b66f596bb
More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
109 <img src=\"img/fap.png\" alt=\"FAP\" /> |
fa9b66f596bb
More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
110 <p> |
fa9b66f596bb
More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
111 Pure Amiga demoscene party, all traditional Amiga compos and purely Amiga-oriented program. |
fa9b66f596bb
More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
112 <br /> |
fa9b66f596bb
More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
113 <span class=\"notice\"> |
fa9b66f596bb
More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
114 YOU <b>MUST</b> HAVE AT LEAST ONE ENTRY TO COMPETITIONS IF YOU COME TO THE PARTY. |
fa9b66f596bb
More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
115 </span> |
fa9b66f596bb
More work on settings storage.
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
116 </p> |
11
c10bf196390f
Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
117 </div>", |
c10bf196390f
Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
118 "News page header text"), |
29 | 119 |
120 | |
121 "entrySubmitInfo" => array(VT_TEXT, "Rules for entry submission ... ", "Entry submission information blurb"), | |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
122 ); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
123 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
124 $sqlTables = array( |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
125 "news" => "id INTEGER PRIMARY KEY AUTOINCREMENT, utime INT, title VARCHAR(128), text VARCHAR(4096), author VARCHAR(64), persist INT DEFAULT 0", |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
126 "attendees" => "id INTEGER PRIMARY KEY AUTOINCREMENT, regtime INT, name VARCHAR(64), groups VARCHAR(64), oneliner VARCHAR(64), email VARCHAR(80)", |
24
5bc8bd5c7ecc
Make voting toggle for individual compos.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
127 "compos" => "id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(128), description VARCHAR(4096), visible INT DEFAULT 0, voting INT DEFAULT 0", |
28 | 128 "entries" => "id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(64), author VARCHAR(64), uploader_id INT DEFAULT NULL, compo_id INT DEFAULT NULL, filename VARCHAR(128) DEFAULT NULL, screenshot VARCHAR(128) DEFAULT NULL", |
26
7be3f8cf1f7a
Lots of cleanups, preparing for adding entry submission support.
Matti Hamalainen <ccr@tnsp.org>
parents:
25
diff
changeset
|
129 "users" => "id INTEGER PRIMARY KEY AUTOINCREMENT, key VARCHAR(64), name VARCHAR(64), email VARCHAR(64), active INT DEFAULT 0", |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 "votes" => "id INTEGER PRIMARY KEY AUTOINCREMENT, entry_id INT DEFAULT NULL, voter_id INT DEFAULT NULL, value INT DEFAULT 0", |
11
c10bf196390f
Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
131 "settings" => "key VARCHAR(32) PRIMARY KEY, vtype INT, vstr VARCHAR(128), vtext TEXT, vint INT, desc VARCHAR(128)", |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 ); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
133 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
134 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
135 // |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
136 // Check for commandline arguments |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
137 // |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
138 function stConnectDB($dbspec) |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
139 { |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 global $db; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
141 try { |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
142 $db = new PDO($dbspec); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
143 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 catch (PDOException $e) { |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 error_log("Could not connect to SQL database '".$dbspec."': ".$e->getMessage()."."); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
146 return FALSE; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
147 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
148 return TRUE; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
149 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
151 |
11
c10bf196390f
Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
152 function stCreateOneTable($name, $schema) |
c10bf196390f
Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
153 { |
c10bf196390f
Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
154 return (stExecSQL("CREATE TABLE ".$name." (".$schema.")") !== FALSE) ? TRUE : FALSE; |
c10bf196390f
Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
155 } |
c10bf196390f
Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
156 |
c10bf196390f
Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
157 |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
158 function stCreateTables() |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
159 { |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
160 global $sqlTables; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
161 echo "Creating tables...\n"; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
162 foreach ($sqlTables as $name => $schema) |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
163 { |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
164 echo " - '".$name."'\n"; |
11
c10bf196390f
Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
165 if (!stCreateOneTable($name, $schema)) |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
166 return FALSE; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
167 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
168 return TRUE; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
169 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
170 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
171 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
172 function stAddSettings() |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
173 { |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
174 global $siteDefaults; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
175 echo "Adding settings to settings table.\n"; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
176 foreach ($siteDefaults as $key => $value) |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
177 { |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
178 switch ($value[0]) |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
179 { |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
180 case VT_TEXT: $type = "%s"; $var = "vtext"; break; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
181 case VT_STR: $type = "%s"; $var = "vstr"; break; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 case VT_BOOL: $type = "%B"; $var = "vint"; break; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 case VT_INT: $type = "%d"; $var = "vint"; break; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
184 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
185 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
186 $sql = stPrepareSQL( |
11
c10bf196390f
Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
187 "INSERT INTO settings (key,vtype,".$var.",desc) VALUES (%s,%d,".$type.",%s)", |
c10bf196390f
Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
188 $key, $value[0], $value[1], $value[2]); |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
189 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
190 stExecSQL($sql); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
191 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
192 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
193 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
194 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
195 if ($argc < 2) |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
196 { |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
197 echo "Usage: ".$argv[0]." <mode> [args]\n". |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
198 "Where mode is one of following:\n". |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
199 "\n". |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
200 " new [dbspec] Create a new database with given PDO spec\n". |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
201 " or default to the one in mconfig.inc.php\n". |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
202 "\n". |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
203 " reset [dbspec] Reset settings (similar to 'new').\n". |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
204 "\n"; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
205 exit; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
206 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
207 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
208 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
209 if (($spec = stCArg(2)) === FALSE) |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
210 $spec = $siteSettings["sqlDB"]; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
211 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
212 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
213 if (!stConnectDB($spec)) |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
214 die("Could not connect to SQL database '".$spec."'.\n"); |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
215 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
216 echo "Using database spec '".$spec."'.\n"; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
217 |
27
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
218 switch (stCArgLC(1)) |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
219 { |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
220 case "new": |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
221 if (stCreateTables()) |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
222 stAddSettings(); |
27
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
223 |
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
224 if (substr($spec, 0, 7) == "sqlite:") |
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
225 { |
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
226 $filename = substr($spec, 7); |
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
227 echo "NOTICE! It seems you have SQLite database in use, changing permission ". |
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
228 "of the target file '".$filename."' to 0600, for security. You may have to ". |
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
229 "loosen up that for the things to actually work, but be careful. Having your ". |
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
230 "database world-readable in the web is NOT good.\n"; |
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
231 |
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
232 if (chmod($filename, 0600) === FALSE) |
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
233 { |
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
234 echo "ERROR! Could not set permissions!\n"; |
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
235 } |
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
236 } |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
237 break; |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
238 |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
239 case "reset": |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
240 echo "Deleting old settings.\n"; |
11
c10bf196390f
Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
241 stExecSQL("DROP TABLE settings"); |
c10bf196390f
Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
242 |
c10bf196390f
Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
243 if (stCreateOneTable("settings", $sqlTables["settings"])) |
c10bf196390f
Improve database initialization script.
Matti Hamalainen <ccr@tnsp.org>
parents:
9
diff
changeset
|
244 stAddSettings(); |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
245 break; |
27
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
246 |
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
247 default: |
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
248 echo "ERROR! Invalid operation mode '".stCArg(1)."'.\n"; |
b27204653615
Work on adding support for entry submission.
Matti Hamalainen <ccr@tnsp.org>
parents:
26
diff
changeset
|
249 break; |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
250 } |
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
251 |
28 | 252 |
253 // | |
254 // Clean up permissions | |
255 // | |
256 foreach (array("createdb.php", "keygen.php") as $filename) | |
257 { | |
258 if (chmod($filename, 0700) === FALSE) | |
259 { | |
260 echo "ERROR! Could not set permissions for '$filename'!\n"; | |
261 } | |
262 } | |
263 | |
8
4c5f651aa107
Migrate certain settings to SQL database, cleanups, etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
264 ?> |