<commit_before><?php

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

namespace Sonata\PageBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\Output;

class MigrateToJsonTypeCommand extends BaseCommand
{
    public function configure()
    {
        $this->setName('sonata:page:migrate-block-json');
        $this->addOption('table', null, InputOption::VALUE_OPTIONAL, 'Block table', 'block');
        $this->setDescription('Migrate all block settings to the doctrine JsonType');
    }

    public function execute(InputInterface $input, OutputInterface $output)
    {
        $count = 0;
        $table = $input->getOption('table');
        $connection = $this->getContainer()->get('doctrine.orm.entity_manager')->getConnection();
        $blocks = $connection->fetchAll("SELECT * FROM $table");

        foreach($blocks as $block) {
            // if the row need to migrate
            if (0 !== strpos($block['settings'], '{') && $block['settings'] !== '[]') {
                $block['settings'] = json_encode(unserialize($block['settings']));
                $count++;
            }
            $connection->update($table, array('settings' => $block['settings']), array('id' => $block['id']));
        }

        $output->writeln("Migrated $count blocks");
    }
}
<commit_msg>sonata:page:migrate-block-json update only migrated data<commit_after><?php

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

namespace Sonata\PageBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\Output;

class MigrateToJsonTypeCommand extends BaseCommand
{
    public function configure()
    {
        $this->setName('sonata:page:migrate-block-json');
        $this->addOption('table', null, InputOption::VALUE_OPTIONAL, 'Block table', 'block');
        $this->setDescription('Migrate all block settings to the doctrine JsonType');
    }

    public function execute(InputInterface $input, OutputInterface $output)
    {
        $count = 0;
        $table = $input->getOption('table');
        $connection = $this->getContainer()->get('doctrine.orm.entity_manager')->getConnection();
        $blocks = $connection->fetchAll("SELECT * FROM $table");

        foreach($blocks as $block) {
            // if the row need to migrate
            if (0 !== strpos($block['settings'], '{') && $block['settings'] !== '[]') {
                $block['settings'] = json_encode(unserialize($block['settings']));
                $connection->update($table, array('settings' => $block['settings']), array('id' => $block['id']));
                $count++;
            }
        }

        $output->writeln("Migrated $count blocks");
    }
}

{'fraction_non_alphanumeric': 0.14757393051966694, 'fraction_numerical': 0.0011484352569623888, 'mean_word_length': 3.483912483912484, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 33, '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': '3293915', 'n_tokens_mistral': 967, 'n_tokens_neox': 955, 'n_words': 218}