IPB UPGRADE MODULE:: IPB 2.0.2 -> IPB 2.0.3 | > Script written by Matt Mecham | > Date started: 23rd April 2004 | > "So what, pop is dead - it's no great loss. So many facelifts, it's face flew off" +-------------------------------------------------------------------------- */ if ( ! defined( 'IN_IPB' ) ) { print "

Incorrect access

You cannot access this file directly. If you have recently upgraded, make sure you upgraded all the relevant files."; exit(); } class version_upgrade { var $this_version = '21003'; var $upgrade_from = '20013'; var $first_step = 'update your database to include the new schematic modifications and convert polls and calendar events.'; var $md5_check = ''; var $base_url = ''; var $mod_to_run = ''; /*-------------------------------------------------------------------------*/ // CONSTRUCTOR /*-------------------------------------------------------------------------*/ function version_upgrade() { } function version_process() { $this->md5_check = $this->ipsclass->return_md5_check(); $this->base_url = "index.php?act=work&loginkey={$this->ipsclass->input['loginkey']}&securekey={$this->ipsclass->input['securekey']}&mid={$this->ipsclass->input['mid']}"; if ( is_array( $this->ipsclass->modules_to_run ) and count( $this->ipsclass->modules_to_run ) ) { $tmp = array_shift( $this->ipsclass->modules_to_run ); $this->mod_to_run = implode( ', ', $this->ipsclass->modules_to_run ); } if ( ! $this->mod_to_run ) { $this->mod_to_run = 'None'; } } /*-------------------------------------------------------------------------*/ // Auto run.. /*-------------------------------------------------------------------------*/ function auto_run() { //-------------------------------- // What are we doing? // sql1 (tables) => sql2 (alter member) => sql3 (alter topics) => sql4 (alter other) => sql5 (inserts) => polls => calendar => skin => DONE //-------------------------------- switch( $this->ipsclass->input['workact'] ) { case 'sql': $this->upgrade_sql(0); break; case 'sql1': $this->upgrade_sql(1); break; case 'sql2': $this->upgrade_sql(2); break; case 'sql3': $this->upgrade_sql(3); break; case 'sql4': $this->upgrade_sql(4); break; case 'polls': $this->convert_polls(); break; case 'calevents': $this->convert_calevents(); break; case 'skin': $this->add_skin(); break; default: $this->upgrade_intro(); break; } } /*-------------------------------------------------------------------------*/ // CALENDAR EVENTS /*-------------------------------------------------------------------------*/ function add_skin() { //----------------------------------------- // Get default wrapper //----------------------------------------- if ( file_exists( THIS_PATH.'upg_'.$this->ipsclass->current_version.'/components.php' ) ) { require_once( THIS_PATH.'upg_'.$this->ipsclass->current_version.'/components.php' ); } //----------------------------------------- // Turn off all other skins //----------------------------------------- $this->ipsclass->DB->do_update( 'skin_sets', array( 'set_default' => 0 ) ); //----------------------------------------- // Insert new skin... //----------------------------------------- $this->ipsclass->DB->do_insert( 'skin_sets', array( 'set_name' => 'IPB 2.1 Default', 'set_image_dir' => 1, 'set_hidden' => 0, 'set_default' => 1, 'set_css_method' => 0, 'set_skin_set_parent' => -1, 'set_author_email' => '', 'set_author_name' => 'IPB 2.1 Default', 'set_author_url' => '', 'set_css' => $CSS, 'set_cache_css' => $CSS, 'set_wrapper' => $WRAPPER, 'set_cache_wrapper' => $WRAPPER, 'set_emoticon_folder' => 'default', ) ); $new_id = $this->ipsclass->DB->get_insert_id(); //----------------------------------------- // Remove member's choice //----------------------------------------- $this->ipsclass->DB->do_update( 'members', array( 'skin' => '' ) ); //----------------------------------------- // Done... //----------------------------------------- $this->ipsclass->core->redirect( "index.php?act=done&loginkey={$this->ipsclass->input['loginkey']}&securekey={$this->ipsclass->input['securekey']}&mid={$this->ipsclass->input['mid']}", "Skin added, proceeding to the next step..." ); } /*-------------------------------------------------------------------------*/ // CALENDAR EVENTS /*-------------------------------------------------------------------------*/ function convert_calevents() { $start = intval($_GET['st']); $lend = 50; $end = $start + $lend; //----------------------------------------- // In steps... //----------------------------------------- $this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'calendar_events', 'limit' => array( $start, $lend ) ) ); $o = $this->ipsclass->DB->simple_exec(); //----------------------------------------- // Do it... //----------------------------------------- if ( $this->ipsclass->DB->get_num_rows($o) ) { //----------------------------------------- // Got some to convert! //----------------------------------------- while ( $r = $this->ipsclass->DB->fetch_row($o) ) { $recur_remap = array( 'w' => 1, 'm' => 2, 'y' => 3 ); $begin_date = $this->ipsclass->date_getgmdate( $r['unix_stamp'] ); $end_date = $this->ipsclass->date_getgmdate( $r['end_unix_stamp'] ); if ( ! $begin_date OR ! $end_date ) { continue; } $day = $begin_date['mday']; $month = $begin_date['mon']; $year = $begin_date['year']; $end_day = $end_date['mday']; $end_month = $end_date['mon']; $end_year = $end_date['year']; $_final_unix_from = gmmktime(0, 0, 0, $month, $day, $year ); //----------------------------------------- // Recur or ranged... //----------------------------------------- if ( $r['event_repeat'] OR $r['event_ranged'] ) { $_final_unix_to = gmmktime(23, 59, 59, $end_month, $end_day, $end_year); } else { $_final_unix_to = 0; } $new_event = array( 'event_calendar_id' => 1, 'event_member_id' => $r['userid'], 'event_content' => $r['event_text'], 'event_title' => $r['title'], 'event_smilies' => $r['show_emoticons'], 'event_perms' => $r['read_perms'], 'event_private' => $r['priv_event'], 'event_approved' => 1, 'event_unixstamp' => $r['unix_stamp'], 'event_recurring' => $r['event_repeat'] AND $recur_remap[ $r['repeat_unit'] ] ? $recur_remap[ $r['repeat_unit'] ] : 0, 'event_tz' => 0, 'event_unix_from' => $_final_unix_from, 'event_unix_to' => $_final_unix_to ); //----------------------------------------- // INSERT //----------------------------------------- $this->ipsclass->DB->do_insert( 'cal_events', $new_event ); } $msg = "Calendar events: $start to $end completed...."; $this->ipsclass->core->redirect( "index.php?act=work&loginkey={$this->ipsclass->input['loginkey']}&securekey={$this->ipsclass->input['securekey']}&mid={$this->ipsclass->input['mid']}&workact=calevents&st={$end}", $msg ); } else { $msg = "Calendar events converted. Creating new IPB 2.1 skin..."; $this->ipsclass->core->redirect( "index.php?act=work&loginkey={$this->ipsclass->input['loginkey']}&securekey={$this->ipsclass->input['securekey']}&mid={$this->ipsclass->input['mid']}&workact=skin", $msg ); } } /*-------------------------------------------------------------------------*/ // POLLS /*-------------------------------------------------------------------------*/ function convert_polls() { $start = intval($_GET['st']); $lend = 50; $end = $start + $lend; $max = intval($_GET['max']); $converted = intval( $_GET['conv'] ); //----------------------------------------- // First off.. grab number of polls to convert //----------------------------------------- if ( ! $max ) { $total = $this->ipsclass->DB->build_and_exec_query( array( 'select' => 'COUNT(*) as max', 'from' => 'topics', 'where' => "poll_state IN ('open', 'close', 'closed')" ) ); $max = $total['max']; } //----------------------------------------- // In steps... //----------------------------------------- $this->ipsclass->DB->simple_construct( array( 'select' => '*', 'from' => 'topics', 'where' => "poll_state IN ('open', 'close', 'closed' )", 'limit' => array( 0, $lend ) ) ); $o = $this->ipsclass->DB->simple_exec(); //----------------------------------------- // Do it... //----------------------------------------- if ( $this->ipsclass->DB->get_num_rows($o) ) { //----------------------------------------- // Got some to convert! //----------------------------------------- while ( $r = $this->ipsclass->DB->fetch_row($o) ) { $converted++; $new_poll = array( 1 => array() ); $poll_data = $this->ipsclass->DB->build_and_exec_query( array( 'select' => '*', 'from' => 'polls', 'where' => "tid=".$r['tid'] ) ); if ( ! $poll_data['pid'] ) { continue; } if ( ! $poll_data['poll_question'] ) { $poll_data['poll_question'] = $r['title']; } //----------------------------------------- // Kick start new poll //----------------------------------------- $new_poll[1]['question'] = $poll_data['poll_question']; //----------------------------------------- // Get OLD polls //----------------------------------------- $poll_answers = unserialize( stripslashes( $poll_data['choices'] ) ); reset($poll_answers); foreach ( $poll_answers as $entry ) { $id = $entry[0]; $choice = $entry[1]; $votes = $entry[2]; $total_votes += $votes; if ( strlen($choice) < 1 ) { continue; } $new_poll[ 1 ]['choice'][ $id ] = $choice; $new_poll[ 1 ]['votes'][ $id ] = $votes; } //----------------------------------------- // Got something? //----------------------------------------- if ( count( $new_poll[1]['choice'] ) ) { $this->ipsclass->DB->do_update( 'polls' , array( 'choices' => serialize( $new_poll ) ), 'tid='.$r['tid'] ); $this->ipsclass->DB->do_update( 'topics', array( 'poll_state' => 1 ), 'tid='.$r['tid'] ); } //----------------------------------------- // All done? //----------------------------------------- if ( $converted >= $max ) { $done = 1; continue; } } } else { $done = 1; } if ( ! $done ) { $msg = "Polls: $start to $end completed...."; $this->ipsclass->core->redirect( "index.php?act=work&loginkey={$this->ipsclass->input['loginkey']}&securekey={$this->ipsclass->input['securekey']}&mid={$this->ipsclass->input['mid']}&workact=polls&st={$end}&max={$max}".'&conv='.$converted, $msg ); } else { $msg = "Polls converted, proceeding to the next step..."; $this->ipsclass->core->redirect( "index.php?act=work&loginkey={$this->ipsclass->input['loginkey']}&securekey={$this->ipsclass->input['securekey']}&mid={$this->ipsclass->input['mid']}&workact=calevents&st=0", $msg ); } } /*-------------------------------------------------------------------------*/ // SQL: 0 /*-------------------------------------------------------------------------*/ function upgrade_sql( $id=0 ) { $man = intval( $this->ipsclass->input['man'] ); $cnt = 0; $SQL = array(); $file = ( $id > 0 ) ? '_updates_'.$id.'.php' : '_updates.php'; $output = ""; if ( file_exists( THIS_PATH . 'upg_' . $this->ipsclass->current_upgrade . '/' . strtolower($this->ipsclass->vars['sql_driver']) . $file ) ) { require_once( THIS_PATH . 'upg_' . $this->ipsclass->current_upgrade . '/' . strtolower($this->ipsclass->vars['sql_driver']) . $file ); foreach( $SQL as $q ) { $q = str_replace( "<%time%>", time(), $q ); //-------------------------------- // Run or show? //-------------------------------- if ( $man ) { $output .= preg_replace("/\sibf_(\S+?)([\s\.,]|$)/", " ".$this->ipsclass->DB->obj['sql_tbl_prefix']."\\1\\2", preg_replace( "/\s{1,}/", " ", $q ) )."\n"; } else { $this->ipsclass->DB->query( $q ); } $cnt++; } } //-------------------------------- // Next page... //-------------------------------- if ( $id != 4 ) { $nextid = $id + 1; $url = "index.php?act=work&man={$man}&loginkey={$this->ipsclass->input['loginkey']}&securekey={$this->ipsclass->input['securekey']}&mid={$this->ipsclass->input['mid']}&workact=sql".$nextid; //-------------------------------- // Run or show? //-------------------------------- if ( $man ) { $this->ipsclass->template->content .= "
SQL Queries: Step $nextid
PLEASE RUN THESE QUERIES BEFORE CONTINUING



» Show next...
"; $this->ipsclass->template->output(); } else { $this->ipsclass->core->redirect( $url, "$cnt queries run...." ); } } else { $this->ipsclass->core->redirect( "index.php?act=work&loginkey={$this->ipsclass->input['loginkey']}&securekey={$this->ipsclass->input['securekey']}&mid={$this->ipsclass->input['mid']}&workact=polls&st=0", "$cnt queries run...." ); } } /*-------------------------------------------------------------------------*/ // INTRO /*-------------------------------------------------------------------------*/ function upgrade_intro() { $this->ipsclass->template->content .= "
Welcome to the IPB Upgrade System
This upgrade module will upgrade you from {$this->ipsclass->versions[$this->upgrade_from]} to {$this->ipsclass->versions[$this->this_version]}

This first step will {$this->first_step}

If you have a large database and would prefer to run the SQL queries manually (to overcome PHP timeouts), please click here to proceed.

» Proceed (with auto SQL insertion)...

Modules to run after this module: {$this->mod_to_run}
"; if ( ! is_writeable( CACHE_PATH . 'cache/skin_cache' ) ) { $this->ipsclass->template->content .= "
WARNING: cache/skin_cache is not writeable
Please check the CHMOD value on this folder before continuing. Failure to do so could mean that your skin files will not be installed correctly.
"; } $this->ipsclass->template->output(); } } ?>