<commit_before><?php

namespace Rogue\Console\Commands;

use League\Csv\Reader;
use Rogue\Models\Action;
use Illuminate\Console\Command;

class ImportPrePostMetaDataActions extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'rogue:prepostmetadataactionsimport {path}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Imports backfill of actions for all posts pre post metadata in the given (link to a) CSV file.';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        // Make a local copy of the CSV
        $path = $this->argument('path');
        $this->line('rogue:prepostmetadataactionsimport: Loading in csv from ' . $path);

        $temp = tempnam(sys_get_temp_dir(), 'command_csv');
        file_put_contents($temp, fopen($this->argument('path'), 'r'));

        // Load the actions from the CSV
        $backfill_actions_csv = Reader::createFromPath($temp, 'r');
        $backfill_actions_csv->setHeaderOffset(0);
        $backfill_actions = iterator_to_array($backfill_actions_csv->getRecords());

        // Import each backfill action
        $this->line('rogue:prepostmetadataactionsimport: Loading in csv from ' . $path);

        foreach ($backfill_actions as $backfill_action) {
            // See if the action exists
            $existing_action = Action::where('campaign_id', $backfill_action['campaign_id'])->where('name', $backfill_action['action'])->first();

            // Create the action if there isn't one already
            if (! $existing_action) {
                $action = Action::forceCreate([
                    'name' => $backfill_action['action'],
                    'campaign_id' => $backfill_action['campaign_id'],
                    'post_type' => $backfill_action['type'],
                    'reportback' => $backfill_action['reportback'],
                    'civic_action' => $backfill_action['civic_action'],
                    'scholarship_entry' => $backfill_action['scholarship_entry'],
                    'active' => $backfill_action['active'],
                    'noun' => $backfill_action['noun'],
                    'verb' => $backfill_action['verb'],
                ]);

                $this->line('rogue:prepostmetadataactionsimport: Created action ' . $action->id);
            }
        }

        // Tell everyone we're done!
        $this->line('rogue:prepostmetadataactionsimport: ALL DONE!');
    }
}<commit_msg>uses create instead of forceCreate<commit_after><?php

namespace Rogue\Console\Commands;

use League\Csv\Reader;
use Rogue\Models\Action;
use Illuminate\Console\Command;

class ImportPrePostMetaDataActions extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'rogue:prepostmetadataactionsimport {path}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Imports backfill of actions for all posts pre post metadata in the given (link to a) CSV file.';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        // Make a local copy of the CSV
        $path = $this->argument('path');
        $this->line('rogue:prepostmetadataactionsimport: Loading in csv from ' . $path);

        $temp = tempnam(sys_get_temp_dir(), 'command_csv');
        file_put_contents($temp, fopen($this->argument('path'), 'r'));

        // Load the actions from the CSV
        $backfill_actions_csv = Reader::createFromPath($temp, 'r');
        $backfill_actions_csv->setHeaderOffset(0);
        $backfill_actions = iterator_to_array($backfill_actions_csv->getRecords());

        // Import each backfill action
        $this->line('rogue:prepostmetadataactionsimport: Loading in csv from ' . $path);

        foreach ($backfill_actions as $backfill_action) {
            // See if the action exists
            $existing_action = Action::where('campaign_id', $backfill_action['campaign_id'])->where('name', $backfill_action['action'])->first();

            // Create the action if there isn't one already
            if (! $existing_action) {
                $action = Action::create([
                    'name' => $backfill_action['action'],
                    'campaign_id' => $backfill_action['campaign_id'],
                    'post_type' => $backfill_action['type'],
                    'reportback' => $backfill_action['reportback'],
                    'civic_action' => $backfill_action['civic_action'],
                    'scholarship_entry' => $backfill_action['scholarship_entry'],
                    'active' => $backfill_action['active'],
                    'noun' => $backfill_action['noun'],
                    'verb' => $backfill_action['verb'],
                ]);

                $this->line('rogue:prepostmetadataactionsimport: Created action ' . $action->id);
            }
        }

        // Tell everyone we're done!
        $this->line('rogue:prepostmetadataactionsimport: ALL DONE!');
    }
}
{'fraction_non_alphanumeric': 0.1291020555355211, 'fraction_numerical': 0.0003606202668589975, 'mean_word_length': 2.3156007172743576, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, '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': '672084', 'n_tokens_mistral': 1567, 'n_tokens_neox': 1505, 'n_words': 344}