Skip to content

Commit

Permalink
Merge branch 'refs/heads/1.x' into 160-tags-in-element-editor
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/DependencyInjection/PimcoreStudioBackendExtension.php
  • Loading branch information
alexz707 committed May 23, 2024
2 parents 54af8fc + 06c1489 commit b50882e
Show file tree
Hide file tree
Showing 12 changed files with 448 additions and 1 deletion.
22 changes: 22 additions & 0 deletions config/schedules.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: false

# controllers are imported separately to make sure they're public
# and have a tag that allows actions to type-hint services
Pimcore\Bundle\StudioBackendBundle\Schedule\Controller\:
resource: '../src/Schedule/Controller'
public: true
tags: [ 'controller.service_arguments' ]

Pimcore\Bundle\StudioBackendBundle\Schedule\Service\ScheduleServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Schedule\Service\ScheduleService

Pimcore\Bundle\StudioBackendBundle\Schedule\Repository\ScheduleRepositoryInterface:
class: Pimcore\Bundle\StudioBackendBundle\Schedule\Repository\ScheduleRepository

Pimcore\Bundle\StudioBackendBundle\Schedule\Hydrator\ScheduleHydratorInterface:
class: Pimcore\Bundle\StudioBackendBundle\Schedule\Hydrator\ScheduleHydrator

2 changes: 1 addition & 1 deletion src/Note/Controller/Element/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function __construct(
#[FilterParameter('notes')]
#[FieldFilterParameter]
#[SuccessResponse(
description: 'Paginated assets with total count as header param',
description: 'Paginated notes with total count as header param',
content: new CollectionJson(new NoteCollection())
)]
#[DefaultResponses([
Expand Down
5 changes: 5 additions & 0 deletions src/OpenApi/Config/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
name: Tags::Translation->name,
description: 'Get translations either for a single key or multiple keys'
)]
#[Tag(
name: Tags::Schedule->name,
description: 'Get schedules for an element'
)]
#[Tag(
name: Tags::Settings->name,
description: 'Get Settings'
Expand All @@ -84,6 +88,7 @@ enum Tags: string
case NotesForElement = 'Notes for Element';
case Properties = 'Properties';
case PropertiesForElement = 'Properties for Element';
case Schedule = 'Schedule';
case Settings = 'Settings';
case Tags = 'Tags';
case Translation = 'Translation';
Expand Down
79 changes: 79 additions & 0 deletions src/Schedule/Controller/Element/CollectionController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Schedule\Controller\Element;

use OpenApi\Attributes\Get;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\Note\Attributes\Response\Property\NoteCollection;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Content\ItemsJson;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\ElementTypeParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\IdParameter;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\Content\CollectionJson;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\DefaultResponses;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
use Pimcore\Bundle\StudioBackendBundle\Schedule\Schema\Schedule;
use Pimcore\Bundle\StudioBackendBundle\Schedule\Service\ScheduleServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\HttpResponseCodes;
use Pimcore\Bundle\StudioBackendBundle\Util\Traits\PaginatedResponseTrait;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Serializer\SerializerInterface;

/**
* @internal
*/
final class CollectionController extends AbstractApiController
{
use PaginatedResponseTrait;

public function __construct(
SerializerInterface $serializer,
private readonly ScheduleServiceInterface $scheduleService
)
{
parent::__construct($serializer);
}

#[Route('/schedules/{elementType}/{id}', name: 'pimcore_studio_api_get_element_schedules', methods: ['GET'])]
#[Get(
path: self::API_PATH . '/schedules/{elementType}/{id}',
operationId: 'getSchedulesForElementByTypeAndId',
summary: 'Get schedules for an element',
security: self::SECURITY_SCHEME,
tags: [Tags::Schedule->name]
)]
#[ElementTypeParameter]
#[IdParameter(type: 'element')]
#[SuccessResponse(
description: 'Paginated schedules',
content: new ItemsJson(Schedule::class)
)]
#[DefaultResponses([
HttpResponseCodes::UNAUTHORIZED,
HttpResponseCodes::NOT_FOUND
])]
public function getSchedules(
string $elementType,
int $id
): JsonResponse
{
$tasks = $this->scheduleService->listSchedules($elementType, $id);

return $this->jsonResponse(['items' => $tasks]);
}
}
39 changes: 39 additions & 0 deletions src/Schedule/Event/ScheduleEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Schedule\Event;

