<commit_before><?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class SetupElasticsearch extends Command
{
  /**
   * The name and signature of the console command.
   *
   * @var string
   */
  protected $signature = 'es:setup';

  /**
   * The console command description.
   *
   * @var string
   */
  protected $description = 'Create Elasticsearch index and types with proper mapping for specified locale.';

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

  /**
   * Execute the console command.
   *
   * @return mixed
   */
  public function handle()
  {
    $BASE_PATH = "app/Console/Commands/SetupElasticsearch";

    $client = new \GuzzleHttp\Client(['http_errors' => false]);

    $host = 'localhost:9200';
    $hosts = config('elasticsearch.hosts');
    if (!empty($hosts)) {
      $host = reset($hosts);
      $this->comment('Your ES host is: ' . $host);
    }

    // get available locales based on directory names
    $available_locales = array_map('basename', glob($BASE_PATH ."/*", GLOB_ONLYDIR));

    // let user select from available locales
    $locale_options = array_merge(['all'], $available_locales);
    $selected_locale = $this->choice('Which locale(s) do you want to set up?', $locale_options, 0);

    if ($selected_locale == 'all') {
      foreach ($available_locales as $key => $locale) {
        $this->setup_for_locale($client, $host, $BASE_PATH, $locale);  
      }
    }
    else {
      $this->setup_for_locale($client, $host, $BASE_PATH, $selected_locale);
    }
<commit_msg>WEBUMENIA-464 check for missing ES setup configurations for enabled translatable locales<commit_after><?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class SetupElasticsearch extends Command
{
  /**
   * The name and signature of the console command.
   *
   * @var string
   */
  protected $signature = 'es:setup';

  /**
   * The console command description.
   *
   * @var string
   */
  protected $description = 'Create Elasticsearch index and types with proper mapping for specified locale.';

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

  /**
   * Execute the console command.
   *
   * @return mixed
   */
  public function handle()
  {
    $BASE_PATH = "app/Console/Commands/SetupElasticsearch";

    $client = new \GuzzleHttp\Client(['http_errors' => false]);

    $host = 'localhost:9200';
    $hosts = config('elasticsearch.hosts');
    if (!empty($hosts)) {
      $host = reset($hosts);
      $this->comment('Your ES host is: ' . $host);
    }

    // get available locales based on directory names
    $available_es_locales = array_map('basename', glob($BASE_PATH ."/*", GLOB_ONLYDIR));

    $missing_es_locales = array_diff(config('translatable.locales'), $available_es_locales);
    // dd($missing_es_locales);

    // check if we have defined ES schema for every enabled locale for translatable models
    if (!empty($missing_es_locales)) {
      $this->error('ES setup configuration is missing for the following localizations: [' . implode(', ', $missing_es_locales). ']');
      $this->error('Please add ES setup configuration or disable them in the application');

      return;
    }

    // let user select from available locales
    $locale_options = array_merge(['all'], $available_es_locales);
    $selected_locale = $this->choice('Which locale(s) do you want to set up?', $locale_options, 0);

    if ($selected_locale == 'all') {
      foreach ($available_es_locales as $key => $locale) {
        $this->setup_for_locale($client, $host, $BASE_PATH, $locale);
      }
    }
    else {
      $this->setup_for_locale($client, $host, $BASE_PATH, $selected_locale);
    }

{'fraction_non_alphanumeric': 0.13527575442247658, 'fraction_numerical': 0.0033818938605619147, 'mean_word_length': 3.2252747252747254, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '2639430', 'n_tokens_mistral': 1175, 'n_tokens_neox': 1156, 'n_words': 309}