Skip to content

Commit

Permalink
Fix: Section order duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
Rom1-B authored and btry committed Aug 30, 2024
1 parent ed147ef commit eefab6b
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions inc/section.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ public function duplicate(array $options = []) {
public function moveUp() {
global $DB;

$this->fixOrder();

$order = $this->fields['order'];
$formId = $this->fields['plugin_formcreator_forms_id'];
$otherItem = new static();
Expand Down Expand Up @@ -313,6 +315,8 @@ public function moveUp() {
public function moveDown() {
global $DB;

$this->fixOrder();

$order = $this->fields['order'];
$formId = $this->fields['plugin_formcreator_forms_id'];
$otherItem = new static();
Expand Down Expand Up @@ -349,6 +353,34 @@ public function moveDown() {
return $success;
}

public function fixOrder(): void
{
global $DB;

$formId = $this->fields['plugin_formcreator_forms_id'];

$iterator = $DB->request([
'FROM' => static::getTable(),
'WHERE' => [
'AND' => [
'plugin_formcreator_forms_id' => $formId,
]
],
'ORDER' => ['order ASC']
]);
$order = 1;
foreach ($iterator as $row) {
if ($row['order'] !== $order) {
$DB->update(static::getTable(), [
'order' => $order
], [
'id' => $row['id']
]);
}
$order++;
}
}

public static function import(PluginFormcreatorLinker $linker, $input = [], $containerId = 0) {
global $DB;

Expand Down

0 comments on commit eefab6b

Please sign in to comment.