<commit_before><?php
/**
 * InstallHelperComponent
 *
 * @package   CTLT.iPeer
 * @author    <NAME> <<EMAIL>>
 * @copyright 2012 All rights reserved.
 * @license   MIT {@link http://www.opensource.org/licenses/MIT}
 */
class InstallHelperComponent
{
    /**
     * runInsertDataStructure
     *
     * @param mixed $dbConfig
     *
     * @access public
     * @return void
     */
    function runInsertDataStructure($dbConfig)
    {
        $basicSQLFile = CONFIGS . "sql/ipeer.sql";
        $samplesFile = CONFIGS . "sql/ipeer_samples_data.sql";

        //Install database with sample data
        $dataOption = $dbConfig['data_setup_option'];
        if ($dataOption == 'A') {
            //Install database with sample data structure
            $dbConfig['filename'] = $samplesFile;
            $runQuery = $this->dbSource($dbConfig);
        } else if ($dataOption == 'B') {
            //Install database with basic structure
            $dbConfig['filename'] = $basicSQLFile;
            $runQuery = $this->dbSource($dbConfig);
        } else {
            return "Invalid database data setup option.";
        }

        return $runQuery;
    }


    /**
     * Reads an SQL template file and executes the queries inside.
     *
     * @param array $dbConfig - login configuration for the mysql db and the sql
     * template filename
     *
     * @return false if everything executed successfully, an error message
     * otherwise.
     */
    function dbSource($dbConfig)
    {
        // Connect to the server
        var_dump($dbConfig);
        $mysql = mysql_connect($dbConfig['host'],
            $dbConfig['login'],
            $dbConfig['password']);
        if (!$mysql) {
            return('Could not connect: ' . mysql_error());
        }

        // Create the database if not exists
        $ret = mysql_query("CREATE DATABASE IF NOT EXISTS `".$dbConfig['database'].
            "` CHARACTER SET `utf8` COLLATE `utf8_general_ci`;", $mysql);
        if (!$ret) {
            return 'Error creating database: ' . mysql_error();
        }

        // Open the database
        $mysqldb = mysql_select_db($dbConfig['database']);
        if (!$mysqldb) {
            return 'Could not open the database: '. mysql_error();
        }

        // Read the SQL template file
        $template = file($dbConfig['filename'], FILE_SKIP_EMPTY_LINES);
        if (false === $template ) {
            return 'Unable to open SQL template "' . $dbConfig['filename'] . '"';
        }

        // Do the queries<commit_msg>Remove var_dump<commit_after><?php
/**
 * InstallHelperComponent
 *
 * @package   CTLT.iPeer
 * @author    <NAME> <<EMAIL>>
 * @copyright 2012 All rights reserved.
 * @license   MIT {@link http://www.opensource.org/licenses/MIT}
 */
class InstallHelperComponent
{
    /**
     * runInsertDataStructure
     *
     * @param mixed $dbConfig
     *
     * @access public
     * @return void
     */
    function runInsertDataStructure($dbConfig)
    {
        $basicSQLFile = CONFIGS . "sql/ipeer.sql";
        $samplesFile = CONFIGS . "sql/ipeer_samples_data.sql";

        //Install database with sample data
        $dataOption = $dbConfig['data_setup_option'];
        if ($dataOption == 'A') {
            //Install database with sample data structure
            $dbConfig['filename'] = $samplesFile;
            $runQuery = $this->dbSource($dbConfig);
        } else if ($dataOption == 'B') {
            //Install database with basic structure
            $dbConfig['filename'] = $basicSQLFile;
            $runQuery = $this->dbSource($dbConfig);
        } else {
            return "Invalid database data setup option.";
        }

        return $runQuery;
    }


    /**
     * Reads an SQL template file and executes the queries inside.
     *
     * @param array $dbConfig - login configuration for the mysql db and the sql
     * template filename
     *
     * @return false if everything executed successfully, an error message
     * otherwise.
     */
    function dbSource($dbConfig)
    {
        // Connect to the server
        $mysql = mysql_connect($dbConfig['host'],
            $dbConfig['login'],
            $dbConfig['password']);
        if (!$mysql) {
            return('Could not connect: ' . mysql_error());
        }

        // Create the database if not exists
        $ret = mysql_query("CREATE DATABASE IF NOT EXISTS `".$dbConfig['database'].
            "` CHARACTER SET `utf8` COLLATE `utf8_general_ci`;", $mysql);
        if (!$ret) {
            return 'Error creating database: ' . mysql_error();
        }

        // Open the database
        $mysqldb = mysql_select_db($dbConfig['database']);
        if (!$mysqldb) {
            return 'Could not open the database: '. mysql_error();
        }

        // Read the SQL template file
        $template = file($dbConfig['filename'], FILE_SKIP_EMPTY_LINES);
        if (false === $template ) {
            return 'Unable to open SQL template "' . $dbConfig['filename'] . '"';
        }

        // Do the queries
{'fraction_non_alphanumeric': 0.12507444907683143, 'fraction_numerical': 0.0023823704586063135, 'mean_word_length': 2.0813455657492357, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '4929934', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1366, 'n_words': 375}