<commit_before><?php
/**
 * InstallController
 * Note that the InstallController inherits from Controller instead of
 * AppController. AppController brings in dependencies on the currently
 * non-existing database.
 *
 * @uses Controller
 * @package   CTLT.iPeer
 * @author    <NAME> <<EMAIL>>
 * @copyright 2012 All rights reserved.
 * @license   MIT {@link http://www.opensource.org/licenses/MIT}
 */
class InstallController extends Controller
{
    public $uses         = array(
        'InstallValidationStep3',
        'InstallValidationStep4'
    );
    public $components   = array(
        'Session',
        'installHelper',
    );
    public $helpers = array('Session', 'Html', 'Js');
    public $layout = 'installer';


    /**
     * __construct
     *
     *
     * @access protected
     * @return void
     */
    function __construct()
    {
        $this->set('title_for_layout', __('Installation Wizard', true));
        parent::__construct();
    }

    /**
     * Check prereqs for installing iPeer
     * */
    function index()
    {
        if (file_exists(CONFIGS.'installed.txt')) {
            $this->Session->setFlash(__('WARNING: It looks like you already have a instance running. Reinstalling will remove all your current data. Remove app/config/installed.txt to proceed.', true));
        }
    }

    /**
     * install2
     * Ask the user if they agree to the GPL license.
     *
     *
     * @access public
     * @return void
     */
    function install2()
    {
    }


    /**
     * install3
     * Ask the user for how to access the database
     *
     *
     * @access public
     * @return void
     */
    function install3()
    {
        if ($this->data['InstallValidationStep3']['data_setup_option'] == 'C') {
            $this->redirect(array('controller' => 'upgrade'));
            return;
        }

        if (!is_writable(CONFIGS.'database.php')) {
            $this->Session->setFlash(__('Cannot write to the database configuration file. Please change the permission on '.CONFIGS.'/database.php so that it is writable.', true));
        }


        if ($this->data) {
            // we have data submitted
            $this->InstallValidationStep3->set($this->data);
            if (!$this->InstallValidationStep3->validates()) {
                // fails validation
                $this->Session->setFlash(__('Please fill in all fields.', true));
                return;
            }

            // Try to configure the database, configureDatabase() will setFlash
            // with error msg so don't need to do it again
            $ret = $this->configureDatabase();
            if ($ret) {
                // Failed to configure database
                $this->Session->setFlash(__('Database config failed - '.$ret, true));
                return;
            }

            // Success
            $this->redirect(array('action' => 'install4'));
        }
    }


    /**
     * iPeer configuration page, enter the administrator user's name, password,
     * email, site info, etc.
     * */
    function install4()
    {
        if (!is_writable(CONFIGS)) {
            $this->Session->setFlash(__('Cannot write to the configuration directory. Please change the permission on '.CONFIGS.' so that it is writable.', true));
            return;
        }

        if (!file_exists(CONFIGS.'guard.php')) {
            if (!copy(APP.DS.'plugins'.DS.'guard'.DS.'config'.DS.'guard.php', CONFIGS.'guard.php')) {
                $this->Session->setFlash(__('Cannot copy the guard configuration (gurad.php) to the configuration directory.', true));
                return;
            }
        }

        if ($this->data) {
            // we have data submitted

            $this->InstallValidationStep4->set($this->data);
            if (!$this->InstallValidationStep4->validates()) {
                // fails validation
                $this->Session->setFlash(__('Please fill in all fields.', true));
                return;
            }

            // validation successful
            $this->createSuperAdmin(
                $this->data['InstallValidationStep4']['super_admin'],
                $this->data['InstallValidationStep4']['password'],
                $this->data['InstallValidationStep4']['admin_email']
            );

            //update parameters
            $sysparams = array(
                'SysParameter' => array(
                    'system.super_admin' => $this->data['InstallValidationStep4']['super_admin'],
                    'system.admin_email' => $this->data['InstallValidationStep4']['admin_email'],
                    'email.host' => $this->data['InstallValidationStep4']['email_host'],
                    'email.port' => $this->data['InstallValidationStep4']['email_port'],
                    'email.username' => $this->data['InstallValidationStep4']['email_username'],
                    'email.password' => $this->data['InstallValidationStep4']['email_password'],
                )
            );
            $this->installHelper->updateSystemParameters($sysparams);
            // mark this instance as installed
            $f = fopen(CONFIGS.'installed.txt', 'w');
            if (!$f) {
                $this->Session->setFlash(__('Installation failed, unable to write to '. CONFIGS .' dir', true));
                $this->redirect(array('action' => 'install4'));
                return;
            }
            fclose($f);

            // congratulate the user for a successful install
            $this->redirect(array('action' => 'install5'));
        } else {
            // Try to patch the database if needed, note that this database patching
            // is only for small changes, not for large version changes
            $ret = $this->patchDB();
            if ($ret) {
                $this->Session->setFlash(__('Database patching failed - '.$ret, true));
                $this->redirect(array('action' => 'install3'));
                return;
            }
        }
    }

