Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement DBField validation #11403

Open
9 of 10 tasks
emteknetnz opened this issue Sep 26, 2024 · 7 comments
Open
9 of 10 tasks

Implement DBField validation #11403

emteknetnz opened this issue Sep 26, 2024 · 7 comments

Comments

@emteknetnz
Copy link
Member

emteknetnz commented Sep 26, 2024

Consolidate validation systems contained a POC that added DBField validation via a new shared FIeldsValidator class. We agreed that we should proceed with implementing this for CMS 6

Acceptance criteria

  • Technical approach taken in the POC is used
  • Change the double array config from the POC to instead allow options A), B) and C)
  • Types of validation that could be handled on FieldValidator's are identified, e.g. Email, URL, Int size, etc - note the existing data types
  • Existing FormField validate methods are updated to use FieldValidator's where possible Split off as new issue
  • Some new DB fields are created with validation e.g. DBEmail, DBUrl, DBIp
  • New DB fields are autoscaffold existing equivalent FormField if one exists e.g. EmailField, though DBIp would just be a TextField
  • New DBFields are listed in docs on the Data types page
  • DBField validation is mentioned in the developer docs
  • 6.0.0 changelog calls out that data will no longer be inserted and truncated if it exceeds varchar character lengths, etc, instead it will throw a validation exception
  • Discuss / make follow up cards for "things that we might want to consider changing" on the framework PR

New issues created

Kitchen sink CI CMS 6

CMS 5 PRs

CMS 6 PRs

@emteknetnz
Copy link
Member Author

emteknetnz commented Sep 30, 2024

FieldValidators


BooleanValidator

  • Validates that a value is either 1 or 0 - or true/false (gets converted before DB insert?)
  • Note that DBBoolean datatype is tinyint

DBFields

  • DBBoolean (extends FormField)

FormFields

  • CheckboxField

CompositeValidator

  • Calls validate() on child fields

DBFields

  • DBMoney (extends DBComposite)
  • DBPolymorphicForeignKey (extends DBComposite)

FormFields

  • MoneyField

EnumValidator

  • Validate the value is in an fixed set of value

DBFields

  • DBEnum (extends FormField)
  • DBMultiEnum (extends Enum)
  • DBClassName (extends Enum)
  • DBClassNameVarchar

FormFields

  • None

DecimalValidator

  • Validates a value is between minValue and maxValue with respect to the maximum size of the database column
  • Will need to be able to handle signed values (i.e. less than 0)
  • Should not validate number of decimal places, allow database to handle rounding to column precision

DBFields

  • DBDecimal (extends FormField)
  • DBPercentage (extends Decimal)
  • DBCurrency (extends Decimal)
  • DBFloat (extends FormField) too complicated
  • DBDouble (extends FormField) too complicated

FormFields

  • None

DateValidator

  • Validate a date is formatted using DBDate::ISO_DATE = 'y-MM-dd';

DBFields

  • DBDate (extends FormField)

FormFields

  • DateField

DateTimeValidator

  • Validate a datetime is formatted using public const ISO_DATETIME = 'y-MM-dd HH:mm:ss';

DBFields

  • DBDateTime (extends DBDate)

FormFields

  • DateTimeField

EmailValidator

  • Validates the string is a valid email

DBFields

  • DBEmail (extends DBVarchar) (new field)

FormFields

  • EmailField

IntValidator

  • Validates a value is between minValue and maxValue with respect to the maximum size of the database field
  • Will need to be able to handle signed values (i.e. less than 0)
  • Validate there is no decimal value

DBFields

  • DBInt (extends FormField)
  • DBBigInt (extends DBInt)
  • DBYear (extends FormField)
  • DBForiegnKey (extends DBInt)
  • DBPrimaryKey (extends DBInt)

FormFields

  • None

IpValidator

  • Validates the string is a valid IP address

DBFields

  • DBIp (extends DBVarchar) (new field)

FormFields

  • None

LocaleValidator (extends StringValidator)

  • Validate the string matches a standard locale pattern

DBFields

  • DBLocale (extends DBVarchar)

FormFields

  • None

StringValidator

  • Validate the length of the string is between minLength and maxLength

DBFields

  • DBVarchar (extends DBString)
  • DBText (extends DBString)
  • DBVarchar (extends DBString)
  • DBText (extends DBString)
  • DBClassName (extends DBVarchar)
  • DBHTMLFragment (class is DBHTMLText without shortcode parsing)
  • DBHTMLText (extends DBText) (with shortcode parsing)
  • DBHTMLVarchar (extends DBVarchar)

FormFields

  • TextField
  • TextareaField

TimeValidator

  • Validate a time is formatted using DBTime::ISO_TIME = 'HH:mm:ss';

DBFields

  • DBTime (extends FormField)

FormFields

  • TimeField

UrlValidator

  • Validates the string is a valid url

DBFields

  • DBUrl (extends DBVarchar) (new field)

FormFields

  • UrlField

@GuySartorelli
Copy link
Member

@emteknetnz Don't forget to do a CMS 5 changelog PR for the deprecations.

@GuySartorelli
Copy link
Member

@emteknetnz I can't test these PRs because they need to be rebased after the recent template work got merged in.
Can you please rebase the PRs?

@emteknetnz
Copy link
Member Author

Has been done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants