Skip to content

Commit 46b3b36

Browse files
committed
fixed instalation script
1 parent 2b1e121 commit 46b3b36

File tree

4 files changed

+416
-227
lines changed

4 files changed

+416
-227
lines changed

.env.example

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
DATABASE_URL=mysql://root:[email protected]:3306/crunchbutton
22
ENV=local
33
DEBUG=true
4-
DEBUG_PHONE=0000000000
4+
DEBUG_PHONE=0000000000
5+
ENCRYPTION_KEY=TWENTY_FOUR_CHARS_______

cli/install.php

+27-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,43 @@
11
<?php
22
// this script will run after a successfull heroku deployment
33

4-
echo "\nCreating db schema...";
4+
require_once __DIR__ . '/../vendor/autoload.php';
5+
6+
//require_once('vendor/arzynik/cana/src/Cana/Model.php');
7+
//require_once('vendor/arzynik/cana/src/Cana/Crypt.php');
8+
9+
echo "\nInstalling...";
10+
11+
$url = parse_url(getenv('DATABASE_URL') ?? getenv('JAWSDB_MARIA_URL'));
512

6-
$url = parse_url(getenv('JAWSDB_MARIA_URL'));
713
if (!$url) {
8-
echo "No JAWSDB_MARIA_URL";
14+
echo "\nNo DATABASE_URL or JAWSDB_MARIA_URL";
915
exit(0);
1016
}
1117
$type = $url['scheme'] == 'postgres' ? 'pgsql' : 'mysql';
18+
$options = null;
1219

1320
$db = new \PDO($type.':host='.$url['host'].($url['port'] ? ';port='.$url['port'] : '').';dbname='.substr($url['path'], 1), $url['user'], $url['pass'], $options);
1421
$db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
1522
$db->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
16-
$db->exec(file_get_contents('db/dump.sql'));
1723

24+
if ($argv[1] == '--force') {
25+
// drop all the tables and force install
26+
echo "\nCDroping existing tables...";
27+
28+
$query = "SELECT table_name FROM information_schema.tables WHERE table_schema = '".substr($url['path'], 1)."';";
29+
$exec = "SET FOREIGN_KEY_CHECKS = 0;\n";
30+
foreach ($db->query($query) as $row) {
31+
$exec .= 'DROP TABLE IF EXISTS `'.$row[0]."`;\n";
32+
}
33+
$exec .= "SET FOREIGN_KEY_CHECKS = 1;\n";
34+
$db->exec($exec);
35+
36+
echo "complete.";
37+
}
38+
39+
echo "\nCreating db schema...";
40+
$db->exec(file_get_contents('db/dump.sql'));
1841
echo "complete.\n";
1942

2043
echo "Running db migrate scripts...\n";
@@ -51,8 +74,6 @@
5174

5275
echo "Inserting dummy data...";
5376

54-
require_once('vendor/arzynik/cana/src/Cana/Model.php');
55-
require_once('vendor/arzynik/cana/src/Cana/Crypt.php');
5677
$crypt = new Cana_Crypt(getenv('ENCRYPTION_KEY'));
5778

5879
$sql = str_replace([

composer.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
"mrclay/minify": "^2.2",
1616
"lob/lob-php": "^1.4",
1717
"aws/aws-sdk-php": "^3.12",
18-
"vlucas/phpdotenv": "^2.4"
18+
"vlucas/phpdotenv": "^2.4",
19+
"phpseclib/mcrypt_compat": "dev-master"
1920
},
2021
"require-dev": {
2122
"satooshi/php-coveralls": "dev-master",
2223
"phpunit/phpunit": "^5.0"
2324
}
24-
}
25+
}

0 commit comments

Comments
 (0)