Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f244d1f52a | |||
| 2e09acdc00 | |||
| 461c80d75d | |||
| c361999ea8 | |||
| 0617f19c28 |
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.
|
||||||
|
|||||||
@@ -11,10 +11,10 @@
|
|||||||
"migration",
|
"migration",
|
||||||
"cloner"
|
"cloner"
|
||||||
],
|
],
|
||||||
"homepage": "https://git.file-archive.de/webfarben/DummyCopier",
|
"homepage": "https://github.com/webfarben/DummyCopier",
|
||||||
"support": {
|
"support": {
|
||||||
"source": "https://git.file-archive.de/webfarben/DummyCopier",
|
"source": "https://github.com/webfarben/DummyCopier",
|
||||||
"issues": "https://git.file-archive.de/webfarben/DummyCopier/issues"
|
"issues": "https://github.com/webfarben/DummyCopier/issues"
|
||||||
},
|
},
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -164,6 +164,8 @@
|
|||||||
'moduleMap' => $this->result->moduleMap,
|
'moduleMap' => $this->result->moduleMap,
|
||||||
'newsArchiveMap' => $this->result->newsArchiveMap,
|
'newsArchiveMap' => $this->result->newsArchiveMap,
|
||||||
'calendarMap' => $this->result->calendarMap,
|
'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), ENT_QUOTES, 'UTF-8'); ?></pre>
|
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), ENT_QUOTES, 'UTF-8'); ?></pre>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|||||||
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 |
@@ -327,11 +327,71 @@ final class DummyCopier
|
|||||||
$updates['cal_calendar'] = $this->remapSerializedIds((string) ($row['cal_calendar'] ?? ''), $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 !== []) {
|
if ($updates !== []) {
|
||||||
$updates['tstamp'] = time();
|
$updates['tstamp'] = time();
|
||||||
$this->connection->update('tl_module', $updates, ['id' => $newModuleId]);
|
$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]
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -366,7 +426,7 @@ final class DummyCopier
|
|||||||
$map[(int) $sourceArchiveId] = $newArchiveId;
|
$map[(int) $sourceArchiveId] = $newArchiveId;
|
||||||
$result->copiedNewsArchives++;
|
$result->copiedNewsArchives++;
|
||||||
|
|
||||||
$newsIds = $this->connection->fetchFirstColumn('SELECT id FROM tl_news WHERE pid = ? ORDER BY date, sorting, id', [(int) $sourceArchiveId]);
|
$newsIds = $this->connection->fetchFirstColumn('SELECT id FROM tl_news WHERE pid = ? ORDER BY date, id', [(int) $sourceArchiveId]);
|
||||||
|
|
||||||
foreach ($newsIds as $newsId) {
|
foreach ($newsIds as $newsId) {
|
||||||
$newsRow = $this->fetchRow('tl_news', (int) $newsId);
|
$newsRow = $this->fetchRow('tl_news', (int) $newsId);
|
||||||
@@ -391,7 +451,8 @@ final class DummyCopier
|
|||||||
$newsRow['jumpTo'] = $result->pageMap[(int) $newsRow['jumpTo']];
|
$newsRow['jumpTo'] = $result->pageMap[(int) $newsRow['jumpTo']];
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->insertRow('tl_news', $newsRow);
|
$newNewsId = $this->insertRow('tl_news', $newsRow);
|
||||||
|
$result->newsItemMap[(int) $newsId] = $newNewsId;
|
||||||
$result->copiedNewsItems++;
|
$result->copiedNewsItems++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -431,7 +492,7 @@ final class DummyCopier
|
|||||||
$map[(int) $sourceCalendarId] = $newCalendarId;
|
$map[(int) $sourceCalendarId] = $newCalendarId;
|
||||||
$result->copiedCalendars++;
|
$result->copiedCalendars++;
|
||||||
|
|
||||||
$eventIds = $this->connection->fetchFirstColumn('SELECT id FROM tl_calendar_events WHERE pid = ? ORDER BY startTime, sorting, id', [(int) $sourceCalendarId]);
|
$eventIds = $this->connection->fetchFirstColumn('SELECT id FROM tl_calendar_events WHERE pid = ? ORDER BY startTime, id', [(int) $sourceCalendarId]);
|
||||||
|
|
||||||
foreach ($eventIds as $eventId) {
|
foreach ($eventIds as $eventId) {
|
||||||
$eventRow = $this->fetchRow('tl_calendar_events', (int) $eventId);
|
$eventRow = $this->fetchRow('tl_calendar_events', (int) $eventId);
|
||||||
@@ -456,7 +517,8 @@ final class DummyCopier
|
|||||||
$eventRow['jumpTo'] = $result->pageMap[(int) $eventRow['jumpTo']];
|
$eventRow['jumpTo'] = $result->pageMap[(int) $eventRow['jumpTo']];
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->insertRow('tl_calendar_events', $eventRow);
|
$newEventId = $this->insertRow('tl_calendar_events', $eventRow);
|
||||||
|
$result->eventMap[(int) $eventId] = $newEventId;
|
||||||
$result->copiedEvents++;
|
$result->copiedEvents++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,12 @@ final class DummyCopyResult
|
|||||||
/** @var array<int,int> */
|
/** @var array<int,int> */
|
||||||
public array $calendarMap = [];
|
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