Skip to content

Commit

Permalink
Merge branch 'master' of github.com:/Intermesh/groupoffice
Browse files Browse the repository at this point in the history
  • Loading branch information
derjoachim committed Nov 18, 2024
2 parents e3a6c9c + 77a2aec commit 7dbeaf6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
- Various: route to main grid when details resets / is deleted for mobile view
- Privacy settings: several bug fixes in addressbook overrides
- projects2: automatically convert old project_templates_events to tasks
- Collabora: Added lang variable for collabora
- Finance: Migration checks if all custom fields are available

11-11-2024: 6.8.85
- Billing: Fixed undefined index 'sort'
Expand Down
34 changes: 19 additions & 15 deletions www/go/core/model/FieldSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,34 +174,38 @@ public static function migrateCustomFields(string $fromEntityCls, string $toEnti
$fromEntityType = $fromEntityCls::entityType();
$toEntityType = $toEntityCls::entityType();

$count = \go\core\model\FieldSet::findByEntity($toEntityType->getName())->selectSingleValue("count(*)")->single();
if($count) {
echo "Custom fields for ". $toEntityType->getName()." already migrated\n";

return false;
}

echo "Migrating entity " . $toEntityType->getName() ."\n";

$fieldSets = \go\core\model\FieldSet::findByEntity($fromEntityType->getName());

foreach($fieldSets as $fieldSet) {

echo "Migrating fieldset " . $fieldSet->name . " (". $fieldSet->id .")\n";
$newFieldSet = $fieldSet->copy();
$newFieldSet->setEntity($toEntityType->getName());
if(!$newFieldSet->save()) {
throw new \go\core\orm\exception\SaveException($newFieldSet);

$newFieldSet = FieldSet::findByEntity($toEntityType->getName())->where(['name' => $fieldSet->name])->single();

if(!$newFieldSet) {
$newFieldSet = $fieldSet->copy();
$newFieldSet->setEntity($toEntityType->getName());
if (!$newFieldSet->save()) {
throw new \go\core\orm\exception\SaveException($newFieldSet);
}
}

echo $newFieldSet->id ."\n";

$fields = \go\core\model\Field::find()->where('fieldSetId', '=', $fieldSet->id);
foreach($fields as $field) {
$newField = $field->copy();
$newField->fieldSetId = $newFieldSet->id;
if(!$newField->save()) {
throw new \go\core\orm\exception\SaveException($newField);

// echo "Migrating field " . $field->databaseName . "\n";
$newField = \go\core\model\Field::find()->where('fieldSetId', '=', $newFieldSet->id)->where(['databaseName' => $field->databaseName])->single();

if(!$newField) {
$newField = $field->copy();
$newField->fieldSetId = $newFieldSet->id;
if (!$newField->save()) {
throw new \go\core\orm\exception\SaveException($newField);
}
}
}
}
Expand Down

0 comments on commit 7dbeaf6

Please sign in to comment.