if (is_writable($config_dir)) { file_put_contents($config_dir . DIRECTORY_SEPARATOR . 'connect.json', json_encode(['user' => $con->user, 'password' => $con->password, 'database' => $con->user], JSON_PRETTY_PRINT)); } else { $resp->notify('Could not save database connection settings to file', 'Make sure that config/ is writable'); exit($resp); } } $con_json = \shgysk8zer0\Core\resources\Parser::parseFile('connect.json'); $database = "`{$pdo->escape($con_json->database)}`"; $pdo->query("CREATE DATABASE IF NOT EXISTS {$database}"); $created = $pdo->prepare("GRANT ALL ON {$database}.*\n\t\t\t\t\t\t\tTO :user@'localhost'\n\t\t\t\t\t\t\tIDENTIFIED BY :password;")->bind(['user' => $con_json->user, 'password' => $con_json->password])->execute(); unset($DB); $DB = new \shgysk8zer0\Core\PDO('connect.json'); if ($DB->connected and $created) { if (file_exists(BASE . '/default.sql')) { if ($DB->restore('default')) { $DB->prepare("INSERT INTO `head` (`name`, `value`)\n\t\t\t\t\t\t\t\t\t\tVALUES (:name, :value);"); foreach (['title', 'keywords', 'description', 'robots', 'viewport', 'charset', 'author', 'author_g_plus', 'publisher', 'google_analytics_code', 'rss'] as $prop) { if (isset($head->{$prop})) { $DB->bind(['name' => $prop, 'value' => $head->{$prop}])->execute(); } } $login = new \shgysk8zer0\Core\login($con_json); $login->createFrom(['user' => $site->user, 'password' => $site->password, 'role' => 'admin', 'g_plus' => isset($head->author_g_plus) ? $head->author_g_plus : null, 'name' => $head->author]); $resp->notify('All done! Congratulations!', 'Everything is setup and ready to go!')->reload(); exit($resp); } else { /** * Unable to restore from default.sql */ $resp->notify('We have a problem :(', 'The default database file is invalid. Do a "git pull" and try again. If that still doesn\'t work, file a bug');