root/releases/0.9/lib/dbsetup.php

Revision 1420, 5.3 kB (checked in by rho, 1 year ago)

updated elggadmin

  • don't "print continue" on database modify
  • save sysadminemail on db
  • fixed issue that overwrite debug
  • improved elggadmin form to support types of inputs

Signed-off: Rolando Espinoza La fuente <rho@prosoftpeople.com>

  • Property svn:eol-style set to native
Line 
1 <?php
2 global $db, $METATABLES;
3
4 /// Check if the main tables have been installed yet or not.
5 if (!$METATABLES) {    // No tables yet at all.
6     $maintables = false;
7 } else {
8     $maintables = false;
9     $datalists = false;
10     foreach ($METATABLES as $table) {
11         if (preg_match("/^{$CFG->prefix}users$/", $table)) {
12             $maintables = true;
13         }
14         if (preg_match("/^{$CFG->prefix}datalists$/", $table)) {
15             $datalists = true;
16         }
17     }
18 }
19
20 $strdatabasesuccess = "Yay!"; // well, if people leave never-defined variables about the place...
21
22 $newinstall = false;
23
24 if (!$maintables) {
25     if (file_exists($CFG->dirroot . "lib/db/$CFG->dbtype.sql")) {
26         $db->debug = true;
27         
28         //version check
29         $continue = true;
30         $infoarr = $db->ServerInfo();
31         if (!empty($infoarr['version'])) {
32             switch($CFG->dbtype) {
33                 case "mysql":
34                     if (!preg_match('/^(4\.1|[5-9]\.|[0-9][0-9]+)/', $infoarr['version'])) {
35                         error('Error: Your MySQL version is too old: ' . $infoarr['version'] . '. Elgg requires MySQL 4.1 or newer. 5.0 or newer is recommended.');
36                         $continue = false;
37                     }
38                 break;
39             }
40         }
41         
42         if ($continue) {
43             if (modify_database($CFG->dirroot . "lib/db/$CFG->dbtype.sql")) {
44                 include_once($CFG->dirroot . "version.php");
45                 set_config('version', $version);
46                 $db->debug = false;
47                 notify($strdatabasesuccess, "green");
48                 if (!isset($CFG->newsinitialpassword) || empty($CFG->newsinitialpassword)) {
49                     notify("WARNING: the initial password for the news account is 'password'. This account has administrator privileges, and you should log in and change the password as soon as installation is complete.");
50                 } else {
51                     //$newspassword = $db->qstr(md5($CFG->newsinitialpassword));
52                     //execute_sql("update ".$CFG->prefix."users set password = $newspassword where username = 'news'");
53                     set_field('users', 'password', md5($CFG->newsinitialpassword), 'username', 'news');
54                 }
55                 //execute_sql("update ".$CFG->prefix."users set email = ". $db->qstr($CFG->sysadminemail) ." where username = 'news'");
56                 set_field('users', 'email', $CFG->sysadminemail, 'username', 'news');
57                 // store sysadminemail in db
58                 set_config('sysadminemail', $CFG->sysadminemail);
59
60                 // change initial administrator if it's set
61                 /*
62                 if (!empty($CFG->newsinitialusername)) {
63                     set_field('users', 'name', 'Administrator', 'username', 'news');
64                     set_field('users', 'username', $CFG->newsinitialusername, 'username', 'news');
65                 }
66                  */
67
68             } else {
69                 $db->debug = false;
70                 error("Error: Main databases NOT set up successfully");
71             }
72         }
73     } else {
74         error("Error: Your database ($CFG->dbtype) is not yet fully supported by Elgg.  See the lib/db directory.");
75     }
76     print_continue("index.php");
77     die;
78 }
79
80 if (user_flag_get("admin",$_SESSION['userid'])) {
81     
82     if (empty($CFG->version)) {
83         $CFG->version = 1;
84     }
85
86     if (empty($CFG->release)) {
87         $CFG->release = "";
88     }
89
90     if (!$datalists) {
91         $CFG->version = -1;
92     }
93
94     /// Upgrades
95     include_once($CFG->dirroot . "version.php");              # defines $version
96     include_once($CFG->dirroot . "lib/db/$CFG->dbtype.php");  # defines upgrades
97
98     if ($CFG->version) {
99         if ($version > $CFG->version) {  // upgrade
100
101             $a->oldversion = "$CFG->release ($CFG->version)";
102             $a->newversion = "$release ($version)";
103
104             if (empty($_GET['confirmupgrade'])) {
105                 notice_yesno(__gettext('Need to upgrade database'), $CFG->wwwroot . '?confirmupgrade=yes', '');
106                 exit;
107
108             } else {
109                 $db->debug=true;
110                 if (main_upgrade($CFG->version)) {
111                     $db->debug=false;
112                     if (set_config("version", $version)) {
113                         notify($strdatabasesuccess, "green");
114                         print_continue("index.php");
115                         exit;
116                     } else {
117                         notify("Upgrade failed!  (Could not update version in config table)");
118                     }
119                 } else {
120                     $db->debug=false;
121                     notify("Upgrade failed!  See /version.php");
122                 }
123             }
124         } else if ($version < $CFG->version) {
125             notify("WARNING!!!  The code you are using is OLDER than the version that made these databases!");
126         }
127
128     } else {
129         if (set_config("version", $version)) {
130             print_header("Elgg $release ($version)");
131             print_continue("index.php");
132             die;
133         } else {
134             $db->debug=true;
135             if (main_upgrade(0)) {
136                 print_continue("index.php");
137             } else {
138                 error("A problem occurred inserting current version into databases");
139             }
140             $db->debug=false;
141         }
142     }
143
144 }
145 ?>
Note: See TracBrowser for help on using the browser.