[ Index ] |
|
Code source de dotProject 2.1 RC1 |
1 <?php 2 // $Id: install.inc.php,v 1.2.2.1 2007/02/17 06:03:00 ajdonnison Exp $ 3 4 // Provide fake interface classes and installation functions 5 // so that most db shortcuts will work without, for example, an AppUI instance. 6 7 // Defines required by setMsg, these are different to those used by the real CAppUI. 8 9 define( 'UI_MSG_OK', ''); 10 define('UI_MSG_ALERT', 'Warning: '); 11 define('UI_MSG_WARNING', 'Warning: '); 12 define('UI_MSG_ERROR', 'ERROR: '); 13 # 14 # function to output a message 15 # currently just outputs it expecting there to be a pre block. 16 # but could be changed to format it better - and only needs to be done here. 17 # The flush is called so that the user gets progress as it occurs. It depends 18 # upon the webserver/browser combination though. 19 # 20 function dPmsg($msg) 21 { 22 echo $msg . "\n"; 23 flush(); 24 } 25 26 # 27 # function to return a default value if a variable is not set 28 # 29 30 function InstallDefVal($var, $def) { 31 return isset($var) ? $var : $def; 32 } 33 34 /** 35 * Utility function to return a value from a named array or a specified default 36 */ 37 function dPInstallGetParam( &$arr, $name, $def=null ) { 38 return isset( $arr[$name] ) ? $arr[$name] : $def; 39 } 40 41 /** 42 * Utility function to get last updated dates/versions for the 43 * system. The default is to 44 */ 45 function InstallGetVersion($mode, $db) { 46 $result = array( 47 'last_db_update' => '', 48 'last_code_update' => '', 49 'code_version' => '1.0.2', 50 'db_version' => '1' 51 ); 52 $res = $db->Execute('SELECT * FROM dpversion LIMIT 1'); 53 if ($res && $res->RecordCount() > 0) { 54 $row = $res->FetchRow(); 55 $result['last_db_update'] = str_replace('-', '', $row['last_db_update']); 56 $result['last_code_update'] = str_replace('-', '', $row['last_code_update']); 57 $result['code_version'] = $row['code_version'] ? $row['code_version'] : '1.0.2'; 58 $result['db_version'] = $row['db_version'] ? $row['db_version'] : '1'; 59 } 60 return $result; 61 62 } 63 64 /* 65 * Utility function to split given SQL-Code 66 * @param $sql string SQL-Code 67 * @param $last_update string last update that has been installed 68 */ 69 function InstallSplitSql($sql, $last_update) { 70 global $lastDBUpdate; 71 72 $buffer = array(); 73 $ret = array(); 74 75 $sql = trim($sql); 76 77 $matched = preg_match_all('/\n#\s*(\d{8})\b/', $sql, $matches); 78 if ($matched) { 79 // Used for updating from previous versions, even if the update 80 // is not correctly set. 81 $len = count($matches[0]); 82 $lastDBUpdate = $matches[1][$len-1]; 83 } 84 85 if ($last_update && $last_update != '00000000') { 86 // Find the first occurrance of an update that is 87 // greater than the last_update number. 88 dPmsg("Checking for previous updates"); 89 if ($matched) { 90 for ($i = 0; $i < $len; $i++) { 91 if ((int)$last_update < (int)$matches[1][$i]) { 92 // Remove the SQL up to the point found 93 $match = '/^.*' . trim($matches[0][$i]) . '/Us'; 94 $sql = preg_replace($match, "", $sql); 95 break; 96 } 97 } 98 // If we run out of indicators, we need to debunk, otherwise we will reinstall 99 if ($i == $len) 100 return $ret; 101 } 102 } 103 $sql = ereg_replace("\n#[^\n]*\n", "\n", $sql); 104 105 $in_string = false; 106 107 for($i=0; $i<strlen($sql)-1; $i++) { 108 if($sql[$i] == ";" && !$in_string) { 109 $ret[] = substr($sql, 0, $i); 110 $sql = substr($sql, $i + 1); 111 $i = 0; 112 } 113 114 if($in_string && ($sql[$i] == $in_string) && $buffer[1] != "\\") { 115 $in_string = false; 116 } 117 elseif(!$in_string && ($sql[$i] == '"' || $sql[$i] == "'") && (!isset($buffer[0]) || $buffer[0] != "\\")) { 118 $in_string = $sql[$i]; 119 } 120 if(isset($buffer[1])) { 121 $buffer[0] = $buffer[1]; 122 } 123 $buffer[1] = $sql[$i]; 124 } 125 126 if(!empty($sql)) { 127 $ret[] = $sql; 128 } 129 return($ret); 130 } 131 132 function InstallLoadSQL($sqlfile, $last_update = null) 133 { 134 global $dbErr, $dbMsg, $db; 135 136 // Don't complain about missing files. 137 if (! file_exists($sqlfile)) 138 return; 139 140 $mqr = @get_magic_quotes_runtime(); 141 @set_magic_quotes_runtime(0); 142 143 $pieces = array(); 144 if ($sqlfile) { 145 $query = fread(fopen($sqlfile, "r"), filesize($sqlfile)); 146 $pieces = InstallSplitSql($query, $last_update); 147 } 148 149 @set_magic_quotes_runtime($mqr); 150 $errors = 0; 151 $piece_count = count($pieces); 152 153 for ($i=0; $i<$piece_count; $i++) { 154 $pieces[$i] = trim($pieces[$i]); 155 if(!empty($pieces[$i]) && $pieces[$i] != "#") { 156 if (!$result = $db->Execute($pieces[$i])) { 157 $errors++; 158 $dbErr = true; 159 $dbMsg .= $db->ErrorMsg().'<br>'; 160 } 161 } 162 } 163 dPmsg("There were $errors errors in $piece_count SQL statements"); 164 } 165 166 class InstallerUI { 167 168 var $user_id = 0; 169 170 function setMsg($msg, $msgno = '', $append=false) 171 { 172 return dPmsg($msgno . $msg); 173 } 174 } 175 176 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 18 19:46:52 2007 | par Balluche grâce à PHPXref 0.7 |