58 lines
1.7 KiB
PHP
58 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace KupShop\KupShopBundle\Command;
|
|
|
|
use KupShop\KupShopBundle\Exception\DatabaseUpgradeException;
|
|
use KupShop\KupShopBundle\Util\Logging\SentryLogger;
|
|
use KupShop\KupShopBundle\Util\System\PathFinder;
|
|
use Symfony\Component\Console\Command\Command;
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
use Symfony\Component\Lock\LockFactory;
|
|
|
|
class UpgradeCommand extends Command
|
|
{
|
|
/**
|
|
* @var PathFinder
|
|
*/
|
|
private $pathFinder;
|
|
|
|
public function __construct(PathFinder $pathFinder, protected LockFactory $globalLockFactory)
|
|
{
|
|
parent::__construct();
|
|
$this->pathFinder = $pathFinder;
|
|
}
|
|
|
|
protected function configure()
|
|
{
|
|
$this
|
|
->setName('kupshop:upgrade')
|
|
->setDescription('Run database migrations');
|
|
}
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
{
|
|
$upgrade = new \Upgrade($output->isVerbose());
|
|
|
|
try {
|
|
$lock = $this->globalLockFactory->createLock('upgrade-lock');
|
|
if ($lock->acquire()) {
|
|
$upgrade->run();
|
|
$lock->release();
|
|
} else {
|
|
echo "Upgrade is already running \n";
|
|
getLogger()->notice('Upgrade is already running');
|
|
}
|
|
} catch (\Exception $exception) {
|
|
if (!isLocalDevelopment() && !getenv('CI')) {
|
|
// capture exception to sentry
|
|
getRaven()->setChannel(SentryLogger::CHANNEL_UPGRADE)
|
|
->captureException(new DatabaseUpgradeException('Neprošel upgrade databáze shopu', $exception->getCode(), $exception));
|
|
}
|
|
throw $exception;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
}
|