Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add FuelPHP task * Remove undeeded files * Add DbConfig class for getting db params
- Loading branch information
Showing
13 changed files
with
84 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
class DbConfig | ||
{ | ||
private static $params = []; | ||
|
||
public static function get_params() | ||
{ | ||
if (static::$params !== []) { | ||
return static::$params; | ||
} | ||
|
||
\Config::load('db', true); | ||
$dsn = \Config::get('db.default.connection.dsn'); | ||
list($driver, $tmp) = explode(':', $dsn); | ||
list($hostStr, $dbnameStr) = explode(';', $tmp); | ||
list($tmp, $host) = explode('=', $hostStr); | ||
list($tmp, $dbname) = explode('=', $dbnameStr); | ||
$username = \Config::get('db.default.connection.username'); | ||
$password = \Config::get('db.default.connection.password'); | ||
|
||
static::$params = [ | ||
'host' => $host, | ||
'dbname' => $dbname, | ||
'username' => $username, | ||
'password' => $password, | ||
]; | ||
|
||
return static::$params; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Fuel\Tasks; | ||
|
||
class Setup | ||
{ | ||
public function propel2() | ||
{ | ||
passthru( | ||
'cd ' . APPPATH . '..; | ||
vendor/bin/propel config:convert' | ||
); | ||
} | ||
|
||
public function mysql() | ||
{ | ||
$db = \DbConfig::get_params(); | ||
$dbname = $db['dbname']; | ||
|
||
$scheme_sql = 'CREATE DATABASE IF NOT EXISTS `' . $dbname . '`;'; | ||
$scheme_sql .= 'DROP TABLE IF EXISTS `comment`;'; | ||
$scheme_sql .= 'DROP TABLE IF EXISTS `post`;'; | ||
$scheme_sql .= file_get_contents(APPPATH . '../../schema/php_dev.sql'); | ||
|
||
foreach (explode(';', $scheme_sql) as $sql) { | ||
if (preg_match('/^\n$/u', $sql)) { | ||
continue; | ||
} | ||
|
||
$result = \DB::query($sql)->execute(); | ||
if ($result) { | ||
\Cli::write(\Cli::color($sql, 'green')); | ||
} else { | ||
\Cli::error(\Cli::color($sql, 'red')); | ||
} | ||
} | ||
} | ||
} |