<commit_before><?php

namespace App\Console\Commands\Database;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class RefreshProceduresCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'hms:database:refresh-procedures';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Drop and recreate all database procedures';

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

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $pdo = DB::getPdo();
        $databaseName = DB::getDatabaseName();
        $databaseUsername = DB::getConfig('username');
        $hostname = gethostname();
        if ($hostname == 'hmsdev') {
            $hostname = '%';
        }

        $proceduresDirectory = config('hms.procedures_directory');
        $this->info("Creating procedures form {$proceduresDirectory}");

        $procedureSqlFiles = preg_grep('~\.sql$~', scandir($proceduresDirectory));

        foreach ($procedureSqlFiles as $procedureFile) {
            $this->info('Creating procedures: ' . $procedureFile);
            $sql = file_get_contents($proceduresDirectory . DIRECTORY_SEPARATOR . $procedureFile);

            $sql = str_replace('DELIMITER //', '', $sql);
            $sql = str_replace(" //\nDELIMITER ;", '', $sql);

            $pdo->exec($sql);

            $spname = basename($procedureFile, ".sql");
            if (substr($spname, 0, 3) == "fn_") {
              $query = "GRANT EXECUTE ON FUNCTION $spname TO '$databaseUsername'@'$hostname'";
            } else {
              $query = "GRANT EXECUTE ON PROCEDURE $spname TO '$databaseUsername'@'$hostname'";
            }

            DB::unprepared($query);
        }
    }
}<commit_msg>StyleCI<commit_after><?php

namespace App\Console\Commands\Database;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;

class RefreshProceduresCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'hms:database:refresh-procedures';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Drop and recreate all database procedures';

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

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $pdo = DB::getPdo();
        $databaseName = DB::getDatabaseName();
        $databaseUsername = DB::getConfig('username');
        $hostname = gethostname();
        if ($hostname == 'hmsdev') {
            $hostname = '%';
        }

        $proceduresDirectory = config('hms.procedures_directory');
        $this->info("Creating procedures form {$proceduresDirectory}");

        $procedureSqlFiles = preg_grep('~\.sql$~', scandir($proceduresDirectory));

        foreach ($procedureSqlFiles as $procedureFile) {
            $this->info('Creating procedures: ' . $procedureFile);
            $sql = file_get_contents($proceduresDirectory . DIRECTORY_SEPARATOR . $procedureFile);

            $sql = str_replace('DELIMITER //', '', $sql);
            $sql = str_replace(" //\nDELIMITER ;", '', $sql);

            $pdo->exec($sql);

            $spname = basename($procedureFile, '.sql');
            if (substr($spname, 0, 3) == 'fn_') {
                $query = "GRANT EXECUTE ON FUNCTION $spname TO '$databaseUsername'@'$hostname'";
            } else {
                $query = "GRANT EXECUTE ON PROCEDURE $spname TO '$databaseUsername'@'$hostname'";
            }

            DB::unprepared($query);
        }
    }
}
{'fraction_non_alphanumeric': 0.14022874191944307, 'fraction_numerical': 0.000994530084535057, 'mean_word_length': 2.252223120452708, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '4906565', 'n_tokens_mistral': 1176, 'n_tokens_neox': 1148, 'n_words': 248}