Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions config/xml/Bitrix24.Lib.Journal.Entity.JournalItem.dcm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,26 @@

</id>

<field name="memberId" type="string" column="member_id" nullable="false"/>

<field name="applicationInstallationId" type="uuid" column="application_installation_id" nullable="false"/>

<field name="createdAt" type="carbon_immutable" column="created_at_utc" precision="3" nullable="false"/>

<field name="level" enum-type="string" column="level" nullable="false"/>

<field name="message" type="text" column="message" nullable="false"/>

<field name="label" type="string" column="label" nullable="false"/>

<field name="userId" type="string" column="user_id" nullable="true"/>

<embedded name="context" class="Bitrix24\Lib\Journal\ValueObjects\JournalContext"/>
<embedded name="context" class="Bitrix24\Lib\Journal\Entity\ValueObjects\Context"/>

<indexes>
<index name="idx_journal_composite" columns="application_installation_id,level,created_at_utc"/>
<index name="idx_journal_composite" columns="member_id,application_installation_id,level,created_at_utc"/>
<index name="idx_journal_created_at" columns="created_at_utc"/>
<index name="idx_journal_member_id" columns="member_id"/>
</indexes>
</entity>
</doctrine-mapping>
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xs="https://www.w3.org/2001/XMLSchema"
xmlns:orm="https://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<embeddable name="Bitrix24\Lib\Journal\ValueObjects\JournalContext">
<field name="label" type="string" column="label" nullable="false"/>

<embeddable name="Bitrix24\Lib\Journal\Entity\ValueObjects\Context">
<field name="payload" type="json" column="payload" nullable="true"/>

<field name="bitrix24UserId" type="integer" column="bitrix24_user_id" nullable="true"/>

<field name="ipAddress" type="darsyn_ip" column="ip_address" nullable="true"/>
<field name="ipAddress" type="ip_address" column="ip_address" nullable="true"/>
</embeddable>
</doctrine-mapping>
7 changes: 5 additions & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
use Rector\Config\RectorConfig;
use Rector\Naming\Rector\Class_\RenamePropertyToMatchTypeRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Set\ValueObject\DowngradeLevelSetList;
use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector;
use Rector\Naming\Rector\ClassMethod\RenameParamToMatchTypeRector;

