Changeset 2818

Show
Ignore:
Timestamp:
11/16/08 01:47:42 (8 weeks ago)
Author:
freakerz
Message:

A lot of stuff: removed InstallSchema, renamed install.php, moved the InstallHandler calls to Controller using a constant, new class Installer. This is all experimental so it will change to be much nicer especially the DB stuff.

Location:
branches/081018-handlers/htdocs
Files:
7 added
7 removed
8 modified

Legend:

Unmodified
Added
Removed
  • branches/081018-handlers/htdocs/index.php

    r2689 r2818  
    114114/* Initiate install verifications */ 
    115115 
    116 // Retrieve the configuration file's path. 
    117 $config = Site::get_dir( 'config_file' ); 
    118116 
    119117/** 
     
    123121 * @todo Call the installer from the database classes. 
    124122 */ 
    125 if ( file_exists( $config ) ) { 
     123/*if ( file_exists( $config ) ) { 
    126124    require_once $config; 
    127125 
     
    157155    $installer = new InstallHandler(); 
    158156    $installer->begin_install(); 
    159 } 
     157} */ 
     158 
     159DB::connect(); 
    160160 
    161161/* Habari is installed and we established a connection with the database */ 
     162if ( !defined( 'DEBUG' ) ) define( 'DEBUG', false ); 
    162163 
    163164// Set the locale from database or default locale 
    164 if ( Options::get('locale') ) { 
    165     Locale::set( Options::get('locale') ); 
    166 } 
    167 else { 
    168     Locale::set( 'en-us' ); 
    169 } 
     165Locale::set( Options::get('locale') ); 
    170166if ( Options::get( 'system_locale' ) ) { 
    171167    Locale::set_system_locale( Options::get( 'system_locale' ) ); 
     
    217213Plugins::act('plugins_loaded'); 
    218214 
    219 // Start the session. 
    220 Session::init(); 
     215// Skip session stuff if not installed 
     216if (!defined('NOT_INSTALLED')) { 
     217    // Start the session. 
     218    Session::init(); 
     219} 
    221220 
    222221// Initiating request handling, tell the plugins. 
  • branches/081018-handlers/htdocs/system/classes/controller.php

    r2592 r2818  
    144144        } 
    145145 
     146        if (defined('NOT_INSTALLED') && $matched_rule->name != 'ajax') { 
     147            $matched_rule->handler = 'installhandler'; 
     148            $matched_rule->action = 'begin_install'; 
     149        } 
     150        else { 
     151            Installer::load_schema_install(); 
     152        } 
     153         
    146154        /* OK, we have a matching rule.  Set the action and create a handler */ 
    147155        $controller->action = $matched_rule->action; 
  • branches/081018-handlers/htdocs/system/classes/db.php

    r2592 r2818  
    4848        } 
    4949        else { 
    50             /* We use the config.php variables */ 
    51             $connect_string = $GLOBALS['db_connection']['connection_string']; 
    52             $db_user = $GLOBALS['db_connection']['username']; 
    53             $db_pass = $GLOBALS['db_connection']['password']; 
    54         } 
    55         DB::instance()->connection = DatabaseConnection::ConnectionFactory( $connect_string ); 
     50            // Retrieve the configuration file's path. 
     51            $config = Site::get_dir( 'config_file' ); 
     52            if ( file_exists( $config ) ) { 
     53                require_once $config; 
     54                if ( isset($db_connection) ) { 
     55                    /* We use the config.php variables */ 
     56                    $connect_string = $db_connection['connection_string']; 
     57                    $db_user = $db_connection['username']; 
     58                    $db_pass = $db_connection['password']; 
     59                } 
     60            } 
     61        } 
     62        if (isset($connect_string)) { 
     63            DB::instance()->connection = DatabaseConnection::ConnectionFactory( $connect_string ); 
     64        } 
    5665        if ( NULL != DB::instance()->connection ) { 
    5766            return DB::instance()->connection->connect ($connect_string, $db_user, $db_pass); 
     
    5968        else { 
    6069            // do some error handling here. The connect string does not have a corresponding DB connection object 
    61             print _t('Panic! No database connection class appears to be found for the connection string specified. Please check config.php'); 
     70            //print _t('Panic! No database connection class appears to be found for the connection string specified. Please check config.php'); 
     71            define('NOT_INSTALLED', true); 
    6272        } 
    6373    } 
     
    7989    public static function table( $name ) 
    8090    { 
    81         return DB::instance()->connection->table( $name ); 
     91        if ( NULL != DB::instance()->connection ) { 
     92            echo $name; 
     93            return DB::instance()->connection->table( $name ); 
     94        } 
    8295    } 
    8396 
     
    91104    public static function register_table( $name ) 
    92105    { 
    93         DB::instance()->connection->register_table( $name ); 
     106        if ( NULL != DB::instance()->connection ) { 
     107            DB::instance()->connection->register_table( $name ); 
     108        } 
    94109    } 
    95110 
     
    101116    public static function set_fetch_mode( $mode ) 
    102117    { 
    103         DB::instance()->connection->set_fetch_mode( $mode ); 
     118        if ( NULL != DB::instance()->connection ) { 
     119            DB::instance()->connection->set_fetch_mode( $mode ); 
     120        } 
    104121    } 
    105122 
     
    111128    public static function set_fetch_class( $class_name ) 
    112129    { 
    113         DB::instance()->connection->set_fetch_class( $class_name ); 
     130        if ( NULL != DB::instance()->connection ) { 
     131            DB::instance()->connection->set_fetch_class( $class_name ); 
     132        } 
    114133    } 
    115134 
    116135    public static function exec( $query ) 
    117136    { 
    118         return DB::instance()->connection->exec( $query ); 
     137        if ( NULL != DB::instance()->connection ) { 
     138            return DB::instance()->connection->exec( $query ); 
     139        } 
    119140    } 
    120141 
     
    128149    public static function query( $query, $args = array() ) 
    129150    { 
    130          return DB::instance()->connection->query( $query, $args ); 
     151        if ( NULL != DB::instance()->connection ) { 
     152            return DB::instance()->connection->query( $query, $args ); 
     153        } 
    131154    } 
    132155 
     
    142165    public static function execute_procedure( $procedure, $args = array() ) 
    143166    { 
    144         return DB::instance()->connection->execute_procedure( $procedure, $args ); 
     167        if ( NULL != DB::instance()->connection ) { 
     168            return DB::instance()->connection->execute_procedure( $procedure, $args ); 
     169        } 
    145170    } 
    146171 
     
    151176    public static function begin_transaction() 
    152177    { 
    153         DB::instance()->connection->begin_transaction(); 
     178        if ( NULL != DB::instance()->connection ) { 
     179            DB::instance()->connection->begin_transaction(); 
     180        } 
    154181    } 
    155182 
     
    161188    public static function rollback() 
    162189    { 
    163         DB::instance()->connection->rollback(); 
     190        if ( NULL != DB::instance()->connection ) { 
     191            DB::instance()->connection->rollback(); 
     192        } 
    164193    } 
    165194 
     
    168197     */ 
    169198    public static function commit() { 
    170         DB::instance()->connection->commit(); 
     199        if ( NULL != DB::instance()->connection ) { 
     200            DB::instance()->connection->commit(); 
     201        } 
    171202    } 
    172203 
     
    178209    public static function get_profiles() 
    179210    { 
    180         return DB::instance()->connection->get_profiles(); 
     211        if ( NULL != DB::instance()->connection ) { 
     212            return DB::instance()->connection->get_profiles(); 
     213        } 
    181214    } 
    182215 
     
    188221    private static function add_error( $error ) 
    189222    { 
    190         DB::instance()->connection->add_error( $error ); 
     223        if ( NULL != DB::instance()->connection ) { 
     224            DB::instance()->connection->add_error( $error ); 
     225        } 
    191226    } 
    192227 
     
    197232    public static function get_errors() 
    198233    { 
    199         return DB::instance()->connection->get_errors(); 
     234        if ( NULL != DB::instance()->connection ) { 
     235            return DB::instance()->connection->get_errors(); 
     236        } 
    200237    } 
    201238 
     
    206243    public static function has_errors() 
    207244    { 
    208         return DB::instance()->connection->has_errors(); 
     245        if ( NULL != DB::instance()->connection ) { 
     246            return DB::instance()->connection->has_errors(); 
     247        } 
    209248    } 
    210249 
     
    214253    public static function clear_errors() 
    215254    { 
    216         DB::instance()->connection->clear_errors(); 
     255        if ( NULL != DB::instance()->connection ) { 
     256            DB::instance()->connection->clear_errors(); 
     257        } 
    217258    } 
    218259 
     
    223264    public static function get_last_error() 
    224265    { 
    225         return DB::instance()->connection->get_last_error(); 
     266        if ( NULL != DB::instance()->connection ) { 
     267            return DB::instance()->connection->get_last_error(); 
     268        } 
    226269    } 
    227270 
     
    236279    public static function get_results( $query, $args = array() ) 
    237280    { 
    238         if ( func_num_args() == 3 ) { 
    239             $class_name = func_get_arg( 2 ); 
    240             return DB::instance()->connection->get_results( $query, $args, $class_name ); 
    241         } 
    242         else { 
    243             return DB::instance()->connection->get_results( $query, $args ); 
     281        if ( NULL != DB::instance()->connection ) { 
     282            if ( func_num_args() == 3 ) { 
     283                $class_name = func_get_arg( 2 ); 
     284                return DB::instance()->connection->get_results( $query, $args, $class_name ); 
     285            } 
     286            else { 
     287                return DB::instance()->connection->get_results( $query, $args ); 
     288            } 
    244289        } 
    245290    } 
     
    255300    public static function get_row( $query, $args = array() ) 
    256301    { 
    257         if ( func_num_args() == 3 ) { 
    258             $class_name = func_get_arg( 2 ); 
    259             return DB::instance()->connection->get_row( $query, $args, $class_name ); 
    260         } 
    261         else { 
    262             return DB::instance()->connection->get_row( $query, $args ); 
     302        if ( NULL != DB::instance()->connection ) { 
     303            if ( func_num_args() == 3 ) { 
     304                $class_name = func_get_arg( 2 ); 
     305                return DB::instance()->connection->get_row( $query, $args, $class_name ); 
     306            } 
     307            else { 
     308                return DB::instance()->connection->get_row( $query, $args ); 
     309            } 
    263310        } 
    264311    } 
     
    274321    public static function get_column( $query, $args = array() ) 
    275322    { 
    276          return DB::instance()->connection->get_column( $query, $args ); 
     323        if ( NULL != DB::instance()->connection ) { 
     324            return DB::instance()->connection->get_column( $query, $args ); 
     325        } 
    277326    } 
    278327 
     
    286335    public static function get_value( $query, $args = array() ) 
    287336    { 
    288         return DB::instance()->connection->get_value( $query,  $args ); 
     337        if ( NULL != DB::instance()->connection ) { 
     338            return DB::instance()->connection->get_value( $query,  $args ); 
     339        } 
    289340    } 
    290341 
     
    299350    public static function get_keyvalue( $query, $args = array() ) 
    300351    { 
    301          return DB::instance()->connection->get_keyvalue( $query, $args ); 
     352        if ( NULL != DB::instance()->connection ) { 
     353            return DB::instance()->connection->get_keyvalue( $query, $args ); 
     354        } 
    302355    } 
    303356 
     
    311364    public static function insert( $table, $fieldvalues ) 
    312365    { 
    313         return DB::instance()->connection->insert( $table, $fieldvalues ); 
     366        if ( NULL != DB::instance()->connection ) { 
     367            return DB::instance()->connection->insert( $table, $fieldvalues ); 
     368        } 
    314369    } 
    315370 
     
    323378    public static function exists( $table, $keyfieldvalues ) 
    324379    { 
    325         return DB::instance()->connection->exists( $table, $keyfieldvalues ); 
     380        if ( NULL != DB::instance()->connection ) { 
     381            return DB::instance()->connection->exists( $table, $keyfieldvalues ); 
     382        } 
    326383    } 
    327384 
     
    338395    public static function update( $table, $fieldvalues, $keyfields ) 
    339396    { 
    340          return DB::instance()->connection->update( $table, $fieldvalues, $keyfields ); 
     397        if ( NULL != DB::instance()->connection ) { 
     398            return DB::instance()->connection->update( $table, $fieldvalues, $keyfields ); 
     399        } 
    341400    } 
    342401 
     
    350409    public static function delete( $table, $keyfields ) 
    351410    { 
    352         return DB::instance()->connection->delete( $table, $keyfields ); 
     411        if ( NULL != DB::instance()->connection ) { 
     412            return DB::instance()->connection->delete( $table, $keyfields ); 
     413        } 
    353414    } 
    354415 
     
    364425    public static function last_insert_id() 
    365426    { 
    366         return DB::instance()->connection->last_insert_id( func_num_args() == 1 ? func_get_arg( 0 ) : '' ); 
     427        if ( NULL != DB::instance()->connection ) { 
     428            return DB::instance()->connection->last_insert_id( func_num_args() == 1 ? func_get_arg( 0 ) : '' ); 
     429        } 
    367430    } 
    368431     
     
    374437    public static function row_count() 
    375438    { 
    376         return DB::instance()->connection->row_count(); 
     439        if ( NULL != DB::instance()->connection ) { 
     440            return DB::instance()->connection->row_count(); 
     441        } 
    377442    } 
    378443 
     
    387452    public static function dbdelta( $queries, $execute = true, $silent = true, $doinserts = false ) 
    388453    { 
    389          return DB::instance()->connection->dbdelta( $queries, $execute, $silent, $doinserts ); 
     454        if ( NULL != DB::instance()->connection ) { 
     455            return DB::instance()->connection->dbdelta( $queries, $execute, $silent, $doinserts ); 
     456        } 
    390457    } 
    391458 
     
    397464    public static function upgrade( $old_version ) 
    398465    { 
    399          return DB::instance()->connection->upgrade( $old_version ); 
     466        if ( NULL != DB::instance()->connection ) { 
     467            return DB::instance()->connection->upgrade( $old_version ); 
     468        } 
    400469    } 
    401470     
    402471    public static function get_driver_name() 
    403472    { 
    404         return DB::instance()->connection->get_driver_name(); 
     473        if ( NULL != DB::instance()->connection ) { 
     474            return DB::instance()->connection->get_driver_name(); 
     475        } 
    405476    } 
    406477     
     
    412483    public static function list_tables() 
    413484    { 
    414         return DB::instance()->connection->list_tables(); 
     485        if ( NULL != DB::instance()->connection ) { 
     486            return DB::instance()->connection->list_tables(); 
     487        } 
    415488    } 
    416489     
     
    422495    public static function is_connected() 
    423496    { 
    424         return DB::instance()->connection->is_connected(); 
     497        if (isset(DB::instance()->connection)) { 
     498            return DB::instance()->connection->is_connected(); 
     499        } 
    425500    } 
    426501     
     
    432507    public static function in_transaction() 
    433508    { 
    434         return DB::instance()->connection->in_transaction(); 
     509        if ( NULL != DB::instance()->connection ) { 
     510            return DB::instance()->connection->in_transaction(); 
     511        } 
    435512    } 
    436513} 
  • branches/081018-handlers/htdocs/system/classes/installhandler.php

    r2815 r2818  
    284284         
    285285        // Load available schemas' install script 
    286         foreach ($pdo_drivers as $pdo_driver) { 
    287             $install_file = HABARI_PATH . '/system/schema/' . $pdo_driver . '/install/install.php'; 
    288             if (file_exists($install_file)) { 
    289                 include_once($install_file); 
    290             } 
    291             $classname = $pdo_driver.'Install'; 
    292             if (class_exists($pdo_driver.'Install')) { 
    293                 $this->schemas[$pdo_driver] = new $classname(); 
    294                 // Register plugin hooks 
    295                 $this->schemas[$pdo_driver]->load(); 
    296             } 
    297         } 
     286        Installer::load_schema_install(); 
    298287                         
    299288        $pdo_drivers_ok = count( $pdo_drivers ); 
  • branches/081018-handlers/htdocs/system/classes/options.php

    r2724 r2818  
    126126            'pagination' => 10, 
    127127            'comments_require_id' => false, 
     128            'locale' => 'en-us', 
     129            /* Installer */ 
     130            'next_cron' => date('U') + strtotime('1 year'), // Skip Crontab 
     131            'db_version' => Version::DB_VERSION, // Skip DB Upgrades 
    128132        ); 
    129         $results = DB::get_results( 'SELECT name, value, type FROM ' . DB::table( 'options' ), array(), 'QueryRecord' ); 
    130         foreach($results as $result) { 
    131             if ( $result->type == 1 ) { 
    132                 $this->options[$result->name]= unserialize( $result->value ); 
    133             } 
    134             else { 
    135                 $this->options[$result->name]= $result->value; 
     133        if (DB::is_connected()) { 
     134            $results = DB::get_results( 'SELECT name, value, type FROM ' . DB::table( 'options' ), array(), 'QueryRecord' ); 
     135            foreach($results as $result) { 
     136                if ( $result->type == 1 ) { 
     137                    $this->options[$result->name]= unserialize( $result->value ); 
     138                } 
     139                else { 
     140                    $this->options[$result->name]= $result->value; 
     141                } 
    136142            } 
    137143        } 
  • branches/081018-handlers/htdocs/system/classes/rewriterules.php

    r2813 r2818  
    7979 
    8080        if(!isset($system_rules)) { 
    81             $sql = " 
    82                 SELECT rr.rule_id, rr.name, rr.parse_regex, rr.build_str, rr.handler, rr.action, rr.priority, rr.parameters 
    83                 FROM " . DB::table( 'rewrite_rules' ) . " AS rr 
    84                 WHERE rr.is_active= 1 
    85                 ORDER BY rr.priority"; 
    86             $db_rules = DB::get_results( $sql, array(), 'RewriteRule' ); 
    87  
     81            if (DB::is_connected()) { 
     82                $sql = " 
     83                    SELECT rr.rule_id, rr.name, rr.parse_regex, rr.build_str, rr.handler, rr.action, rr.priority, rr.parameters 
     84                    FROM " . DB::table( 'rewrite_rules' ) . " AS rr 
     85                    WHERE rr.is_active= 1 
     86                    ORDER BY rr.priority"; 
     87                $db_rules = DB::get_results( $sql, array(), 'RewriteRule' ); 
     88            } 
     89            else { 
     90                $db_rules = array(); 
     91            } 
    8892            $system_rules = self::add_system_rules( $db_rules ); 
    8993        } 
  • branches/081018-handlers/htdocs/system/themes/installer/script.js

    r2817 r2818  
    1010    setDatabaseType: function () { 
    1111        for ( var i in habari.installer.schemas ) { 
    12             // May use some function per schema (in their class) to show/hide themselves 
     12            // Any better way of doing this? 
    1313            if (habari.installer.schemas[i] != $('#db_type').val()) { 
    14                 $("fieldset[id*='" + habari.installer.schemas[i] + "settings']").hide(); 
     14                $('#' + habari.installer.schemas[i] + 'settings').hide(); 
    1515            } 
    1616            else { 
    17                 $("fieldset[id*='" + habari.installer.schemas[i] + "settings']").show(); 
     17                $('#' + habari.installer.schemas[i] + 'settings').show(); 
    1818            } 
    1919        } 
     20        habari.installer.checkDBCredentials(); 
    2021    }, 
    2122     
    2223    checkDBCredentials: function() { 
    2324        var toCall = 'habari.installer.' + $('#db_type').val() + '.checkDBCredentials()'; 
    24         if (eval(toCall)) { 
    25             $('.installstep:first').removeClass('done'); 
    26             $('#siteconfiguration').children('.options').fadeOut().removeClass('ready').removeClass('done'); 
    27             $('#install').children('.options').fadeOut().removeClass('ready').removeClass('done'); 
    28         } 
     25        toCall = new Function(toCall); 
     26        toCall(); 
    2927    }, 
    3028     
     
    9088        clearTimeout(checktimer); 
    9189    } 
    92     checktimer = setTimeout(timer, 500); 
     90    checktimer = setTimeout(timer, 800); 
    9391} 
    9492 
     
    185183    itemManage.init(); 
    186184    habari.installer.setDatabaseType(); 
    187     habari.installer.checkDBCredentials(); 
    188185    habari.installer.checkSiteConfiguration(); 
    189186    $('#db_type').change(function(){habari.installer.setDatabaseType()}); 
  • branches/081018-handlers/htdocs/system/themes/installer/theme.php

    r2815 r2818  
    9595        Habari.') . ' <a href="#">' . _t('Learn More...') . '</a>'; 
    9696        // Admin Email 
    97         $form->siteconfiguration_options->append('text', 'admin_email', 'null:null', _t('Username')