[ Index ]
 

Code source de dotProject 2.1 RC1

Accédez au Source d'autres logiciels libres | Soutenez Angelica Josefina !

title

Body

[fermer]

/install/ -> do_install_db.php (source)

   1  <?php // $Id: do_install_db.php,v 1.26.2.9 2007/02/17 06:03:00 ajdonnison Exp $
   2  
   3  include_once  'check_upgrade.php';
   4  if ($_POST['mode'] == 'install' && dPcheckUpgrade() == 'upgrade')
   5   die("Security Check: dotProject seems to be already configured. Communication broken for Security Reasons!");
   6  
   7  ######################################################################################################################
   8  
   9  $baseDir = dirname(dirname(__FILE__));
  10  define('DP_BASE_DIR', $baseDir);
  11  $baseUrl = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') ? 'https://' : 'http://';
  12  $baseUrl .= isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : getenv('HTTP_HOST');
  13  $baseUrl .= isset($_SERVER['SCRIPT_NAME']) ? dirname(dirname($_SERVER['SCRIPT_NAME'])) : dirname(dirname(getenv('SCRIPT_NAME')));
  14  
  15  require_once "$baseDir/install/install.inc.php";
  16  
  17  $AppUI =& new InstallerUI; // Fake AppUI class to appease the db_connect utilities.
  18  
  19  $dbMsg = "";
  20  $cFileMsg = "Not Created";
  21  $dbErr = false;
  22  $cFileErr = false;
  23  
  24  $dbtype = trim( dPInstallGetParam( $_POST, 'dbtype', 'mysql' ) );
  25  $dbhost = trim( dPInstallGetParam( $_POST, 'dbhost', '' ) );
  26  $dbname = trim( dPInstallGetParam( $_POST, 'dbname', '' ) );
  27  $dbuser = trim( dPInstallGetParam( $_POST, 'dbuser', '' ) );
  28  $dbpass = trim( dPInstallGetParam( $_POST, 'dbpass', '' ) );
  29  $dbdrop = dPInstallGetParam( $_POST, 'dbdrop', false );
  30  $mode = dPInstallGetParam( $_POST, 'mode', 'upgrade' );
  31  $dbpersist = dPInstallGetParam( $_POST, 'dbpersist', false );
  32  $dobackup = isset($_POST['dobackup']);
  33  $do_db = isset($_POST['do_db']);
  34  $do_db_cfg = isset($_POST['do_db_cfg']);
  35  $do_cfg = isset($_POST['do_cfg']);
  36  
  37  // Create a dPconfig array for dependent code
  38  $dPconfig = array(
  39   'dbtype' => $dbtype,
  40   'dbhost' => $dbhost,
  41   'dbname' => $dbname,
  42   'dbpass' => $dbpass,
  43   'dbuser' => $dbuser,
  44   'dbpersist' => $dbpersist,
  45   'root_dir' => $baseDir,
  46   'base_url' => $baseUrl
  47  );
  48  
  49  // Version array for moving from version to version.
  50  $versionPath = array(
  51      '1.0.2',
  52      '2.0-alpha',
  53      '2.0-beta',
  54      '2.0',
  55      '2.0.1',
  56      '2.0.2',
  57      '2.0.3',
  58      '2.0.4',
  59      '2.1-rc1',
  60  );
  61  
  62  global $lastDBUpdate;
  63  $lastDBUpdate = '';
  64  
  65  require_once( "$baseDir/lib/adodb/adodb.inc.php" );
  66  @include_once "$baseDir/includes/version.php";
  67  
  68  $db = NewADOConnection($dbtype);
  69  
  70  if(!empty($db)) {
  71    $dbc = $db->Connect($dbhost,$dbuser,$dbpass);
  72    if ($dbc)
  73      $existing_db = $db->SelectDB($dbname);
  74  } else { $dbc = false; }
  75  
  76  
  77  $current_version = $dp_version_major . '.' . $dp_version_minor;
  78  $current_version .= isset($dp_version_patch) ? ".$dp_version_patch" : '';
  79  $current_version .= isset($dp_version_prepatch) ? "-$dp_version_prepatch" : '';
  80  
  81  if ($dobackup){
  82  
  83   if( $dbc ) {
  84    require_once( "$baseDir/lib/adodb/adodb-xmlschema.inc.php" );
  85  
  86    $schema = new adoSchema( $db );
  87  
  88    $sql = $schema->ExtractSchema(true);
  89  
  90    header('Content-Disposition: attachment; filename="dPdbBackup'.date("Ymd").date("His").'.xml"');
  91    header('Content-Type: text/xml');
  92    echo $sql;
  93      exit;
  94   } else {
  95    $backupMsg = "ERROR: No Database Connection available! - Backup not performed!";
  96   }
  97  }
  98  
  99  ?>
 100  <html>
 101  <head>
 102   <title>dotProject Installer</title>
 103   <meta name="Description" content="dotProject Installer">
 104    <link rel="stylesheet" type="text/css" href="../style/default/main.css">
 105  </head>
 106  <body>
 107  <h1><img src="dp.png" align="middle" alt="dotProject Logo"/>&nbsp;dotProject Installer</h1>
 108  <table cellspacing="0" cellpadding="3" border="0" class="tbl" width="100%" align="left">
 109  <tr class='title'><td>Progress:</td></tr>
 110  <tr><td><pre>
 111  <?php
 112  
 113  if ($dobackup)
 114   dPmsg($backupMsg);
 115  
 116  if ($dbc && ($do_db || $do_db_cfg)) {
 117  
 118   if ($mode == 'install') {
 119  
 120    if ($dbdrop) { 
 121     dPmsg("Dropping previous database");
 122     $db->Execute("DROP DATABASE IF EXISTS ".$dbname); 
 123       $existing_db = false;
 124    }
 125  
 126    if (! $existing_db) {
 127          dPmsg("Creating new Database");
 128          $db->Execute("CREATE DATABASE ".$dbname);
 129           $dbError = $db->ErrorNo();
 130   
 131           if ($dbError <> 0 && $dbError <> 1007) {
 132                   $dbErr = true;
 133                  $dbMsg .= "A Database Error occurred. Database has not been created! The provided database details are probably not correct.<br>".$db->ErrorMsg()."<br>";
 134  
 135           }
 136     }
 137   }
 138  
 139   // For some reason a db->SelectDB call here doesn't work.
 140   $db->Execute('USE ' . $dbname);
 141   $db_version = InstallGetVersion($mode, $db);
 142  
 143   $code_updated = '';
 144   if ($mode == 'upgrade') {
 145    dPmsg("Applying database updates");
 146    $last_version = $db_version['code_version'];
 147    // Convert the code version to a version string.
 148    if ($last_version != $current_version) {
 149      // Check for from and to versions
 150      $from_key = array_search($last_version, $versionPath);
 151      $to_key = array_search($current_version, $versionPath);
 152      for ($i = $from_key; $i < $to_key; $i++) {
 153        $from_version = str_replace(array('.','-'), '', $versionPath[$i]);
 154        $to_version = str_replace(array('.','-'), '', $versionPath[$i+1]);
 155        // Only do updates since last update - this is only necessary if updating via CVS of a previous
 156        // version, but well worth doing anyway.
 157        InstallLoadSql("$baseDir/db/upgrade_{$from_version}_to_{$to_version}.sql", $db_version['last_db_update']);
 158        $db_version['last_db_update'] = $lastDBUpdate; // Global set by InstallLoadSql.
 159      }
 160    } else if (file_exists("$baseDir/db/upgrade_latest.sql")) {
 161      // Need to get the installed version again, as it should have been
 162      // updated by the from/to stuff.
 163      InstallLoadSql("$baseDir/db/upgrade_latest.sql", $db_version['last_db_update']);
 164    }
 165   } else {
 166    dPmsg("Installing database");
 167    InstallLoadSql("$baseDir/db/dotproject.sql");
 168    // After all the updates, find the new version information.
 169    $new_version = InstallGetVersion($mode, $db);
 170    $lastDBUpdate = $new_version['last_db_update'];
 171    $code_updated = $new_version['last_code_update'];
 172   }
 173  
 174                  $dbError = $db->ErrorNo();
 175          if ($dbError <> 0 && $dbError <> 1007) {
 176    $dbErr = true;
 177                  $dbMsg .= "A Database Error occurred. Database has probably not been populated completely!<br>".$db->ErrorMsg()."<br>";
 178          }
 179   if ($dbErr) {
 180    $dbMsg = "DB setup incomplete - the following errors occured:<br>".$dbMsg;
 181   } else {
 182    $dbMsg = "Database successfully setup<br>";
 183   }
 184  
 185   if ($mode == 'upgrade') {
 186    dPmsg("Applying data modifications");
 187    // Check for an upgrade script and run it if necessary.
 188    // Note we don't need to run individual version files any more
 189    if (file_exists("$baseDir/db/upgrade_latest.php")) {
 190     include_once "$baseDir/db/upgrade_latest.php";
 191     $code_updated = dPupgrade($db_version['code_version'], $current_version, $db_version['last_code_update']);
 192    } else {
 193          dPmsg("No data updates required");
 194      }
 195   } else {
 196    include_once "$baseDir/db/upgrade_permissions.php"; // Always required on install.
 197   }
 198  
 199   dPmsg("Updating version information");
 200   // No matter what occurs we should update the database version in the dpversion table.
 201   if (empty($lastDBUpdate)) {
 202       $lastDBUpdate = $code_updated;
 203   }
 204   $sql = "UPDATE dpversion
 205   SET db_version = '$dp_version_major',
 206   last_db_update = '$lastDBUpdate',
 207   code_version = '$current_version',
 208   last_code_update = '$code_updated'
 209   WHERE 1";
 210   $db->Execute($sql);
 211  
 212  } else {
 213      $dbMsg = "Not Created";
 214      if (! $dbc) {
 215          $dbErr=1;
 216          $dbMsg .= "<br/>No Database Connection available! "  . ($db ? $db->ErrorMsg() : '');
 217      }
 218  }
 219  
 220  // always create the config file content
 221  
 222   dPmsg("Creating config");
 223   $config = "<?php \n";
 224   $config .= "### Copyright (c) 2004, The dotProject Development Team dotproject.net and sf.net/projects/dotproject ###\n";
 225   $config .= "### All rights reserved. Released under GPL License. For further Information see LICENSE ###\n";
 226   $config .= "\n";
 227   $config .= "### CONFIGURATION FILE AUTOMATICALLY GENERATED BY THE DOTPROJECT INSTALLER ###\n";
 228   $config .= "### FOR INFORMATION ON MANUAL CONFIGURATION AND FOR DOCUMENTATION SEE ./includes/config-dist.php ###\n";
 229   $config .= "\n";
 230   $config .= "\$dPconfig['dbtype'] = '$dbtype';\n";
 231   $config .= "\$dPconfig['dbhost'] = '$dbhost';\n";
 232   $config .= "\$dPconfig['dbname'] = '$dbname';\n";
 233   $config .= "\$dPconfig['dbuser'] = '$dbuser';\n";
 234   $config .= "\$dPconfig['dbpass'] = '$dbpass';\n";
 235   $config .= "\$dPconfig['dbpersist'] = " . ($dbpersist ? 'true' : 'false') . ";\n";
 236   $config .= "\$dPconfig['root_dir'] = \$baseDir;\n";
 237   $config .= "\$dPconfig['base_url'] = \$baseUrl;\n";
 238   $config .= "?>";
 239   $config = trim($config);
 240  
 241  if ($do_cfg || $do_db_cfg){
 242   if ( (is_writable("../includes/config.php")  || ! is_file("../includes/config.php") ) && ($fp = fopen("../includes/config.php", "w"))) {
 243    fputs( $fp, $config, strlen( $config ) );
 244    fclose( $fp );
 245    $cFileMsg = "Config file written successfully\n";
 246   } else {
 247    $cFileErr = true;
 248    $cFileMsg = "Config file could not be written\n";
 249   }
 250  }
 251  
 252  //echo $msg;
 253  ?>
 254  </pre></td></tr>
 255  </table><br/>
 256  <table cellspacing="0" cellpadding="3" border="0" class="tbl" width="100%" align="left">
 257          <tr>
 258              <td class="title" valign="top">Database Installation Feedback:</td>
 259       <td class="item"><b style="color:<?php echo $dbErr ? 'red' : 'green'; ?>"><?php echo $dbMsg; ?></b><?php if ($dbErr) { ?> <br />
 260             Please note that errors relating to dropping indexes during upgrades are <b>NORMAL</b> and do not indicate a problem.
 261               <?php } ?>
 262               </td>
 263           <tr>
 264    <tr>
 265              <td class="title">Config File Creation Feedback:</td>
 266       <td class="item" align="left"><b style="color:<?php echo $cFileErr ? 'red' : 'green'; ?>"><?php echo $cFileMsg; ?></b></td>
 267    </tr>
 268  <?php if(($do_cfg || $do_db_cfg) && $cFileErr){ ?>
 269   <tr>
 270       <td class="item" align="left" colspan="2">The following Content should go to ./includes/config.php. Create that text file manually and copy the following lines in by hand. Delete all empty lines and empty spaces after '?>' and save. This file should be readable by the webserver.</td>
 271    </tr>
 272           <tr>
 273              <td align="center" colspan="2"><textarea class="button" name="dbhost" cols="100" rows="20" title="Content of config.php for manual creation." /><?php echo $msg.$config; ?></textarea></td>
 274           </tr>
 275  <?php } ?>
 276   <tr>
 277       <td class="item" align="center" colspan="2"><br/><b><a href="<?php echo $baseUrl.'/index.php?m=system&a=systemconfig';?>">Login and Configure the dotProject System Environment</a></b></td>
 278    </tr>
 279  <?php if ($mode == 'install') { ?>
 280      <tr>
 281          <td class="item" align="center" colspan="2"><p>The Administrator login has been set to <b>admin</b> with a password of <b>passwd</b>. It is a good idea to change this password when you first log in</p></td>
 282      </tr>
 283  <?php } ?>
 284          </table>
 285  </body>
 286  </html>


Généré le : Sun Feb 18 19:46:52 2007 par Balluche grâce à PHPXref 0.7