38 lines
965 B
PHP
38 lines
965 B
PHP
<?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;
|
|
}
|
|
}
|