Skip to content

Commit

Permalink
Don't depend on Craft when importing DB
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Stark committed Nov 10, 2020
1 parent aa385fe commit aae5f17
Showing 1 changed file with 4 additions and 22 deletions.
26 changes: 4 additions & 22 deletions bin/craft-copy-import-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@
$dotenv->load();
}

// Bootstrap Craft
/** @var \craft\console\Application $app */
define('CRAFT_ENVIRONMENT', getenv('ENVIRONMENT') ?: 'production');
$app = require $root . '/vendor/craftcms/cms/bootstrap/console.php';

if (count($argv) < 2 || stristr($argv[1], '.sql') == false) {
echo "No import file given";
exit(1);
Expand All @@ -52,27 +47,14 @@
exit(1);
}

if ($app->getIsInstalled()) {
echo "Craft is already installed!" . PHP_EOL;
if (!in_array('--force', $argv)) {
echo "Abort. No --force flag given." . PHP_EOL;
exit(1);
}
}

if (!$app->getConfig()->getDb()->password) {
echo "No DB Config found." . PHP_EOL;
exit(1);
}

$db = $app->getConfig()->getDb();
$cmd = 'mysql -u {DB_USER} -p{DB_PASSWORD} -h {DB_SERVER} {DB_DATABASE} < {file} && echo 1';
$tokens = [
'{file}' => $file,
'{DB_USER}' => $db->user,
'{DB_PASSWORD}' => $db->password,
'{DB_SERVER}' => $db->server ?: getenv('DB_SERVER'),
'{DB_DATABASE}' => $db->database ?: getenv('DB_DATABASE'),
'{DB_USER}' => getenv('DB_USER'),
'{DB_PASSWORD}' => getenv('DB_PASSWORD'),
'{DB_SERVER}' => getenv('DB_SERVER'),
'{DB_DATABASE}' => getenv('DB_DATABASE'),
];

$cmd = str_replace(array_keys($tokens), array_values($tokens), $cmd);
Expand Down

0 comments on commit aae5f17

Please sign in to comment.