-
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.
Merge pull request #55 from shopware5/pt-13155/add-instance-id
PT-13155 - Add instance id
- Loading branch information
Showing
31 changed files
with
18,745 additions
and
18,484 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,78 @@ | ||
<?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 RuntimeException; | ||
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,56 @@ | ||
<?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 Exception; | ||
use SwagPaymentPayPalUnified\Setup\InstanceIdService; | ||
|
||
class UpdateTo618 | ||
{ | ||
/** | ||
* @var Connection | ||
*/ | ||
private $connection; | ||
|
||
public function __construct(Connection $connection) | ||
{ | ||
$this->connection = $connection; | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
public function update() | ||
{ | ||
$this->createInstanceTable(); | ||
|
||
try { | ||
(new InstanceIdService($this->connection))->getInstanceId(); | ||
} catch (Exception $e) { | ||
// no need to handle this exception | ||
} | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
private function createInstanceTable() | ||
{ | ||
$this->connection->executeQuery( | ||
' | ||
CREATE TABLE IF NOT EXISTS `swag_payment_paypal_unified_instance` | ||
( | ||
`instance_id` VARCHAR(36) 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
Oops, something went wrong.