<commit_before><?php

class ExportDRCsvTask extends sfBaseTask
{

    protected function configure()
    {
        // // add your own arguments here
        $this->addArguments(array(
            new sfCommandArgument('ids', sfCommandArgument::IS_ARRAY, 'ID Document'),
        ));

        $this->addOptions(array(
            new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name', 'civa'),
            new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
            new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'default'),
        ));

        $this->namespace = 'export';
        $this->name = 'dr-csv';
        $this->briefDescription = '';
        $this->detailedDescription = <<<EOF
The [maintenance:DRVT|INFO] task does things.
Call it with:

  [php symfony maintenance:DRVT|INFO]
EOF;
    }

    protected function execute($arguments = array(), $options = array())
    {
        $databaseManager = new sfDatabaseManager($this->configuration);
        $connection = $databaseManager->getDatabase($options['connection'])->getConnection();

        foreach(file("php://stdin") as $id) {
            $arguments['ids'][] = trim($id);
        }

        foreach ($arguments['ids'] as $id) {
            $dr = DRClient::getInstance()->find($id, acCouchdbClient::HYDRATE_JSON);
            
            if(!$dr) {

                throw new sfCommandArgumentsException("DR non trouvé : '".$id."'");
            }

            $file = sprintf("%s/%s/%s/DR_%s_%s_%s.csv", sfConfig::get('sf_data_dir'), "export/dr/csv", $dr->campagne, $dr->cvi, $dr->campagne, $dr->_rev);

            if(is_file($file)) {

                echo file_get_contents($file);<commit_msg>Creation du dossier si il n'existe pas<commit_after><?php

class ExportDRCsvTask extends sfBaseTask
{

    protected function configure()
    {
        // // add your own arguments here
        $this->addArguments(array(
            new sfCommandArgument('ids', sfCommandArgument::IS_ARRAY, 'ID Document'),
        ));

        $this->addOptions(array(
            new sfCommandOption('application', null, sfCommandOption::PARAMETER_REQUIRED, 'The application name', 'civa'),
            new sfCommandOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev'),
            new sfCommandOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'default'),
        ));

        $this->namespace = 'export';
        $this->name = 'dr-csv';
        $this->briefDescription = '';
        $this->detailedDescription = <<<EOF
The [maintenance:DRVT|INFO] task does things.
Call it with:

  [php symfony maintenance:DRVT|INFO]
EOF;
    }

    protected function execute($arguments = array(), $options = array())
    {
        $databaseManager = new sfDatabaseManager($this->configuration);
        $connection = $databaseManager->getDatabase($options['connection'])->getConnection();

        foreach(file("php://stdin") as $id) {
            $arguments['ids'][] = trim($id);
        }

        foreach ($arguments['ids'] as $id) {
            $dr = DRClient::getInstance()->find($id, acCouchdbClient::HYDRATE_JSON);

            if(!$dr) {

                throw new sfCommandArgumentsException("DR non trouvé : '".$id."'");
            }

            $csvPath = sfConfig::get('sf_data_dir')."/export/dr/csv/".$dr->campagne;
            if(!is_dir($csvPath)) {
                mkdir($csvPath);
            }

            $file = sprintf("%s/DR_%s_%s_%s.csv", $csvPath, $dr->cvi, $dr->campagne, $dr->_rev);

            if(is_file($file)) {

                echo file_get_contents($file);
{'fraction_non_alphanumeric': 0.1563335114911812, 'fraction_numerical': 0.0, 'mean_word_length': 2.761809045226131, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 31, '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': '819518', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1062, 'n_words': 213}