Skip to content

Commit

Permalink
Merge branch '5.x' into feat/no_redirect-http_handler
Browse files Browse the repository at this point in the history
  • Loading branch information
theus77 authored Oct 6, 2023
2 parents 2b7ed7b + 3d20c31 commit 640f163
Show file tree
Hide file tree
Showing 11 changed files with 207 additions and 160 deletions.
69 changes: 68 additions & 1 deletion EMS/core-bundle/src/Command/JobOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,75 @@ public function doWrite(string $message, bool $newline): void
{
$job = $this->jobRepository->findById($this->jobId);
$job->setStatus($message);
$job->setOutput($job->getOutput().$this->getFormatter()->format($message).($newline ? PHP_EOL : ''));
$job->setOutput(self::concatenateAnsiString($job->getOutput() ?? '', $this->getFormatter()->format($message) ?? '').($newline ? PHP_EOL : ''));

$this->jobRepository->save($job);
}

public static function concatenateAnsiString(string $left, string $right): string
{
$pos = \strrpos($left, "\n");
if (false === $pos) {
$content = '';
$lastLine = $left;
} else {
$content = \substr($left, 0, $pos + 1);
$lastLine = \substr($left, $pos + 1);
}
$lines = \explode("\n", $right);
$first = true;
foreach ($lines as $line) {
if ($first) {
$first = false;
} else {
$content .= "\n";
}
$content .= self::concatenateAnsiLines($lastLine, $line);
}

return $content.$lastLine;
}

private static function concatenateAnsiLines(string &$lastLine, string $newLine): string
{
$newLine = \preg_replace("/.\x08/", '', $newLine);
if (null === $newLine) {
throw new \RuntimeException('Unexpected null');
}

\preg_match_all("/\e\[(?P<backspace>[0-9]+)D/", $newLine, $matches, PREG_OFFSET_CAPTURE);
if (!empty($matches['backspace'])) {
$line = '';
$cursor = 0;
foreach ($matches['backspace'] as $backspace) {
$count = (int) $backspace[0];
$line .= \substr($newLine, $cursor, $backspace[1] - 2);
$line = \substr($line, 0, \strlen($line) - $count);
$cursor = $backspace[1] + \strlen($backspace[0]) + 1;
}
$newLine = $line.\substr($newLine, $cursor);
}

\preg_match_all("/\e\[(?P<column>[0-9]+)G/", $newLine, $matches, PREG_OFFSET_CAPTURE);
$cursor = 0;
foreach ($matches['column'] as $column) {
$lastLine .= \substr($newLine, $cursor, $column[1] - 2);
$position = (int) $column[0];
if ($position > \strlen($lastLine)) {
$lastLine = \str_pad($lastLine, $position - 1, ' ', STR_PAD_RIGHT);
} else {
$lastLine = \substr($lastLine, $cursor, $position - 1);
}
$endOfLine = \substr($newLine, $column[1] + \strlen($column[0]) + 1);
$cursor = $column[1] - 1;
}
if (!empty($matches['column'])) {
$newLine = $endOfLine;
}

$output = $lastLine;
$lastLine = $newLine;

return $output;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ public function addFile(MediaLibraryConfig $config, MediaLibraryRequest $request

private function getAjaxModal(): AjaxModal
{
return $this->ajax->newAjaxModel("$this->templateNamespace/components/media_library/modal.html.twig");
return $this->ajax->newAjaxModel("@$this->templateNamespace/components/media_library/modal.html.twig");
}
}
15 changes: 0 additions & 15 deletions EMS/core-bundle/src/Controller/TwigElementsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use EMS\CommonBundle\Service\ElasticaService;
use EMS\CoreBundle\Core\Dashboard\DashboardManager;
use EMS\CoreBundle\Core\UI\Menu;
use EMS\CoreBundle\Entity\Revision;
use EMS\CoreBundle\Repository\RevisionRepository;
use EMS\CoreBundle\Routes;
use EMS\CoreBundle\Service\AssetExtractorService;
use EMS\CoreBundle\Service\ContentTypeService;
Expand All @@ -33,27 +31,14 @@ public function __construct(

public function sideMenuAction(): Response
{
$draftCounterGroupedByContentType = [];

/** @var RevisionRepository $revisionRepository */
$revisionRepository = $this->getDoctrine()->getRepository(Revision::class);
$user = $this->userService->getCurrentUser();

$temp = $revisionRepository->draftCounterGroupedByContentType($user->getCircles(), $this->isGranted('ROLE_USER_MANAGEMENT'));
foreach ($temp as $item) {
$draftCounterGroupedByContentType[$item['content_type_id']] = $item['counter'];
}

$status = $this->elasticaService->getHealthStatus();

if ('green' === $status) {
$status = $this->getAssetExtractorStatus();
}

return $this->render(
"@$this->templateNamespace/elements/side-menu.html.twig",
[
'draftCounterGroupedByContentType' => $draftCounterGroupedByContentType,
'status' => $status,
'menu' => [
$this->userService->getSidebarMenu(),
Expand Down
27 changes: 23 additions & 4 deletions EMS/core-bundle/src/Core/Revision/DraftInProgress.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@
namespace EMS\CoreBundle\Core\Revision;

use EMS\CommonBundle\Entity\EntityInterface;
use EMS\CoreBundle\Core\User\UserManager;
use EMS\CoreBundle\Entity\ContentType;
use EMS\CoreBundle\Repository\RevisionRepository;
use EMS\CoreBundle\Service\EntityServiceInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;

class DraftInProgress implements EntityServiceInterface
{
final public const DISCARD_SELECTED_DRAFT = 'DISCARD_SELECTED_DRAFT';

public function __construct(private readonly RevisionRepository $revisionRepository)
{
public function __construct(
private readonly RevisionRepository $revisionRepository,
private readonly UserManager $userManager,
private readonly AuthorizationCheckerInterface $authorizationChecker,
) {
}

public function isSortable(): bool
Expand All @@ -28,7 +33,16 @@ public function get(int $from, int $size, ?string $orderField, string $orderDire
throw new \RuntimeException('Unexpected context');
}

return $this->revisionRepository->getDraftInProgress($from, $size, $orderField, $orderDirection, $searchValue, $context);
return $this->revisionRepository->getDraftInProgress(
from: $from,
size: $size,
orderField: $orderField,
orderDirection: $orderDirection,
searchValue: $searchValue,
contentType: $context,
circles: $this->userManager->getAuthenticatedUser()->getCircles(),
isAdmin: $this->authorizationChecker->isGranted('ROLE_ADMIN')
);
}

public function getEntityName(): string
Expand All @@ -50,7 +64,12 @@ public function count(string $searchValue = '', $context = null): int
throw new \RuntimeException('Unexpected context');
}

return $this->revisionRepository->countDraftInProgress($searchValue, $context);
return $this->revisionRepository->countDraftInProgress(
searchValue: $searchValue,
contentType: $context,
circles: $this->userManager->getAuthenticatedUser()->getCircles(),
isAdmin: $this->authorizationChecker->isGranted('ROLE_ADMIN')
);
}

public function getByItemName(string $name): ?EntityInterface
Expand Down
Loading

0 comments on commit 640f163

Please sign in to comment.