use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent;
use Pimcore\Bundle\StudioBackendBundle\Schedule\Schema\Schedule;

final class ScheduleEvent extends AbstractPreResponseEvent
{
public const EVENT_NAME = 'pre_response.schedule';
public function __construct(
private readonly Schedule $schedule
)
{
parent::__construct($schedule);
}

/**
* Use this to get additional infos out of the response object
*/
public function getSchedule(): Schedule
{
return $this->schedule;
}
}
39 changes: 39 additions & 0 deletions src/Schedule/Hydrator/ScheduleHydrator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Schedule\Hydrator;

use Pimcore\Bundle\StudioBackendBundle\Schedule\Schema\Schedule;
use Pimcore\Model\Schedule\Task;

/**
* @internal
*/
final class ScheduleHydrator implements ScheduleHydratorInterface
{
public function hydrate(Task $task): Schedule
{
return new Schedule(
$task->getId(),
$task->getCtype(),
$task->getDate(),
$task->getAction(),
$task->getVersion(),
$task->getActive(),
$task->getUserId()
);
}
}
28 changes: 28 additions & 0 deletions src/Schedule/Hydrator/ScheduleHydratorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Schedule\Hydrator;

use Pimcore\Bundle\StudioBackendBundle\Schedule\Schema\Schedule;
use Pimcore\Model\Schedule\Task;

/**
* @internal
*/
interface ScheduleHydratorInterface
{
public function hydrate(Task $task): Schedule;
}
40 changes: 40 additions & 0 deletions src/Schedule/Repository/ScheduleRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Schedule\Repository;

use Pimcore\Bundle\StaticResolverBundle\Models\Element\ServiceResolverInterface;
use Pimcore\Bundle\StudioBackendBundle\Exception\ElementNotFoundException;
use Pimcore\Bundle\StudioBackendBundle\Util\Traits\ElementProviderTrait;
use Pimcore\Model\Schedule\Task;

final readonly class ScheduleRepository implements ScheduleRepositoryInterface
{
use ElementProviderTrait;

public function __construct(private ServiceResolverInterface $serviceResolver)
{

}

/**
* @return array<int, Task>
*/
public function listSchedules(string $elementType, int $id): array
{
return $this->getElement($this->serviceResolver, $elementType, $id)->getScheduledTasks();
}
}
22 changes: 22 additions & 0 deletions src/Schedule/Repository/ScheduleRepositoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Schedule\Repository;

interface ScheduleRepositoryInterface
{
public function listSchedules(string $elementType, int $id): array;
}
88 changes: 88 additions & 0 deletions src/Schedule/Schema/Schedule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Schedule\Schema;

use OpenApi\Attributes\Property;
use OpenApi\Attributes\Schema;
use Pimcore\Bundle\StudioBackendBundle\Util\Schema\AdditionalAttributesInterface;
use Pimcore\Bundle\StudioBackendBundle\Util\Traits\AdditionalAttributesTrait;

/**
* @internal
*/
#[Schema(
title: 'Schedule',
type: 'object'
)]
final class Schedule implements AdditionalAttributesInterface
{
use AdditionalAttributesTrait;

public function __construct(
#[Property(description: 'id', type: 'integer', example: 666)]
private readonly int $id,
#[Property(description: 'ctype', type: 'string', example: 'Type of element')]
private readonly string $ctype,
#[Property(description: 'Date of schedule', type: 'integer', example: 1634025600)]
private readonly int $date,
#[Property(description: 'Action', type: 'string', enum: ['publish-version', 'delete'])]
private readonly ?string $action,
#[Property(description: 'Version ID', type: 'integer', example: 987)]
private readonly ?int $version,
#[Property(description: 'Active', type: 'boolean', example: true)]
private readonly bool $active,
#[Property(description: 'User ID', type: 'integer', example: 999)]
private readonly int $userId
) {

}

public function getId(): int
{
return $this->id;
}

public function getCtype(): string
{
return $this->ctype;
}

public function getDate(): int
{
return $this->date;
}

public function getAction(): string
{
return $this->action;
}

public function getVersion(): int
{
return $this->version;
}

public function isActive(): bool
{
return $this->active;
}

public function getUserId(): int
{
return $this->userId;
}
}
Loading

0 comments on commit b50882e

Please sign in to comment.