Skip to content

Commit e3803c8

Browse files
committed
Merge branch 'release/2.2.0'
2 parents 117f148 + 6fc4de1 commit e3803c8

File tree

8 files changed

+184
-35
lines changed

8 files changed

+184
-35
lines changed

Block/Adminhtml/System/Config/DeploymentConfigInfo.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,47 @@
44

55
use Magento\Config\Block\System\Config\Form\Field;
66
use Magento\Framework\Data\Form\Element\AbstractElement;
7+
use JustBetter\Sentry\Helper\Version;
8+
use Magento\Backend\Block\Template\Context;
79

810
class DeploymentConfigInfo extends Field
911
{
12+
/**
13+
* @var Version
14+
*/
15+
private $version;
16+
1017
/**
1118
* @var string
1219
*/
1320
protected $_template = 'system/config/deployment-config-info.phtml';
1421

22+
/**
23+
* DeploymentConfigInfo constructor.
24+
* @param Context $context
25+
* @param array $data
26+
* @param Version $version
27+
*/
28+
public function __construct(
29+
Context $context,
30+
Version $version,
31+
array $data = []
32+
) {
33+
$this->version = $version;
34+
parent::__construct($context, $data);
35+
}
36+
1537
public function render(AbstractElement $element)
1638
{
1739
return $this->_toHtml();
1840
}
41+
42+
/**
43+
* Get static version
44+
* @return string
45+
*/
46+
public function getVersion()
47+
{
48+
return $this->version->getValue();
49+
}
1950
}

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
CHANGELOG
22

