-
Notifications
You must be signed in to change notification settings - Fork 804
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 #4223 in SW/shopware from SW-17001/5.2/Implements-…
…FRW-API-call to 5.2 * commit 'f9d6be4396da6f7440a7a34e1287965adfb741ce': SW-17001 - Adds tracking to InstallCommand SW-17001 - Refactors unique id generation, adds notification calls
- Loading branch information
Showing
16 changed files
with
567 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
class Migrations_Migration796 extends Shopware\Components\Migrations\AbstractMigration | ||
{ | ||
public function up($modus) | ||
{ | ||
$sql = <<<SQL | ||
INSERT INTO s_core_config_elements (form_id, name, value, label, description, type, required, position, scope) | ||
VALUES ('0', 'trackingUniqueId', 's:0:"";', 'Unique identifier', '', 'text', '0', '0', '1') | ||
SQL; | ||
|
||
$statement = $this->getConnection()->prepare("SELECT id FROM s_core_config_elements WHERE name = 'update-unique-id'"); | ||
$statement->execute(); | ||
$id = $statement->fetchColumn(); | ||
|
||
if (!empty($id)) { | ||
$sql = 'UPDATE s_core_config_elements SET name="trackingUniqueId" WHERE id=' . $this->getConnection()->quote($id); | ||
} | ||
|
||
$this->addSql($sql); | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
engine/Shopware/Bundle/PluginInstallerBundle/Service/UniqueIdGenerator/UniqueIdGenerator.php
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,104 @@ | ||
<?php | ||
/** | ||
* Shopware 5 | ||
* Copyright (c) shopware AG. | ||
* | ||
* According to our dual licensing model, this program can be used either | ||
* under the terms of the GNU Affero General Public License, version 3, | ||
* or under a proprietary license. | ||
* | ||
* The texts of the GNU Affero General Public License with an additional | ||
* permission and of our proprietary license can be found at and | ||
* in the LICENSE file you have received along with this program. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* "Shopware" is a registered trademark of shopware AG. | ||
* The licensing of the program under the AGPLv3 does not imply a | ||
* trademark license. Therefore any rights, title and interest in | ||
* our trademarks remain entirely with us. | ||
*/ | ||
namespace Shopware\Bundle\PluginInstallerBundle\Service\UniqueIdGenerator; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use Shopware\Components\Random; | ||
use Shopware\Bundle\PluginInstallerBundle\Service\UniqueIdGeneratorInterface; | ||
|
||
/** | ||
* Class UniqueIdGenerator. | ||
* | ||
* A simple class for storing a generated unique Id in the database. | ||
*/ | ||
class UniqueIdGenerator implements UniqueIdGeneratorInterface | ||
{ | ||
/** | ||
* @var Connection | ||
*/ | ||
private $connection; | ||
|
||
/** | ||
* @param Connection $connection | ||
*/ | ||
public function __construct(Connection $connection) | ||
{ | ||
$this->connection = $connection; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getUniqueId() | ||
{ | ||
if ($uniqueId = $this->readUniqueIdFromDb()) { | ||
return $uniqueId; | ||
} | ||
|
||
$uniqueId = Random::getAlphanumericString(32); | ||
|
||
$this->storeUniqueIdInDb($uniqueId); | ||
|
||
return $uniqueId; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
private function readUniqueIdFromDb() | ||
{ | ||
$sql = <<<'sql' | ||
SELECT s_core_config_values.value FROM s_core_config_values | ||
INNER JOIN s_core_config_elements | ||
ON s_core_config_values.element_id = s_core_config_elements.id | ||
AND s_core_config_elements.name LIKE 'trackingUniqueId' | ||
WHERE s_core_config_values.shop_id = 1 | ||
sql; | ||
$uniqueId = $this->connection->fetchColumn($sql); | ||
|
||
if ($uniqueId !== false && is_string($uniqueId)) { | ||
return unserialize($uniqueId); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* @param string $uniqueId | ||
*/ | ||
private function storeUniqueIdInDb($uniqueId) | ||
{ | ||
$sql = <<<'sql' | ||
INSERT INTO s_core_config_values (element_id, shop_id, value) VALUES ( | ||
(SELECT id FROM s_core_config_elements WHERE name LIKE 'trackingUniqueId' LIMIT 1), 1, :value | ||
) | ||
sql; | ||
|
||
$this->connection->executeUpdate( | ||
$sql, [ | ||
'value' => serialize($uniqueId), | ||
] | ||
); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
engine/Shopware/Bundle/PluginInstallerBundle/Service/UniqueIdGeneratorInterface.php
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,37 @@ | ||
<?php | ||
/** | ||
* Shopware 5 | ||
* Copyright (c) shopware AG. | ||
* | ||
* According to our dual licensing model, this program can be used either | ||
* under the terms of the GNU Affero General Public License, version 3, | ||
* or under a proprietary license. | ||
* | ||
* The texts of the GNU Affero General Public License with an additional | ||
* permission and of our proprietary license can be found at and | ||
* in the LICENSE file you have received along with this program. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* "Shopware" is a registered trademark of shopware AG. | ||
* The licensing of the program under the AGPLv3 does not imply a | ||
* trademark license. Therefore any rights, title and interest in | ||
* our trademarks remain entirely with us. | ||
*/ | ||
namespace Shopware\Bundle\PluginInstallerBundle\Service; | ||
|
||
/** | ||
* Interface UniqueIdInterface. | ||
* | ||
* A simple interface for services capable of generating unique ids. | ||
*/ | ||
interface UniqueIdGeneratorInterface | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function getUniqueId(); | ||
} |
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
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,79 @@ | ||
<?php | ||
/** | ||
* Shopware 5 | ||
* Copyright (c) shopware AG | ||
* | ||
* According to our dual licensing model, this program can be used either | ||
* under the terms of the GNU Affero General Public License, version 3, | ||
* or under a proprietary license. | ||
* | ||
* The texts of the GNU Affero General Public License with an additional | ||
* permission and of our proprietary license can be found at and | ||
* in the LICENSE file you have received along with this program. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* "Shopware" is a registered trademark of shopware AG. | ||
* The licensing of the program under the AGPLv3 does not imply a | ||
* trademark license. Therefore any rights, title and interest in | ||
* our trademarks remain entirely with us. | ||
*/ | ||
|
||
namespace Shopware\Recovery\Common\Service; | ||
|
||
use Shopware\Recovery\Common\HttpClient\Client; | ||
|
||
class Notification | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $apiEndPoint; | ||
|
||
/** | ||
* @var Client | ||
*/ | ||
private $client; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $uniqueId; | ||
|
||
/** | ||
* @param string $apiEndPoint | ||
* @param string $uniqueId | ||
* @param Client $client | ||
*/ | ||
public function __construct($apiEndPoint, $uniqueId, Client $client) | ||
{ | ||
$this->apiEndPoint = $apiEndPoint; | ||
$this->client = $client; | ||
$this->uniqueId = $uniqueId; | ||
} | ||
|
||
/** | ||
* @param string $eventName | ||
* @param array $additionalInformation | ||
* @return array|false | ||
*/ | ||
public function doTrackEvent($eventName, $additionalInformation = []) | ||
{ | ||
$payload = [ | ||
'additionalData' => $additionalInformation, | ||
'instanceId' => $this->uniqueId, | ||
'event' => $eventName, | ||
]; | ||
|
||
try { | ||
$response = $this->client->post($this->apiEndPoint.'/tracking/events', json_encode($payload)); | ||
} catch (\Exception $ex) { | ||
return false; | ||
} | ||
|
||
return json_decode($response->getBody(), true) ?: false; | ||
} | ||
} |
Oops, something went wrong.