80 lines
2.5 KiB
PHP
80 lines
2.5 KiB
PHP
<?php
|
|
|
|
use humhub\components\Migration;
|
|
|
|
class m260402_080000_add_display_override_profile_fields extends Migration
|
|
{
|
|
public function safeUp()
|
|
{
|
|
if ($this->db->getSchema()->getTableSchema('rescue_field_definition', true) === null) {
|
|
return;
|
|
}
|
|
|
|
$createdAt = date('Y-m-d H:i:s');
|
|
$rows = [
|
|
['tile_display_fields', 'Tile Display Fields', 250],
|
|
['hero_display_fields', 'Hero Display Fields', 251],
|
|
];
|
|
|
|
foreach ($rows as $row) {
|
|
[$fieldKey, $label, $sortOrder] = $row;
|
|
|
|
$existingId = (new \yii\db\Query())
|
|
->select('id')
|
|
->from('rescue_field_definition')
|
|
->where([
|
|
'module_id' => 'animal_management',
|
|
'group_key' => 'animal_profile',
|
|
'field_key' => $fieldKey,
|
|
])
|
|
->scalar($this->db);
|
|
|
|
if ($existingId) {
|
|
$this->update('rescue_field_definition', [
|
|
'label' => $label,
|
|
'input_type' => 'text',
|
|
'required' => 0,
|
|
'is_core' => 1,
|
|
'is_active' => 1,
|
|
'visibility' => 'internal',
|
|
'sort_order' => $sortOrder,
|
|
'updated_at' => $createdAt,
|
|
], ['id' => (int)$existingId]);
|
|
continue;
|
|
}
|
|
|
|
$this->insert('rescue_field_definition', [
|
|
'module_id' => 'animal_management',
|
|
'group_key' => 'animal_profile',
|
|
'field_key' => $fieldKey,
|
|
'label' => $label,
|
|
'input_type' => 'text',
|
|
'required' => 0,
|
|
'is_core' => 1,
|
|
'is_active' => 1,
|
|
'visibility' => 'internal',
|
|
'options' => '{}',
|
|
'sort_order' => $sortOrder,
|
|
'created_at' => $createdAt,
|
|
'updated_at' => $createdAt,
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function safeDown()
|
|
{
|
|
if ($this->db->getSchema()->getTableSchema('rescue_field_definition', true) === null) {
|
|
return;
|
|
}
|
|
|
|
$this->update('rescue_field_definition', [
|
|
'is_core' => 0,
|
|
'updated_at' => date('Y-m-d H:i:s'),
|
|
], [
|
|
'module_id' => 'animal_management',
|
|
'group_key' => 'animal_profile',
|
|
'field_key' => ['tile_display_fields', 'hero_display_fields'],
|
|
]);
|
|
}
|
|
}
|