예제 #1
0
 /**
  * Executes the specified modifications.
  *
  * @param	boolean	Whether to close the list tags at the end of exeuction
  */
 function execute($close_list = true)
 {
     if (!$this->inside_list) {
         echo "<ul>\n";
         $this->inside_list = true;
     }
     foreach ($this->modifications as $modification) {
         if (!empty($modification['message'])) {
             echo "\t<li>{$modification['message']}</li>\n";
         }
         $data =& $modification['data'];
         if (!empty($modification['alter'])) {
             $db_alter =& $this->setup_db_alter_class($data['table']);
         } else {
             unset($db_alter);
         }
         $alter_result = null;
         switch ($modification['modification_type']) {
             case 'add_field':
                 $alter_result = $db_alter->add_field($data);
                 break;
             case 'drop_field':
                 $alter_result = $db_alter->drop_field($data['name']);
                 break;
             case 'add_index':
                 $alter_result = $db_alter->add_index($data['name'], $data['fields'], $data['type']);
                 break;
             case 'drop_index':
                 $alter_result = $db_alter->drop_index($data['name']);
                 break;
             case 'run_query':
                 $error_state = $this->db->reporterror;
                 if ($error_state) {
                     $this->db->hide_errors();
                 }
                 $query_result = $this->db->query_write($data['query']);
                 if ($errno = $this->db->errno()) {
                     if (!in_array($errno, $data['ignorable_errors'])) {
                         echo "</ul>";
                         $this->db->show_errors();
                         $this->db->sql = $data['query'];
                         $this->db->halt();
                     } else {
                         // error occurred, but was ignorable
                         $this->db->errno = 0;
                     }
                 }
                 if ($error_state) {
                     $this->db->show_errors();
                 }
                 break;
             case 'show_message':
                 // do nothing -- just show the message
                 break;
             case 'debug_break':
                 echo "</ul><div>Debug break point. Stopping execution.</div>";
                 exit;
             default:
                 trigger_error("<strong>vB_UpgradeQueries</strong>: Invalid modification type '{$modification['modification_type']}' specified.", E_USER_ERROR);
         }
         if ($alter_result === false) {
             if ($db_alter->error_no == ERRDB_MYSQL) {
                 echo "</ul>";
                 $this->db->show_errors();
                 $this->db->sql = $db_alter->sql;
                 $this->db->connection_recent = null;
                 $this->db->error = $db_alter->error_desc;
                 $this->db->errno = -1;
                 $this->db->halt();
             } else {
                 if (ob_start()) {
                     print_r($modification);
                     $results = ob_get_contents();
                     ob_end_clean();
                 } else {
                     $results = serialize($modification);
                 }
                 echo "\t\t<!-- {$results}\n\t\t" . "Error information: " . $db_alter->error_no . " / " . htmlspecialchars($db_alter->error_desc) . " -->\n\n";
             }
         }
     }
     if ($close_list) {
         echo "</ul>\n";
         $this->inside_list = false;
     }
     $this->modifications = array();
 }