<commit_before><?php
/**
 * here application
 *
 * @package   here
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright (C) 2016-2019 <NAME>
 * @license   MIT License
 * @link      https://github.com/lsalio/here
 */
namespace Here\Admin\Controller;

use Here\Admin\Library\Mvc\Controller\AbstractController;
use Here\Provider\Administrator\Administrator;
use Phalcon\Http\ResponseInterface;
use Throwable;


/**
 * Class SetupController
 * @package Here\Admin\Controller
 */
final class SetupController extends AbstractController {

    /**
     * Sets the title of the setup-wizard
     *
     * @return ResponseInterface|void
     */
    final public function initialize() {
        parent::initialize();

        if (container('administrator')->exists()) {
            return $this->response->redirect(['for' => 'explore']);
        }
    }

    /**
     * Setups the administrator
     */
    final public function indexAction() {
        $this->tag::setTitle($this->translator->_('setup_wizard'));
        if (container('environment', 'production')) {
            $this->view->cache(['key' => 'setup-wizard']);
        }
    }

    /**
     * Completed the administrator register
     */
    final public function completeAction() {
        $this->tag::setTitle($this->translator->_('setup_complete'));
        if (!$this->security->checkToken()) {
            return $this->response->redirect(['for' => 'setup-wizard']);
        }

        try {
            /** @var Administrator $administrator */
            $administrator = container('administrator');

            $username = $this->request->getPost('username', 'trim');
            $password = $this->request->getPost('password', 'trim');
            $email = $this->request->getPost('email', 'trim');
            $author = $administrator->create($username, $password, $email);

            return $this->response->redirect(['for' => 'explorer']);
        } catch (Throwable $e) {
            $this->view->setVar('error_message', $e->getMessage());
        }
    }

}<commit_msg>add transaction and fix redirect error<commit_after><?php
/**
 * here application
 *
 * @package   here
 * @author    <NAME> <<EMAIL>>
 * @copyright Copyright (C) 2016-2019 <NAME>
 * @license   MIT License
 * @link      https://github.com/lsalio/here
 */
namespace Here\Admin\Controller;

use Here\Admin\Library\Mvc\Controller\AbstractController;
use Here\Provider\Administrator\Administrator;
use Phalcon\Http\ResponseInterface;
use Throwable;


/**
 * Class SetupController
 * @package Here\Admin\Controller
 */
final class SetupController extends AbstractController {

    /**
     * Sets the title of the setup-wizard
     *
     * @return ResponseInterface|void
     */
    final public function initialize() {
        parent::initialize();

        if (container('administrator')->exists()) {
            return $this->response->redirect(['for' => 'explore']);
        }
    }

    /**
     * Setups the administrator
     */
    final public function indexAction() {
        $this->tag::setTitle($this->translator->_('setup_wizard'));
        if (container('environment', 'production')) {
            $this->view->cache(['key' => 'setup-wizard']);
        }
    }

    /**
     * Completed the administrator register
     */
    final public function completeAction() {
        $this->tag::setTitle($this->translator->_('setup_complete'));
        if (!$this->security->checkToken()) {
            return $this->response->redirect(['for' => 'setup-wizard']);
        }

        try {
            $this->db->begin();
            /** @var Administrator $administrator */
            $administrator = container('administrator');

            $username = $this->request->getPost('username', 'trim');
            $password = $this->request->getPost('password', 'trim');
            $email = $this->request->getPost('email', 'trim');
            $author = $administrator->create($username, $password, $email);

            $this->db->commit();
            return $this->response->redirect(['for' => 'explore']);
        } catch (Throwable $e) {
            $this->db->rollback();
            $this->view->setVar('error_message', $e->getMessage());
        }
    }

}
{'fraction_non_alphanumeric': 0.166270783847981, 'fraction_numerical': 0.003800475059382423, 'mean_word_length': 2.5899403239556693, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 79, 'https://': 2, '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': '3218013', 'n_tokens_mistral': 1160, 'n_tokens_neox': 1126, 'n_words': 226}