|
|
|
|
@ -67,13 +67,35 @@ final class UserCopyAdminService
|
|
|
|
|
*/
|
|
|
|
|
public function workspace(array $query = []): array
|
|
|
|
|
{
|
|
|
|
|
$manifestByKey = [];
|
|
|
|
|
foreach ($this->manifest['entries'] as $manifestEntry) {
|
|
|
|
|
$manifestByKey[$manifestEntry['key']] = $manifestEntry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$pages = [];
|
|
|
|
|
$pageLabels = [];
|
|
|
|
|
foreach ($this->manifest['pages'] as $pageKey => $definition) {
|
|
|
|
|
$pageLabels[$pageKey] = (string) $definition['label'];
|
|
|
|
|
$pages[] = [
|
|
|
|
|
'id' => $pageKey,
|
|
|
|
|
'label' => (string) $definition['label'],
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
$groupIds = [];
|
|
|
|
|
foreach ($this->manifest['entries'] as $manifestEntry) {
|
|
|
|
|
$groupIds[(string) $manifestEntry['editor_group']] = true;
|
|
|
|
|
}
|
|
|
|
|
ksort($groupIds, SORT_STRING);
|
|
|
|
|
$groups = [];
|
|
|
|
|
foreach (array_keys($groupIds) as $groupId) {
|
|
|
|
|
$groups[] = [
|
|
|
|
|
'id' => $groupId,
|
|
|
|
|
'label' => $pageLabels[$groupId]
|
|
|
|
|
?? ($groupId === 'common.shared'
|
|
|
|
|
? '公共框架' : $groupId),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$selectedPage = isset($query['page']) && is_string($query['page'])
|
|
|
|
|
? trim($query['page']) : '';
|
|
|
|
|
if ($selectedPage === '') {
|
|
|
|
|
@ -82,6 +104,29 @@ final class UserCopyAdminService
|
|
|
|
|
if (!isset($this->manifest['pages'][$selectedPage])) {
|
|
|
|
|
throw new UserCopyCatalogException('Unknown user copy page.');
|
|
|
|
|
}
|
|
|
|
|
$channel = 'legacy';
|
|
|
|
|
if (array_key_exists('channel', $query)) {
|
|
|
|
|
if (!is_string($query['channel'])) {
|
|
|
|
|
throw new UserCopyAdminException('文案编辑通道无效。');
|
|
|
|
|
}
|
|
|
|
|
$candidate = trim($query['channel']);
|
|
|
|
|
if ($candidate !== '') {
|
|
|
|
|
$channel = $candidate;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!in_array($channel, ['legacy', 'page', 'advanced', 'all'], true)) {
|
|
|
|
|
throw new UserCopyAdminException('文案编辑通道无效。');
|
|
|
|
|
}
|
|
|
|
|
$selectedGroup = '';
|
|
|
|
|
if (array_key_exists('group', $query)) {
|
|
|
|
|
if (!is_string($query['group'])) {
|
|
|
|
|
throw new UserCopyAdminException('文案编辑分组无效。');
|
|
|
|
|
}
|
|
|
|
|
$selectedGroup = trim($query['group']);
|
|
|
|
|
if ($selectedGroup !== '' && !isset($groupIds[$selectedGroup])) {
|
|
|
|
|
throw new UserCopyAdminException('文案编辑分组无效。');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$localeRows = $this->database->table('ui_copy_locales')
|
|
|
|
|
->whereNull('source_claim')
|
|
|
|
|
@ -106,45 +151,71 @@ final class UserCopyAdminService
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$entryRows = $this->database->table('ui_copy_entries')
|
|
|
|
|
$allEntryRows = $this->database->table('ui_copy_entries')
|
|
|
|
|
->where('state', 'active')
|
|
|
|
|
->whereIn(
|
|
|
|
|
'scope',
|
|
|
|
|
$this->manifest['pages'][$selectedPage]['scopes']
|
|
|
|
|
)
|
|
|
|
|
->orderBy('copy_key')
|
|
|
|
|
->get()
|
|
|
|
|
->all();
|
|
|
|
|
$entriesByKey = [];
|
|
|
|
|
foreach ($entryRows as $entry) {
|
|
|
|
|
$entriesByKey[(string) $entry->copy_key] = $entry;
|
|
|
|
|
$allEntries = [];
|
|
|
|
|
foreach ($allEntryRows as $entry) {
|
|
|
|
|
$allEntries[(string) $entry->copy_key] = $entry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$projectionReady = true;
|
|
|
|
|
try {
|
|
|
|
|
$allEntries = [];
|
|
|
|
|
foreach ($this->database->table('ui_copy_entries')
|
|
|
|
|
->where('state', 'active')->orderBy('copy_key')->get()->all()
|
|
|
|
|
as $entry) {
|
|
|
|
|
$allEntries[(string) $entry->copy_key] = $entry;
|
|
|
|
|
}
|
|
|
|
|
$this->assertManifestProjection($allEntries);
|
|
|
|
|
} catch (UserCopyAdminException) {
|
|
|
|
|
$projectionReady = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$selectedScopes = array_fill_keys(
|
|
|
|
|
$this->manifest['pages'][$selectedPage]['scopes'],
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
$entryRows = [];
|
|
|
|
|
foreach ($allEntryRows as $entry) {
|
|
|
|
|
$copyKey = (string) $entry->copy_key;
|
|
|
|
|
$manifestEntry = $manifestByKey[$copyKey] ?? null;
|
|
|
|
|
$inSelectedPage = isset($selectedScopes[(string) $entry->scope]);
|
|
|
|
|
$matchesChannel = match ($channel) {
|
|
|
|
|
'legacy' => $inSelectedPage,
|
|
|
|
|
'page' => $inSelectedPage
|
|
|
|
|
&& is_array($manifestEntry)
|
|
|
|
|
&& $manifestEntry['editor_surface'] === 'page',
|
|
|
|
|
'advanced' => is_array($manifestEntry)
|
|
|
|
|
&& $manifestEntry['editor_surface'] !== 'page',
|
|
|
|
|
'all' => is_array($manifestEntry),
|
|
|
|
|
};
|
|
|
|
|
if (!$matchesChannel) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if ($selectedGroup !== ''
|
|
|
|
|
&& (!is_array($manifestEntry)
|
|
|
|
|
|| $manifestEntry['editor_group'] !== $selectedGroup)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
$entryRows[] = $entry;
|
|
|
|
|
}
|
|
|
|
|
$entriesByKey = [];
|
|
|
|
|
foreach ($entryRows as $entry) {
|
|
|
|
|
$entriesByKey[(string) $entry->copy_key] = $entry;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$drafts = [];
|
|
|
|
|
$publishedItems = [];
|
|
|
|
|
$currentGeneration = null;
|
|
|
|
|
$entryIds = array_map(
|
|
|
|
|
static fn ($entry): int => (int) $entry->id,
|
|
|
|
|
$entryRows
|
|
|
|
|
);
|
|
|
|
|
if ($selectedLocaleRow !== null) {
|
|
|
|
|
foreach ($this->database->table('ui_copy_drafts')
|
|
|
|
|
->where('locale_id', (int) $selectedLocaleRow->id)
|
|
|
|
|
->whereIn('entry_id', array_map(
|
|
|
|
|
static fn ($entry): int => (int) $entry->id,
|
|
|
|
|
$entryRows
|
|
|
|
|
))
|
|
|
|
|
->get()->all() as $draft) {
|
|
|
|
|
$drafts[(int) $draft->entry_id] = $draft;
|
|
|
|
|
if ($entryIds !== []) {
|
|
|
|
|
foreach ($this->database->table('ui_copy_drafts')
|
|
|
|
|
->where('locale_id', (int) $selectedLocaleRow->id)
|
|
|
|
|
->whereIn('entry_id', $entryIds)
|
|
|
|
|
->get()->all() as $draft) {
|
|
|
|
|
$drafts[(int) $draft->entry_id] = $draft;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$current = $this->store->current();
|
|
|
|
|
$candidate = $current['locales'][$selectedLocale]['generation']
|
|
|
|
|
@ -156,13 +227,10 @@ final class UserCopyAdminService
|
|
|
|
|
->where('catalog_generation', $candidate)
|
|
|
|
|
->where('state', 'ready')
|
|
|
|
|
->first();
|
|
|
|
|
if ($publication !== null) {
|
|
|
|
|
if ($publication !== null && $entryIds !== []) {
|
|
|
|
|
foreach ($this->database->table('ui_copy_revision_items')
|
|
|
|
|
->where('publication_id', (int) $publication->id)
|
|
|
|
|
->whereIn('entry_id', array_map(
|
|
|
|
|
static fn ($entry): int => (int) $entry->id,
|
|
|
|
|
$entryRows
|
|
|
|
|
))
|
|
|
|
|
->whereIn('entry_id', $entryIds)
|
|
|
|
|
->get()->all() as $item) {
|
|
|
|
|
$publishedItems[(int) $item->entry_id] = [
|
|
|
|
|
'text' => (string) $item->published_text,
|
|
|
|
|
@ -177,10 +245,6 @@ final class UserCopyAdminService
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$manifestByKey = [];
|
|
|
|
|
foreach ($this->manifest['entries'] as $manifestEntry) {
|
|
|
|
|
$manifestByKey[$manifestEntry['key']] = $manifestEntry;
|
|
|
|
|
}
|
|
|
|
|
$entries = [];
|
|
|
|
|
$coverage = [
|
|
|
|
|
'total' => count($entryRows),
|
|
|
|
|
@ -232,6 +296,12 @@ final class UserCopyAdminService
|
|
|
|
|
? array_keys($contract) : [],
|
|
|
|
|
'severity' => is_string($manifestEntry['toast_tone'] ?? null)
|
|
|
|
|
? $manifestEntry['toast_tone'] : 'info',
|
|
|
|
|
'editor_surface' => is_string(
|
|
|
|
|
$manifestEntry['editor_surface'] ?? null
|
|
|
|
|
) ? $manifestEntry['editor_surface'] : null,
|
|
|
|
|
'editor_group' => is_string(
|
|
|
|
|
$manifestEntry['editor_group'] ?? null
|
|
|
|
|
) ? $manifestEntry['editor_group'] : null,
|
|
|
|
|
'state' => $state,
|
|
|
|
|
'hidden' => $hidden,
|
|
|
|
|
'draft_version' => $draftDto['version'] ?? 0,
|
|
|
|
|
@ -261,6 +331,7 @@ final class UserCopyAdminService
|
|
|
|
|
return [
|
|
|
|
|
'schema' => 1,
|
|
|
|
|
'pages' => $pages,
|
|
|
|
|
'groups' => $groups,
|
|
|
|
|
'locales' => array_map(static fn (array $locale): array => [
|
|
|
|
|
'id' => $locale['locale'],
|
|
|
|
|
'label' => $locale['display_name'],
|
|
|
|
|
@ -270,6 +341,10 @@ final class UserCopyAdminService
|
|
|
|
|
'page' => $selectedPage,
|
|
|
|
|
'locale' => $selectedLocale,
|
|
|
|
|
],
|
|
|
|
|
'authoring' => [
|
|
|
|
|
'channel' => $channel,
|
|
|
|
|
'group' => $selectedGroup,
|
|
|
|
|
],
|
|
|
|
|
'coverage' => $coverage,
|
|
|
|
|
'entries' => $entries,
|
|
|
|
|
'current_generation' => $currentGeneration,
|
|
|
|
|
|