feat: Add CronJob functionality and integrate with existing services
- Implemented CronJobProcessor for managing scheduled jobs and processing job queues. - Created CronJobRepository for database interactions related to cron jobs. - Defined CronJobType for job types, statuses, and backoff calculations. - Added ApiloLogger for logging actions related to API interactions. - Enhanced UpdateController to check for updates and display update logs. - Updated FormAction to include a preview action for forms. - Modified ApiRouter to handle new dependencies for OrderAdminService and ProductsApiController. - Extended DictionariesApiController to manage attributes and producers. - Enhanced ProductsApiController with variant management and image upload functionality. - Updated ShopBasketController and ShopProductController to sort attributes and handle custom fields. - Added configuration for cron jobs in config.php. - Initialized apilo-sync-queue.json for managing sync tasks.
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
namespace api\Controllers;
|
||||
|
||||
use api\ApiRouter;
|
||||
use Domain\Attribute\AttributeRepository;
|
||||
use Domain\Producer\ProducerRepository;
|
||||
use Domain\ShopStatus\ShopStatusRepository;
|
||||
use Domain\Transport\TransportRepository;
|
||||
use Domain\PaymentMethod\PaymentMethodRepository;
|
||||
@@ -11,15 +13,21 @@ class DictionariesApiController
|
||||
private $statusRepo;
|
||||
private $transportRepo;
|
||||
private $paymentRepo;
|
||||
private $attrRepo;
|
||||
private $producerRepo;
|
||||
|
||||
public function __construct(
|
||||
ShopStatusRepository $statusRepo,
|
||||
TransportRepository $transportRepo,
|
||||
PaymentMethodRepository $paymentRepo
|
||||
PaymentMethodRepository $paymentRepo,
|
||||
AttributeRepository $attrRepo,
|
||||
ProducerRepository $producerRepo
|
||||
) {
|
||||
$this->statusRepo = $statusRepo;
|
||||
$this->transportRepo = $transportRepo;
|
||||
$this->paymentRepo = $paymentRepo;
|
||||
$this->attrRepo = $attrRepo;
|
||||
$this->producerRepo = $producerRepo;
|
||||
}
|
||||
|
||||
public function statuses(): void
|
||||
@@ -79,4 +87,122 @@ class DictionariesApiController
|
||||
|
||||
ApiRouter::sendSuccess($result);
|
||||
}
|
||||
|
||||
public function attributes(): void
|
||||
{
|
||||
if (!ApiRouter::requireMethod('GET')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$attributes = $this->attrRepo->listForApi();
|
||||
|
||||
ApiRouter::sendSuccess($attributes);
|
||||
}
|
||||
|
||||
public function ensure_attribute(): void
|
||||
{
|
||||
if (!ApiRouter::requireMethod('POST')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$body = ApiRouter::getJsonBody();
|
||||
if (!is_array($body)) {
|
||||
ApiRouter::sendError('BAD_REQUEST', 'Missing or invalid JSON body', 400);
|
||||
return;
|
||||
}
|
||||
|
||||
$name = trim((string) ($body['name'] ?? ''));
|
||||
if ($name === '') {
|
||||
ApiRouter::sendError('BAD_REQUEST', 'Missing name', 400);
|
||||
return;
|
||||
}
|
||||
|
||||
$type = (int) ($body['type'] ?? 0);
|
||||
$lang = trim((string) ($body['lang'] ?? 'pl'));
|
||||
if ($lang === '') {
|
||||
$lang = 'pl';
|
||||
}
|
||||
|
||||
$result = $this->attrRepo->ensureAttributeForApi($name, $type, $lang);
|
||||
if (!is_array($result) || (int) ($result['id'] ?? 0) <= 0) {
|
||||
ApiRouter::sendError('INTERNAL_ERROR', 'Failed to ensure attribute', 500);
|
||||
return;
|
||||
}
|
||||
|
||||
ApiRouter::sendSuccess([
|
||||
'id' => (int) ($result['id'] ?? 0),
|
||||
'created' => !empty($result['created']),
|
||||
]);
|
||||
}
|
||||
|
||||
public function ensure_attribute_value(): void
|
||||
{
|
||||
if (!ApiRouter::requireMethod('POST')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$body = ApiRouter::getJsonBody();
|
||||
if (!is_array($body)) {
|
||||
ApiRouter::sendError('BAD_REQUEST', 'Missing or invalid JSON body', 400);
|
||||
return;
|
||||
}
|
||||
|
||||
$attributeId = (int) ($body['attribute_id'] ?? 0);
|
||||
if ($attributeId <= 0) {
|
||||
ApiRouter::sendError('BAD_REQUEST', 'Missing or invalid attribute_id', 400);
|
||||
return;
|
||||
}
|
||||
|
||||
$name = trim((string) ($body['name'] ?? ''));
|
||||
if ($name === '') {
|
||||
ApiRouter::sendError('BAD_REQUEST', 'Missing name', 400);
|
||||
return;
|
||||
}
|
||||
|
||||
$lang = trim((string) ($body['lang'] ?? 'pl'));
|
||||
if ($lang === '') {
|
||||
$lang = 'pl';
|
||||
}
|
||||
|
||||
$result = $this->attrRepo->ensureAttributeValueForApi($attributeId, $name, $lang);
|
||||
if (!is_array($result) || (int) ($result['id'] ?? 0) <= 0) {
|
||||
ApiRouter::sendError('INTERNAL_ERROR', 'Failed to ensure attribute value', 500);
|
||||
return;
|
||||
}
|
||||
|
||||
ApiRouter::sendSuccess([
|
||||
'id' => (int) ($result['id'] ?? 0),
|
||||
'created' => !empty($result['created']),
|
||||
]);
|
||||
}
|
||||
|
||||
public function ensure_producer(): void
|
||||
{
|
||||
if (!ApiRouter::requireMethod('POST')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$body = ApiRouter::getJsonBody();
|
||||
if (!is_array($body)) {
|
||||
ApiRouter::sendError('BAD_REQUEST', 'Missing or invalid JSON body', 400);
|
||||
return;
|
||||
}
|
||||
|
||||
$name = trim((string) ($body['name'] ?? ''));
|
||||
if ($name === '') {
|
||||
ApiRouter::sendError('BAD_REQUEST', 'Missing name', 400);
|
||||
return;
|
||||
}
|
||||
|
||||
$result = $this->producerRepo->ensureProducerForApi($name);
|
||||
if ((int) ($result['id'] ?? 0) <= 0) {
|
||||
ApiRouter::sendError('INTERNAL_ERROR', 'Failed to ensure producer', 500);
|
||||
return;
|
||||
}
|
||||
|
||||
ApiRouter::sendSuccess([
|
||||
'id' => (int) ($result['id'] ?? 0),
|
||||
'created' => !empty($result['created']),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user