<commit_before><?php defined('SYSPATH') OR die('No direct access allowed.');
/**
 * S7Ncms - www.s7n.de
 *
 * Copyright (c) 2007-2009, <NAME> <eduard at baun.de>
 * All rights reserved.
 *
 * See license.txt for full text and disclaimer
 *
 * @author <NAME> <eduard at baun.de>
 * @copyright <NAME>, 2007-2009
 * @version $Id$
 */
class Install_Controller extends Template_Controller {

    public function index()
    {
        $dbuser='';
        $dbpass='';
        $dbhost='';
        $dbdatabase='';
        if($_POST)
        {
            echo Kohana::debug($this->input->post());
            $dbuser=$_POST['dbuser'];
            $dbpass=$_POST['dbpass'];
            $dbhost=$_POST['dbhost'];
            $dbdatabase= $_POST['dbdatabase'];
        }
            
            $this->template->dberror="";
            
            $config = array
            (
                'benchmark'     => FALSE,
                'persistent'    => FALSE,
                'connection'    => array
                (
                    'type'     => 'mysql',
                    'user'     => 'bla',
                    'pass'     => '<PASSWORD>',
                    'host'     => 'jo',
                    'port'     => FALSE,
                    'socket'   => FALSE,
                    'database' => 'test'
                ),
                'character_set' => 'utf8',
                'table_prefix'  => '<?php echo $table_prefix ?>',
                'object'        => TRUE,
                'cache'         => TRUE,
                'escape'        => TRUE
            );
            
            try
            {
                $this->check_mysql($dbhost, $dbdatabase, $dbuser, $dbpass);
                
                echo "db ok";
                // weiter gehts, alles ok
            } 
            catch (Exception $e)
            {
                echo "db not ok";
                $this->template->dberror =$e->getMessage();
            }

    }
    
    
    private function check_mysql($host, $database, $username, $password) {
                $link = @mysql_connect($host, $username, $password);
                if(!$link) {
                        $error = '';
                        
                        if(strpos(mysql_error(), 'Access denied') !== false) {
                                $error = 'wrong username or password';
                        } elseif(strpos(mysql_error(), 'server host') !== false) {
                                $error = 'unknown host: '.$host;
                        } elseif(strpos(mysql_error(), 'connect to') !== false) {
                                $error = 'Can\'t connect to host: '.$host;
                        }else {
                                $error = mysql_error();
                        }
                        
                        throw new Exception($error);
                        return $error;
                }
                
                $select = mysql_select_db($database, $link);
                if (!$select) {
                    throw new Exception(mysql_error());
                        return mysql_error();
                }
                
                return true;
        }

}


<commit_msg>refactoring<commit_after><?php defined('SYSPATH') OR die('No direct access allowed.');
/**
 * S7Ncms - www.s7n.de
 *
 * Copyright (c) 2007-2009, <NAME> <eduard at baun.de>
 * All rights reserved.
 *
 * See license.txt for full text and disclaimer
 *
 * @author <NAME> <eduard at baun.de>
 * @copyright <NAME>, 2007-2009
 * @version $Id$
 */
class Install_Controller extends Template_Controller {

	public function index()
	{
		// TODO check
	}
	
	public function step_database()
	{
		$dbuser='';
		$dbpass='';
		$dbhost='';
		$dbdatabase='';

		if($_POST)
		{
			$dbuser=$_POST['dbuser'];
			$dbpass=$_POST['dbpass'];
			$dbhost=$_POST['dbhost'];
			$dbdatabase= $_POST['dbdatabase'];
		}
			
		$this->template->dberror="";
		
		try
		{
			$this->check_mysql($dbhost, $dbdatabase, $dbuser, $dbpass);
			
			echo "db ok";
			// weiter gehts, alles ok
		} 
		catch (Exception $e)
		{
			echo "db not ok";
			$this->template->dberror =$e->getMessage();
		}
	}
	
	
	private function check_mysql($host, $database, $username, $password) {
		$link = @mysql_connect($host, $username, $password);
		if(!$link) {
				$error = '';
				
				if(strpos(mysql_error(), 'Access denied') !== false) {
						$error = 'wrong username or password';
				} elseif(strpos(mysql_error(), 'server host') !== false) {
						$error = 'unknown host: '.$host;
				} elseif(strpos(mysql_error(), 'connect to') !== false) {
						$error = 'Can\'t connect to host: '.$host;
				}else {
						$error = mysql_error();
				}
				
				throw new Exception($error);
				return $error;
		}
		
		$select = mysql_select_db($database, $link);
		if (!$select) {
			throw new Exception(mysql_error());
				return mysql_error();
		}
		
		return true;
	}

}
{'fraction_non_alphanumeric': 0.1482008538320797, 'fraction_numerical': 0.007521854035373044, 'mean_word_length': 1.4514200298953661, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2862946', 'n_tokens_mistral': 1581, 'n_tokens_neox': 1393, 'n_words': 309}