Skip to content

Commit

Permalink
Fixed segmentation fault
Browse files Browse the repository at this point in the history
  • Loading branch information
stereomon committed Jan 25, 2024
1 parent 28c3cc5 commit c08ad8f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 26 deletions.
24 changes: 24 additions & 0 deletions src/Spryker/Glue/AppKernel/Controller/AppConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

namespace Spryker\Glue\AppKernel\Controller;

use Generated\Shared\Transfer\AppConfigCriteriaTransfer;
use Generated\Shared\Transfer\AppConfigTransfer;
use Generated\Shared\Transfer\GlueRequestTransfer;
use Generated\Shared\Transfer\GlueResponseTransfer;
use Spryker\Glue\AppKernel\AppKernelConfig;
use Spryker\Glue\Kernel\Backend\Controller\AbstractController;
use Spryker\Zed\AppKernel\Persistence\Exception\AppConfigNotFoundException;

/**
* @method \Spryker\Glue\AppKernel\AppKernelFactory getFactory()
Expand All @@ -36,6 +38,8 @@ public function postConfigureAction(GlueRequestTransfer $glueRequestTransfer): G
$appConfigTransfer = $this->getFactory()->createGlueRequestMapper()
->mapGlueRequestTransferToAppConfigTransfer($glueRequestTransfer, new AppConfigTransfer());

$appConfigTransfer = $this->updateStatus($appConfigTransfer);

$appConfigResponseTransfer = $this->getFactory()->getAppKernelFacade()
->saveConfig($appConfigTransfer);

Expand All @@ -48,4 +52,24 @@ public function postConfigureAction(GlueRequestTransfer $glueRequestTransfer): G
$appConfigResponseTransfer->getAppConfig(),
);
}

/**
* @param \Generated\Shared\Transfer\AppConfigTransfer $appConfigTransfer
*
* @return \Generated\Shared\Transfer\AppConfigTransfer
*/
protected function updateStatus(AppConfigTransfer $appConfigTransfer): AppConfigTransfer
{
if ($appConfigTransfer->getStatus() === null) {
try {
$existingAppConfigTransfer = $this->getFactory()->getAppKernelFacade()
->getConfig((new AppConfigCriteriaTransfer())->setTenantIdentifier($appConfigTransfer->getTenantIdentifier()));

$appConfigTransfer->setStatus($existingAppConfigTransfer->getStatus());
} catch (AppConfigNotFoundException) {
}
}

return $appConfigTransfer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Spryker\Glue\AppKernel\Dependency\Facade;

use Generated\Shared\Transfer\AppConfigCriteriaTransfer;
use Generated\Shared\Transfer\AppConfigResponseTransfer;
use Generated\Shared\Transfer\AppConfigTransfer;
use Generated\Shared\Transfer\AppDisconnectResponseTransfer;
Expand All @@ -27,6 +28,16 @@ public function __construct($appKernelFacade)
$this->appKernelFacade = $appKernelFacade;
}

/**
* @param \Generated\Shared\Transfer\AppConfigCriteriaTransfer $appConfigCriteriaTransfer
*
* @return \Generated\Shared\Transfer\AppConfigTransfer
*/
public function getConfig(AppConfigCriteriaTransfer $appConfigCriteriaTransfer): AppConfigTransfer
{
return $this->appKernelFacade->getConfig($appConfigCriteriaTransfer, new AppConfigTransfer());
}

/**
* @param \Generated\Shared\Transfer\AppConfigTransfer $appConfigTransfer
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@

namespace Spryker\Glue\AppKernel\Dependency\Facade;

use Generated\Shared\Transfer\AppConfigCriteriaTransfer;
use Generated\Shared\Transfer\AppConfigResponseTransfer;
use Generated\Shared\Transfer\AppConfigTransfer;
use Generated\Shared\Transfer\AppDisconnectResponseTransfer;
use Generated\Shared\Transfer\AppDisconnectTransfer;

interface AppKernelToAppKernelFacadeInterface
{
/**
* @param \Generated\Shared\Transfer\AppConfigCriteriaTransfer $appConfigCriteriaTransfer
*
* @return \Generated\Shared\Transfer\AppConfigTransfer
*/
public function getConfig(AppConfigCriteriaTransfer $appConfigCriteriaTransfer): AppConfigTransfer;

/**
* @param \Generated\Shared\Transfer\AppConfigTransfer $appConfigTransfer
*
Expand Down
26 changes: 0 additions & 26 deletions src/Spryker/Zed/AppKernel/Business/Writer/ConfigWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

namespace Spryker\Zed\AppKernel\Business\Writer;

use Generated\Shared\Transfer\AppConfigCriteriaTransfer;
use Generated\Shared\Transfer\AppConfigResponseTransfer;
use Generated\Shared\Transfer\AppConfigTransfer;
use Spryker\Client\SecretsManager\Exception\MissingSecretsManagerProviderPluginException;
Expand All @@ -16,7 +15,6 @@
use Spryker\Zed\AppKernel\Business\EncryptionConfigurator\PropelEncryptionConfiguratorInterface;
use Spryker\Zed\AppKernel\Persistence\AppKernelEntityManagerInterface;
use Spryker\Zed\AppKernel\Persistence\AppKernelRepositoryInterface;
use Spryker\Zed\AppKernel\Persistence\Exception\AppConfigNotFoundException;
use Spryker\Zed\Kernel\Persistence\EntityManager\TransactionTrait;
use Throwable;

Expand Down Expand Up @@ -55,8 +53,6 @@ public function saveConfig(AppConfigTransfer $appConfigTransfer): AppConfigRespo
{
try {
$appConfigTransfer = $this->getTransactionHandler()->handleTransaction(function () use ($appConfigTransfer) {
$appConfigTransfer = $this->updateStatus($appConfigTransfer);

return $this->doSaveAppConfig($appConfigTransfer);
});

Expand All @@ -68,28 +64,6 @@ public function saveConfig(AppConfigTransfer $appConfigTransfer): AppConfigRespo
}
}

/**
* @param \Generated\Shared\Transfer\AppConfigTransfer $appConfigTransfer
*
* @return \Generated\Shared\Transfer\AppConfigTransfer
*/
protected function updateStatus(AppConfigTransfer $appConfigTransfer): AppConfigTransfer
{
try {
/** @var \Generated\Shared\Transfer\AppConfigTransfer $existingAppConfigTransfer */
$existingAppConfigTransfer = $this->appKernelRepository->findAppConfigByCriteria(
(new AppConfigCriteriaTransfer())->setTenantIdentifier($appConfigTransfer->getTenantIdentifierOrFail()),
new AppConfigTransfer(),
);
} catch (AppConfigNotFoundException) {
return $appConfigTransfer;
}

$appConfigTransfer->setStatus($existingAppConfigTransfer->getStatus());

return $appConfigTransfer;
}

/**
* @param \Generated\Shared\Transfer\AppConfigTransfer $appConfigTransfer
*
Expand Down

0 comments on commit c08ad8f

Please sign in to comment.