WIP
This commit is contained in:
37
backend/src/bastion/Services/CronApiKeyRegenerator.php
Normal file
37
backend/src/bastion/Services/CronApiKeyRegenerator.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Bastion\Services;
|
||||
|
||||
use Openguru\OpenCartFramework\Config\Settings;
|
||||
|
||||
class CronApiKeyRegenerator
|
||||
{
|
||||
private Settings $settings;
|
||||
private SettingsService $settingsUpdateService;
|
||||
|
||||
public function __construct(Settings $settings, SettingsService $settingsUpdateService)
|
||||
{
|
||||
$this->settings = $settings;
|
||||
$this->settingsUpdateService = $settingsUpdateService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Генерирует новый API-ключ для URL cron-job.org и сохраняет в настройки.
|
||||
*
|
||||
* @return string новый api_key
|
||||
*/
|
||||
public function regenerate(): string
|
||||
{
|
||||
$newApiKey = bin2hex(random_bytes(32));
|
||||
$all = $this->settings->getAll();
|
||||
if (! isset($all['cron'])) {
|
||||
$all['cron'] = [];
|
||||
}
|
||||
$all['cron']['api_key'] = $newApiKey;
|
||||
$this->settingsUpdateService->update($all);
|
||||
|
||||
return $newApiKey;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user