-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
73e5dbb
commit 4fc8087
Showing
13 changed files
with
255 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
/** | ||
* (c) shopware AG <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SwagPaymentPayPalUnified\Setup; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use SwagPaymentPayPalUnified\Components\Uuid; | ||
|
||
final class InstanceIdService | ||
{ | ||
/** | ||
* @var Connection | ||
*/ | ||
private $connection; | ||
|
||
public function __construct(Connection $connection) | ||
{ | ||
$this->connection = $connection; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getInstanceId() | ||
{ | ||
$instanceId = $this->get(); | ||
|
||
if ($instanceId === null) { | ||
$instanceId = $this->create(); | ||
} | ||
|
||
return $instanceId; | ||
} | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
private function get() | ||
{ | ||
$result = $this->connection->createQueryBuilder() | ||
->select('instance_id') | ||
->from('swag_payment_paypal_unified_instance') | ||
->execute() | ||
->fetchColumn(); | ||
|
||
if (!$result) { | ||
return null; | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
private function create() | ||
{ | ||
$instanceId = Uuid::generateUuid(); | ||
|
||
$this->connection->createQueryBuilder() | ||
->insert('swag_payment_paypal_unified_instance') | ||
->values(['instance_id' => ':instanceId']) | ||
->setParameter('instanceId', $instanceId) | ||
->execute(); | ||
|
||
if ($instanceId !== $this->get()) { | ||
throw new \RuntimeException('Could not create instance id'); | ||
} | ||
|
||
return $instanceId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* (c) shopware AG <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SwagPaymentPayPalUnified\Setup\Versions; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use SwagPaymentPayPalUnified\Setup\InstanceIdService; | ||
|
||
class UpdateTo618 | ||
{ | ||
public function __construct(Connection $connection) | ||
{ | ||
$this->connection = $connection; | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function update() | ||
{ | ||
$this->createInstanceTable(); | ||
|
||
(new InstanceIdService($this->connection))->getInstanceId(); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
private function createInstanceTable() | ||
{ | ||
$this->connection->executeQuery( | ||
' | ||
CREATE TABLE IF NOT EXISTS `swag_payment_paypal_unified_instance` | ||
( | ||
`instance_id` VARCHAR(255) NOT NULL | ||
) ENGINE = InnoDB | ||
DEFAULT CHARSET = utf8 | ||
COLLATE = utf8_unicode_ci;' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
/** | ||
* (c) shopware AG <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SwagPaymentPayPalUnified\Tests\Functional\Setup; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use SwagPaymentPayPalUnified\Setup\InstanceIdService; | ||
use SwagPaymentPayPalUnified\Tests\Functional\ContainerTrait; | ||
|
||
class InstanceIdServiceTest extends TestCase | ||
{ | ||
use ContainerTrait; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testGetInstanceId() | ||
{ | ||
$connection = $this->getContainer()->get('dbal_connection'); | ||
$instanceIdService = new InstanceIdService($connection); | ||
|
||
$instanceId = $instanceIdService->getInstanceId(); | ||
static::assertNotEmpty($instanceId); | ||
|
||
$connection->executeQuery('DELETE FROM swag_payment_paypal_unified_instance WHERE true'); | ||
|
||
$instanceId = $instanceIdService->getInstanceId(); | ||
static::assertNotEmpty($instanceId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* (c) shopware AG <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace SwagPaymentPayPalUnified\Tests\Functional\Setup; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use SwagPaymentPayPalUnified\Setup\InstanceIdService; | ||
use SwagPaymentPayPalUnified\Setup\Versions\UpdateTo618; | ||
use SwagPaymentPayPalUnified\Tests\Functional\ContainerTrait; | ||
use SwagPaymentPayPalUnified\Tests\Functional\DatabaseHelperTrait; | ||
|
||
class UpdateTo618Test extends TestCase | ||
{ | ||
use ContainerTrait; | ||
use DatabaseHelperTrait; | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function testUpdate() | ||
{ | ||
$sql = 'DROP TABLE `swag_payment_paypal_unified_instance`'; | ||
$connection = $this->getContainer()->get('dbal_connection'); | ||
$connection->exec($sql); | ||
static::assertFalse($this->checkTableExists($connection, 'swag_payment_paypal_unified_instance')); | ||
|
||
$updater = new UpdateTo618($connection); | ||
$updater->update(); | ||
$updater->update(); | ||
|
||
static::assertTrue($this->checkTableExists($connection, 'swag_payment_paypal_unified_instance')); | ||
|
||
$result = $connection->createQueryBuilder() | ||
->select('instance_id') | ||
->from('swag_payment_paypal_unified_instance') | ||
->execute() | ||
->fetchColumn(); | ||
|
||
static::assertNotEmpty($result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters