PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/test/dummyDBCreator.php

#
PHP | 671 lines | 562 code | 93 blank | 16 comment | 55 complexity | e129b5e4f220c83c910cd02b3c9abd2c MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1
  1. <?php
  2. /*
  3. Copyright (C) 2009-2010 Fabio Mattei <burattino@gmail.com>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. include ('../system/config.php');
  16. class DbCreator {
  17. private $connection;
  18. public function connect() {
  19. $this->connection = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
  20. mysql_select_db(DB_NAME, $this->connection);
  21. }
  22. public function closeConnection() {
  23. if ($this->connection) {
  24. mysql_close($this->connection);
  25. }
  26. }
  27. public function createTableNumbers() {
  28. $cmd = "CREATE TABLE ".TBPREFIX."numbers (
  29. id int(11) NOT NULL auto_increment,
  30. indexnumber int,
  31. published int NOT NULL DEFAULT '0',
  32. title varchar(255),
  33. subtitle text,
  34. summary text,
  35. commentsallowed int,
  36. metadescription text,
  37. metakeyword text,
  38. created datetime,
  39. updated datetime,
  40. PRIMARY KEY (id));";
  41. $result = mysql_query($cmd, $this->connection);
  42. return $result;
  43. }
  44. public function populateTableNumbers() {
  45. $cmd = "insert into ".TBPREFIX."numbers (id, indexnumber, published, title, subtitle, summary, commentsallowed, metadescription, metakeyword, created, updated)
  46. values (1, 1, 1, 'My first number', 'Subtitle to my first number',
  47. 'Summary of my first number', 1, '', '', NOW(), NOW())";
  48. $result = mysql_query($cmd, $this->connection);
  49. $cmd = "insert into ".TBPREFIX."numbers (id, indexnumber, published, title, subtitle, summary, commentsallowed, metadescription, metakeyword, created, updated)
  50. values (2, 2, 1, 'My second number', 'Subtitle to my second number',
  51. 'Summary of my second number', 1, '', '', NOW(), NOW())";
  52. $result = mysql_query($cmd, $this->connection);
  53. $cmd = "insert into ".TBPREFIX."numbers (id, indexnumber, published, title, subtitle, summary, commentsallowed, metadescription, metakeyword, created, updated)
  54. values (3, 3, 1, 'My third number', 'Subtitle to my third number',
  55. 'Summary of my third number', 0, '', '', NOW(), NOW())";
  56. $result = mysql_query($cmd, $this->connection);
  57. $cmd = "insert into ".TBPREFIX."numbers (id, indexnumber, published, title, subtitle, summary, commentsallowed, metadescription, metakeyword, created, updated)
  58. values (4, 4, 1, 'My 4th number', 'Subtitle to my first number',
  59. 'Summary of my first number', 1, '', '', NOW(), NOW())";
  60. $result = mysql_query($cmd, $this->connection);
  61. $cmd = "insert into ".TBPREFIX."numbers (id, indexnumber, published, title, subtitle, summary, commentsallowed, metadescription, metakeyword, created, updated)
  62. values (5, 5, 1, 'My 5th number', 'Subtitle to my second number',
  63. 'Summary of my second number', 1, '', '', NOW(), NOW())";
  64. $result = mysql_query($cmd, $this->connection);
  65. $cmd = "insert into ".TBPREFIX."numbers (id, indexnumber, published, title, subtitle, summary, commentsallowed, metadescription, metakeyword, created, updated)
  66. values (6, 6, 1, 'My 6th number', 'Subtitle to my third number',
  67. 'Summary of my third number', 0, '', '', NOW(), NOW())";
  68. $result = mysql_query($cmd, $this->connection);
  69. $cmd = "insert into ".TBPREFIX."numbers (id, indexnumber, published, title, subtitle, summary, commentsallowed, metadescription, metakeyword, created, updated)
  70. values (7, 7, 1, 'My 7th number', 'Subtitle to my first number',
  71. 'Summary of my first number', 1, '', '', NOW(), NOW())";
  72. $result = mysql_query($cmd, $this->connection);
  73. $cmd = "insert into ".TBPREFIX."numbers (id, indexnumber, published, title, subtitle, summary, commentsallowed, metadescription, metakeyword, created, updated)
  74. values (8, 8, 1, 'My 8th number', 'Subtitle to my second number',
  75. 'Summary of my second number', 1, '', '', NOW(), NOW())";
  76. $result = mysql_query($cmd, $this->connection);
  77. $cmd = "insert into ".TBPREFIX."numbers (id, indexnumber, published, title, subtitle, summary, commentsallowed, metadescription, metakeyword, created, updated)
  78. values (9, 9, 1, 'My 9th number', 'Subtitle to my third number',
  79. 'Summary of my third number', 0, '', '', NOW(), NOW())";
  80. $result = mysql_query($cmd, $this->connection);
  81. $cmd = "insert into ".TBPREFIX."numbers (id, indexnumber, published, title, subtitle, summary, commentsallowed, metadescription, metakeyword, created, updated)
  82. values (10, 10, 1, 'My 10 number', 'Subtitle to my first number',
  83. 'Summary of my first number', 1, '', '', NOW(), NOW())";
  84. $result = mysql_query($cmd, $this->connection);
  85. $cmd = "insert into ".TBPREFIX."numbers (id, indexnumber, published, title, subtitle, summary, commentsallowed, metadescription, metakeyword, created, updated)
  86. values (11, 11, 1, 'My 11 number', 'Subtitle to my second number',
  87. 'Summary of my second number', 1, '', '', NOW(), NOW())";
  88. $result = mysql_query($cmd, $this->connection);
  89. $cmd = "insert into ".TBPREFIX."numbers (id, indexnumber, published, title, subtitle, summary, commentsallowed, metadescription, metakeyword, created, updated)
  90. values (12, 12, 1, 'My 12 number', 'Subtitle to my third number',
  91. 'Summary of my third number', 0, '', '', NOW(), NOW())";
  92. $result = mysql_query($cmd, $this->connection);
  93. $cmd = "insert into ".TBPREFIX."numbers (id, indexnumber, published, title, subtitle, summary, commentsallowed, metadescription, metakeyword, created, updated)
  94. values (13, 13, 1, 'My 13 number', 'Subtitle to my first number',
  95. 'Summary of my first number', 1, '', '', NOW(), NOW())";
  96. $result = mysql_query($cmd, $this->connection);
  97. $cmd = "insert into ".TBPREFIX."numbers (id, indexnumber, published, title, subtitle, summary, commentsallowed, metadescription, metakeyword, created, updated)
  98. values (14, 14, 1, 'My 14th number', 'Subtitle to my second number',
  99. 'Summary of my second number', 1, '', '', NOW(), NOW())";
  100. $result = mysql_query($cmd, $this->connection);
  101. $cmd = "insert into ".TBPREFIX."numbers (id, indexnumber, published, title, subtitle, summary, commentsallowed, metadescription, metakeyword, created, updated)
  102. values (15, 15, 0, 'My 15th number', 'Subtitle to my third number',
  103. 'Summary of my third number', 0, '', '', NOW(), NOW())";
  104. $result = mysql_query($cmd, $this->connection);
  105. return $result;
  106. }
  107. public function dropTableNumbers() {
  108. $cmd="DROP TABLE IF EXISTS ".TBPREFIX."numbers;";
  109. $result = mysql_query($cmd, $this->connection);
  110. return $result;
  111. }
  112. public function createTableArticles() {
  113. $cmd = "CREATE TABLE ".TBPREFIX."articles (
  114. id int(11) NOT NULL auto_increment,
  115. number_id int(11),
  116. category_id int(11),
  117. indexnumber int,
  118. published int NOT NULL DEFAULT '0',
  119. title varchar(255),
  120. subtitle text,
  121. summary text,
  122. body text,
  123. commentsallowed int,
  124. tag text,
  125. metadescription text,
  126. metakeyword text,
  127. created datetime,
  128. updated datetime,
  129. PRIMARY KEY (id));";
  130. $result = mysql_query($cmd, $this->connection);
  131. return $result;
  132. }
  133. public function populateTableArticles() {
  134. $cmd = "insert into ".TBPREFIX."articles (id, number_id, category_id, indexnumber, published, title, subtitle, summary, body, commentsallowed, tag, metadescription, metakeyword, created, updated) values
  135. (1, 1, 1, 1, 1, 'My first Article', 'Subtitle of my first article', 'summary of my first article',
  136. 'Body of my first article', 1, 'history, flowers',
  137. 'metadescription of my first article', 'metakeyword of my first article', now(), now())";
  138. $result = mysql_query($cmd, $this->connection);
  139. $cmd = "insert into ".TBPREFIX."articles (id, number_id, category_id, indexnumber, published, title, subtitle, summary, body, commentsallowed, tag, metadescription, metakeyword, created, updated) values
  140. (2, 1, 1, 2, 1, 'My second Article', 'Subtitle of my second article', 'summary of my second article',
  141. 'Body of my second article', 1, 'flowers, hello',
  142. 'metadescription of my second article', 'metakeyword of my second article', now(), now())";
  143. $result = mysql_query($cmd, $this->connection);
  144. $cmd = "insert into ".TBPREFIX."articles (id, number_id, category_id, indexnumber, published, title, subtitle, summary, body, commentsallowed, tag, metadescription, metakeyword, created, updated) values
  145. (3, 1, 2, 3, 0, 'My third Article', 'Subtitle of my third article', 'summary of my third article',
  146. 'Body of my third article', 1, 'roman history, bike',
  147. 'metadescription of my third article', 'metakeyword of my third article', now(), now())";
  148. $result = mysql_query($cmd, $this->connection);
  149. $cmd = "insert into ".TBPREFIX."articles (id, number_id, category_id, indexnumber, published, title, subtitle, summary, body, commentsallowed, tag, metadescription, metakeyword, created, updated) values
  150. (4, 1, 1, 4, 1, 'My first Article', 'Subtitle of my first article', 'summary of my first article',
  151. 'Body of my first article', 1, 'bike, flowers',
  152. 'metadescription of my first article', 'metakeyword of my first article', now(), now())";
  153. $result = mysql_query($cmd, $this->connection);
  154. $cmd = "insert into ".TBPREFIX."articles (id, number_id, category_id, indexnumber, published, title, subtitle, summary, body, commentsallowed, tag, metadescription, metakeyword, created, updated) values
  155. (5, 1, 1, 5, 1, 'My second Article', 'Subtitle of my second article', 'summary of my second article',
  156. 'Body of my second article', 1, 'tag of my second article',
  157. 'metadescription of my second article', 'metakeyword of my second article', now(), now())";
  158. $result = mysql_query($cmd, $this->connection);
  159. $cmd = "insert into ".TBPREFIX."articles (id, number_id, category_id, indexnumber, published, title, subtitle, summary, body, commentsallowed, tag, metadescription, metakeyword, created, updated) values
  160. (6, 1, 1, 6, 1, 'My third Article', 'Subtitle of my third article', 'summary of my third article',
  161. 'Body of my third article', 1, 'tag of my third article',
  162. 'metadescription of my third article', 'metakeyword of my third article', now(), now())";
  163. $result = mysql_query($cmd, $this->connection);
  164. $cmd = "insert into ".TBPREFIX."articles (id, number_id, category_id, indexnumber, published, title, subtitle, summary, body, commentsallowed, tag, metadescription, metakeyword, created, updated) values
  165. (7, 1, 1, 7, 1, 'My first Article', 'Subtitle of my first article', 'summary of my first article',
  166. 'Body of my first article', 1, 'tag of my first article',
  167. 'metadescription of my first article', 'metakeyword of my first article', now(), now())";
  168. $result = mysql_query($cmd, $this->connection);
  169. $cmd = "insert into ".TBPREFIX."articles (id, number_id, category_id, indexnumber, published, title, subtitle, summary, body, commentsallowed, tag, metadescription, metakeyword, created, updated) values
  170. (8, 1, 1, 8, 1, 'My second Article', 'Subtitle of my second article', 'summary of my second article',
  171. 'Body of my second article', 1, 'tag of my second article',
  172. 'metadescription of my second article', 'metakeyword of my second article', now(), now())";
  173. $result = mysql_query($cmd, $this->connection);
  174. $cmd = "insert into ".TBPREFIX."articles (id, number_id, category_id, indexnumber, published, title, subtitle, summary, body, commentsallowed, tag, metadescription, metakeyword, created, updated) values
  175. (9, 1, 1, 9, 1, 'My third Article', 'Subtitle of my third article', 'summary of my third article',
  176. 'Body of my third article', 1, 'tag of my third article',
  177. 'metadescription of my third article', 'metakeyword of my third article', now(), now())";
  178. $result = mysql_query($cmd, $this->connection);
  179. $cmd = "insert into ".TBPREFIX."articles (id, number_id, category_id, indexnumber, published, title, subtitle, summary, body, commentsallowed, tag, metadescription, metakeyword, created, updated) values
  180. (10, 1, 1, 10, 1, 'My first Article', 'Subtitle of my first article', 'summary of my first article',
  181. 'Body of my first article', 1, 'tag of my first article',
  182. 'metadescription of my first article', 'metakeyword of my first article', now(), now())";
  183. $result = mysql_query($cmd, $this->connection);
  184. $cmd = "insert into ".TBPREFIX."articles (id, number_id, category_id, indexnumber, published, title, subtitle, summary, body, commentsallowed, tag, metadescription, metakeyword, created, updated) values
  185. (11, 1, 1, 11, 1, 'My second Article', 'Subtitle of my second article', 'summary of my second article',
  186. 'Body of my second article', 1, 'tag of my second article',
  187. 'metadescription of my second article', 'metakeyword of my second article', now(), now())";
  188. $result = mysql_query($cmd, $this->connection);
  189. $cmd = "insert into ".TBPREFIX."articles (id, number_id, category_id, indexnumber, published, title, subtitle, summary, body, commentsallowed, tag, metadescription, metakeyword, created, updated) values
  190. (12, 1, 1, 12, 1, 'My third Article', 'Subtitle of my third article', 'summary of my third article',
  191. 'Body of my third article', 1, 'tag of my third article',
  192. 'metadescription of my third article', 'metakeyword of my third article', now(), now())";
  193. $result = mysql_query($cmd, $this->connection);
  194. $cmd = "insert into ".TBPREFIX."articles (id, number_id, category_id, indexnumber, published, title, subtitle, summary, body, commentsallowed, tag, metadescription, metakeyword, created, updated) values
  195. (13, 1, 1, 13, 1, 'My first Article', 'Subtitle of my first article', 'summary of my first article',
  196. 'Body of my first article', 1, 'tag of my first article',
  197. 'metadescription of my first article', 'metakeyword of my first article', now(), now())";
  198. $result = mysql_query($cmd, $this->connection);
  199. $cmd = "insert into ".TBPREFIX."articles (id, number_id, category_id, indexnumber, published, title, subtitle, summary, body, commentsallowed, tag, metadescription, metakeyword, created, updated) values
  200. (14, 1, 1, 14, 1, 'My second Article', 'Subtitle of my second article', 'summary of my second article',
  201. 'Body of my second article', 1, 'tag of my second article',
  202. 'metadescription of my second article', 'metakeyword of my second article', now(), now())";
  203. $result = mysql_query($cmd, $this->connection);
  204. $cmd = "insert into ".TBPREFIX."articles (id, number_id, category_id, indexnumber, published, title, subtitle, summary, body, commentsallowed, tag, metadescription, metakeyword, created, updated) values
  205. (15, 1, 1, 15, 1, 'My third Article', 'Subtitle of my third article', 'summary of my third article',
  206. 'Body of my third article', 1, 'roman history, flowers, hello',
  207. 'metadescription of my third article', 'metakeyword of my third article', now(), now())";
  208. $result = mysql_query($cmd, $this->connection);
  209. $cmd = "insert into ".TBPREFIX."articles (id, number_id, category_id, indexnumber, published, title, subtitle, summary, body, commentsallowed, tag, metadescription, metakeyword, created, updated) values
  210. (16, 14, 1, 15, 1, 'My final Article', 'Subtitle of my final article', 'summary of my final article',
  211. 'Body of my final article', 1, 'bike, hello',
  212. 'metadescription of my final article', 'metakeyword of my final article', now(), now())";
  213. $result = mysql_query($cmd, $this->connection);
  214. return $result;
  215. }
  216. public function dropTableArticles() {
  217. $cmd="DROP TABLE IF EXISTS ".TBPREFIX."articles;";
  218. $result = mysql_query($cmd, $this->connection);
  219. return $result;
  220. }
  221. public function createTableComments() {
  222. $cmd = "CREATE TABLE ".TBPREFIX."comments (
  223. id int(11) NOT NULL auto_increment,
  224. article_id int(11),
  225. title varchar(255),
  226. published int NOT NULL DEFAULT '0',
  227. body text,
  228. signature text,
  229. created datetime,
  230. updated datetime,
  231. PRIMARY KEY (id));";
  232. $result = mysql_query($cmd, $this->connection);
  233. return $result;
  234. }
  235. public function populateTableComments() {
  236. $cmd = "insert into ".TBPREFIX."comments (id, article_id, published, title, body, signature, created, updated) values
  237. (1, 1, 1, 'My first comment', 'text of my first comment', 'signature of my first comment', now(), now())";
  238. $result = mysql_query($cmd, $this->connection);
  239. $cmd = "insert into ".TBPREFIX."comments (id, article_id, published, title, body, signature, created, updated) values
  240. (2, 1, 0, 'My first comment', 'text of my first comment', 'signature of my first comment', now(), now())";
  241. $result = mysql_query($cmd, $this->connection);
  242. return $result;
  243. }
  244. public function dropTableComments() {
  245. $cmd="DROP TABLE IF EXISTS ".TBPREFIX."comments;";
  246. $result = mysql_query($cmd, $this->connection);
  247. return $result;
  248. }
  249. public function createTablePages() {
  250. $cmd = "CREATE TABLE ".TBPREFIX."pages (
  251. id int(11) NOT NULL auto_increment,
  252. title varchar(255),
  253. published int NOT NULL DEFAULT '0',
  254. indexnumber int,
  255. subtitle text,
  256. summary text,
  257. body text,
  258. tag text,
  259. metadescription text,
  260. metakeyword text,
  261. created datetime,
  262. updated datetime,
  263. PRIMARY KEY (id));";
  264. $result = mysql_query($cmd, $this->connection);
  265. return $result;
  266. }
  267. public function populateTablePages() {
  268. $cmd = "insert into ".TBPREFIX."pages (id, indexnumber, published, title, subtitle, summary, body, tag, metadescription, metakeyword, created, updated) values
  269. (1, 1, 1, 'My firts Page', 'Subtitle of my first page', 'summary of my first page',
  270. 'Body of my first page', 'tag of my first page',
  271. 'metadescription of my first page', 'metakeyword of my first page', NOW(), NOW())";
  272. $result = mysql_query($cmd, $this->connection);
  273. $cmd = "insert into ".TBPREFIX."pages (id, indexnumber, published, title, subtitle, summary, body, tag, metadescription, metakeyword, created, updated) values
  274. (2, 2, 1, 'My second Page', 'Subtitle of my second page', 'summary of my second page',
  275. 'Body of my second page', 'tag of my second page',
  276. 'metadescription of my first page', 'metakeyword of my first page', NOW(), NOW())";
  277. $result = mysql_query($cmd, $this->connection);
  278. $cmd = "insert into ".TBPREFIX."pages (id, indexnumber, published, title, subtitle, summary, body, tag, metadescription, metakeyword, created, updated) values
  279. (3, 3, 0, 'My third Page', 'Subtitle of my third page', 'summary of my third page',
  280. 'Body of my third page', 'tag of my third page',
  281. 'metadescription of my third page', 'metakeyword of my third page', NOW(), NOW())";
  282. $result = mysql_query($cmd, $this->connection);
  283. return $result;
  284. }
  285. public function dropTablePages() {
  286. $cmd="DROP TABLE IF EXISTS ".TBPREFIX."pages;";
  287. $result = mysql_query($cmd, $this->connection);
  288. return $result;
  289. }
  290. public function createTableUsers() {
  291. $cmd = "CREATE TABLE ".TBPREFIX."users (
  292. id int(11) NOT NULL auto_increment,
  293. name varchar(255),
  294. username varchar(255),
  295. password varchar(255),
  296. body text,
  297. role varchar(255),
  298. toshow int NOT NULL DEFAULT '1',
  299. email varchar(255),
  300. msn varchar(255),
  301. skype varchar(255),
  302. created datetime,
  303. updated datetime,
  304. PRIMARY KEY (id));";
  305. $result = mysql_query($cmd, $this->connection);
  306. return $result;
  307. }
  308. public function populateTableUsers() {
  309. $cmd = "insert into ".TBPREFIX."users (name, username, password, body, role, toshow, email, msn, skype, created, updated) values
  310. ('New User', 'newuser', '".md5('psw')."', 'short description', '', 1, 'email@email.com', 'abcdef@abcdef.com', 'abcdef', NOW(), NOW())";
  311. $result = mysql_query($cmd, $this->connection);
  312. $cmd = "insert into ".TBPREFIX."users (name, username, password, body, role, toshow, email, msn, skype, created, updated) values
  313. ('Second User', 'seconduser', '".md5("second")."', 'short description', 'role', 1, 'email@email.com', 'abcdef@abcdef.com', 'abcdef', NOW(), NOW())";
  314. $result = mysql_query($cmd, $this->connection);
  315. $cmd = "insert into ".TBPREFIX."users (name, username, password, body, role, toshow, email, msn, skype, created, updated) values
  316. ('New User', 'user', '".md5("psw")."',
  317. 'Tityre, tu patulae recubans sub tegmine fagi siluestrem tenui musam meditaris auena: nos patriae finis et dulcia linquimus arua. nos patriam fugimus: tu, Tityre, lentus in umbra formosam resonare doces Amaryllida siluas. O Meliboee, deus nobis haec otia fecit. namque erit ille mihi semper deus, illius aram saepe tener nostris ab ouilibus imbuet agnus. ille meas errare boues, ut cernis, et ipsum ludere quae uellem calamo permisit agresti. Non equidem inuideo, miror magis; undique totis',
  318. 'publisher', 1, 'email@email.com', 'abcdef@abcdef.com', 'abcdef', '2009-08-06', '2009-08-06')";
  319. $result = mysql_query($cmd, $this->connection);
  320. return $result;
  321. }
  322. public function dropTableUsers() {
  323. $cmd="DROP TABLE IF EXISTS ".TBPREFIX."users;";
  324. $result = mysql_query($cmd, $this->connection);
  325. return $result;
  326. }
  327. public function createTableUsersArticles() {
  328. $cmd = "CREATE TABLE ".TBPREFIX."users_articles (
  329. id int(11) NOT NULL auto_increment,
  330. article_id int(11),
  331. user_id int(11),
  332. PRIMARY KEY (id));";
  333. $result = mysql_query($cmd, $this->connection);
  334. return $result;
  335. }
  336. public function populateTableUsersArticles() {
  337. $cmd = "insert into ".TBPREFIX."users_articles (id, article_id, user_id) values (1, 1, 1)";
  338. $result = mysql_query($cmd, $this->connection);
  339. $cmd = "insert into ".TBPREFIX."users_articles (id, article_id, user_id) values (2, 1, 2)";
  340. $result = mysql_query($cmd, $this->connection);
  341. $cmd = "insert into ".TBPREFIX."users_articles (id, article_id, user_id) values (3, 2, 1)";
  342. $result = mysql_query($cmd, $this->connection);
  343. $cmd = "insert into ".TBPREFIX."users_articles (id, article_id, user_id) values (4, 3, 2)";
  344. $result = mysql_query($cmd, $this->connection);
  345. return $result;
  346. }
  347. public function dropTableUsersArticles() {
  348. $cmd="DROP TABLE IF EXISTS ".TBPREFIX."users_articles;";
  349. $result = mysql_query($cmd, $this->connection);
  350. return $result;
  351. }
  352. public function createCategories() {
  353. $cmd = "CREATE TABLE ".TBPREFIX."categories (
  354. id int(11) NOT NULL auto_increment,
  355. name varchar(255),
  356. description text,
  357. published int NOT NULL DEFAULT '0',
  358. indexnumber int,
  359. created datetime,
  360. updated datetime,
  361. PRIMARY KEY (id));";
  362. $result = mysql_query($cmd, $this->connection);
  363. return $result;
  364. }
  365. public function populateCategories() {
  366. $cmd = "insert into ".TBPREFIX."categories (name, description, published, indexnumber, created, updated) values
  367. ('News', 'News Articles', 1, 1, '2009-08-06', '2009-08-06')";
  368. $result = mysql_query($cmd, $this->connection);
  369. $cmd = "insert into ".TBPREFIX."categories (name, description, published, indexnumber, created, updated) values
  370. ('Sport', 'Sport Articles', 1, 2, '2009-08-06', '2009-08-06')";
  371. $result = mysql_query($cmd, $this->connection);
  372. $cmd = "insert into ".TBPREFIX."categories (name, description, published, indexnumber, created, updated) values
  373. ('Relax', 'Relaxing Articles', 0, 3, '2009-08-06', '2009-08-06')";
  374. $result = mysql_query($cmd, $this->connection);
  375. return $result;
  376. }
  377. public function dropCategories() {
  378. $cmd="DROP TABLE IF EXISTS ".TBPREFIX."categories;";
  379. $result = mysql_query($cmd, $this->connection);
  380. return $result;
  381. }
  382. public function createTableOptions() {
  383. $cmd = "CREATE TABLE ".TBPREFIX."options (
  384. id int(11) NOT NULL auto_increment,
  385. name varchar(255),
  386. type varchar(255),
  387. value varchar(255),
  388. PRIMARY KEY (id));";
  389. $result = mysql_query($cmd, $this->connection);
  390. return $result;
  391. }
  392. public function populateTableOptions() {
  393. $cmd = "insert into ".TBPREFIX."options (name, type, value) values
  394. ('commandSandBox', 'plugin', 'active')";
  395. $result = mysql_query($cmd, $this->connection);
  396. $cmd = "insert into ".TBPREFIX."options (name, type, value) values
  397. ('filterSandBox', 'plugin', 'active')";
  398. $result = mysql_query($cmd, $this->connection);
  399. $cmd = "insert into ".TBPREFIX."options (name, type, value) values
  400. ('default', 'template', 'active')";
  401. $result = mysql_query($cmd, $this->connection);
  402. return $result;
  403. }
  404. public function dropTableOptions() {
  405. $cmd="DROP TABLE IF EXISTS ".TBPREFIX."options;";
  406. $result = mysql_query($cmd, $this->connection);
  407. return $result;
  408. }
  409. function createSchema() {
  410. if ($this->connection) {
  411. $result = $this->createTableNumbers();
  412. if ($result) {
  413. $out = "Table Numbers created<BR>";
  414. } else {
  415. $out = "Table Numbers NOT created<BR>";;
  416. }
  417. $result = $this->createCategories();
  418. if ($result) {
  419. $out .= "Table Categories created<BR>";
  420. } else {
  421. $out .= "Table Categories NOT created<BR>";;
  422. }
  423. $result = $this->createTableArticles();
  424. if ($result) {
  425. $out .= "Table Articles created<BR>";
  426. } else {
  427. $out .= "Table Articles NOT created<BR>";;
  428. }
  429. $result = $this->createTableComments();
  430. if ($result) {
  431. $out .= "Table Comments created<BR>";
  432. } else {
  433. $out .= "Table Comments NOT created<BR>";;
  434. }
  435. $result = $this->createTablePages();
  436. if ($result) {
  437. $out .= "Table Pages created<BR>";
  438. } else {
  439. $out .= "Table Pages NOT created<BR>";;
  440. }
  441. $result = $this->createTableUsers();
  442. if ($result) {
  443. $out .= "Table Users created<BR>";
  444. } else {
  445. $out .= "Table Users NOT created<BR>";;
  446. }
  447. $result = $this->createTableUsersArticles();
  448. if ($result) {
  449. $out .= "Table Users created<BR>";
  450. } else {
  451. $out .= "Table Users NOT created<BR>";
  452. }
  453. $result = $this->createTableOptions();
  454. if ($result) {
  455. $out .= "Table Options created<BR>";
  456. } else {
  457. $out .= "Table Options NOT created<BR>";
  458. }
  459. } else {
  460. $out = "Error in the connection <br>".mysql_errno().": ".mysql_error();
  461. }
  462. return $out;
  463. }
  464. function populateSchema() {
  465. if ($this->connection) {
  466. $result = $this->populateTableNumbers();
  467. if ($result) {
  468. $out = "Dummy data Number Created<BR>";
  469. } else {
  470. $out = "Dummy data Number NOT created<BR>";;
  471. }
  472. $result = $this->populateCategories();
  473. if ($result) {
  474. $out .= "Dummy data Categories Created<BR>";
  475. } else {
  476. $out .= "Dummy data Categories NOT created<BR>";;
  477. }
  478. $result = $this->populateTableArticles();
  479. if ($result) {
  480. $out .= "Dummy data Article Created<BR>";
  481. } else {
  482. $out .= "Dummy data Article NOT created<BR>";;
  483. }
  484. $result = $this->populateTableComments();
  485. if ($result) {
  486. $out .= "Dummy data Comment Created<BR>";
  487. } else {
  488. $out .= "Dummy data Comment NOT created<BR>";;
  489. }
  490. $result = $this->populateTablePages();
  491. if ($result) {
  492. $out .= "Dummy data Page Created<BR>";
  493. } else {
  494. $out .= "Dummy data Page NOT created<BR>";;
  495. }
  496. $result = $this->populateTableUsers();
  497. if ($result) {
  498. $out .= "Dummy data User Created<BR>";
  499. } else {
  500. $out .= "Dummy data User NOT created<BR>";;
  501. }
  502. $result = $this->populateTableUsersArticles();
  503. if ($result) {
  504. $out .= "Dummy data Relation User<->Article Created<BR>";
  505. } else {
  506. $out .= "Dummy data Relation User<->Article NOT created<BR>";;
  507. }
  508. $result = $this->populateTableOptions();
  509. if ($result) {
  510. $out .= "Dummy data Relation Options Created<BR>";
  511. } else {
  512. $out .= "Dummy data Relation Options NOT created<BR>";;
  513. }
  514. } else {
  515. $out = "Error in the connection <br>".mysql_errno().": ".mysql_error();
  516. }
  517. return $out;
  518. }
  519. function dropSchema() {
  520. if ($this->connection) {
  521. $result = $this->dropTableNumbers();
  522. if ($result) {
  523. $out = "Table Number dropped<BR>";
  524. } else {
  525. $out = "Table Number NOT dropped<BR>";;
  526. }
  527. $result = $this->dropCategories();
  528. if ($result) {
  529. $out .= "Table Categories dropped<BR>";
  530. } else {
  531. $out .= "Table Categories NOT dropped<BR>";;
  532. }
  533. $result = $this->dropTableArticles();
  534. if ($result) {
  535. $out .= "Table Article dropped<BR>";
  536. } else {
  537. $out .= "Table Article NOT dropped<BR>";;
  538. }
  539. $result = $this->dropTableComments();
  540. if ($result) {
  541. $out .= "Table Comment dropped<BR>";
  542. } else {
  543. $out .= "Table Comment NOT dropped<BR>";;
  544. }
  545. $result = $this->dropTablePages();
  546. if ($result) {
  547. $out .= "Table Page dropped<BR>";
  548. } else {
  549. $out .= "Table Page NOT dropped<BR>";;
  550. }
  551. $result = $this->dropTableUsers();
  552. if ($result) {
  553. $out .= "Table User dropped<BR>";
  554. } else {
  555. $out .= "Table User NOT dropped<BR>";;
  556. }
  557. $result = $this->dropTableUsersArticles();
  558. if ($result) {
  559. $out .= "Table Relation User<->Article dropped<BR>";
  560. } else {
  561. $out .= "Table Relation User<->Article NOT dropped<BR>";;
  562. }
  563. $result = $this->dropTableOptions();
  564. if ($result) {
  565. $out .= "Table Relation Options dropped<BR>";
  566. } else {
  567. $out .= "Table Relation Options NOT dropped<BR>";;
  568. }
  569. } else {
  570. $out = "Error in the connection <br>".mysql_errno().": ".mysql_error();
  571. }
  572. return $out;
  573. }
  574. }
  575. ?>