Files
animal_management/migrations/m260402_040000_add_image_profile_fields.php
2026-04-04 13:13:00 -04:00

62 lines
1.8 KiB
PHP

<?php
use humhub\components\Migration;
class m260402_040000_add_image_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 = [
['cover_image_url', 'Cover image URL', 230],
['profile_image_url', 'Profile image URL', 240],
];
foreach ($rows as $row) {
[$fieldKey, $label, $sortOrder] = $row;
$exists = (new \yii\db\Query())
->from('rescue_field_definition')
->where(['module_id' => 'animal_management', 'field_key' => $fieldKey])
->exists($this->db);
if ($exists) {
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' => 0,
'is_active' => 1,
'visibility' => 'public',
'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->delete('rescue_field_definition', [
'module_id' => 'animal_management',
'field_key' => ['cover_image_url', 'profile_image_url'],
'is_core' => 0,
]);
}
}