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

Release/2.1.0 - WIP #119

Draft
wants to merge 39 commits into
base: master
Choose a base branch
from
Draft

Release/2.1.0 - WIP #119

wants to merge 39 commits into from

Conversation

JJJ
Copy link
Collaborator

@JJJ JJJ commented Aug 31, 2021

Work in progress!

JJJ and others added 29 commits August 30, 2021 21:24
* Fix return types in Query
* Docs: improvents recommended by phpstan-wordpress.

Props szepeviktor.

Co-authored-by: Viktor Szépe <[email protected]>
This change ensures that, going forward, this methods parameter signature better matches the other _item() methods.

This should be /relatively/ safe to do thanks to it being private. I've looked at all of the projects I'm aware of that use Berlin, and they are all uneffected.
This refactors the Table::create() SQL generator to explode an array of parts, which should make it easier to make more edits to later.
* Column: improvements to $pattern
* Always a string (no false)
* Add link to PHP docs
* Update description to remove "string replace"
* Set UUID to %s
* Base: prevent double prefixing in apply_prefix()
* Column: correct inline doc
* Column: rename private references from pattern to format.
* Autoloader: minor code cleanup
* Column: various improvements:
* Tons of inline & block docs
* Smarter default class values
* Column::args are saved during parse_args() for later reuse
* Prefer get_object_vars() over another array of args
* Add "extra" support to special_args()
* Add is_ methods for some other types
* Add is_extra() method for comparing extra values
* Add sanitize_extra() for allowing specific values
* Improve fallback support in sanitize_pattern()
* Improve fallback support in sanitize_validation()
* Remove function_exists check for gmdate() from validate_datetime()
* Legitimize validate_numeric() and use where appropriate
* Improve get_create_string() with support for binary, more types, null, etc...
* Base: introduce sanitize_column_name()
* Allows upper-case letters in table and column names.
* Swaps out sanitize_key() usage for a custom preg_replace: '/^[a-zA-Z0-9_\-]+$/'
* Table: use Base::sanitize_column_name()
* Also fix return value inline comment in count()
* Column: introduce validate() and validate_int()
* validate() centralizes column value validation into the most logical location, and validate_int() allows for falling back to $default in a way that intval obviously could not.
* Base: update regex.
* Base: add stash_args() method
* Also avoid errors in apply_prefix() if not a string.
* Column: use stash_args()
* Also bail early if no arguments to parse.
* Schema: add support for indexes.
* Move filters into methods and their own section
* Improve docs, and add missing docs
* Default values for item_names to prevent fatals
* Add setup() method and move set_ methods out of __construct() and into it
* Minimize touches to this->columns for future Schema/Structure work
* Remove assumptions that primary column must be an int that uses absint/intval - see #124
* Add some todo's for MySQL 8 improvements
* Improve support for CURRENT_TIMESTAMP in relevant columns
* Add get_columns_field_by() to retrieve a single field from a matching array of values to a single key - primarily used for getting an array of column patterns when querying, to return an array of formats for sprintf()
* Improve readability of do_action_ref_array() calls
* Clean-up get_item_ids()
* Rename parse_where() to parse_query_vars()
* Add parse_where() and parse_join() – likely get renamed in the future
* Use wp_parse_list() instead of wp_parse_id_list() - likely needs its own handler
* Prevent fatals from return values of get_search_sql()
* Abstract repeated code into new get_in_sql() method to escape/prepare/format IN (%s) SQL
* Introduce parse_query_var() and use it in place of repeated query_vars[] touches - attempts to internally parse comma separated strings (might remove)
* Introduce undocumented $column->by check to allow a column to not be queried directly by its name
* Refactor parse_query_vars() to improve its internal patterns, for future abstraction
* Fallback in parse_fields() and parse_groupby() to prevent fatal errors
* Introduce parse_single_orderby, parse_limits, parse_join, and parse_where - refactor parse_orderby
* Some minor clean-up to shape_items()
* Bail early in get_item_fields() to avoid trying to filter empty fields
* Introduce validate_item_field() to call $column->validate(), and use it inside shape_item_id() and more. This centralizes validation and ensures they always return the same results.
* Update add_item() and update_item() to skip database if $save fails validation
* Update copy_item() to shape the item ID, as it is not done inside of get_item_raw()
* Update delete_item() to match other item changes above
* All _item() functions use get_columns_field_by() to get patterns to send into wpdb queries for proper formatting (including delete_all_item_meta) - see #137
* Update validate_item() to use validate_item_field()
* Use shape_item_id() in update_item_cache() - also use is_scalar() in place of is_numeric() when making assumptions about the shape of the primary column
* Stop shaping the ID inside of get_non_cached_ids(), as item IDs are (or should be) previously shaped
* Gut get_results() and make it use the query() method - this needs more work
* Query: Introduce filter_search_columns()
* Switch it to using apply_filters_ref_array() - minor back-compat break
* Add direct Schema support
* Get columns directly from Schema
* Deprecate $columns var
* Introduce set_query_clause_defaults() for allowing the query & request clauses to be updated easier
* Add keys to query & request clauses
* Refactor the way that counts & searches are parsed
* Always include columns when count & groupby are used together
* Pass query_vars into more parse_ methods to further abstract their usages for future un-privating
* Override query_vars in parse_query() when counting
* Introduce parse_count()
* Rename parse_where/join to _clauses() suffix
* Pass arguments into default_item(), and use array_combine()
* Swap some var orders in prime_item_caches()
* All: update @copyright and README
* Remove $columns
* Improve query parsing to allow reuse for second COUNT(*) query_clause overrides
* Add support for SELECT & EXPLAIN clauses
* Add several new methods to abstract out newly repeated behaviors
* Add is_valid_column() and get_query_var() and get_column_name_alias() to help with repeated code patterns
* Add parse_query_vars() again, to help abstract only the parsing part
* Use get_meta_type() when updating meta data
* Update prime_item_caches() to not bail early so it can continue on and try updating meta data
* Base: minor refactor to magic methods, and is_success()
* Query: MySQL 8 support
* Remove $columns
* Improve query parsing to allow reuse for second COUNT(*) query_clause overrides
* Add support for SELECT & EXPLAIN clauses
* Add several new methods to abstract out newly repeated behaviors
* Add is_valid_column() and get_query_var() and get_column_name_alias() to help with repeated code patterns
* Add parse_query_vars() again, to help abstract only the parsing part
* Use get_meta_type() when updating meta data
* Update prime_item_caches() to not bail early so it can continue on and try updating meta data
* Resolve PHPStan Level 0 errors
* Fix boolean handling
* Revert change for get_sql
* Make $index public
This ends up being easier to understand than following the code backwards.
* Query: Add support for query handlers.
* Break apart parse_where() into multiple methods
* These new methods return an array of where & join clauses
* Those clauses get merged together to maintain backwards compatibility
* Query: normalize Join/Where order.
* Query: graduate "join" to first-class clause.
* Schema: these need to stay protected
* Query: remove array_flip from get_column_names
* Query: docs
* All: improve code consistency
* Bail early with specific (non retval) values
* Improve inline docs
* Remove some unuseful references
@szepeviktor
Copy link
Contributor

Once this was a gift for a WP plugin developer: https://gist.github.com/szepeviktor/ddb1bfd12d93accd318cc081637956ec

@JJJ
Copy link
Collaborator Author

JJJ commented Jul 2, 2022

Once this was a gift...

Yes! Berlin will absolutely benefit from exactly this kind of abstraction.

See also: #39 🤧

@szepeviktor
Copy link
Contributor

See also: #39 🤧

I see #69 also.

src/Database/Query.php Outdated Show resolved Hide resolved
@szepeviktor
Copy link
Contributor

As this change is very big could it be named v3?

Co-authored-by: Viktor Szépe <[email protected]>
@JJJ
Copy link
Collaborator Author

JJJ commented Jul 5, 2022

As this change is very big could it be named v3?

I was thinking about this, too. Probably yes, IMO.

@szepeviktor
Copy link
Contributor

szepeviktor commented Jul 5, 2022

On PHP 8.0

composer update
vendor/bin/phpstan analyze src/ --level=1

Please ignore apply_filters invoked with 3 parameters.

On lower levels PHPStan will complain about PHPDoc blocks, on higher levels you get your rewards 💎 💎 💎

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

Successfully merging this pull request may close these issues.

3 participants