root/releases/0.672/lib/dbsetup.php

Revision 701, 4.1 kB (checked in by sven, 2 years ago)

reduce the number of $db->metatables calls per page from 3 to 1, using a global variable which is updated when modify_database() is called

  • 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         if (modify_database($CFG->dirroot . "lib/db/$CFG->dbtype.sql")) {
28             include_once($CFG->dirroot . "version.php");
29             set_config('version', $version);
30             $db->debug = false;
31             notify($strdatabasesuccess, "green");
32             if (!isset($CFG->newsinitialpassword) || empty($CFG->newsinitialpassword)) {
33                 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.");
34             } else {
35                 //$newspassword = $db->qstr(md5($CFG->newsinitialpassword));
36                 //execute_sql("update ".$CFG->prefix."users set password = $newspassword where username = 'news'");
37                 set_field('users', 'password', md5($CFG->newsinitialpassword), 'username', 'news');
38             }
39             //execute_sql("update ".$CFG->prefix."users set email = ". $db->qstr($CFG->sysadminemail) ." where username = 'news'");
40             set_field('users', 'email', $CFG->sysadminemail, 'username', 'news');
41         } else {
42             $db->debug = false;
43             error("Error: Main databases NOT set up successfully");
44         }
45     } else {
46         error("Error: Your database ($CFG->dbtype) is not yet fully supported by Elgg.  See the lib/db directory.");
47     }
48     print_continue("index.php");
49     die;
50 }
51
52 if (user_flag_get("admin",$_SESSION['userid'])) {
53     
54     if (empty($CFG->version)) {
55         $CFG->version = 1;
56     }
57
58     if (empty($CFG->release)) {
59         $CFG->release = "";
60     }
61
62     if (!$datalists) {
63         $CFG->version = -1;
64     }
65
66     /// Upgrades
67     include_once($CFG->dirroot . "version.php");              # defines $version
68     include_once($CFG->dirroot . "lib/db/$CFG->dbtype.php");  # defines upgrades
69
70     if ($CFG->version) {
71         if ($version > $CFG->version) {  // upgrade
72
73             $a->oldversion = "$CFG->release ($CFG->version)";
74             $a->newversion = "$release ($version)";
75
76             if (empty($_GET['confirmupgrade'])) {
77                 notice_yesno(__gettext('Need to upgrade database'), $CFG->wwwroot . '?confirmupgrade=yes', '');
78                 exit;
79
80             } else {
81                 $db->debug=true;
82                 if (main_upgrade($CFG->version)) {
83                     $db->debug=false;
84                     if (set_config("version", $version)) {
85                         notify($strdatabasesuccess, "green");
86                         print_continue("index.php");
87                         exit;
88                     } else {
89                         notify("Upgrade failed!  (Could not update version in config table)");
90                     }
91                 } else {
92                     $db->debug=false;
93                     notify("Upgrade failed!  See /version.php");
94                 }
95             }
96         } else if ($version < $CFG->version) {
97             notify("WARNING!!!  The code you are using is OLDER than the version that made these databases!");
98         }
99
100     } else {
101         if (set_config("version", $version)) {
102             print_header("Elgg $release ($version)");
103             print_continue("index.php");
104             die;
105         } else {
106             $db->debug=true;
107             if (main_upgrade(0)) {
108                 print_continue("index.php");
109             } else {
110                 error("A problem occurred inserting current version into databases");
111             }
112             $db->debug=false;
113         }
114     }
115
116 }
117 ?>
Note: See TracBrowser for help on using the browser.