-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EnumField: propertyName to use the identifier provided in the form (n…
…o more prefix) The migration adjust existing form so the new identifier is the previously calculated one
- Loading branch information
Showing
5 changed files
with
39 additions
and
14 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
includes/migrations/20240621202127_RefactorEnumFieldPropertyName.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
use YesWiki\Bazar\Field\EnumField; | ||
use YesWiki\Bazar\Service\FieldFactory; | ||
use YesWiki\Bazar\Service\FormManager; | ||
use YesWiki\Core\YesWikiMigration; | ||
|
||
class RefactorEnumFieldPropertyName extends YesWikiMigration | ||
{ | ||
public function run() | ||
{ | ||
$formManager = $this->getService(FormManager::class); | ||
$fieldFactory = $this->getService(FieldFactory::class); | ||
$forms = $formManager->getAll(); | ||
foreach ($forms as $form) { | ||
$newTemplate = []; | ||
foreach ($form['template'] as $fieldArray) { | ||
$field = $fieldFactory->create($fieldArray); | ||
if ($field instanceof EnumField) { | ||
$fieldArray[EnumField::FIELD_NAME] = $field->getType() . $field->getLinkedObjectName() . $field->getName(); | ||
} | ||
$newTemplate[] = $fieldArray; | ||
} | ||
$form['bn_template'] = $formManager->encodeTemplate($newTemplate); | ||
$formManager->update($form); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters