processwire-requests
processwire-requests copied to clipboard
Can $hasTags include a database column check?
Short description of the enhancement
When creating fields programmatically that use the tags feature (FieldtypeImage, FieldtypeFile) for some reason the schema database update doesn't seem to check whether the column actually exists in the field table or not.
This shows up when trying to create a field in RockMigrations where the 'useTags' setting > 0.
The issue is that the correct SQL appears in the schema when you return
$fieldtypes->FiletypeFile->getDatabaseSchema
but the updateDatabaseSchema call that follows seems to detect that the table already has tags
via:
https://github.com/processwire/processwire/blob/3cc76cc886a49313b4bfb9a1a904bd88d11b7cb7/wire/modules/Fieldtype/FieldtypeFile/FieldtypeFile.module#L1164
and so the structure of the table is not altered.
When you try to access saved field data, the inputfield value throws an error because field_name.tags column doesn't exist.
Current vs. suggested behavior
I am thinking the $hasTags declaration perhaps needs another sanity check on the DB to be sure the tags column really exists if it is defined in the schema?
Why would the enhancement be useful to users?
This would allow modules like RockMigrations to create fields with the useTags option (Image and File). Right now this is not possible simply by includes 'useTags' => 1 in the field settings array.