Changeset 4410 for trunk/install.php


Ignore:
Timestamp:
12/02/09 21:27:06 (9 years ago)
Author:
nikrou
Message:

Feature 1255 :

  • add postgres database engine
  • change installation process to allow postgres or mysql database
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/install.php

    r4385 r4410  
    2525define('PHPWG_ROOT_PATH','./'); 
    2626 
    27 /** 
    28  * loads an sql file and executes all queries 
    29  * 
    30  * Before executing a query, $replaced is... replaced by $replacing. This is 
    31  * useful when the SQL file contains generic words. Drop table queries are 
    32  * not executed. 
    33  * 
    34  * @param string filepath 
    35  * @param string replaced 
    36  * @param string replacing 
    37  * @return void 
    38  */ 
    39 function execute_sqlfile($filepath, $replaced, $replacing) 
    40 { 
    41   $sql_lines = file($filepath); 
    42   $query = ''; 
    43   foreach ($sql_lines as $sql_line) 
    44   { 
    45     $sql_line = trim($sql_line); 
    46     if (preg_match('/(^--|^$)/', $sql_line)) 
    47     { 
    48       continue; 
    49     } 
    50     $query.= ' '.$sql_line; 
    51     // if we reached the end of query, we execute it and reinitialize the 
    52     // variable "query" 
    53     if (preg_match('/;$/', $sql_line)) 
    54     { 
    55       $query = trim($query); 
    56       $query = str_replace($replaced, $replacing, $query); 
    57       // we don't execute "DROP TABLE" queries 
    58       if (!preg_match('/^DROP TABLE/i', $query)) 
    59       { 
    60         global $install_charset_collate; 
    61         if ( !empty($install_charset_collate) ) 
    62         { 
    63           if ( preg_match('/^(CREATE TABLE .*)[\s]*;[\s]*/im', $query, $matches) ) 
    64           { 
    65             $query = $matches[1].' '.$install_charset_collate.';'; 
    66           } 
    67         } 
    68         pwg_query($query); 
    69       } 
    70       $query = ''; 
    71     } 
    72   } 
    73 } 
     27include(PHPWG_ROOT_PATH . 'admin/include/functions_install.inc.php'); 
    7428 
    7529@set_magic_quotes_runtime(0); // Disable magic_quotes_runtime 
     
    150104$dbpasswd = (!empty($_POST['dbpasswd'])) ? $_POST['dbpasswd'] : ''; 
    151105$dbname = (!empty($_POST['dbname'])) ? $_POST['dbname'] : ''; 
     106$dblayer = (!empty($_POST['dblayer'])) ? $_POST['dblayer'] : 'mysql'; 
    152107 
    153108if (isset($_POST['install'])) 
     
    183138include(PHPWG_ROOT_PATH . 'include/config_default.inc.php'); 
    184139@include(PHPWG_ROOT_PATH. 'include/config_local.inc.php'); 
    185 include(PHPWG_ROOT_PATH . 'include/dblayer/functions_mysql.inc.php'); 
     140include(PHPWG_ROOT_PATH .'include/dblayer/functions_'.$dblayer.'.inc.php'); 
    186141include(PHPWG_ROOT_PATH . 'include/constants.php'); 
    187142include(PHPWG_ROOT_PATH . 'include/functions.inc.php'); 
     
    233188//----------------------------------------------------- template initialization 
    234189include( PHPWG_ROOT_PATH .'include/template.class.php'); 
    235 $template=new Template(PHPWG_ROOT_PATH.'admin/template/goto', 'roma'); 
     190$template = new Template(PHPWG_ROOT_PATH.'admin/template/goto', 'roma'); 
    236191$template->set_filenames( array('install'=>'install.tpl') ); 
    237192$step = 1; 
     
    239194if ( isset( $_POST['install'] )) 
    240195{ 
    241   if ( @mysql_connect( $_POST['dbhost'], 
    242                        $_POST['dbuser'], 
    243                        $_POST['dbpasswd'] ) ) 
    244   { 
    245     if ( @mysql_select_db($_POST['dbname'] ) ) 
    246     { 
    247       array_push( $infos, l10n('step1_confirmation') ); 
     196  if (($pwg_db_link = pwg_db_connect($_POST['dbhost'], $_POST['dbuser'],  
     197                                     $_POST['dbpasswd'], $_POST['dbname']))!==false)  
     198  { 
     199 
     200    array_push( $infos, l10n('step1_confirmation') ); 
     201 
     202    $required_version = constant('REQUIRED_'.strtoupper($conf['dblayer']).'_VERSION'); 
     203    if ( version_compare(pwg_get_db_version(), $required_version, '>=') ) 
     204    { 
     205      $pwg_charset = 'utf-8'; 
     206      $pwg_db_charset = 'utf8'; 
     207      if ($dblayer=='mysql') 
     208      { 
     209        $install_charset_collate = "DEFAULT CHARACTER SET $pwg_db_charset"; 
     210      } 
     211      else  
     212      { 
     213        $install_charset_collate = ''; 
     214      } 
    248215    } 
    249216    else 
    250217    { 
    251       array_push( $errors, l10n('step1_err_db') ); 
    252     } 
    253     if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') ) 
    254     { 
    255       $pwg_charset='utf-8'; 
    256       $pwg_db_charset='utf8'; 
    257       $install_charset_collate = "DEFAULT CHARACTER SET $pwg_db_charset"; 
    258     } 
    259     else 
    260     { 
    261       $pwg_charset='iso-8859-1'; 
    262       $pwg_db_charset='latin1'; 
     218      $pwg_charset = 'iso-8859-1'; 
     219      $pwg_db_charset = 'latin1'; 
    263220      $install_charset_collate = ''; 
    264221      if ( !array_key_exists($language, get_languages($pwg_charset) ) ) 
     
    293250    $step = 2; 
    294251    $file_content = '<?php 
    295 $conf[\'dblayer\'] = \'mysql\'; 
     252$conf[\'dblayer\'] = \''.$dblayer.'\'; 
    296253$conf[\'db_base\'] = \''.$dbname.'\'; 
    297254$conf[\'db_user\'] = \''.$dbuser.'\'; 
     
    327284    // tables creation, based on piwigo_structure.sql 
    328285    execute_sqlfile( 
    329       PHPWG_ROOT_PATH.'install/piwigo_structure.sql', 
     286      PHPWG_ROOT_PATH.'install/piwigo_structure-'.$dblayer.'.sql', 
    330287      DEFAULT_PREFIX_TABLE, 
    331288      $table_prefix 
     
    337294      $table_prefix 
    338295      ); 
     296 
     297    $query = ' 
     298INSERT INTO piwigo_config (param,value,comment)  
     299   VALUES (\'secret_key\',\'md5('.pwg_db_cast_to_text(DB_RANDOM_FUNCTION.'()').')\', 
     300   \'a secret key specific to the gallery for internal use\');'; 
     301    pwg_query($query); 
    339302 
    340303    // fill $conf global array 
     
    390353 
    391354//------------------------------------------------------ start template output 
     355$dbengines = available_engines(); 
     356 
    392357foreach (get_languages('utf-8') as $language_code => $language_name) 
    393358{ 
     
    403368  array( 
    404369    'T_CONTENT_ENCODING' => 'utf-8', 
    405     'RELEASE'=>PHPWG_VERSION, 
     370    'RELEASE' => PHPWG_VERSION, 
    406371    'F_ACTION' => 'install.php?language=' . $language, 
    407     'F_DB_HOST'=>$dbhost, 
    408     'F_DB_USER'=>$dbuser, 
    409     'F_DB_NAME'=>$dbname, 
     372    'F_DB_ENGINES' => $dbengines, 
     373    'F_DB_LAYER' => $dblayer, 
     374    'F_DB_HOST' => $dbhost, 
     375    'F_DB_USER' => $dbuser, 
     376    'F_DB_NAME' => $dbname, 
    410377    'F_DB_PREFIX' => $table_prefix, 
    411     'F_ADMIN'=>$admin_name, 
    412     'F_ADMIN_EMAIL'=>$admin_mail, 
    413     'L_INSTALL_HELP'=>sprintf(l10n('install_help'), PHPWG_URL.'/forum'), 
     378    'F_ADMIN' => $admin_name, 
     379    'F_ADMIN_EMAIL' => $admin_mail, 
     380    'L_INSTALL_HELP' => sprintf(l10n('install_help'), PHPWG_URL.'/forum'), 
    414381    )); 
    415382 
Note: See TracChangeset for help on using the changeset viewer.