return RectorConfig::configure()
->withPaths([
Expand Down Expand Up @@ -48,5 +49,7 @@
strictBooleans: true
)
->withSkip([
RenamePropertyToMatchTypeRector::class
RenamePropertyToMatchTypeRector::class,
RenameParamToMatchTypeRector::class,
FlipTypeControlToUseExclusiveTypeRector::class,
]);
2 changes: 1 addition & 1 deletion src/ApplicationInstallations/UseCase/Install/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Bitrix24\Lib\ApplicationInstallations\UseCase\Install;

use Bitrix24\Lib\Bitrix24Accounts\ValueObjects\Domain;
use Bitrix24\Lib\Kernel\ValueObjects\Domain;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

нейминг

use Bitrix24\SDK\Application\ApplicationStatus;
use Bitrix24\SDK\Application\PortalLicenseFamily;
use Bitrix24\SDK\Core\Credentials\AuthToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Bitrix24\Lib\ApplicationInstallations\UseCase\OnAppInstall;

use Bitrix24\Lib\Bitrix24Accounts\ValueObjects\Domain;
use Bitrix24\Lib\Kernel\ValueObjects\Domain;

/**
* Command is called when installation occurs through UI.
Expand Down
2 changes: 1 addition & 1 deletion src/ApplicationInstallations/UseCase/Uninstall/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Bitrix24\Lib\ApplicationInstallations\UseCase\Uninstall;

use Bitrix24\Lib\Bitrix24Accounts\ValueObjects\Domain;
use Bitrix24\Lib\Kernel\ValueObjects\Domain;

readonly class Command
{
Expand Down
2 changes: 1 addition & 1 deletion src/Bitrix24Accounts/UseCase/ChangeDomainUrl/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Bitrix24\Lib\Bitrix24Accounts\UseCase\ChangeDomainUrl;

use Bitrix24\Lib\Bitrix24Accounts\ValueObjects\Domain;
use Bitrix24\Lib\Kernel\ValueObjects\Domain;

readonly class Command
{
Expand Down
2 changes: 1 addition & 1 deletion src/Bitrix24Accounts/UseCase/InstallFinish/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Bitrix24\Lib\Bitrix24Accounts\UseCase\InstallFinish;

use Bitrix24\Lib\Bitrix24Accounts\ValueObjects\Domain;
use Bitrix24\Lib\Kernel\ValueObjects\Domain;

readonly class Command
{
Expand Down
2 changes: 1 addition & 1 deletion src/Bitrix24Accounts/UseCase/InstallStart/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Bitrix24\Lib\Bitrix24Accounts\UseCase\InstallStart;

use Bitrix24\Lib\Bitrix24Accounts\ValueObjects\Domain;
use Bitrix24\Lib\Kernel\ValueObjects\Domain;
use Bitrix24\SDK\Core\Credentials\AuthToken;
use Bitrix24\SDK\Core\Credentials\Scope;

Expand Down
21 changes: 12 additions & 9 deletions src/Journal/Controller/JournalAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,31 @@
namespace Bitrix24\Lib\Journal\Controller;

use Bitrix24\Lib\Journal\Entity\LogLevel;
use Bitrix24\Lib\Journal\ReadModel\JournalItemReadRepository;
use Bitrix24\Lib\Journal\Infrastructure\Doctrine\JournalItemReadRepository;
use Bitrix24\Lib\Kernel\ValueObjects\Domain;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Uid\Uuid;

/**
* Admin controller for journal management
* Developer should configure routes in their application
* Developer should configure routes in their application.
*/
class JournalAdminController extends AbstractController
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Будет вынесен в другой реп, сейчас выпиливаем

{
public function __construct(
private readonly JournalItemReadRepository $journalReadRepository
) {
}
) {}

/**
* List journal items with filters and pagination
* List journal items with filters and pagination.
*/
public function list(Request $request): Response
{
$page = max(1, $request->query->getInt('page', 1));
$domainUrl = $request->query->get('domain');
$memberId = $request->query->get('member_id');
$levelValue = $request->query->get('level');
$label = $request->query->get('label');

Expand All @@ -47,8 +48,9 @@ public function list(Request $request): Response
}

$pagination = $this->journalReadRepository->findWithFilters(
domainUrl: $domainUrl ?: null,
level: $level,
memberId: $memberId ?: null,
domain: $domainUrl ? new Domain($domainUrl) : null,
logLevel: $level,
label: $label ?: null,
page: $page,
limit: 50
Expand All @@ -61,6 +63,7 @@ public function list(Request $request): Response
'pagination' => $pagination,
'currentFilters' => [
'domain' => $domainUrl,
'member_id' => $memberId,
'level' => $levelValue,
'label' => $label,
],
Expand All @@ -71,7 +74,7 @@ public function list(Request $request): Response
}

/**
* Show journal item details
* Show journal item details.
*/
public function show(string $id): Response
{
Expand All @@ -83,7 +86,7 @@ public function show(string $id): Response

$journalItem = $this->journalReadRepository->findById($uuid);

if (!$journalItem) {
if (null === $journalItem) {
throw $this->createNotFoundException('Journal item not found');
}

Expand Down
22 changes: 14 additions & 8 deletions src/Journal/Docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ $factory = $container->get(JournalLoggerFactory::class);

// Создаем логгер для конкретной установки приложения
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Доку пересоздадим, когда будет итоговая архитектура журнала

$installationId = Uuid::fromString('...');
$logger = $factory->createLogger($installationId);
$memberId = '...';
$logger = $factory->createLogger($memberId, $installationId);

// Используем как обычный PSR-3 логгер
$logger->info('Синхронизация завершена', [
Expand Down Expand Up @@ -50,6 +51,7 @@ use Bitrix24\Lib\Journal\Services\JournalLogger;
use Bitrix24\Lib\Journal\Infrastructure\Doctrine\DoctrineDbalJournalItemRepository;

$logger = new JournalLogger(
memberId: $memberId,
applicationInstallationId: $installationId,
repository: $repository,
entityManager: $entityManager
Expand All @@ -74,13 +76,14 @@ $logger->debug('Отладочная информация');
use Bitrix24\Lib\Journal\Entity\JournalItem;

// Создание через статические методы
$item = JournalItem::info($installationId, 'Сообщение', [
$item = JournalItem::info($memberId, $installationId, 'Сообщение', [
'label' => 'custom.label',
'payload' => ['key' => 'value']
]);

// Или через create с явным указанием уровня
$item = JournalItem::create(
memberId: $memberId,
applicationInstallationId: $installationId,
level: LogLevel::error,
message: 'Сообщение об ошибке',
Expand All @@ -103,10 +106,9 @@ $entityManager->flush();

// Поиск
$item = $repository->findById($uuid);
$items = $repository->findByApplicationInstallationId($installationId, LogLevel::error, 50, 0);
$items = $repository->findByApplicationInstallationId($memberId, $installationId, LogLevel::error, 50, 0);

// Очистка
$deleted = $repository->deleteByApplicationInstallationId($installationId);
$deleted = $repository->deleteOlderThan(new CarbonImmutable('-30 days'));
```

Expand All @@ -126,14 +128,15 @@ $repository->clear();
### 4. Admin UI (ReadModel)

```php
use Bitrix24\Lib\Journal\ReadModel\JournalItemReadRepository;
use Bitrix24\Lib\Journal\Infrastructure\Doctrine\JournalItemReadRepository;

$readRepo = new JournalItemReadRepository($entityManager, $paginator);

// Получение с фильтрами и пагинацией
$pagination = $readRepo->findWithFilters(
domainUrl: 'example.bitrix24.ru',
level: LogLevel::error,
memberId: '66c9893d5f30e6.45265697',
domain: new Domain('example.bitrix24.ru'),
logLevel: LogLevel::error,
label: 'b24.api.error',
page: 1,
limit: 50
Expand Down Expand Up @@ -185,6 +188,7 @@ class MyTest extends TestCase
$entityManager = $this->createMock(EntityManagerInterface::class);

$this->logger = new JournalLogger(
'66c9893d5f30e6.45265697',
Uuid::v7(),
$this->repository,
$entityManager
Expand Down Expand Up @@ -215,13 +219,15 @@ class MyTest extends TestCase

Таблица `journal_item` с полями:
- `id` (UUID) - PK
- `member_id` (string) - ID портала Bitrix24
- `application_installation_id` (UUID) - FK к установке приложения
- `created_at_utc` (timestamp) - время создания
- `level` (string) - уровень логирования
- `message` (text) - сообщение
- `label`, `payload`, `bitrix24_user_id`, `ip_address` - поля контекста

Индексы:
- `application_installation_id`
- `member_id, application_installation_id, level, created_at_utc` (composite)
- `member_id`
- `created_at_utc`
- `level`
Loading
Loading