You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
873 B
39 lines
873 B
<?php |
|
|
|
namespace app\commands; |
|
|
|
use yii\console\Controller; |
|
use SqlFormatter; |
|
|
|
/** |
|
* Hejiang Toolkit |
|
*/ |
|
class HjController extends Controller |
|
{ |
|
/** |
|
* Default command. |
|
*/ |
|
public function actionIndex() |
|
{ |
|
echo 'please specify a command you wanna run.'; |
|
} |
|
|
|
/** |
|
* Pack sql querys as upgrade script format. |
|
*/ |
|
public function actionFormatSql() |
|
{ |
|
$sql = stream_get_contents(fopen("php://stdin", "r")); |
|
$sql = SqlFormatter::compress($sql); |
|
$sqlList = SqlFormatter::splitQuery($sql); |
|
if(!$sqlList){ |
|
throw new \Exception('No SQL given'); |
|
} |
|
echo '{' . PHP_EOL; |
|
foreach($sqlList as $sql){ |
|
$sql = trim($sql); |
|
echo "\thj_pdo_run(\"$sql\");" . PHP_EOL; |
|
} |
|
echo '}' . PHP_EOL; |
|
} |
|
}
|
|
|