78 $dd = dbxContentLng::ddContent((
string)
$lng);
80 $rows =
$db->select(
$dd,
'',
'id,permalink',
'id',
'ASC',
'', 0, 0, 0);
81 if (!is_array(
$rows)) {
87 foreach (
$rows as $row) {
88 $id = (int)($row[
'id'] ?? 0);
89 $old = trim((
string)($row[
'permalink'] ??
''));
90 $legacyKey = strtolower(trim(str_replace(
'\\',
'/', $old),
'/'));
91 if (dbxContent_permalink::isValid($old)) {
96 $candidate = dbxContent_permalink::canonicalFromLegacy($old);
98 if ($candidate ===
'') {
99 $candidate =
'seite-' . $id;
102 $baseCandidate = $candidate;
104 while (isset($used[$candidate]) && $used[$candidate] !== $id) {
105 $suffix =
'-' . $number;
106 $candidate = rtrim(substr($baseCandidate, 0, 254 - strlen($suffix)),
'-') . $suffix;
109 if (!dbxContent_permalink::isValid($candidate)) {
110 throw new RuntimeException(
"Migration erzeugt ungueltigen Permalink {$candidate} fuer {$table}#{$id}.");
112 $used[$candidate] = $id;
114 if ($candidate !== $old) {
115 if (
$db->update(
$dd, array(
'permalink' => $candidate), $id, 0) !== 1) {
116 throw new RuntimeException(
"Permalink konnte nicht aktualisiert werden: {$table}#{$id}.");
118 $changes[$old] = $candidate;
123 if ($changes !== array()) {
124 uksort($changes,
static function(
string $left,
string $right):
int {
125 return strlen($right) <=> strlen($left);
127 $contentRows =
$db->select(
$dd,
'',
'id,content',
'id',
'ASC',
'', 0, 0, 0);
128 foreach ((is_array($contentRows) ? $contentRows : array()) as $contentRow) {
129 $before = (string)($contentRow[
'content'] ??
'');
130 if ($before ===
'') {
133 $after = str_replace(array_keys($changes), array_values($changes), $before);
135 if (
$db->update(
$dd, array(
'content' =>
$after), (
int)$contentRow[
'id'], 0) !== 1) {
136 throw new RuntimeException(
"Content-Links konnten nicht aktualisiert werden: {$table}#{$contentRow['id']}.");
143 $result[
'tables'][
$table] = array(
'rows' => count(
$rows),
'changed' => count($changes));
147 throw new RuntimeException(
'Transaktion konnte nicht abgeschlossen werden.');
149}
catch (Throwable $e) {
151 fwrite(STDERR, $e->getMessage() .
"\nBackup: {$backupFile}\n");