diff --git a/src/CoreBundle/DataFixtures/ExtraFieldFixtures.php b/src/CoreBundle/DataFixtures/ExtraFieldFixtures.php index 434e69530ae..37e7964f9dc 100644 --- a/src/CoreBundle/DataFixtures/ExtraFieldFixtures.php +++ b/src/CoreBundle/DataFixtures/ExtraFieldFixtures.php @@ -417,8 +417,9 @@ public static function getExtraFields(): array 'display_text' => 'My terms', 'item_type' => ExtraField::USER_FIELD_TYPE, 'value_type' => ExtraField::FIELD_TYPE_TEXT, - 'visible_to_self' => true, - 'changeable' => true, + 'visible_to_self' => false, + 'visible_to_others' => false, + 'changeable' => false, ], [ 'variable' => 'new_tracking_system', @@ -563,9 +564,9 @@ public static function getExtraFields(): array : (\defined(ExtraField::class.'::FIELD_TYPE_GEOLOCATION') ? ExtraField::FIELD_TYPE_GEOLOCATION : ExtraField::FIELD_TYPE_TEXT), - 'visible_to_self' => true, - 'visible_to_others' => true, - 'changeable' => true, + 'visible_to_self' => false, + 'visible_to_others' => false, + 'changeable' => false, ], [ 'variable' => 'timezone', @@ -596,9 +597,9 @@ public static function getExtraFields(): array : (\defined(ExtraField::class.'::FIELD_TYPE_GEOLOCATION') ? ExtraField::FIELD_TYPE_GEOLOCATION : ExtraField::FIELD_TYPE_TEXT), - 'visible_to_self' => true, - 'visible_to_others' => true, - 'changeable' => true, + 'visible_to_self' => false, + 'visible_to_others' => false, + 'changeable' => false, ], [ 'variable' => 'time', diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20240416110300.php b/src/CoreBundle/Migrations/Schema/V200/Version20240416110300.php index 31f9947949a..624eea9994e 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20240416110300.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20240416110300.php @@ -22,6 +22,8 @@ public function up(Schema $schema): void { $extraFields = ExtraFieldFixtures::getExtraFields(); + $protectedFlagsVars = ['my_terms', 'terms_ville', 'terms_villedustage']; + foreach ($extraFields as $field) { $existingField = $this->connection->executeQuery( 'SELECT * FROM extra_field WHERE variable = :variable AND item_type = :item_type', @@ -34,25 +36,45 @@ public function up(Schema $schema): void if (!$existingField) { // Insert new field if it does not exist $this->connection->insert('extra_field', [ - 'item_type' => $field['item_type'], - 'value_type' => $field['value_type'], - 'variable' => $field['variable'], - 'display_text' => $field['display_text'], - 'visible_to_self' => isset($field['visible_to_self']) ? (int) $field['visible_to_self'] : 0, - 'visible_to_others' => isset($field['visible_to_others']) ? (int) $field['visible_to_others'] : 0, - 'changeable' => isset($field['changeable']) ? (int) $field['changeable'] : 0, - 'filter' => isset($field['filter']) ? (int) $field['filter'] : 0, - 'created_at' => (new DateTime())->format('Y-m-d H:i:s'), + 'item_type' => $field['item_type'], + 'value_type' => $field['value_type'], + 'variable' => $field['variable'], + 'display_text' => $field['display_text'], + 'visible_to_self' => isset($field['visible_to_self']) ? (int) $field['visible_to_self'] : 0, + 'visible_to_others'=> isset($field['visible_to_others'])? (int) $field['visible_to_others']: 0, + 'changeable' => isset($field['changeable']) ? (int) $field['changeable'] : 0, + 'filter' => isset($field['filter']) ? (int) $field['filter'] : 0, + 'created_at' => (new \DateTime())->format('Y-m-d H:i:s'), ]); - } else { - // Update existing field - $this->connection->update('extra_field', [ - 'display_text' => $field['display_text'], - 'visible_to_self' => isset($field['visible_to_self']) ? (int) $field['visible_to_self'] : 0, - 'visible_to_others' => isset($field['visible_to_others']) ? (int) $field['visible_to_others'] : 0, - 'changeable' => isset($field['changeable']) ? (int) $field['changeable'] : 0, - 'filter' => isset($field['filter']) ? (int) $field['filter'] : 0, - ], [ + continue; + } + + $updateData = [ + 'display_text' => $field['display_text'], + ]; + + if (isset($field['filter'])) { + $updateData['filter'] = (int) $field['filter']; + } + + if (isset($field['value_type']) && (int)$existingField['value_type'] !== (int)$field['value_type']) { + $updateData['value_type'] = (int)$field['value_type']; + } + + if (!in_array($field['variable'], $protectedFlagsVars, true)) { + if (array_key_exists('visible_to_self', $field)) { + $updateData['visible_to_self'] = (int) $field['visible_to_self']; + } + if (array_key_exists('visible_to_others', $field)) { + $updateData['visible_to_others'] = (int) $field['visible_to_others']; + } + if (array_key_exists('changeable', $field)) { + $updateData['changeable'] = (int) $field['changeable']; + } + } + + if (!empty($updateData)) { + $this->connection->update('extra_field', $updateData, [ 'id' => $existingField['id'], ]); }