<commit_before><?php
/*
 * This file is part of the CSBill package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CSBill\InstallBundle\Installer\Step;

use Symfony\Component\Process\Process;
use Symfony\Component\Yaml\Parser;
use Symfony\Component\Yaml\Dumper;
use Symfony\Component\Yaml\Exception\ParseException;

use CSBill\InstallBundle\Installer\Step;

class DatabaseConfig extends Step
{
    /**
     * The view to render for this installation step
     *
     * @param string $view;
     */
    public $view = 'CSBillInstallBundle:Install:database_config.html.twig';

    /**
     * The title to display when this installation step is active
     *
     * @var string $title
     */
    public $title = 'Database Configuration';

    /**
     * Array containing all the PDO drivers that is installed
     *
     * @var array $drivers
     */
    public $drivers;

    /**
     * The root directory of the application
     *
     * @var string
     */
    private $root_dir;

    /**
     * Array containing all the parameters for the database config
     *
     * @var array $params
     */
    public $params = array(	'database_driver' 	=> '',
                            'database_host' 	=> '',
                            'database_user' 	=> '',
                            'database_password' => '',
                            'database_port' 	=> 3306,
                            'database_name' 	=> '');

    /**
     * Validates that the databse exists, and we are able to connect to it
     *
     * @param  array   $request
     * @return boolean
     */
    public function validate(array $request)
    {
        if (empty($request['database_driver'])) {
            $this->addError('Please Choose a Database Driver');
        }

        if (empty($request['database_host'])) {
            $this->addError('Please enter the hostname of the database');
        }

        if (empty($request['database_user'])) {
            $this->addError('Please enter the user name of the database');
        }

        /*if (empty($request['database_password'])) {
            $this->addError('Please enter the password of the database');
        }*/

        if (empty($request['database_name'])) {
            $this->addError('Please enter the name of the database. Note: The database should already exist');
        }

        if (count($this->getErrors()) === 0) {
            $connectionFactory = $this->container->get('doctrine.dbal.connection_factory');
            $connection = $connectionFactory->createConnection(array(
                'driver' => $request['database_driver'],
                'user' => $request['database_user'],
                'password' => $request['database_password'],
                'host' => $request['database_host'],
                'dbname' => $request['database_name'],
            ));

            try {
                $connection->connect();
            } catch (\PDOException $e) {
                $this->addError($e->getMessage());
            }
        }

        return count($this->getErrors()) === 0;
    }

    /**
     * Writes the database configuration to the parameters.yml file, and runs all the database migrations and fixtures
     *
     * @param array $request
     */
    public function process(array $request)
    {
        $this->root_dir = $this->get('kernel')->getRootDir();

        $config = array_intersect_key($request, $this->params);

        $this->writeConfigFile($config);

        $this->executeMigrations();
    }

    /**
     * Checks the system to make sure it meets the minimum requirements
     *
     * @return void
     */
    public function start()
    {
        $this->drivers = \PDO::getAvailableDrivers();
    }

    /**
     * Writes all the configuration values to the paramaters file
     *
     * @param  array          $params
     * @throws ParseException
     * @return void;
     */
    public function writeConfigFile($params = array())
    {<commit_msg>[InstallBundle] Load data fixtures when installing<commit_after><?php
/*
 * This file is part of the CSBill package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CSBill\InstallBundle\Installer\Step;

use Symfony\Component\Process\Process;
use Symfony\Component\Yaml\Parser;
use Symfony\Component\Yaml\Dumper;
use Symfony\Component\Yaml\Exception\ParseException;

use CSBill\InstallBundle\Installer\Step;

class DatabaseConfig extends Step
{
    /**
     * The view to render for this installation step
     *
     * @param string $view;
     */
    public $view = 'CSBillInstallBundle:Install:database_config.html.twig';

    /**
     * The title to display when this installation step is active
     *
     * @var string $title
     */
    public $title = 'Database Configuration';

    /**
     * Array containing all the PDO drivers that is installed
     *
     * @var array $drivers
     */
    public $drivers;

    /**
     * The root directory of the application
     *
     * @var string
     */
    private $root_dir;

    /**
     * Array containing all the parameters for the database config
     *
     * @var array $params
     */
    public $params = array( 'database_driver'     => '',
                            'database_host'     => '',
                            'database_user'     => '',
                            'database_password' => '',
                            'database_port'     => 3306,
                            'database_name'     => '');

    /**
     * Validates that the databse exists, and we are able to connect to it
     *
     * @param  array   $request
     * @return boolean
     */
    public function validate(array $request)
    {
        if (empty($request['database_driver'])) {
            $this->addError('Please Choose a Database Driver');
        }

        if (empty($request['database_host'])) {
            $this->addError('Please enter the hostname of the database');
        }

        if (empty($request['database_user'])) {
            $this->addError('Please enter the user name of the database');
        }

        /*if (empty($request['database_password'])) {
            $this->addError('Please enter the password of the database');
        }*/

        if (empty($request['database_name'])) {
            $this->addError('Please enter the name of the database. Note: The database should already exist');
        }

        if (count($this->getErrors()) === 0) {
            $connectionFactory = $this->container->get('doctrine.dbal.connection_factory');
            $connection = $connectionFactory->createConnection(array(
                'driver' => $request['database_driver'],
                'user' => $request['database_user'],
                'password' => $request['database_password'],
                'host' => $request['database_host'],
                'dbname' => $request['database_name'],
            ));

            try {
                $connection->connect();
            } catch (\PDOException $e) {
                $this->addError($e->getMessage());
            }
        }

        return count($this->getErrors()) === 0;
    }

    /**
     * Writes the database configuration to the parameters.yml file, and runs all the database migrations and fixtures
     *
     * @param array $request
     */
    public function process(array $request)
    {
        $this->root_dir = $this->get('kernel')->getRootDir();

        $config = array_intersect_key($request, $this->params);

        $this->writeConfigFile($config);

        $this->executeMigrations();
        $this->executeFixtures();
    }

    /**
     * Checks the system to make sure it meets the minimum requirements
     *
     * @return void
     */
    public function start()
    {
        $this->drivers = \PDO::getAvailableDrivers();
    }

    /**
     * Writes all the configuration values to the paramaters file
     *
     * @param  array          $params
     * @throws ParseException
     * @return void;
     */
    public function writeConfigFile($params = array())
    {
{'fraction_non_alphanumeric': 0.12418142129517341, 'fraction_numerical': 0.0014552510308028135, 'mean_word_length': 2.046545991872922, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 72, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5524727', 'n_tokens_mistral': 2222, 'n_tokens_neox': 2163, 'n_words': 586}