Set the minimum value of maturity_days and transplant_days to 1.

This commit is contained in:
Michael Stenta 2024-02-21 08:46:54 -05:00
parent 78e1aad0d5
commit ff89fb7a34
4 changed files with 44 additions and 2 deletions

View File

@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Changed
- [Set the minimum value of maturity_days and transplant_days to 1 #794](https://github.com/farmOS/farmOS/pull/794)
### Fixed
- [Check for correct update operation access in location hierarchy form #800](https://github.com/farmOS/farmOS/pull/800)

View File

@ -18,7 +18,7 @@ translatable: false
default_value: { }
default_value_callback: ''
settings:
min: null
min: 1
max: null
prefix: ''
suffix: ' day| days'

View File

@ -18,7 +18,7 @@ translatable: false
default_value: { }
default_value_callback: ''
settings:
min: null
min: 1
max: null
prefix: ''
suffix: ' day| days'

View File

@ -0,0 +1,38 @@
<?php
/**
* @file
* Post update hooks for the farm_plant_type module.
*/
use Drupal\field\Entity\FieldConfig;
/**
* Set the minimum value of maturity_days and transplant_days to 1.
*/
function farm_plant_type_post_update_min_1_day(&$sandbox) {
// Set the min setting of both fields to 1.
$field_names = [
'maturity_days',
'transplant_days',
];
foreach ($field_names as $field_name) {
$field = FieldConfig::load('taxonomy_term.plant_type.' . $field_name);
if (!empty($field)) {
$field->setSetting('min', 1);
$field->save();
}
}
// Delete any zero values from the database.
$tables = [
'taxonomy_term__maturity_days' => 'maturity_days_value',
'taxonomy_term__transplant_days' => 'transplant_days_value',
'taxonomy_term_revision__maturity_days' => 'maturity_days_value',
'taxonomy_term_revision__transplant_days' => 'transplant_days_value',
];
foreach ($tables as $table => $column) {
\Drupal::database()->query('DELETE FROM {' . $table . '} WHERE ' . $column . ' = 0');
}
}