Changeset 1141 in subversion


Ignore:
Timestamp:
Feb 26, 2008 4:10:07 AM (5 years ago)
Author:
thomasb
Message:

Fix database initialization and check write access on the DB; update INSTALL instructions

Location:
trunk/roundcubemail
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/INSTALL

    r1115 r1141  
    3636   - /logs 
    37373. Create a new database and a database user for RoundCube (see DATABASE SETUP) 
    38 4. Create database tables using the queries in file 'SQL/*.initial.sql' 
    39    (* stands for your database type) 
    40 5. Rename the files config/*.inc.php.dist to config/*.inc.php 
    41 6. Modify the files in config/* to suit your local environment 
     384. Point your browser to http:///url-to-roundcube/installer/ 
     395. Follow the instructions of the install script (or see MANUAL CONFINGURATION) 
     406. After creating and testing the configuration, remove the installer directory 
    42417. Done! 
    4342 
     
    110109 
    111110 
    112 CONFIGURATION 
    113 ============= 
     111MANUAL CONFIGURATION 
     112==================== 
    114113 
    115114First of all, rename the files config/*.inc.php.dist to config/*.inc.php. 
    116115You can then change these files according to your environment and your needs. 
    117116Details about the config parameters can be found in the config files. 
     117See http://trac.roundcube.net/wiki/Howto_Install for even more guidance. 
    118118 
    119119You can also modify the default .htaccess file. This is necessary to 
  • trunk/roundcubemail/installer/config.php

    r1139 r1141  
    66require_once 'include/rcube_html.inc'; 
    77 
    8 $RCI->get_defaults(); 
     8$RCI->load_defaults(); 
    99 
    1010if (!empty($_POST['submit'])) { 
  • trunk/roundcubemail/installer/rcube_install.php

    r1139 r1141  
    5353   * Read the default config files and store properties 
    5454   */ 
    55   function get_defaults() 
     55  function load_defaults() 
    5656  { 
    5757    $this->_load_config('.php.dist'); 
     
    7575    include '../config/main.inc' . $suffix; 
    7676    if (is_array($rcmail_config)) { 
    77       $this->config = $rcmail_config; 
     77      $this->config += $rcmail_config; 
    7878    } 
    7979       
     
    237237     
    238238    return $out; 
     239  } 
     240   
     241   
     242  /** 
     243   * Initialize the database with the according schema 
     244   * 
     245   * @param object rcube_db Database connection 
     246   * @return boolen True on success, False on error 
     247   */ 
     248  function init_db($DB) 
     249  { 
     250    $db_map = array('pgsql' => 'postgres', 'mysqli' => 'mysql'); 
     251    $engine = isset($db_map[$DB->db_provider]) ? $db_map[$DB->db_provider] : $DB->db_provider; 
     252     
     253    // find out db version 
     254    if ($engine == 'mysql') { 
     255      $DB->query('SELECT VERSION() AS version'); 
     256      $sql_arr = $DB->fetch_assoc(); 
     257      $version = floatval($sql_arr['version']); 
     258       
     259      if ($version >= 4.1) 
     260        $engine = 'mysql5'; 
     261    } 
     262     
     263    // read schema file from /SQL/* 
     264    $fname = "../SQL/$engine.initial.sql"; 
     265    if ($lines = @file($fname, FILE_SKIP_EMPTY_LINES)) { 
     266      $buff = ''; 
     267      foreach ($lines as $i => $line) { 
     268        if (eregi('^--', $line)) 
     269          continue; 
     270           
     271        $buff .= $line . "\n"; 
     272        if (eregi(';$', trim($line))) { 
     273          $DB->query($buff); 
     274          $buff = ''; 
     275        } 
     276      } 
     277    } 
     278    else { 
     279      $this->fail('DB Schema', "Cannot read the schema file: $fname"); 
     280      return false; 
     281    } 
     282     
     283    if ($err = $this->get_error()) { 
     284      $this->fail('DB Schema', "Error creating database schema: $err"); 
     285      return false; 
     286    } 
     287 
     288    return true; 
    239289  } 
    240290   
  • trunk/roundcubemail/installer/styles.css

    r1139 r1141  
    124124  font-size: 9pt; 
    125125  width: 100%; 
    126   height: 40em; 
     126  height: 30em; 
    127127} 
    128128 
  • trunk/roundcubemail/installer/test.php

    r1139 r1141  
    5050        if (!($db_error_msg = $DB->is_error())) { 
    5151            $RCI->pass('DSN (write)'); 
     52            echo '<br />'; 
    5253            $db_working = true; 
    5354        } 
    5455        else { 
    55             $RCI->fail('DSN (write)', "Error: $db_error_msg"); 
     56            $RCI->fail('DSN (write)', $db_error_msg); 
     57            echo '<p class="hint">Make sure that the configured database extists and that the user as write privileges<br />'; 
     58            echo 'DSN: ' . $RCI->config['db_dsnw'] . '</p>'; 
    5659        } 
    57         echo '<br />'; 
    5860    } 
    5961    else { 
     
    6769// initialize db with schema found in /SQL/* 
    6870if ($db_working && $_POST['initdb']) { 
    69     $engine = preg_match('/^([a-z]+):/i', $RCI->config['db_dsnw'], $regs) ? $regs[1] : 'mysql'; 
    70     $fname = '../SQL/' . ($engine == 'pgsql' ? 'postgres' : $engine) . '.initial.sql'; 
    71     if ($sql = @file_get_contents($fname)) { 
    72         $DB->query($sql); 
    73     } 
    74     else { 
    75         $RCI->fail('DB Schema', "Cannot read the schema file: $fname"); 
    76     } 
    77      
    78     if ($err = $RCI->get_error()) { 
    79         $RCI->fail('DB Schema', "Error creating database schema: $err"); 
     71    if (!($success = $RCI->init_db($DB))) { 
    8072        $db_working = false; 
    81         echo '<p class="warning">Please try to inizialize the database manually as described in the INSTALL guide.</p>'; 
    82         echo '<br />'; 
     73        echo '<p class="warning">Please try to inizialize the database manually as described in the INSTALL guide. 
     74          Make sure that the configured database extists and that the user as write privileges</p>'; 
    8375    } 
    8476} 
    8577 
     78// test database 
    8679if ($db_working) { 
    87     $success = $DB->query("SELECT count(*) FROM {$RCI->config['db_table_users']}"); 
    88     if (!$success) { 
     80    $db_read = $DB->query("SELECT count(*) FROM {$RCI->config['db_table_users']}"); 
     81    if (!$db_read) { 
    8982        $RCI->fail('DB Schema', "Database not initialized"); 
     83        $db_working = false; 
    9084        echo '<p><input type="submit" name="initdb" value="Initialize database" /></p>'; 
    9185    } 
     
    9488    } 
    9589    echo '<br />'; 
     90} 
     91 
     92// more database tests 
     93if ($db_working) { 
     94    // write test 
     95    $db_write = $DB->query("INSERT INTO {$RCI->config['db_table_cache']} (session_id, cache_key, data, user_id) VALUES (?, ?, ?, 0)", '1234567890abcdef', 'test', 'test'); 
     96    $insert_id = $DB->insert_id($RCI->config['db_sequence_cache']); 
    9697     
     98    if ($db_write && $insert_id) { 
     99      $RCI->pass('DB Write'); 
     100      $DB->query("DELETE FROM {$RCI->config['db_table_cache']} WHERE cache_id=?", $insert_id); 
     101    } 
     102    else { 
     103      $RCI->fail('DB Write', $RCI->get_error()); 
     104    } 
     105    echo '<br />';     
     106     
     107    // check timezone settings 
    97108    $tz_db = 'SELECT ' . $DB->unixtimestamp($DB->now()) . ' AS tz_db'; 
    98109    $tz_db = $DB->query($tz_db); 
     
    105116    if (abs($tz_diff) > 1800) { 
    106117        $RCI->fail('DB Time', "Database time differs {$td_ziff}s from PHP time"); 
    107     } else { 
     118    } 
     119    else { 
    108120        $RCI->pass('DB Time'); 
    109121    } 
    110      
    111122} 
    112  
    113123 
    114124?> 
Note: See TracChangeset for help on using the changeset viewer.