    /**
     * install5
     * Installation done page
     *
     * @access public
     * @return void
     */<commit_msg>fixed missing function issue when installing<commit_after><?php
/**
 * InstallController
 * Note that the InstallController inherits from Controller instead of
 * AppController. AppController brings in dependencies on the currently
 * non-existing database.
 *
 * @uses Controller
 * @package   CTLT.iPeer
 * @author    <NAME> <<EMAIL>>
 * @copyright 2012 All rights reserved.
 * @license   MIT {@link http://www.opensource.org/licenses/MIT}
 */
class InstallController extends Controller
{
    public $uses         = array(
        'InstallValidationStep3',
        'InstallValidationStep4'
    );
    public $components   = array(
        'Session',
        'installHelper',
    );
    public $helpers = array('Session', 'Html', 'Js');
    public $layout = 'installer';


    /**
     * __construct
     *
     *
     * @access protected
     * @return void
     */
    function __construct()
    {
        $this->set('title_for_layout', __('Installation Wizard', true));
        parent::__construct();
    }

    /**
     * Check prereqs for installing iPeer
     * */
    function index()
    {
        if (file_exists(CONFIGS.'installed.txt')) {
            $this->Session->setFlash(__('WARNING: It looks like you already have a instance running. Reinstalling will remove all your current data. Remove app/config/installed.txt to proceed.', true));
        }
    }

    /**
     * install2
     * Ask the user if they agree to the GPL license.
     *
     *
     * @access public
     * @return void
     */
    function install2()
    {
    }


    /**
     * install3
     * Ask the user for how to access the database
     *
     *
     * @access public
     * @return void
     */
    function install3()
    {
        if ($this->data['InstallValidationStep3']['data_setup_option'] == 'C') {
            $this->redirect(array('controller' => 'upgrade'));
            return;
        }

        if (!is_writable(CONFIGS.'database.php')) {
            $this->Session->setFlash(__('Cannot write to the database configuration file. Please change the permission on '.CONFIGS.'/database.php so that it is writable.', true));
        }


        if ($this->data) {
            // we have data submitted
            $this->InstallValidationStep3->set($this->data);
            if (!$this->InstallValidationStep3->validates()) {
                // fails validation
                $this->Session->setFlash(__('Please fill in all fields.', true));
                return;
            }

            // Try to configure the database, configureDatabase() will setFlash
            // with error msg so don't need to do it again
            $ret = $this->configureDatabase();
            if ($ret) {
                // Failed to configure database
                $this->Session->setFlash(__('Database config failed - '.$ret, true));
                return;
            }

            // Success
            $this->redirect(array('action' => 'install4'));
        }
    }


    /**
     * iPeer configuration page, enter the administrator user's name, password,
     * email, site info, etc.
     * */
    function install4()
    {
        if (!is_writable(CONFIGS)) {
            $this->Session->setFlash(__('Cannot write to the configuration directory. Please change the permission on '.CONFIGS.' so that it is writable.', true));
            return;
        }

        if (!file_exists(CONFIGS.'guard.php')) {
            if (!copy(APP.DS.'plugins'.DS.'guard'.DS.'config'.DS.'guard.php', CONFIGS.'guard.php')) {
                $this->Session->setFlash(__('Cannot copy the guard configuration (gurad.php) to the configuration directory.', true));
                return;
            }
        }

        if ($this->data) {
            // we have data submitted

            $this->InstallValidationStep4->set($this->data);
            if (!$this->InstallValidationStep4->validates()) {
                // fails validation
                $this->Session->setFlash(__('Please fill in all fields.', true));
                return;
            }

            // validation successful
            $this->createSuperAdmin(
                $this->data['InstallValidationStep4']['super_admin'],
                $this->data['InstallValidationStep4']['password'],
                $this->data['InstallValidationStep4']['admin_email']
            );

            //update parameters
            $sysparams = array(
                'SysParameter' => array(
                    'system.super_admin' => $this->data['InstallValidationStep4']['super_admin'],
                    'system.admin_email' => $this->data['InstallValidationStep4']['admin_email'],
                    'email.host' => $this->data['InstallValidationStep4']['email_host'],
                    'email.port' => $this->data['InstallValidationStep4']['email_port'],
                    'email.username' => $this->data['InstallValidationStep4']['email_username'],
                    'email.password' => $this->data['InstallValidationStep4']['email_password'],
                )
            );
            $this->installHelper->updateSystemParameters($sysparams);
            // mark this instance as installed
            $f = fopen(CONFIGS.'installed.txt', 'w');
            if (!$f) {
                $this->Session->setFlash(__('Installation failed, unable to write to '. CONFIGS .' dir', true));
                $this->redirect(array('action' => 'install4'));
                return;
            }
            fclose($f);

            // congratulate the user for a successful install
            $this->redirect(array('action' => 'install5'));
        } /*else {
            // Try to patch the database if needed, note that this database patching
            // is only for small changes, not for large version changes
            $ret = $this->patchDB();
            if ($ret) {
                $this->Session->setFlash(__('Database patching failed - '.$ret, true));
                $this->redirect(array('action' => 'install3'));
                return;
            }
        }*/
    }

    /**
     * install5
     * Installation done page
     *
     * @access public
     * @return void
     */
{'fraction_non_alphanumeric': 0.13472346664494583, 'fraction_numerical': 0.004887187423637696, 'mean_word_length': 1.8767572633552014, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 135, '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': '3296774', 'n_tokens_mistral': 3199, 'n_tokens_neox': 3057, 'n_words': 777}