Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
Add db seeder
Browse files Browse the repository at this point in the history
  • Loading branch information
Akkadius committed Jan 6, 2019
1 parent 434e821 commit 35f3b50
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions cli/db-seed.php
@@ -0,0 +1,41 @@
<?php

/**
* Created by PhpStorm.
* User: cmiles
* Date: 6/9/18
* Time: 9:46 PM
*/
$origin_directory = getcwd();
$temporary_location = "/tmp/db_source/";

/**
* Download file
*/
$peq_dump = file_get_contents('http://edit.peqtgc.com/weekly/peq_beta.zip');
if (!file_exists($temporary_location)) {
mkdir($temporary_location);
file_put_contents($temporary_location . 'peq_beta.zip', $peq_dump);
}

/**
* Source database
*/
echo "Installing unzip, mysql-client if not installed...\n";
exec("apt-get update && apt-get -y install unzip mysql-client");
echo "Unzipping peq_beta.zip...\n";
exec("unzip -o {$temporary_location}peq_beta.zip -d {$temporary_location}");
echo "Creating database PEQ...\n";
exec('mysql -h mariadb -uroot -proot -e "CREATE DATABASE peq" 2>&1 | grep -v \'Warning\'');
echo "Sourcing data...\n";
chdir($temporary_location);
exec("mysql -h mariadb -uroot -proot peq < peqbeta.sql 2>&1 | grep -v 'Warning'");
exec("mysql -h mariadb -uroot -proot peq < player_tables.sql 2>&1 | grep -v 'Warning'");
chdir($origin_directory);
echo "Seeding complete!\n";

/**
* Unlink
*/
array_map('unlink', glob($temporary_location . "*.*"));
rmdir($temporary_location);

0 comments on commit 35f3b50

Please sign in to comment.