49 lines
1.1 KiB
PHP
49 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace KupShop\DevelopmentBundle\Resources\upgrades;
|
|
|
|
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
|
|
|
class CreateTestDBUpgrade extends \UpgradeNew
|
|
{
|
|
protected $priority = -1100;
|
|
|
|
public function check_dbExists()
|
|
{
|
|
if (!defined('TEST_SUITE') || TEST_SUITE != 'engine') {
|
|
return false;
|
|
}
|
|
|
|
$databaseName = TEST_DB_NAME;
|
|
|
|
$exists = $this->ensureDbExists($databaseName) || $this->checkTableExists('products', $databaseName);
|
|
|
|
if (!$exists) {
|
|
sqlQuery("USE {$databaseName}");
|
|
}
|
|
|
|
return $exists;
|
|
}
|
|
|
|
/** Create testing database */
|
|
public function upgrade_dbExists()
|
|
{
|
|
$container = ServiceContainer::getContainer();
|
|
$command = sprintf(
|
|
'mysql -u %s -h %s -p%s %s < %s',
|
|
'root',
|
|
$container->getParameter('kupshop.db.host'),
|
|
'strongpassword',
|
|
TEST_DB_NAME,
|
|
__DIR__.'/database.sql'
|
|
);
|
|
exec($command, $output, $return);
|
|
|
|
\Settings::clearCache(true);
|
|
|
|
sqlQuery('USE '.TEST_DB_NAME);
|
|
|
|
$this->upgradeOK();
|
|
}
|
|
}
|