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

CRM/Logging - Fix various bugs in schema parsing #13441

Merged
merged 2 commits into from
Feb 24, 2019

Conversation

pfigel
Copy link
Contributor

@pfigel pfigel commented Jan 13, 2019

Overview

CRM_Logging_Schema contains a number of helper methods for parsing table schemas. The results are then used to create or alter log tables.

Before

Some of these methods contain bugs that produce incorrect or incomplete results:

  • CRM_Logging_Schema::getIndexesForTable only queries for constraints, not returning any indexes.
  • CRM_Logging_Schema::getIndexesForTable returns an array in the form [0 => ['constraint_name' => 'foo']], meaning lookups via in_array won't work.
  • CRM_Logging_Schema::columnSpecsOf contains an off-by-one error and a wrongly used substr parameter causing column lengths to include surrounding parenthesis. This would result in a varchar(42)column returning a length of (42).

After

  • CRM_Logging_Schema::getIndexesForTable returns constraints as well as indexes.
  • CRM_Logging_Schema::getIndexesForTable returns an array in the form of ['index1', 'index2', ...]
  • CRM_Logging_Schema::columnSpecsOf returns column lengths without surrounding parenthesis.

@civicrm-builder
Copy link

Can one of the admins verify this patch?

@civibot
Copy link

civibot bot commented Jan 13, 2019

(Standard links)

@civibot civibot bot added the master label Jan 13, 2019
@seamuslee001
Copy link
Contributor

Jenkins add to whitelist

@eileenmcnaughton
Copy link
Contributor

This looks promising! @aydun any chance you could take a look at this one?

@aydun
Copy link
Contributor

aydun commented Jan 15, 2019

Ok, I'll take a look - hopefully later this week.

@colemanw
Copy link
Member

That would be great @aydun - thanks.

Copy link
Contributor

@aydun aydun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good, and does what it says. Good to see a test.

getIndexesForTable is only called from updateLogTableSchema so looks fairly low impact. Would be good to fix the enum length thing but I don't think it actually causes any failures.

CRM/Logging/Schema.php Show resolved Hide resolved
tests/phpunit/CRM/Logging/SchemaTest.php Show resolved Hide resolved
tests/phpunit/CRM/Logging/SchemaTest.php Show resolved Hide resolved
@pfigel
Copy link
Contributor Author

pfigel commented Jan 25, 2019

Thanks @aydun! I added some code that should handle enums as well as tests for length/enum changes getting pushed through to log tables.

@pfigel
Copy link
Contributor Author

pfigel commented Jan 25, 2019

@civicrm-builder retest this please

@eileenmcnaughton
Copy link
Contributor

@aydun I see you have reviewed this & @pfigel has responded to your feedback - is it good to merge?

This fixes a couple of bugs in the schema parsing methods used by
Civi's extended logging feature:

- CRM_Logging_Schema::getIndexesForTable only queried for constraints,
  not returning any indexes.
- CRM_Logging_Schema::getIndexesForTable returned an array in the form
  [0 => ['constraint_name' => 'foo']] rather than the expected array
  of index names (i.e. ['foo']).
- CRM_Logging_Schema::columnSpecsOf contained an off-by-one error and
  a wrongly used substr parameter causing column lengths to include
  surrounding parenthesis. This would result in a "varchar(42)"
  column returning a length of "(42)" instead of "42".
Instead of storing permitted enum values in the LENGTH array key
when extracting column information, this adds a separate ENUM_VALUES
key. When schema differences are calculated for enum columns, this
value triggers a change when new permitted values are added.
@eileenmcnaughton
Copy link
Contributor

I'm going to merge this - I feel like feedback has been responded to & test coverage is great. I would also note this code is accessed only when updating logging tables & has pretty reasonable coverage so that gives me some confidence

@eileenmcnaughton eileenmcnaughton merged commit 78df177 into civicrm:master Feb 24, 2019
@pfigel pfigel deleted the fix-schema-parsing branch February 24, 2019 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants