Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f244d1f52a | |||
| 2e09acdc00 | |||
| 461c80d75d | |||
| c361999ea8 | |||
| 0617f19c28 | |||
| 30e5a28ce3 | |||
| 42cef07833 | |||
| c9b29620ab | |||
| 7aa8b77d2f | |||
| ddc6b06452 | |||
| 06a70b8611 | |||
| 6170b255a3 | |||
| 323ab20c6b | |||
| 9ee7aea69b |
71
README.md
71
README.md
@@ -1,43 +1,52 @@
|
|||||||
# Contao Dummy Copier (Scaffold)
|
# Contao Dummy Copier
|
||||||
|
|
||||||
Dieses Bundle stellt ein Backend-Modul `Dummy Copier` bereit, um bestehende Dummyseiten, Inhalte, Module und Verzeichnisse zu kopieren und Referenzen automatisiert umzubiegen.
|
Dieses Bundle stellt ein Backend-Modul `Dummy Copier` bereit, um bestehende Dummydaten in Contao kontrolliert zu vervielfaeltigen und interne Referenzen auf die neuen Zielobjekte umzubiegen.
|
||||||
|
|
||||||
## Enthaltene Funktionen
|
## Funktionsumfang
|
||||||
|
|
||||||
- Rekursives Kopieren von Seitenbaeumen (`tl_page`)
|
- rekursives Kopieren von Seitenbaeumen aus `tl_page`
|
||||||
- Optionales Kopieren von Artikeln und Content (`tl_article`, `tl_content`)
|
- optionales Kopieren von Artikeln und verschachtelten Inhaltselementen aus `tl_article` und `tl_content`
|
||||||
- Optionales Kopieren von Modulen (`tl_module`)
|
- optionales Kopieren von Modulen aus `tl_module`
|
||||||
- Automatisches Umstellen von:
|
- optionales Kopieren von Newsarchiven samt Newsbeitraegen aus `tl_news_archive` und `tl_news`
|
||||||
- Content-Elementen vom Typ `module` auf kopierte Modul-IDs
|
- optionales Kopieren von Kalendern samt Events aus `tl_calendar` und `tl_calendar_events`
|
||||||
- `jumpTo` in kopierten Seiten/Modulen/Content auf kopierte Seiten, falls vorhanden
|
- optionales Spiegeln von Verzeichnissen im Dateisystem
|
||||||
- Optionales Kopieren von Verzeichnissen (Dateisystem-Mirror)
|
- Dry-Run zur Vorschau ohne Schreibzugriffe
|
||||||
- Dry-Run Modus ohne Schreibzugriff
|
|
||||||
|
## Automatische Referenzanpassungen
|
||||||
|
|
||||||
|
- `jumpTo` in kopierten Seiten, Modulen, Content-Elementen, Newsarchiven, News, Kalendern und Events
|
||||||
|
- Modulreferenzen in Content-Elementen vom Typ `module`
|
||||||
|
- Alias-Referenzen in verschachtelten Content-Elementen (`cteAlias`)
|
||||||
|
- Archiv-Zuordnungen in kopierten Modulen (`news_archives`, `cal_calendar`)
|
||||||
|
- Reader-Module in kopierten Modulen (`news_readerModule`, `cal_readerModule`)
|
||||||
|
- verwandte News (`related`), sofern die referenzierten News ebenfalls mitkopiert wurden
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
1. Bundle in dein Contao-Projekt legen (oder als VCS-Paket einbinden).
|
Installation ueber Packagist:
|
||||||
2. `composer install` oder `composer update acme/contao-dummy-copier`
|
|
||||||
3. Cache leeren.
|
|
||||||
4. Backend-Modul `Dummy Copier` unter `System` oeffnen.
|
|
||||||
|
|
||||||
## Bedienung (aktueller Stand)
|
```bash
|
||||||
|
composer require webfarben/contao-dummy-copier
|
||||||
|
```
|
||||||
|
|
||||||
- Quellobjekte werden ueber Mehrfachauswahlfelder ausgewaehlt (Seiten, Module, Content, Verzeichnisse).
|
Danach wie ueblich:
|
||||||
- Seiten und Verzeichnisse werden in Baumdarstellung (Einrueckung nach Hierarchie) angezeigt.
|
|
||||||
- Alle Mehrfachauswahlfelder haben Live-Filter sowie `Alle`/`Keine` Buttons.
|
|
||||||
- Ziel-Elternseite wird per Auswahlfeld gesetzt.
|
|
||||||
|
|
||||||
Bei kompatibler Contao-Umgebung nutzt das Modul native `pageTree`/`fileTree` Widgets fuer Seiten und Verzeichnisse.
|
```bash
|
||||||
Falls die Widget-Initialisierung versionsbedingt fehlschlaegt, wird automatisch auf die Select-Fallbacks gewechselt.
|
php vendor/bin/contao-setup
|
||||||
- Setze optional Zielverzeichnis, Zielartikel-ID und Praefix.
|
php vendor/bin/console contao:migrate
|
||||||
- Aktiviere Optionen nach Bedarf (`inkl. Content`, `Module kopieren`, `Verzeichnisse kopieren`, `Dry-Run`).
|
```
|
||||||
|
|
||||||
Hinweis: Das Modul akzeptiert weiterhin CSV-Werte als Fallback, falls du Felder per POST automatisiert befuellst.
|
Das Backend-Modul `Dummy Copier` erscheint anschliessend unter `System`.
|
||||||
|
|
||||||
## Wichtige Hinweise
|
## Bedienung
|
||||||
|
|
||||||
- Nach Verzeichnis-Kopien ggf. `contao:filesync` ausfuehren, damit DBAFS konsistent ist.
|
- Quellobjekte werden ueber Mehrfachauswahlfelder ausgewaehlt.
|
||||||
- Dieses Grundgeruest ist bewusst pragmatisch und kann erweitert werden um:
|
- Seiten, Module, Newsarchive, Kalender und Verzeichnisse koennen separat kombiniert werden.
|
||||||
- PageTree/FileTree Picker statt CSV
|
- Alle Mehrfachauswahlfelder besitzen Live-Filter sowie `Alle`/`Keine` Buttons.
|
||||||
- Feldspezifisches Mapping fuer News/Event/Archive-Felder in `tl_module`
|
- Inhaltselemente von Seiten werden bei aktiver Option automatisch mitkopiert.
|
||||||
- Job-Queue via Messenger bei sehr grossen Kopierlaeufen
|
- Ueber ein Praefix lassen sich Titel, Namen und Aliase der Kopien kenntlich machen.
|
||||||
|
|
||||||
|
## Hinweise
|
||||||
|
|
||||||
|
- Nach Dateikopien ggf. `php vendor/bin/console contao:filesync` ausfuehren, damit die DBAFS-Daten synchronisiert werden.
|
||||||
|
- Das Bundle ist fuer pragmatische Redaktions- und Setup-Workflows gedacht. Projektspezifische Sonderfelder oder Referenzen koennen bei Bedarf erweitert werden.
|
||||||
|
|||||||
@@ -3,6 +3,24 @@
|
|||||||
"description": "Contao backend module to clone dummy pages, content elements, modules and rewire references.",
|
"description": "Contao backend module to clone dummy pages, content elements, modules and rewire references.",
|
||||||
"type": "contao-bundle",
|
"type": "contao-bundle",
|
||||||
"license": "proprietary",
|
"license": "proprietary",
|
||||||
|
"keywords": [
|
||||||
|
"contao",
|
||||||
|
"contao-bundle",
|
||||||
|
"backend",
|
||||||
|
"dummy",
|
||||||
|
"migration",
|
||||||
|
"cloner"
|
||||||
|
],
|
||||||
|
"homepage": "https://github.com/webfarben/DummyCopier",
|
||||||
|
"support": {
|
||||||
|
"source": "https://github.com/webfarben/DummyCopier",
|
||||||
|
"issues": "https://github.com/webfarben/DummyCopier/issues"
|
||||||
|
},
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Webfarben"
|
||||||
|
}
|
||||||
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^8.1",
|
"php": "^8.1",
|
||||||
"contao/core-bundle": "^4.13 || ^5.0",
|
"contao/core-bundle": "^4.13 || ^5.0",
|
||||||
|
|||||||
@@ -2,5 +2,5 @@
|
|||||||
|
|
||||||
$GLOBALS['BE_MOD']['system']['dummy_copier'] = [
|
$GLOBALS['BE_MOD']['system']['dummy_copier'] = [
|
||||||
'callback' => Webfarben\DummyCopier\Backend\DummyCopierModule::class,
|
'callback' => Webfarben\DummyCopier\Backend\DummyCopierModule::class,
|
||||||
'icon' => 'bundles/acmedummycopier/icon.svg',
|
'icon' => 'bundles/dummycopier/icon.svg',
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
<?php $this->extend('be_main'); ?>
|
|
||||||
|
|
||||||
<?php $this->block('main'); ?>
|
|
||||||
<form action="<?= $this->action; ?>" method="post" style="max-width:900px;">
|
<form action="<?= $this->action; ?>" method="post" style="max-width:900px;">
|
||||||
<input type="hidden" name="REQUEST_TOKEN" value="<?= $this->requestToken; ?>">
|
<input type="hidden" name="REQUEST_TOKEN" value="<?= $this->requestToken; ?>">
|
||||||
<input type="hidden" name="FORM_SUBMIT" value="tl_dummy_copier">
|
<input type="hidden" name="FORM_SUBMIT" value="tl_dummy_copier">
|
||||||
@@ -11,13 +8,17 @@
|
|||||||
.dc-tools { margin: 0.25rem 0 0.5rem; display: flex; gap: 0.5rem; }
|
.dc-tools { margin: 0.25rem 0 0.5rem; display: flex; gap: 0.5rem; }
|
||||||
.dc-filter { width: 100%; margin: 0.25rem 0; }
|
.dc-filter { width: 100%; margin: 0.25rem 0; }
|
||||||
.dc-button { padding: 0.15rem 0.45rem; }
|
.dc-button { padding: 0.15rem 0.45rem; }
|
||||||
|
.dc-section { border: 1px solid #ccc; padding: 1rem; margin-bottom: 1.5rem; border-radius: 4px; }
|
||||||
|
.dc-section h3 { margin: 0 0 0.75rem; font-size: 1rem; font-weight: bold; }
|
||||||
|
.dc-hint { color: #666; font-size: 0.85rem; margin: 0.25rem 0 0.75rem; }
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<!-- Abschnitt 1: Quell-Seiten -->
|
||||||
|
<div class="dc-section">
|
||||||
|
<h3>1. Quell-Seiten auswaehlen</h3>
|
||||||
|
<p class="dc-hint">Alle Artikel und Inhaltselemente der gewaehlten Seiten werden automatisch mitkopiert (sofern Option "inkl. Content" aktiv ist).</p>
|
||||||
<p>
|
<p>
|
||||||
<label>Quell-Seiten (Mehrfachauswahl):<br>
|
<label>Quell-Seiten (Mehrfachauswahl):<br>
|
||||||
<?php if (!empty($this->sourcePagesWidget)): ?>
|
|
||||||
<?= $this->sourcePagesWidget; ?>
|
|
||||||
<?php else: ?>
|
|
||||||
<input class="dc-filter" type="text" data-filter-for="sourcePages" placeholder="Seiten filtern...">
|
<input class="dc-filter" type="text" data-filter-for="sourcePages" placeholder="Seiten filtern...">
|
||||||
<span class="dc-tools">
|
<span class="dc-tools">
|
||||||
<button class="dc-button" type="button" data-select-all="sourcePages">Alle</button>
|
<button class="dc-button" type="button" data-select-all="sourcePages">Alle</button>
|
||||||
@@ -25,15 +26,19 @@
|
|||||||
</span>
|
</span>
|
||||||
<select id="sourcePages" name="sourcePages[]" multiple size="12" style="width:100%;">
|
<select id="sourcePages" name="sourcePages[]" multiple size="12" style="width:100%;">
|
||||||
<?php foreach (($this->pageChoices ?? []) as $id => $label): ?>
|
<?php foreach (($this->pageChoices ?? []) as $id => $label): ?>
|
||||||
<option value="<?= (int) $id; ?>" <?= in_array((int) $id, ($this->selected['sourcePages'] ?? []), true) ? 'selected' : ''; ?>><?= $this->specialchars((string) $label); ?></option>
|
<option value="<?= (int) $id; ?>" <?= in_array((int) $id, ($this->selected['sourcePages'] ?? []), true) ? 'selected' : ''; ?>><?= htmlspecialchars((string) $label, ENT_QUOTES, 'UTF-8'); ?></option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
<?php endif; ?>
|
|
||||||
</label>
|
</label>
|
||||||
</p>
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Abschnitt 2: Quell-Module -->
|
||||||
|
<div class="dc-section">
|
||||||
|
<h3>2. Quell-Module auswaehlen</h3>
|
||||||
|
<p class="dc-hint">Ausgewaehlte Module werden kopiert; Referenzen in den kopierten Seiten werden automatisch auf die neuen Module umgebogen.</p>
|
||||||
<p>
|
<p>
|
||||||
<label>Quell-Module (Mehrfachauswahl):<br>
|
<label>Module (Mehrfachauswahl):<br>
|
||||||
<input class="dc-filter" type="text" data-filter-for="sourceModules" placeholder="Module filtern...">
|
<input class="dc-filter" type="text" data-filter-for="sourceModules" placeholder="Module filtern...">
|
||||||
<span class="dc-tools">
|
<span class="dc-tools">
|
||||||
<button class="dc-button" type="button" data-select-all="sourceModules">Alle</button>
|
<button class="dc-button" type="button" data-select-all="sourceModules">Alle</button>
|
||||||
@@ -41,83 +46,128 @@
|
|||||||
</span>
|
</span>
|
||||||
<select id="sourceModules" name="sourceModules[]" multiple size="10" style="width:100%;">
|
<select id="sourceModules" name="sourceModules[]" multiple size="10" style="width:100%;">
|
||||||
<?php foreach (($this->moduleChoices ?? []) as $id => $label): ?>
|
<?php foreach (($this->moduleChoices ?? []) as $id => $label): ?>
|
||||||
<option value="<?= (int) $id; ?>" <?= in_array((int) $id, ($this->selected['sourceModules'] ?? []), true) ? 'selected' : ''; ?>><?= $this->specialchars((string) $label); ?></option>
|
<option value="<?= (int) $id; ?>" <?= in_array((int) $id, ($this->selected['sourceModules'] ?? []), true) ? 'selected' : ''; ?>><?= htmlspecialchars((string) $label, ENT_QUOTES, 'UTF-8'); ?></option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
</p>
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Abschnitt 3: Quell-Verzeichnisse -->
|
||||||
|
<div class="dc-section">
|
||||||
|
<h3>3. Newsarchive auswaehlen (optional)</h3>
|
||||||
|
<p class="dc-hint">Ausgewaehlte Newsarchive und ihre Newsbeitraege werden kopiert.</p>
|
||||||
<p>
|
<p>
|
||||||
<label>Quell-Content (optional, Mehrfachauswahl):<br>
|
<label>Newsarchive (Mehrfachauswahl):<br>
|
||||||
<input class="dc-filter" type="text" data-filter-for="sourceContent" placeholder="Content filtern...">
|
<input class="dc-filter" type="text" data-filter-for="sourceNewsArchives" placeholder="Newsarchive filtern...">
|
||||||
<span class="dc-tools">
|
<span class="dc-tools">
|
||||||
<button class="dc-button" type="button" data-select-all="sourceContent">Alle</button>
|
<button class="dc-button" type="button" data-select-all="sourceNewsArchives">Alle</button>
|
||||||
<button class="dc-button" type="button" data-select-none="sourceContent">Keine</button>
|
<button class="dc-button" type="button" data-select-none="sourceNewsArchives">Keine</button>
|
||||||
</span>
|
</span>
|
||||||
<select id="sourceContent" name="sourceContent[]" multiple size="10" style="width:100%;">
|
<select id="sourceNewsArchives" name="sourceNewsArchives[]" multiple size="8" style="width:100%;">
|
||||||
<?php foreach (($this->contentChoices ?? []) as $id => $label): ?>
|
<?php foreach (($this->newsArchiveChoices ?? []) as $id => $label): ?>
|
||||||
<option value="<?= (int) $id; ?>" <?= in_array((int) $id, ($this->selected['sourceContent'] ?? []), true) ? 'selected' : ''; ?>><?= $this->specialchars((string) $label); ?></option>
|
<option value="<?= (int) $id; ?>" <?= in_array((int) $id, ($this->selected['sourceNewsArchives'] ?? []), true) ? 'selected' : ''; ?>><?= htmlspecialchars((string) $label, ENT_QUOTES, 'UTF-8'); ?></option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
</p>
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Abschnitt 4: Kalender -->
|
||||||
|
<div class="dc-section">
|
||||||
|
<h3>4. Kalender auswaehlen (optional)</h3>
|
||||||
|
<p class="dc-hint">Ausgewaehlte Kalender und ihre Events werden kopiert.</p>
|
||||||
<p>
|
<p>
|
||||||
<label>Quell-Verzeichnisse (optional, Mehrfachauswahl):<br>
|
<label>Kalender (Mehrfachauswahl):<br>
|
||||||
<?php if (!empty($this->sourceDirectoriesWidget)): ?>
|
<input class="dc-filter" type="text" data-filter-for="sourceCalendars" placeholder="Kalender filtern...">
|
||||||
<?= $this->sourceDirectoriesWidget; ?>
|
<span class="dc-tools">
|
||||||
<?php else: ?>
|
<button class="dc-button" type="button" data-select-all="sourceCalendars">Alle</button>
|
||||||
|
<button class="dc-button" type="button" data-select-none="sourceCalendars">Keine</button>
|
||||||
|
</span>
|
||||||
|
<select id="sourceCalendars" name="sourceCalendars[]" multiple size="8" style="width:100%;">
|
||||||
|
<?php foreach (($this->calendarChoices ?? []) as $id => $label): ?>
|
||||||
|
<option value="<?= (int) $id; ?>" <?= in_array((int) $id, ($this->selected['sourceCalendars'] ?? []), true) ? 'selected' : ''; ?>><?= htmlspecialchars((string) $label, ENT_QUOTES, 'UTF-8'); ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
|
</label>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Abschnitt 5: Quell-Verzeichnisse -->
|
||||||
|
<div class="dc-section">
|
||||||
|
<h3>5. Quell-Verzeichnisse auswaehlen (optional)</h3>
|
||||||
|
<p class="dc-hint">Optionale Dateiverzeichnisse, die gespiegelt werden sollen.</p>
|
||||||
|
<p>
|
||||||
|
<label>Verzeichnisse (Mehrfachauswahl):<br>
|
||||||
<input class="dc-filter" type="text" data-filter-for="sourceDirectories" placeholder="Verzeichnisse filtern...">
|
<input class="dc-filter" type="text" data-filter-for="sourceDirectories" placeholder="Verzeichnisse filtern...">
|
||||||
<span class="dc-tools">
|
<span class="dc-tools">
|
||||||
<button class="dc-button" type="button" data-select-all="sourceDirectories">Alle</button>
|
<button class="dc-button" type="button" data-select-all="sourceDirectories">Alle</button>
|
||||||
<button class="dc-button" type="button" data-select-none="sourceDirectories">Keine</button>
|
<button class="dc-button" type="button" data-select-none="sourceDirectories">Keine</button>
|
||||||
</span>
|
</span>
|
||||||
<select id="sourceDirectories" name="sourceDirectories[]" multiple size="10" style="width:100%;">
|
<select id="sourceDirectories" name="sourceDirectories[]" multiple size="8" style="width:100%;">
|
||||||
<?php foreach (($this->directoryChoices ?? []) as $path => $label): ?>
|
<?php foreach (($this->directoryChoices ?? []) as $path => $label): ?>
|
||||||
<option value="<?= $this->specialchars((string) $path); ?>" <?= in_array((string) $path, ($this->selected['sourceDirectories'] ?? []), true) ? 'selected' : ''; ?>><?= $this->specialchars((string) $label); ?></option>
|
<option value="<?= htmlspecialchars((string) $path, ENT_QUOTES, 'UTF-8'); ?>" <?= in_array((string) $path, ($this->selected['sourceDirectories'] ?? []), true) ? 'selected' : ''; ?>><?= htmlspecialchars((string) $label, ENT_QUOTES, 'UTF-8'); ?></option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
<?php endif; ?>
|
|
||||||
</label>
|
</label>
|
||||||
</p>
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Abschnitt 4: Kopieroptionen -->
|
||||||
|
<div class="dc-section">
|
||||||
|
<h3>6. Kopieroptionen</h3>
|
||||||
|
<p><label><input type="checkbox" name="includeContent" value="1" <?= ($this->selected['includeContent'] ?? true) ? 'checked' : ''; ?>> Artikel & Inhaltselemente der Seiten mitkopieren</label></p>
|
||||||
|
<p><label><input type="checkbox" name="copyModules" value="1" <?= ($this->selected['copyModules'] ?? true) ? 'checked' : ''; ?>> Module kopieren und in den kopierten Seiten neu verlinken</label></p>
|
||||||
|
<p><label><input type="checkbox" name="copyDirectories" value="1" <?= ($this->selected['copyDirectories'] ?? false) ? 'checked' : ''; ?>> Ausgewaehlte Verzeichnisse in Ziel-Verzeichnis kopieren</label></p>
|
||||||
|
<p><label><input type="checkbox" name="dryRun" value="1" <?= ($this->selected['dryRun'] ?? false) ? 'checked' : ''; ?>> Dry-Run (nur Vorschau, keine Schreibzugriffe)</label></p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Abschnitt 5: Ziel -->
|
||||||
|
<div class="dc-section">
|
||||||
|
<h3>7. Ziel & Benennung</h3>
|
||||||
<p>
|
<p>
|
||||||
<label>Ziel-Elternseite:<br>
|
<label>Ziel-Elternseite (Pflichtfeld):<br>
|
||||||
<?php if (!empty($this->targetParentPageWidget)): ?>
|
|
||||||
<?= $this->targetParentPageWidget; ?>
|
|
||||||
<?php else: ?>
|
|
||||||
<select name="targetParentPage" required style="width:100%;">
|
<select name="targetParentPage" required style="width:100%;">
|
||||||
<option value="">Bitte waehlen</option>
|
<option value="">Bitte waehlen</option>
|
||||||
<?php foreach (($this->pageChoices ?? []) as $id => $label): ?>
|
<?php foreach (($this->pageChoices ?? []) as $id => $label): ?>
|
||||||
<option value="<?= (int) $id; ?>" <?= ((int) ($this->selected['targetParentPage'] ?? 0) === (int) $id) ? 'selected' : ''; ?>><?= $this->specialchars((string) $label); ?></option>
|
<option value="<?= (int) $id; ?>" <?= ((int) ($this->selected['targetParentPage'] ?? 0) === (int) $id) ? 'selected' : ''; ?>><?= htmlspecialchars((string) $label, ENT_QUOTES, 'UTF-8'); ?></option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
<?php endif; ?>
|
|
||||||
</label>
|
</label>
|
||||||
</p>
|
</p>
|
||||||
|
<p>
|
||||||
<p><label>Ziel-Artikel ID (nur fuer einzelne Content-IDs):<br><input type="number" name="targetArticle" min="0" value="<?= (int) ($this->selected['targetArticle'] ?? 0); ?>"></label></p>
|
<label>Ziel-Verzeichnis fuer Dateien (z. B. files/kunden/kunde-x):<br>
|
||||||
<p><label>Ziel-Verzeichnis (z. B. files/kunden/kunde-x):<br><input type="text" name="targetDirectory" style="width:100%" value="<?= $this->specialchars((string) ($this->selected['targetDirectory'] ?? '')); ?>"></label></p>
|
<input type="text" name="targetDirectory" style="width:100%" placeholder="files/kunden/mein-kunde" value="<?= htmlspecialchars((string) ($this->selected['targetDirectory'] ?? ''), ENT_QUOTES, 'UTF-8'); ?>">
|
||||||
<p><label>Praefix fuer Titel/Name/Alias:<br><input type="text" name="namePrefix" placeholder="kunde-x-" value="<?= $this->specialchars((string) ($this->selected['namePrefix'] ?? '')); ?>"></label></p>
|
</label>
|
||||||
|
</p>
|
||||||
<p><label><input type="checkbox" name="includeContent" value="1" checked> Seiten inkl. Artikel/Content kopieren</label></p>
|
<p>
|
||||||
<p><label><input type="checkbox" name="copyModules" value="1" checked> Module kopieren und neu verlinken</label></p>
|
<label>Praefix fuer Titel / Name / Alias der Kopien:<br>
|
||||||
<p><label><input type="checkbox" name="copyDirectories" value="1"> Verzeichnisse kopieren</label></p>
|
<input type="text" name="namePrefix" style="width:100%" placeholder="z. B. kunde-x-" value="<?= htmlspecialchars((string) ($this->selected['namePrefix'] ?? ''), ENT_QUOTES, 'UTF-8'); ?>">
|
||||||
<p><label><input type="checkbox" name="dryRun" value="1"> Dry-Run (keine Schreibzugriffe)</label></p>
|
</label>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<p><button class="tl_submit" type="submit">Ausfuehren</button></p>
|
<p><button class="tl_submit" type="submit">Ausfuehren</button></p>
|
||||||
|
|
||||||
<?php if (isset($this->result) && \is_object($this->result)): ?>
|
<?php if (isset($this->result) && \is_object($this->result)): ?>
|
||||||
<h3>Ergebnis</h3>
|
<h3>Ergebnis</h3>
|
||||||
<pre><?= json_encode([
|
<pre><?= htmlspecialchars(json_encode([
|
||||||
'copiedPages' => $this->result->copiedPages,
|
'copiedPages' => $this->result->copiedPages,
|
||||||
'copiedModules' => $this->result->copiedModules,
|
'copiedModules' => $this->result->copiedModules,
|
||||||
'copiedContent' => $this->result->copiedContent,
|
'copiedContent' => $this->result->copiedContent,
|
||||||
|
'copiedNewsArchives'=> $this->result->copiedNewsArchives,
|
||||||
|
'copiedNewsItems' => $this->result->copiedNewsItems,
|
||||||
|
'copiedCalendars' => $this->result->copiedCalendars,
|
||||||
|
'copiedEvents' => $this->result->copiedEvents,
|
||||||
'copiedDirectories' => $this->result->copiedDirectories,
|
'copiedDirectories' => $this->result->copiedDirectories,
|
||||||
'pageMap' => $this->result->pageMap,
|
'pageMap' => $this->result->pageMap,
|
||||||
'moduleMap' => $this->result->moduleMap,
|
'moduleMap' => $this->result->moduleMap,
|
||||||
|
'newsArchiveMap' => $this->result->newsArchiveMap,
|
||||||
|
'calendarMap' => $this->result->calendarMap,
|
||||||
|
'newsItemMap' => $this->result->newsItemMap,
|
||||||
|
'eventMap' => $this->result->eventMap,
|
||||||
'notes' => $this->result->notes,
|
'notes' => $this->result->notes,
|
||||||
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); ?></pre>
|
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), ENT_QUOTES, 'UTF-8'); ?></pre>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
@@ -127,11 +177,7 @@
|
|||||||
document.querySelectorAll('[data-filter-for]').forEach(function (input) {
|
document.querySelectorAll('[data-filter-for]').forEach(function (input) {
|
||||||
input.addEventListener('input', function () {
|
input.addEventListener('input', function () {
|
||||||
var select = byId(input.getAttribute('data-filter-for'));
|
var select = byId(input.getAttribute('data-filter-for'));
|
||||||
|
if (!select) { return; }
|
||||||
if (!select) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var query = (input.value || '').toLowerCase();
|
var query = (input.value || '').toLowerCase();
|
||||||
Array.prototype.forEach.call(select.options, function (option) {
|
Array.prototype.forEach.call(select.options, function (option) {
|
||||||
option.hidden = query !== '' && option.text.toLowerCase().indexOf(query) === -1;
|
option.hidden = query !== '' && option.text.toLowerCase().indexOf(query) === -1;
|
||||||
@@ -142,15 +188,9 @@
|
|||||||
document.querySelectorAll('[data-select-all]').forEach(function (button) {
|
document.querySelectorAll('[data-select-all]').forEach(function (button) {
|
||||||
button.addEventListener('click', function () {
|
button.addEventListener('click', function () {
|
||||||
var select = byId(button.getAttribute('data-select-all'));
|
var select = byId(button.getAttribute('data-select-all'));
|
||||||
|
if (!select) { return; }
|
||||||
if (!select) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Array.prototype.forEach.call(select.options, function (option) {
|
Array.prototype.forEach.call(select.options, function (option) {
|
||||||
if (!option.hidden) {
|
if (!option.hidden) { option.selected = true; }
|
||||||
option.selected = true;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -158,11 +198,7 @@
|
|||||||
document.querySelectorAll('[data-select-none]').forEach(function (button) {
|
document.querySelectorAll('[data-select-none]').forEach(function (button) {
|
||||||
button.addEventListener('click', function () {
|
button.addEventListener('click', function () {
|
||||||
var select = byId(button.getAttribute('data-select-none'));
|
var select = byId(button.getAttribute('data-select-none'));
|
||||||
|
if (!select) { return; }
|
||||||
if (!select) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Array.prototype.forEach.call(select.options, function (option) {
|
Array.prototype.forEach.call(select.options, function (option) {
|
||||||
option.selected = false;
|
option.selected = false;
|
||||||
});
|
});
|
||||||
@@ -171,4 +207,3 @@
|
|||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
</form>
|
</form>
|
||||||
<?php $this->endblock(); ?>
|
|
||||||
|
|||||||
70
public/icon.svg
Normal file
70
public/icon.svg
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg
|
||||||
|
viewBox="0 0 32 32"
|
||||||
|
fill="none"
|
||||||
|
version="1.1"
|
||||||
|
id="svg10"
|
||||||
|
sodipodi:docname="icon.svg"
|
||||||
|
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg">
|
||||||
|
<defs
|
||||||
|
id="defs14" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
id="namedview12"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
borderopacity="1.0"
|
||||||
|
inkscape:showpageshadow="2"
|
||||||
|
inkscape:pageopacity="0.0"
|
||||||
|
inkscape:pagecheckerboard="0"
|
||||||
|
inkscape:deskcolor="#d1d1d1"
|
||||||
|
showgrid="false"
|
||||||
|
inkscape:zoom="32"
|
||||||
|
inkscape:cx="14.015625"
|
||||||
|
inkscape:cy="16"
|
||||||
|
inkscape:window-width="2560"
|
||||||
|
inkscape:window-height="1408"
|
||||||
|
inkscape:window-x="2560"
|
||||||
|
inkscape:window-y="0"
|
||||||
|
inkscape:window-maximized="1"
|
||||||
|
inkscape:current-layer="svg10" />
|
||||||
|
<rect
|
||||||
|
x="4"
|
||||||
|
y="5"
|
||||||
|
width="11"
|
||||||
|
height="9"
|
||||||
|
rx="2"
|
||||||
|
stroke="#1f2937"
|
||||||
|
stroke-width="2"
|
||||||
|
id="rect2" />
|
||||||
|
<rect
|
||||||
|
x="18"
|
||||||
|
y="5"
|
||||||
|
width="11"
|
||||||
|
height="9"
|
||||||
|
rx="2"
|
||||||
|
stroke="#1f2937"
|
||||||
|
stroke-width="2"
|
||||||
|
opacity="0.55"
|
||||||
|
id="rect4" />
|
||||||
|
<rect
|
||||||
|
x="4"
|
||||||
|
y="18"
|
||||||
|
width="11"
|
||||||
|
height="9"
|
||||||
|
rx="2"
|
||||||
|
stroke="#1f2937"
|
||||||
|
stroke-width="2"
|
||||||
|
opacity="0.55"
|
||||||
|
id="rect6" />
|
||||||
|
<path
|
||||||
|
d="m 19,22.5 h 9 m -4,-4 4,4 -4,4"
|
||||||
|
stroke="#0f766e"
|
||||||
|
stroke-width="2.5"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
id="path8" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 1.6 KiB |
@@ -8,13 +8,10 @@ use Webfarben\DummyCopier\Service\DummyCopier;
|
|||||||
use Webfarben\DummyCopier\Service\DummyCopyOptions;
|
use Webfarben\DummyCopier\Service\DummyCopyOptions;
|
||||||
use Contao\BackendModule;
|
use Contao\BackendModule;
|
||||||
use Contao\Environment;
|
use Contao\Environment;
|
||||||
use Contao\FileTree;
|
|
||||||
use Contao\Input;
|
use Contao\Input;
|
||||||
use Contao\Message;
|
use Contao\Message;
|
||||||
use Contao\PageTree;
|
|
||||||
use Contao\StringUtil;
|
use Contao\StringUtil;
|
||||||
use Contao\System;
|
use Contao\System;
|
||||||
use Contao\Widget;
|
|
||||||
use Doctrine\DBAL\Connection;
|
use Doctrine\DBAL\Connection;
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
|
|
||||||
@@ -28,40 +25,44 @@ class DummyCopierModule extends BackendModule
|
|||||||
$connection = System::getContainer()->get('database_connection');
|
$connection = System::getContainer()->get('database_connection');
|
||||||
|
|
||||||
$this->Template->action = Environment::get('request');
|
$this->Template->action = Environment::get('request');
|
||||||
$this->Template->requestToken = \defined('REQUEST_TOKEN') ? REQUEST_TOKEN : '';
|
$this->Template->requestToken = $this->getCsrfToken();
|
||||||
$this->Template->pageChoices = $this->getPageChoices($connection);
|
$this->Template->pageChoices = $this->getPageChoices($connection);
|
||||||
$this->Template->moduleChoices = $this->getModuleChoices($connection);
|
$this->Template->moduleChoices = $this->getModuleChoices($connection);
|
||||||
$this->Template->contentChoices = $this->getContentChoices($connection);
|
$this->Template->newsArchiveChoices = $this->getNewsArchiveChoices($connection);
|
||||||
|
$this->Template->calendarChoices = $this->getCalendarChoices($connection);
|
||||||
$this->Template->directoryChoices = $this->getDirectoryChoices();
|
$this->Template->directoryChoices = $this->getDirectoryChoices();
|
||||||
$this->Template->sourcePagesWidget = '';
|
|
||||||
$this->Template->targetParentPageWidget = '';
|
|
||||||
$this->Template->sourceDirectoriesWidget = '';
|
|
||||||
$targetParentPageId = $this->parseSingleIdInput(Input::postRaw('targetParentPage'));
|
$targetParentPageId = $this->parseSingleIdInput(Input::postRaw('targetParentPage'));
|
||||||
|
$isPost = Input::post('FORM_SUBMIT') === 'tl_dummy_copier';
|
||||||
|
|
||||||
$this->Template->selected = [
|
$this->Template->selected = [
|
||||||
'sourcePages' => $this->parseIdInput(Input::postRaw('sourcePages')),
|
'sourcePages' => $this->parseIdInput(Input::postRaw('sourcePages')),
|
||||||
'sourceModules' => $this->parseIdInput(Input::postRaw('sourceModules')),
|
'sourceModules' => $this->parseIdInput(Input::postRaw('sourceModules')),
|
||||||
'sourceContent' => $this->parseIdInput(Input::postRaw('sourceContent')),
|
'sourceNewsArchives' => $this->parseIdInput(Input::postRaw('sourceNewsArchives')),
|
||||||
|
'sourceCalendars' => $this->parseIdInput(Input::postRaw('sourceCalendars')),
|
||||||
'sourceDirectories' => $this->parsePathInput(Input::postRaw('sourceDirectories')),
|
'sourceDirectories' => $this->parsePathInput(Input::postRaw('sourceDirectories')),
|
||||||
'targetParentPage' => $targetParentPageId,
|
'targetParentPage' => $targetParentPageId,
|
||||||
'targetArticle' => (int) Input::post('targetArticle'),
|
|
||||||
'targetDirectory' => trim((string) Input::post('targetDirectory')),
|
'targetDirectory' => trim((string) Input::post('targetDirectory')),
|
||||||
'namePrefix' => trim((string) Input::post('namePrefix')),
|
'namePrefix' => trim((string) Input::post('namePrefix')),
|
||||||
|
'includeContent' => !$isPost || (bool) Input::post('includeContent'),
|
||||||
|
'copyModules' => !$isPost || (bool) Input::post('copyModules'),
|
||||||
|
'copyDirectories' => $isPost && (bool) Input::post('copyDirectories'),
|
||||||
|
'dryRun' => $isPost && (bool) Input::post('dryRun'),
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->prepareTreeWidgets();
|
if (!$isPost) {
|
||||||
|
|
||||||
if (Input::post('FORM_SUBMIT') !== 'tl_dummy_copier') {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$options = new DummyCopyOptions(
|
$options = new DummyCopyOptions(
|
||||||
$this->parseIdInput(Input::postRaw('sourcePages')),
|
$this->parseIdInput(Input::postRaw('sourcePages')),
|
||||||
$this->parseIdInput(Input::postRaw('sourceModules')),
|
$this->parseIdInput(Input::postRaw('sourceModules')),
|
||||||
$this->parseIdInput(Input::postRaw('sourceContent')),
|
$this->parseIdInput(Input::postRaw('sourceNewsArchives')),
|
||||||
|
$this->parseIdInput(Input::postRaw('sourceCalendars')),
|
||||||
|
[],
|
||||||
$this->parsePathInput(Input::postRaw('sourceDirectories')),
|
$this->parsePathInput(Input::postRaw('sourceDirectories')),
|
||||||
$targetParentPageId,
|
$targetParentPageId,
|
||||||
(int) Input::post('targetArticle'),
|
0,
|
||||||
trim((string) Input::post('targetDirectory')),
|
trim((string) Input::post('targetDirectory')),
|
||||||
trim((string) Input::post('namePrefix')),
|
trim((string) Input::post('namePrefix')),
|
||||||
(bool) Input::post('includeContent'),
|
(bool) Input::post('includeContent'),
|
||||||
@@ -79,10 +80,14 @@ class DummyCopierModule extends BackendModule
|
|||||||
$result = $copier->execute($options);
|
$result = $copier->execute($options);
|
||||||
|
|
||||||
Message::addConfirmation(sprintf(
|
Message::addConfirmation(sprintf(
|
||||||
'Fertig. Seiten: %d, Module: %d, Content: %d, Verzeichnisse: %d',
|
'Fertig. Seiten: %d, Module: %d, Content: %d, Newsarchive: %d, Newsbeitraege: %d, Kalender: %d, Events: %d, Verzeichnisse: %d',
|
||||||
$result->copiedPages,
|
$result->copiedPages,
|
||||||
$result->copiedModules,
|
$result->copiedModules,
|
||||||
$result->copiedContent,
|
$result->copiedContent,
|
||||||
|
$result->copiedNewsArchives,
|
||||||
|
$result->copiedNewsItems,
|
||||||
|
$result->copiedCalendars,
|
||||||
|
$result->copiedEvents,
|
||||||
$result->copiedDirectories
|
$result->copiedDirectories
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -143,85 +148,24 @@ class DummyCopierModule extends BackendModule
|
|||||||
return $ids[0] ?? 0;
|
return $ids[0] ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function prepareTreeWidgets(): void
|
private function getCsrfToken(): string
|
||||||
{
|
{
|
||||||
if (!class_exists(PageTree::class) || !class_exists(FileTree::class) || !class_exists(Widget::class)) {
|
$container = System::getContainer();
|
||||||
return;
|
|
||||||
|
// Contao 5: use Symfony CSRF token manager
|
||||||
|
if ($container->has('contao.csrf.token_manager')) {
|
||||||
|
return $container
|
||||||
|
->get('contao.csrf.token_manager')
|
||||||
|
->getToken((string) $container->getParameter('contao.csrf_token_name'))
|
||||||
|
->getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
// Contao 4 fallback
|
||||||
$selectedPages = $this->parseIdInput(Input::postRaw('sourcePages'));
|
if (\defined('REQUEST_TOKEN')) {
|
||||||
$selectedParent = (int) Input::post('targetParentPage');
|
return REQUEST_TOKEN;
|
||||||
$selectedDirectories = $this->parsePathInput(Input::postRaw('sourceDirectories'));
|
|
||||||
|
|
||||||
$this->Template->sourcePagesWidget = $this->renderPageTreeWidget(
|
|
||||||
'sourcePages',
|
|
||||||
'Quell-Seiten (pageTree)',
|
|
||||||
$selectedPages,
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->Template->targetParentPageWidget = $this->renderPageTreeWidget(
|
|
||||||
'targetParentPage',
|
|
||||||
'Ziel-Elternseite (pageTree)',
|
|
||||||
$selectedParent > 0 ? [$selectedParent] : [],
|
|
||||||
false
|
|
||||||
);
|
|
||||||
|
|
||||||
$this->Template->sourceDirectoriesWidget = $this->renderFileTreeWidget(
|
|
||||||
'sourceDirectories',
|
|
||||||
'Quell-Verzeichnisse (fileTree)',
|
|
||||||
$selectedDirectories
|
|
||||||
);
|
|
||||||
} catch (\Throwable $exception) {
|
|
||||||
// If widget rendering differs by Contao version, the module falls back to select boxes.
|
|
||||||
$this->Template->sourcePagesWidget = '';
|
|
||||||
$this->Template->targetParentPageWidget = '';
|
|
||||||
$this->Template->sourceDirectoriesWidget = '';
|
|
||||||
Message::addInfo('Tree-Widgets konnten nicht initialisiert werden, Fallback-Auswahl wird verwendet.');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function renderPageTreeWidget(string $name, string $label, array $value, bool $multiple): string
|
return '';
|
||||||
{
|
|
||||||
$attributes = Widget::getAttributesFromDca([
|
|
||||||
'inputType' => 'pageTree',
|
|
||||||
'label' => [$label, ''],
|
|
||||||
'eval' => [
|
|
||||||
'fieldType' => $multiple ? 'checkbox' : 'radio',
|
|
||||||
'multiple' => $multiple,
|
|
||||||
'tl_class' => 'clr',
|
|
||||||
],
|
|
||||||
], $name, $value, $name, 'tl_dummy_copier');
|
|
||||||
|
|
||||||
$attributes['id'] = $name;
|
|
||||||
$attributes['name'] = $name;
|
|
||||||
|
|
||||||
$widget = new PageTree($attributes);
|
|
||||||
|
|
||||||
return $widget->generate();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function renderFileTreeWidget(string $name, string $label, array $value): string
|
|
||||||
{
|
|
||||||
$attributes = Widget::getAttributesFromDca([
|
|
||||||
'inputType' => 'fileTree',
|
|
||||||
'label' => [$label, ''],
|
|
||||||
'eval' => [
|
|
||||||
'fieldType' => 'checkbox',
|
|
||||||
'filesOnly' => false,
|
|
||||||
'files' => false,
|
|
||||||
'multiple' => true,
|
|
||||||
'tl_class' => 'clr',
|
|
||||||
],
|
|
||||||
], $name, $value, $name, 'tl_dummy_copier');
|
|
||||||
|
|
||||||
$attributes['id'] = $name;
|
|
||||||
$attributes['name'] = $name;
|
|
||||||
|
|
||||||
$widget = new FileTree($attributes);
|
|
||||||
|
|
||||||
return $widget->generate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -290,7 +234,12 @@ class DummyCopierModule extends BackendModule
|
|||||||
*/
|
*/
|
||||||
private function getModuleChoices(Connection $connection): array
|
private function getModuleChoices(Connection $connection): array
|
||||||
{
|
{
|
||||||
$rows = $connection->fetchAllAssociative('SELECT id, name, type FROM tl_module ORDER BY id');
|
$rows = $connection->fetchAllAssociative(
|
||||||
|
'SELECT m.id, m.name, m.type, t.name AS theme_name
|
||||||
|
FROM tl_module m
|
||||||
|
LEFT JOIN tl_theme t ON t.id = m.pid
|
||||||
|
ORDER BY t.name, m.type, m.name'
|
||||||
|
);
|
||||||
$choices = [];
|
$choices = [];
|
||||||
|
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
@@ -302,38 +251,14 @@ class DummyCopierModule extends BackendModule
|
|||||||
|
|
||||||
$name = trim((string) ($row['name'] ?? 'Modul ' . $id));
|
$name = trim((string) ($row['name'] ?? 'Modul ' . $id));
|
||||||
$type = trim((string) ($row['type'] ?? ''));
|
$type = trim((string) ($row['type'] ?? ''));
|
||||||
$label = $type !== '' ? sprintf('%s (%s)', $name, $type) : $name;
|
$theme = trim((string) ($row['theme_name'] ?? ''));
|
||||||
|
$label = $theme !== '' ? sprintf('[%s] %s (%s)', $theme, $name, $type) : sprintf('%s (%s)', $name, $type);
|
||||||
$choices[$id] = sprintf('%s [ID %d]', $label, $id);
|
$choices[$id] = sprintf('%s [ID %d]', $label, $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $choices;
|
return $choices;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return array<int,string>
|
|
||||||
*/
|
|
||||||
private function getContentChoices(Connection $connection): array
|
|
||||||
{
|
|
||||||
$rows = $connection->fetchAllAssociative('SELECT id, type, pid, headline FROM tl_content ORDER BY id');
|
|
||||||
$choices = [];
|
|
||||||
|
|
||||||
foreach ($rows as $row) {
|
|
||||||
$id = (int) ($row['id'] ?? 0);
|
|
||||||
|
|
||||||
if ($id < 1) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$type = trim((string) ($row['type'] ?? 'content'));
|
|
||||||
$pid = (int) ($row['pid'] ?? 0);
|
|
||||||
$headline = $this->normalizeHeadline($row['headline'] ?? null);
|
|
||||||
$label = $headline !== '' ? sprintf('%s: %s', $type, $headline) : $type;
|
|
||||||
$choices[$id] = sprintf('%s [ID %d, Artikel %d]', $label, $id, $pid);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $choices;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<string,string>
|
* @return array<string,string>
|
||||||
*/
|
*/
|
||||||
@@ -370,6 +295,50 @@ class DummyCopierModule extends BackendModule
|
|||||||
return $choices;
|
return $choices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int,string>
|
||||||
|
*/
|
||||||
|
private function getNewsArchiveChoices(Connection $connection): array
|
||||||
|
{
|
||||||
|
$rows = $connection->fetchAllAssociative('SELECT id, title FROM tl_news_archive ORDER BY title');
|
||||||
|
$choices = [];
|
||||||
|
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
$id = (int) ($row['id'] ?? 0);
|
||||||
|
|
||||||
|
if ($id < 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$title = trim((string) ($row['title'] ?? ''));
|
||||||
|
$choices[$id] = sprintf('%s [ID %d]', $title !== '' ? $title : ('Newsarchiv ' . $id), $id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $choices;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<int,string>
|
||||||
|
*/
|
||||||
|
private function getCalendarChoices(Connection $connection): array
|
||||||
|
{
|
||||||
|
$rows = $connection->fetchAllAssociative('SELECT id, title FROM tl_calendar ORDER BY title');
|
||||||
|
$choices = [];
|
||||||
|
|
||||||
|
foreach ($rows as $row) {
|
||||||
|
$id = (int) ($row['id'] ?? 0);
|
||||||
|
|
||||||
|
if ($id < 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$title = trim((string) ($row['title'] ?? ''));
|
||||||
|
$choices[$id] = sprintf('%s [ID %d]', $title !== '' ? $title : ('Kalender ' . $id), $id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $choices;
|
||||||
|
}
|
||||||
|
|
||||||
private function normalizeHeadline($headline): string
|
private function normalizeHeadline($headline): string
|
||||||
{
|
{
|
||||||
if (\is_string($headline)) {
|
if (\is_string($headline)) {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Webfarben\DummyCopier\Service;
|
namespace Webfarben\DummyCopier\Service;
|
||||||
|
|
||||||
|
use Contao\StringUtil;
|
||||||
use Doctrine\DBAL\Connection;
|
use Doctrine\DBAL\Connection;
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
|
|
||||||
@@ -29,6 +30,10 @@ final class DummyCopier
|
|||||||
$result->copiedModules = $options->copyModules ? $this->countRows('tl_module', $options->sourceModuleIds) : 0;
|
$result->copiedModules = $options->copyModules ? $this->countRows('tl_module', $options->sourceModuleIds) : 0;
|
||||||
$result->copiedContent = $this->estimateContentCount($options);
|
$result->copiedContent = $this->estimateContentCount($options);
|
||||||
$result->copiedDirectories = $options->copyDirectories ? \count($options->sourceDirectories) : 0;
|
$result->copiedDirectories = $options->copyDirectories ? \count($options->sourceDirectories) : 0;
|
||||||
|
$result->copiedNewsArchives = $this->countRows('tl_news_archive', $options->sourceNewsArchiveIds);
|
||||||
|
$result->copiedNewsItems = $this->countByPid('tl_news', 'pid', $options->sourceNewsArchiveIds);
|
||||||
|
$result->copiedCalendars = $this->countRows('tl_calendar', $options->sourceCalendarIds);
|
||||||
|
$result->copiedEvents = $this->countByPid('tl_calendar_events', 'pid', $options->sourceCalendarIds);
|
||||||
$result->addNote('Dry-Run aktiv: Es wurden keine Daten geschrieben.');
|
$result->addNote('Dry-Run aktiv: Es wurden keine Daten geschrieben.');
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
@@ -49,6 +54,14 @@ final class DummyCopier
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($options->sourceNewsArchiveIds !== []) {
|
||||||
|
$result->newsArchiveMap = $this->copyNewsArchives($options->sourceNewsArchiveIds, $options->namePrefix, $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($options->sourceCalendarIds !== []) {
|
||||||
|
$result->calendarMap = $this->copyCalendars($options->sourceCalendarIds, $options->namePrefix, $result);
|
||||||
|
}
|
||||||
|
|
||||||
if ($options->targetArticleId > 0) {
|
if ($options->targetArticleId > 0) {
|
||||||
foreach ($options->sourceContentIds as $sourceContentId) {
|
foreach ($options->sourceContentIds as $sourceContentId) {
|
||||||
$this->copySingleContent($sourceContentId, $options->targetArticleId, $result->moduleMap, $result);
|
$this->copySingleContent($sourceContentId, $options->targetArticleId, $result->moduleMap, $result);
|
||||||
@@ -57,6 +70,10 @@ final class DummyCopier
|
|||||||
|
|
||||||
$this->rewriteReferences($result);
|
$this->rewriteReferences($result);
|
||||||
|
|
||||||
|
if ($options->copyModules) {
|
||||||
|
$this->rewriteModuleArchiveReferences($result);
|
||||||
|
}
|
||||||
|
|
||||||
if ($options->copyDirectories) {
|
if ($options->copyDirectories) {
|
||||||
$this->copyDirectories($options, $result);
|
$this->copyDirectories($options, $result);
|
||||||
}
|
}
|
||||||
@@ -149,11 +166,25 @@ final class DummyCopier
|
|||||||
|
|
||||||
$newArticleId = $this->insertRow('tl_article', $articleRow);
|
$newArticleId = $this->insertRow('tl_article', $articleRow);
|
||||||
|
|
||||||
$contentIds = $this->connection->fetchFirstColumn('SELECT id FROM tl_content WHERE ptable = ? AND pid = ? ORDER BY sorting', ['tl_article', (int) $articleId]);
|
$this->copyArticleContentTree((int) $articleId, $newArticleId, $moduleMap, $result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copies top-level article content and all nested child elements recursively.
|
||||||
|
*
|
||||||
|
* @param array<int,int> $moduleMap
|
||||||
|
*/
|
||||||
|
private function copyArticleContentTree(int $sourceArticleId, int $targetArticleId, array $moduleMap, DummyCopyResult $result): void
|
||||||
|
{
|
||||||
|
$visited = [];
|
||||||
|
$contentIds = $this->connection->fetchFirstColumn(
|
||||||
|
'SELECT id FROM tl_content WHERE ptable = ? AND pid = ? ORDER BY sorting',
|
||||||
|
['tl_article', $sourceArticleId]
|
||||||
|
);
|
||||||
|
|
||||||
foreach ($contentIds as $contentId) {
|
foreach ($contentIds as $contentId) {
|
||||||
$this->copySingleContent((int) $contentId, $newArticleId, $moduleMap, $result);
|
$this->copyContentRecursive((int) $contentId, 'tl_article', $targetArticleId, $moduleMap, $result, $visited);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,18 +193,34 @@ final class DummyCopier
|
|||||||
*/
|
*/
|
||||||
private function copySingleContent(int $sourceContentId, int $targetArticleId, array $moduleMap, DummyCopyResult $result): void
|
private function copySingleContent(int $sourceContentId, int $targetArticleId, array $moduleMap, DummyCopyResult $result): void
|
||||||
{
|
{
|
||||||
|
$visited = [];
|
||||||
|
$this->copyContentRecursive($sourceContentId, 'tl_article', $targetArticleId, $moduleMap, $result, $visited);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recursively copies one content element and its children.
|
||||||
|
*
|
||||||
|
* @param array<int,int> $moduleMap
|
||||||
|
*/
|
||||||
|
private function copyContentRecursive(int $sourceContentId, string $targetPtable, int $targetPid, array $moduleMap, DummyCopyResult $result, array &$visited): int
|
||||||
|
{
|
||||||
|
if (isset($visited[$sourceContentId])) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$visited[$sourceContentId] = true;
|
||||||
$contentRow = $this->fetchRow('tl_content', $sourceContentId);
|
$contentRow = $this->fetchRow('tl_content', $sourceContentId);
|
||||||
|
|
||||||
if ($contentRow === null) {
|
if ($contentRow === null) {
|
||||||
$result->addNote(sprintf('Content %d nicht gefunden, wurde uebersprungen.', $sourceContentId));
|
$result->addNote(sprintf('Content %d nicht gefunden, wurde uebersprungen.', $sourceContentId));
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($contentRow['id']);
|
unset($contentRow['id']);
|
||||||
$contentRow['pid'] = $targetArticleId;
|
$contentRow['pid'] = $targetPid;
|
||||||
$contentRow['ptable'] = 'tl_article';
|
$contentRow['ptable'] = $targetPtable;
|
||||||
$contentRow['tstamp'] = time();
|
$contentRow['tstamp'] = time();
|
||||||
$contentRow['sorting'] = $this->nextSorting('tl_content', 'pid', $targetArticleId, 'ptable', 'tl_article');
|
$contentRow['sorting'] = $this->nextSorting('tl_content', 'pid', $targetPid, 'ptable', $targetPtable);
|
||||||
|
|
||||||
if (($contentRow['type'] ?? '') === 'module') {
|
if (($contentRow['type'] ?? '') === 'module') {
|
||||||
$oldModule = (int) ($contentRow['module'] ?? 0);
|
$oldModule = (int) ($contentRow['module'] ?? 0);
|
||||||
@@ -184,12 +231,24 @@ final class DummyCopier
|
|||||||
}
|
}
|
||||||
|
|
||||||
$newContentId = $this->insertRow('tl_content', $contentRow);
|
$newContentId = $this->insertRow('tl_content', $contentRow);
|
||||||
|
$result->contentMap[$sourceContentId] = $newContentId;
|
||||||
$result->copiedContent++;
|
$result->copiedContent++;
|
||||||
$result->copiedContentIds[] = $newContentId;
|
$result->copiedContentIds[] = $newContentId;
|
||||||
|
|
||||||
if (isset($contentRow['jumpTo'], $result->pageMap[(int) $contentRow['jumpTo']])) {
|
if (isset($contentRow['jumpTo'], $result->pageMap[(int) $contentRow['jumpTo']])) {
|
||||||
$this->connection->update('tl_content', ['jumpTo' => $result->pageMap[(int) $contentRow['jumpTo']]], ['id' => $newContentId]);
|
$this->connection->update('tl_content', ['jumpTo' => $result->pageMap[(int) $contentRow['jumpTo']]], ['id' => $newContentId]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$childIds = $this->connection->fetchFirstColumn(
|
||||||
|
'SELECT id FROM tl_content WHERE ptable = ? AND pid = ? ORDER BY sorting',
|
||||||
|
['tl_content', $sourceContentId]
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($childIds as $childId) {
|
||||||
|
$this->copyContentRecursive((int) $childId, 'tl_content', $newContentId, $moduleMap, $result, $visited);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $newContentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function rewriteReferences(DummyCopyResult $result): void
|
private function rewriteReferences(DummyCopyResult $result): void
|
||||||
@@ -226,6 +285,245 @@ final class DummyCopier
|
|||||||
$params
|
$params
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($result->contentMap as $oldContentId => $newContentId) {
|
||||||
|
$sourceAliasTarget = (int) $this->connection->fetchOne(
|
||||||
|
'SELECT cteAlias FROM tl_content WHERE id = ? AND type = ?',
|
||||||
|
[$oldContentId, 'alias']
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($sourceAliasTarget < 1 || !isset($result->contentMap[$sourceAliasTarget])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->connection->update(
|
||||||
|
'tl_content',
|
||||||
|
['cteAlias' => $result->contentMap[$sourceAliasTarget]],
|
||||||
|
['id' => $newContentId, 'type' => 'alias']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function rewriteModuleArchiveReferences(DummyCopyResult $result): void
|
||||||
|
{
|
||||||
|
if ($result->moduleMap === []) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($result->moduleMap as $newModuleId) {
|
||||||
|
$row = $this->fetchRow('tl_module', $newModuleId);
|
||||||
|
|
||||||
|
if ($row === null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$updates = [];
|
||||||
|
|
||||||
|
if (array_key_exists('news_archives', $row) && $result->newsArchiveMap !== []) {
|
||||||
|
$updates['news_archives'] = $this->remapSerializedIds((string) ($row['news_archives'] ?? ''), $result->newsArchiveMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array_key_exists('cal_calendar', $row) && $result->calendarMap !== []) {
|
||||||
|
$updates['cal_calendar'] = $this->remapSerializedIds((string) ($row['cal_calendar'] ?? ''), $result->calendarMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array_key_exists('news_readerModule', $row)) {
|
||||||
|
$oldReaderModuleId = (int) ($row['news_readerModule'] ?? 0);
|
||||||
|
|
||||||
|
if ($oldReaderModuleId > 0 && isset($result->moduleMap[$oldReaderModuleId])) {
|
||||||
|
$updates['news_readerModule'] = $result->moduleMap[$oldReaderModuleId];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (array_key_exists('cal_readerModule', $row)) {
|
||||||
|
$oldReaderModuleId = (int) ($row['cal_readerModule'] ?? 0);
|
||||||
|
|
||||||
|
if ($oldReaderModuleId > 0 && isset($result->moduleMap[$oldReaderModuleId])) {
|
||||||
|
$updates['cal_readerModule'] = $result->moduleMap[$oldReaderModuleId];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($updates !== []) {
|
||||||
|
$updates['tstamp'] = time();
|
||||||
|
$this->connection->update('tl_module', $updates, ['id' => $newModuleId]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->rewriteNewsItemReferences($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function rewriteNewsItemReferences(DummyCopyResult $result): void
|
||||||
|
{
|
||||||
|
if ($result->newsItemMap === []) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($result->newsItemMap as $oldNewsId => $newNewsId) {
|
||||||
|
$sourceRow = $this->fetchRow('tl_news', $oldNewsId);
|
||||||
|
|
||||||
|
if ($sourceRow === null || !array_key_exists('related', $sourceRow)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$related = StringUtil::deserialize((string) ($sourceRow['related'] ?? ''), true);
|
||||||
|
|
||||||
|
if ($related === []) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$mappedRelated = [];
|
||||||
|
|
||||||
|
foreach ($related as $relatedIdValue) {
|
||||||
|
$relatedId = (int) $relatedIdValue;
|
||||||
|
|
||||||
|
if ($relatedId < 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$mappedRelated[] = (string) ($result->newsItemMap[$relatedId] ?? $relatedId);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->connection->update(
|
||||||
|
'tl_news',
|
||||||
|
[
|
||||||
|
'related' => StringUtil::serialize($mappedRelated),
|
||||||
|
'tstamp' => time(),
|
||||||
|
],
|
||||||
|
['id' => $newNewsId]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int> $sourceArchiveIds
|
||||||
|
*
|
||||||
|
* @return array<int,int>
|
||||||
|
*/
|
||||||
|
private function copyNewsArchives(array $sourceArchiveIds, string $prefix, DummyCopyResult $result): array
|
||||||
|
{
|
||||||
|
$map = [];
|
||||||
|
|
||||||
|
foreach ($sourceArchiveIds as $sourceArchiveId) {
|
||||||
|
$archiveRow = $this->fetchRow('tl_news_archive', (int) $sourceArchiveId);
|
||||||
|
|
||||||
|
if ($archiveRow === null) {
|
||||||
|
$result->addNote(sprintf('Newsarchiv %d nicht gefunden, wurde uebersprungen.', $sourceArchiveId));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($archiveRow['id']);
|
||||||
|
$archiveRow['tstamp'] = time();
|
||||||
|
|
||||||
|
if (isset($archiveRow['title'])) {
|
||||||
|
$archiveRow['title'] = $this->prefixed((string) $archiveRow['title'], $prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($archiveRow['jumpTo']) && isset($result->pageMap[(int) $archiveRow['jumpTo']])) {
|
||||||
|
$archiveRow['jumpTo'] = $result->pageMap[(int) $archiveRow['jumpTo']];
|
||||||
|
}
|
||||||
|
|
||||||
|
$newArchiveId = $this->insertRow('tl_news_archive', $archiveRow);
|
||||||
|
$map[(int) $sourceArchiveId] = $newArchiveId;
|
||||||
|
$result->copiedNewsArchives++;
|
||||||
|
|
||||||
|
$newsIds = $this->connection->fetchFirstColumn('SELECT id FROM tl_news WHERE pid = ? ORDER BY date, id', [(int) $sourceArchiveId]);
|
||||||
|
|
||||||
|
foreach ($newsIds as $newsId) {
|
||||||
|
$newsRow = $this->fetchRow('tl_news', (int) $newsId);
|
||||||
|
|
||||||
|
if ($newsRow === null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($newsRow['id']);
|
||||||
|
$newsRow['pid'] = $newArchiveId;
|
||||||
|
$newsRow['tstamp'] = time();
|
||||||
|
|
||||||
|
if (isset($newsRow['headline'])) {
|
||||||
|
$newsRow['headline'] = $this->prefixed((string) $newsRow['headline'], $prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($newsRow['alias']) && trim((string) $newsRow['alias']) !== '') {
|
||||||
|
$newsRow['alias'] = $this->makeUniqueAliasInTable('tl_news', $this->prefixed((string) $newsRow['alias'], $prefix));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($newsRow['jumpTo']) && isset($result->pageMap[(int) $newsRow['jumpTo']])) {
|
||||||
|
$newsRow['jumpTo'] = $result->pageMap[(int) $newsRow['jumpTo']];
|
||||||
|
}
|
||||||
|
|
||||||
|
$newNewsId = $this->insertRow('tl_news', $newsRow);
|
||||||
|
$result->newsItemMap[(int) $newsId] = $newNewsId;
|
||||||
|
$result->copiedNewsItems++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $map;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int> $sourceCalendarIds
|
||||||
|
*
|
||||||
|
* @return array<int,int>
|
||||||
|
*/
|
||||||
|
private function copyCalendars(array $sourceCalendarIds, string $prefix, DummyCopyResult $result): array
|
||||||
|
{
|
||||||
|
$map = [];
|
||||||
|
|
||||||
|
foreach ($sourceCalendarIds as $sourceCalendarId) {
|
||||||
|
$calendarRow = $this->fetchRow('tl_calendar', (int) $sourceCalendarId);
|
||||||
|
|
||||||
|
if ($calendarRow === null) {
|
||||||
|
$result->addNote(sprintf('Kalender %d nicht gefunden, wurde uebersprungen.', $sourceCalendarId));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($calendarRow['id']);
|
||||||
|
$calendarRow['tstamp'] = time();
|
||||||
|
|
||||||
|
if (isset($calendarRow['title'])) {
|
||||||
|
$calendarRow['title'] = $this->prefixed((string) $calendarRow['title'], $prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($calendarRow['jumpTo']) && isset($result->pageMap[(int) $calendarRow['jumpTo']])) {
|
||||||
|
$calendarRow['jumpTo'] = $result->pageMap[(int) $calendarRow['jumpTo']];
|
||||||
|
}
|
||||||
|
|
||||||
|
$newCalendarId = $this->insertRow('tl_calendar', $calendarRow);
|
||||||
|
$map[(int) $sourceCalendarId] = $newCalendarId;
|
||||||
|
$result->copiedCalendars++;
|
||||||
|
|
||||||
|
$eventIds = $this->connection->fetchFirstColumn('SELECT id FROM tl_calendar_events WHERE pid = ? ORDER BY startTime, id', [(int) $sourceCalendarId]);
|
||||||
|
|
||||||
|
foreach ($eventIds as $eventId) {
|
||||||
|
$eventRow = $this->fetchRow('tl_calendar_events', (int) $eventId);
|
||||||
|
|
||||||
|
if ($eventRow === null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
unset($eventRow['id']);
|
||||||
|
$eventRow['pid'] = $newCalendarId;
|
||||||
|
$eventRow['tstamp'] = time();
|
||||||
|
|
||||||
|
if (isset($eventRow['title'])) {
|
||||||
|
$eventRow['title'] = $this->prefixed((string) $eventRow['title'], $prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($eventRow['alias']) && trim((string) $eventRow['alias']) !== '') {
|
||||||
|
$eventRow['alias'] = $this->makeUniqueAliasInTable('tl_calendar_events', $this->prefixed((string) $eventRow['alias'], $prefix));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($eventRow['jumpTo']) && isset($result->pageMap[(int) $eventRow['jumpTo']])) {
|
||||||
|
$eventRow['jumpTo'] = $result->pageMap[(int) $eventRow['jumpTo']];
|
||||||
|
}
|
||||||
|
|
||||||
|
$newEventId = $this->insertRow('tl_calendar_events', $eventRow);
|
||||||
|
$result->eventMap[(int) $eventId] = $newEventId;
|
||||||
|
$result->copiedEvents++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $map;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function copyDirectories(DummyCopyOptions $options, DummyCopyResult $result): void
|
private function copyDirectories(DummyCopyOptions $options, DummyCopyResult $result): void
|
||||||
@@ -272,11 +570,16 @@ final class DummyCopier
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function makeUniqueAlias(string $baseAlias): string
|
private function makeUniqueAlias(string $baseAlias): string
|
||||||
|
{
|
||||||
|
return $this->makeUniqueAliasInTable('tl_page', $baseAlias);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function makeUniqueAliasInTable(string $table, string $baseAlias): string
|
||||||
{
|
{
|
||||||
$alias = $this->slugify($baseAlias);
|
$alias = $this->slugify($baseAlias);
|
||||||
$counter = 1;
|
$counter = 1;
|
||||||
|
|
||||||
while ((int) $this->connection->fetchOne('SELECT COUNT(*) FROM tl_page WHERE alias = ?', [$alias]) > 0) {
|
while ((int) $this->connection->fetchOne(sprintf('SELECT COUNT(*) FROM %s WHERE alias = ?', $table), [$alias]) > 0) {
|
||||||
$alias = $this->slugify($baseAlias) . '-' . $counter;
|
$alias = $this->slugify($baseAlias) . '-' . $counter;
|
||||||
$counter++;
|
$counter++;
|
||||||
}
|
}
|
||||||
@@ -326,9 +629,41 @@ final class DummyCopier
|
|||||||
return (int) $this->connection->fetchOne(sprintf('SELECT COUNT(*) FROM %s WHERE id IN (%s)', $table, $placeholders), $ids);
|
return (int) $this->connection->fetchOne(sprintf('SELECT COUNT(*) FROM %s WHERE id IN (%s)', $table, $placeholders), $ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function countByPid(string $table, string $pidField, array $pidValues): int
|
||||||
|
{
|
||||||
|
if ($pidValues === []) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$placeholders = implode(',', array_fill(0, \count($pidValues), '?'));
|
||||||
|
|
||||||
|
return (int) $this->connection->fetchOne(sprintf('SELECT COUNT(*) FROM %s WHERE %s IN (%s)', $table, $pidField, $placeholders), $pidValues);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<int,int> $idMap
|
||||||
|
*/
|
||||||
|
private function remapSerializedIds(string $serialized, array $idMap): string
|
||||||
|
{
|
||||||
|
$values = StringUtil::deserialize($serialized, true);
|
||||||
|
$mapped = [];
|
||||||
|
|
||||||
|
foreach ($values as $value) {
|
||||||
|
$id = (int) $value;
|
||||||
|
|
||||||
|
if ($id < 1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$mapped[] = (string) ($idMap[$id] ?? $id);
|
||||||
|
}
|
||||||
|
|
||||||
|
return StringUtil::serialize($mapped);
|
||||||
|
}
|
||||||
|
|
||||||
private function estimateContentCount(DummyCopyOptions $options): int
|
private function estimateContentCount(DummyCopyOptions $options): int
|
||||||
{
|
{
|
||||||
$count = \count($options->sourceContentIds);
|
$count = $this->countContentTree(array_map('intval', $options->sourceContentIds));
|
||||||
|
|
||||||
if (!$options->includeContent || $options->sourcePageIds === []) {
|
if (!$options->includeContent || $options->sourcePageIds === []) {
|
||||||
return $count;
|
return $count;
|
||||||
@@ -342,10 +677,55 @@ final class DummyCopier
|
|||||||
}
|
}
|
||||||
|
|
||||||
$articlePlaceholders = implode(',', array_fill(0, \count($articleIds), '?'));
|
$articlePlaceholders = implode(',', array_fill(0, \count($articleIds), '?'));
|
||||||
|
$rootContentIds = $this->connection->fetchFirstColumn(
|
||||||
return $count + (int) $this->connection->fetchOne(
|
sprintf('SELECT id FROM tl_content WHERE ptable = ? AND pid IN (%s)', $articlePlaceholders),
|
||||||
sprintf('SELECT COUNT(*) FROM tl_content WHERE ptable = ? AND pid IN (%s)', $articlePlaceholders),
|
|
||||||
array_merge(['tl_article'], array_map('intval', $articleIds))
|
array_merge(['tl_article'], array_map('intval', $articleIds))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($rootContentIds === []) {
|
||||||
|
return $count;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $count + $this->countContentTree(array_map('intval', $rootContentIds));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Counts content roots and all nested descendants.
|
||||||
|
*
|
||||||
|
* @param array<int,int> $rootIds
|
||||||
|
*/
|
||||||
|
private function countContentTree(array $rootIds): int
|
||||||
|
{
|
||||||
|
if ($rootIds === []) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$seen = [];
|
||||||
|
$queue = array_values(array_filter($rootIds, static fn (int $id): bool => $id > 0));
|
||||||
|
|
||||||
|
while ($queue !== []) {
|
||||||
|
$currentBatch = [];
|
||||||
|
|
||||||
|
foreach ($queue as $id) {
|
||||||
|
if (!isset($seen[$id])) {
|
||||||
|
$seen[$id] = true;
|
||||||
|
$currentBatch[] = $id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($currentBatch === []) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$placeholders = implode(',', array_fill(0, \count($currentBatch), '?'));
|
||||||
|
$children = $this->connection->fetchFirstColumn(
|
||||||
|
sprintf('SELECT id FROM tl_content WHERE ptable = ? AND pid IN (%s)', $placeholders),
|
||||||
|
array_merge(['tl_content'], $currentBatch)
|
||||||
|
);
|
||||||
|
|
||||||
|
$queue = array_map('intval', $children);
|
||||||
|
}
|
||||||
|
|
||||||
|
return \count($seen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ final class DummyCopyOptions
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
public readonly array $sourcePageIds,
|
public readonly array $sourcePageIds,
|
||||||
public readonly array $sourceModuleIds,
|
public readonly array $sourceModuleIds,
|
||||||
|
public readonly array $sourceNewsArchiveIds,
|
||||||
|
public readonly array $sourceCalendarIds,
|
||||||
public readonly array $sourceContentIds,
|
public readonly array $sourceContentIds,
|
||||||
public readonly array $sourceDirectories,
|
public readonly array $sourceDirectories,
|
||||||
public readonly int $targetParentPageId,
|
public readonly int $targetParentPageId,
|
||||||
|
|||||||
@@ -10,6 +10,10 @@ final class DummyCopyResult
|
|||||||
public int $copiedModules = 0;
|
public int $copiedModules = 0;
|
||||||
public int $copiedContent = 0;
|
public int $copiedContent = 0;
|
||||||
public int $copiedDirectories = 0;
|
public int $copiedDirectories = 0;
|
||||||
|
public int $copiedNewsArchives = 0;
|
||||||
|
public int $copiedNewsItems = 0;
|
||||||
|
public int $copiedCalendars = 0;
|
||||||
|
public int $copiedEvents = 0;
|
||||||
|
|
||||||
/** @var array<int,int> */
|
/** @var array<int,int> */
|
||||||
public array $pageMap = [];
|
public array $pageMap = [];
|
||||||
@@ -17,6 +21,21 @@ final class DummyCopyResult
|
|||||||
/** @var array<int,int> */
|
/** @var array<int,int> */
|
||||||
public array $moduleMap = [];
|
public array $moduleMap = [];
|
||||||
|
|
||||||
|
/** @var array<int,int> */
|
||||||
|
public array $contentMap = [];
|
||||||
|
|
||||||
|
/** @var array<int,int> */
|
||||||
|
public array $newsArchiveMap = [];
|
||||||
|
|
||||||
|
/** @var array<int,int> */
|
||||||
|
public array $calendarMap = [];
|
||||||
|
|
||||||
|
/** @var array<int,int> */
|
||||||
|
public array $newsItemMap = [];
|
||||||
|
|
||||||
|
/** @var array<int,int> */
|
||||||
|
public array $eventMap = [];
|
||||||
|
|
||||||
/** @var array<string> */
|
/** @var array<string> */
|
||||||
public array $notes = [];
|
public array $notes = [];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user