<commit_before><?php

namespace Application\Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\ORM\Query;

/**
 * Auto-generated Migration: Please modify to your needs!
 */
class Version20150430100623 extends AbstractMigration
{
    /**
     * @param Schema $schema
     */
    public function up(Schema $schema)
    {
        $conn = $this->connection;

        $groupNames = [
            'Admins' => ['role' => 'ROLE_ADMIN'],
            'Models' => ['role' => 'ROLE_MODEL'],
            'Clients' => ['role' => 'ROLE_CLIENT'],
        ];

        foreach ($groupNames as $groupName => $data) {
            // Check if the groups exist
            $statement = $conn->prepare('SELECT COUNT(*) cnt FROM groups WHERE name LIKE :group_name');
            $statement->execute([':group_name' => $groupName]);
            $res = $statement->fetch(Query::HYDRATE_SINGLE_SCALAR);
            $count = (int) $res[0];

            if ($count == 0) {
                $this->addSql("INSERT INTO `groups` (`name`, `roles`, `date_added`, `date_updated`) VALUES "
                        . "(:name, :role,	'2015-03-27 10:24:49', NULL)", [
                    ':name' => $groupName,
                    ':role' => "a:1:{i:0;s:10:\"" . $data['role'] . "\";}"
                ]);
            }
        }

        // Check if the admin exists
        $res = $conn->query('SELECT COUNT(*) cnt FROM users WHERE username_canonical LIKE \'admin\'')->fetch(Query::HYDRATE_SINGLE_SCALAR);
        $adminCount = (int) $res[0];

        if ($adminCount == 0) {
            // Add admin user
            $this->addSql(
                "INSERT INTO `users` "
                    . "(`thumbnail_id`, `username`, `username_canonical`, `email`, `email_canonical`, `enabled`, "
                    . "`salt`, `password`, `last_login`, `locked`, `expired`, `expires_at`, `confirmation_token`, "
                    . "`password_requested_at`, `roles`, `credentials_expired`, `credentials_expire_at`, `firstname`, `lastname`, "
                    . "`date_of_birth`, `facebook_id`, `vkontakte_id`, `twitter_id`, `google_id`, `github_id`, "
                    . "`date_added`, `date_updated`, `sort_order`, `created_at`, `updated_at`, `website`, `biography`, "
                    . "`gender`, `locale`, `timezone`, `phone`, `facebook_uid`, `facebook_name`, `facebook_data`, "
                    . "`twitter_uid`, `twitter_name`, `twitter_data`, `gplus_uid`, `gplus_name`, `gplus_data`, `token`, "
                    . "`two_step_code`, `facebook_url`, `instagram_url`, `instagram_id`, `activated`, `activation_token`, "
                    . "`model_notified`, `last_visited_date`, `coins`, `is_online`) "
                . "VALUES "<commit_msg>Fix groups migration.<commit_after><?php

namespace Application\Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\ORM\Query;

/**
 * Auto-generated Migration: Please modify to your needs!
 */
class Version20150430100623 extends AbstractMigration
{
    /**
     * @param Schema $schema
     */
    public function up(Schema $schema)
    {
        $conn = $this->connection;

        $groupNames = [
            'Admins' => ['role' => 'ROLE_ADMIN'],
            'Models' => ['role' => 'ROLE_MODEL'],
            'Clients' => ['role' => 'ROLE_CLIENT'],
        ];

        foreach ($groupNames as $groupName => $data) {
            // Check if the groups exist
            $statement = $conn->prepare('SELECT COUNT(*) cnt FROM groups WHERE name LIKE :group_name');
            $statement->execute([':group_name' => $groupName]);
            $res = $statement->fetch(Query::HYDRATE_SINGLE_SCALAR);
            $count = (int) $res[0];

            if ($count == 0) {
                $this->addSql("INSERT INTO `groups` (`name`, `roles`, `date_added`, `date_updated`) VALUES "
                        . "(:name, :role,	'2015-03-27 10:24:49', NULL)", [
                    ':name' => $groupName,
                    ':role' => "a:1:{i:0;s:".strlen($data['role']).":\"" . $data['role'] . "\";}"
                ]);
            }
        }

        // Check if the admin exists
        $res = $conn->query('SELECT COUNT(*) cnt FROM users WHERE username_canonical LIKE \'admin\'')->fetch(Query::HYDRATE_SINGLE_SCALAR);
        $adminCount = (int) $res[0];

        if ($adminCount == 0) {
            // Add admin user
            $this->addSql(
                "INSERT INTO `users` "
                    . "(`thumbnail_id`, `username`, `username_canonical`, `email`, `email_canonical`, `enabled`, "
                    . "`salt`, `password`, `last_login`, `locked`, `expired`, `expires_at`, `confirmation_token`, "
                    . "`password_requested_at`, `roles`, `credentials_expired`, `credentials_expire_at`, `firstname`, `lastname`, "
                    . "`date_of_birth`, `facebook_id`, `vkontakte_id`, `twitter_id`, `google_id`, `github_id`, "
                    . "`date_added`, `date_updated`, `sort_order`, `created_at`, `updated_at`, `website`, `biography`, "
                    . "`gender`, `locale`, `timezone`, `phone`, `facebook_uid`, `facebook_name`, `facebook_data`, "
                    . "`twitter_uid`, `twitter_name`, `twitter_data`, `gplus_uid`, `gplus_name`, `gplus_data`, `token`, "
                    . "`two_step_code`, `facebook_url`, `instagram_url`, `instagram_id`, `activated`, `activation_token`, "
                    . "`model_notified`, `last_visited_date`, `coins`, `is_online`) "
                . "VALUES "
{'fraction_non_alphanumeric': 0.17428725121032812, 'fraction_numerical': 0.012551551013089475, 'mean_word_length': 2.312351543942993, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 39, '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': '5519160', 'n_tokens_mistral': 1783, 'n_tokens_neox': 1661, 'n_words': 346}