Skip to content

Commit eefab6b

Browse files
Rom1-Bbtry
authored andcommitted
Fix: Section order duplicates
1 parent ed147ef commit eefab6b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

inc/section.class.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,8 @@ public function duplicate(array $options = []) {
270270
public function moveUp() {
271271
global $DB;
272272

273+
$this->fixOrder();
274+
273275
$order = $this->fields['order'];
274276
$formId = $this->fields['plugin_formcreator_forms_id'];
275277
$otherItem = new static();
@@ -313,6 +315,8 @@ public function moveUp() {
313315
public function moveDown() {
314316
global $DB;
315317

318+
$this->fixOrder();
319+
316320
$order = $this->fields['order'];
317321
$formId = $this->fields['plugin_formcreator_forms_id'];
318322
$otherItem = new static();
@@ -349,6 +353,34 @@ public function moveDown() {
349353
return $success;
350354
}
351355

356+
public function fixOrder(): void
357+
{
358+
global $DB;
359+
360+
$formId = $this->fields['plugin_formcreator_forms_id'];
361+
362+
$iterator = $DB->request([
363+
'FROM' => static::getTable(),
364+
'WHERE' => [
365+
'AND' => [
366+
'plugin_formcreator_forms_id' => $formId,
367+
]
368+
],
369+
'ORDER' => ['order ASC']
370+
]);
371+
$order = 1;
372+
foreach ($iterator as $row) {
373+
if ($row['order'] !== $order) {
374+
$DB->update(static::getTable(), [
375+
'order' => $order
376+
], [
377+
'id' => $row['id']
378+
]);
379+
}
380+
$order++;
381+
}
382+
}
383+
352384
public static function import(PluginFormcreatorLinker $linker, $input = [], $containerId = 0) {
353385
global $DB;
354386

0 commit comments

Comments
 (0)