3+
2019-11-22 - 2.2.0
4+
5+
* Merged PR (https://github.com/justbetter/magento2-sentry/pull/37) thanks to https://github.com/DominicWatts
6+
* Merged PR (https://github.com/justbetter/magento2-sentry/pull/38) thanks to https://github.com/matthiashamacher
7+
38
2019-11-22 - 2.1.0
49

510
* Merged PR (https://github.com/justbetter/magento2-sentry/pull/33) thanks to https://github.com/DominicWatts

Helper/Data.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Data extends AbstractHelper
2525
* @var array
2626
*/
2727
protected $configKeys = [
28-
'domain',
28+
'dsn',
2929
'log_level',
3030
'mage_mode_development',
3131
'environment',
@@ -70,7 +70,7 @@ public function __construct(
7070
*/
7171
public function getDSN()
7272
{
73-
return $this->config['domain'];
73+
return $this->config['dsn'];
7474
}
7575

7676
/**

Helper/Version.php

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
3+
namespace JustBetter\Sentry\Helper;
4+
5+
use Magento\Framework\App\DeploymentConfig;
6+
use Magento\Framework\App\ObjectManager;
7+
use Magento\Framework\Config\ConfigOptionsListConstants;
8+
use Psr\Log\LoggerInterface;
9+
use Magento\Framework\App\Helper\AbstractHelper;
10+
11+
/**
12+
* Deployment version of static files
13+
*/
14+
class Version extends AbstractHelper
15+
{
16+
/**
17+
* @var \Magento\Framework\App\State
18+
*/
19+
private $appState;
20+
21+
/**
22+
* @var \Magento\Framework\App\View\Deployment\Version\StorageInterface
23+
*/
24+
private $versionStorage;
25+
26+
/**
27+
* @var string
28+
*/
29+
private $cachedValue;
30+
31+
/**
32+
* @var LoggerInterface
33+
*/
34+
private $logger;
35+
36+
/**
37+
* @var DeploymentConfig
38+
*/
39+
private $deploymentConfig;
40+
41+
/**
42+
* @param \Magento\Framework\App\State $appState
43+
* @param Version\StorageInterface $versionStorage
44+
* @param DeploymentConfig|null $deploymentConfig
45+
*/
46+
public function __construct(
47+
\Magento\Framework\App\State $appState,
48+
\Magento\Framework\App\View\Deployment\Version\StorageInterface $versionStorage,
49+
DeploymentConfig $deploymentConfig = null
50+
) {
51+
$this->appState = $appState;
52+
$this->versionStorage = $versionStorage;
53+
$this->deploymentConfig = $deploymentConfig ?: ObjectManager::getInstance()->get(DeploymentConfig::class);
54+
}
55+
56+
/**
57+
* Retrieve deployment version of static files
58+
*
59+
* @return string
60+
*/
61+
public function getValue()
62+
{
63+
if (!$this->cachedValue) {
64+
$this->cachedValue = $this->readValue($this->appState->getMode());
65+
}
66+
return $this->cachedValue;
67+
}
68+
69+
/**
70+
* Load or generate deployment version of static files depending on the application mode
71+
* @param string $appMode
72+
* @return string
73+
*/
74+
protected function readValue($appMode)
75+
{
76+
$result = $this->versionStorage->load();
77+
if (!$result) {
78+
if ($appMode == \Magento\Framework\App\State::MODE_PRODUCTION
79+
&& !$this->deploymentConfig->getConfigData(
80+
ConfigOptionsListConstants::CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION
81+
)
82+
) {
83+
$this->getLogger()->critical('Can not load static content version.');
84+
throw new \UnexpectedValueException(
85+
"Unable to retrieve deployment version of static files from the file system."
86+
);
87+
}
88+
$result = $this->generateVersion();
89+
$this->versionStorage->save($result);
90+
}
91+
return $result;
92+
}
93+
94+
/**
95+
* Generate version of static content
96+
* @return int
97+
*/
98+
private function generateVersion()
99+
{
100+
return time();
101+
}
102+
103+
/**
104+
* Get logger
105+
* @return LoggerInterface
106+
*/
107+
private function getLogger()
108+
{
109+
if ($this->logger == null) {
110+
$this->logger = \Magento\Framework\App\ObjectManager::getInstance()
111+
->get(LoggerInterface::class);
112+
}
113+
return $this->logger;
114+
}
115+
}

Model/ReleaseIdentifier.php

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,31 @@
33

44
namespace JustBetter\Sentry\Model;
55

6-
use Magento\Framework\App\Filesystem\DirectoryList;
7-
use Magento\Framework\Filesystem;
6+
use JustBetter\Sentry\Helper\Version;
87

98
class ReleaseIdentifier
109
{
11-
const RELEASE_FILE = 'sentry-releaseid.txt';
12-
13-
/** @var Filesystem */
14-
private $filesystem;
15-
16-
/** @var DirectoryList */
17-
private $directoryList;
18-
19-
/** @var string */
20-
private $releaseId;
21-
22-
public function __construct(Filesystem $filesystem, DirectoryList $directoryList)
23-
{
24-
$this->filesystem = $filesystem;
25-
$this->directoryList = $directoryList;
10+
/**
11+
* @var Version
12+
*/
13+
private $version;
14+
15+
/**
16+
* ReleaseIdentifier constructor.
17+
* @param Version $version
18+
*/
19+
public function __construct(
20+
Version $version
21+
) {
22+
$this->version = $version;
2623
}
2724

25+
/**
26+
* Get release ID from magento internal release number
27+
* @return string
28+
*/
2829
public function getReleaseId()
2930
{
30-
if (empty($this->releaseId) && $this->releaseId !== false) {
31-
$reader = $this->filesystem->getDirectoryRead(DirectoryList::VAR_DIR);
32-
33-
if (!$reader->isFile(self::RELEASE_FILE)) {
34-
$this->releaseId = false;
35-
return false;
36-
}
37-
38-
$this->releaseId = trim($reader->readFile(self::RELEASE_FILE));
39-
}
40-
41-
return $this->releaseId;
31+
return $this->version->getValue();
4232
}
4333
}

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ This module uses the [Magento Deployment Configuration](https://devdocs.magento.
1414

1515
```
1616
'sentry' => [
17-
'domain' => 'example.com', // place your DSN here (i.e. https://<hash>@sentry.io/<projectid>)
17+
'dsn' => 'example.com',
1818
'environment' => null,
1919
'log_level' => \Monolog\Logger::WARNING,
2020
'mage_mode_development' => false,
@@ -23,10 +23,16 @@ This module uses the [Magento Deployment Configuration](https://devdocs.magento.
2323

2424
Next to that there are some configuration options under Stores > Configuration > JustBetter > Sentry.
2525

26+
### Configuration values
27+
* `dsn`: Please enter here the DSN you got from Sentry for your project. You can find the DSN in the project settings under "Client Key (DSN)"
28+
* `environment`: Here you can specify the environment under which the deployed version is running. Common used environments are production, staging, and development. With this option you can differentiate between errors which happen on the staging and i.e. on the production system
29+
* `log_level`: With this configuration you can specify from which logging level on Sentry should get the messages
30+
* `mage_mode_development`: If this option is set to true you will receive issues in Sentry even if you're Magento is running in develop mode.
31+
2632
## Optional error page configuration
2733
- Optional you can configure custom error pages in pub/errors. You can use the sentry feedback form and insert here the sentry log ID. The Sentry Log Id is captured in de customer session and can be retrieved in `processor.php`. Soon(2020-Q1) I'll integrate this in the module.
2834

29-
## Compability
35+
## Compatibility
3036
The module is tested on Magento version 2.2.x & 2.3.x with sentry sdk version 2.x. Magento 2.1.x is not supported by us anymore, feel free to fork this project or make a pull request.
3137

3238
## Ideas, bugs or suggestions?

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "justbetter/magento2-sentry",
33
"description": "Magento 2 Logger for Sentry",
44
"type": "magento2-module",
5-
"version": "2.1.0",
5+
"version": "2.2.0",
66
"license": "MIT",
77
"require": {
88
"php": ">=7.0",

view/adminhtml/templates/system/config/deployment-config-info.phtml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
<pre>
1212
<?= /* @noEscape */ htmlentities("
1313
'sentry' => [
14-
'domain' => 'example.com',
14+
'dsn' => 'example.com',
1515
'environment' => null,
1616
'log_level' => \Monolog\Logger::WARNING,
1717
'mage_mode_development' => false,
1818
]"); ?>
1919
</pre>
20+
21+
<p><?= $block->escapeHtml(__("Release ID: %1", $block->getVersion())); ?></p>
2022
</td>

0 commit comments

Comments
 (0)