Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
C
commerce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
20
Merge Requests
20
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
commerce
Commits
c5ef8cd8
Commit
c5ef8cd8
authored
Oct 21, 2020
by
eiriksm
Committed by
mglaman
Oct 21, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2907367
by mglaman, eiriksm, AlanHDev, bojanz: Add indexes to important fields
parent
d85d85a5
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
144 additions
and
0 deletions
+144
-0
modules/order/commerce_order.install
modules/order/commerce_order.install
+17
-0
modules/order/src/Entity/Order.php
modules/order/src/Entity/Order.php
+4
-0
modules/payment/commerce_payment.install
modules/payment/commerce_payment.install
+21
-0
modules/payment/src/Entity/Payment.php
modules/payment/src/Entity/Payment.php
+4
-0
modules/payment/src/Entity/PaymentMethod.php
modules/payment/src/Entity/PaymentMethod.php
+4
-0
modules/product/commerce_product.install
modules/product/commerce_product.install
+17
-0
modules/product/src/Entity/ProductVariation.php
modules/product/src/Entity/ProductVariation.php
+5
-0
modules/promotion/commerce_promotion.install
modules/promotion/commerce_promotion.install
+17
-0
modules/promotion/src/Entity/Coupon.php
modules/promotion/src/Entity/Coupon.php
+4
-0
src/CommerceContentEntityStorageSchema.php
src/CommerceContentEntityStorageSchema.php
+51
-0
No files found.
modules/order/commerce_order.install
View file @
c5ef8cd8
...
...
@@ -5,6 +5,7 @@
* Install, update and uninstall functions for the Order module.
*/
use
Drupal\commerce\CommerceContentEntityStorageSchema
;
use
Drupal\Core\Field\BaseFieldDefinition
;
use
Drupal\Core\Session\AccountInterface
;
...
...
@@ -207,3 +208,19 @@ function commerce_order_update_8209() {
$view
->
save
(
TRUE
);
}
}
/**
* Ensure new field indexes on the order entity.
*/
function
commerce_order_update_8210
()
{
$entity_type_manager
=
\
Drupal
::
entityTypeManager
();
$definition_update_manager
=
\
Drupal
::
entityDefinitionUpdateManager
();
// Get the current order entity type definition, ensure the storage schema
// class is set.
$entity_type
=
$entity_type_manager
->
getDefinition
(
'commerce_order'
)
->
setHandlerClass
(
'storage_schema'
,
CommerceContentEntityStorageSchema
::
class
);
// Regenerate entity type indexes.
$definition_update_manager
->
updateEntityType
(
$entity_type
);
}
modules/order/src/Entity/Order.php
View file @
c5ef8cd8
...
...
@@ -35,6 +35,7 @@ use Drupal\profile\Entity\ProfileInterface;
* handlers = {
* "event" = "Drupal\commerce_order\Event\OrderEvent",
* "storage" = "Drupal\commerce_order\OrderStorage",
* "storage_schema" = "Drupal\commerce\CommerceContentEntityStorageSchema",
* "access" = "Drupal\commerce_order\OrderAccessControlHandler",
* "query_access" = "Drupal\commerce_order\OrderQueryAccessHandler",
* "permission_provider" = "Drupal\commerce_order\OrderPermissionProvider",
...
...
@@ -60,6 +61,9 @@ use Drupal\profile\Entity\ProfileInterface;
* base_table = "commerce_order",
* admin_permission = "administer commerce_order",
* permission_granularity = "bundle",
* field_indexes = {
* "order_number"
* },
* entity_keys = {
* "id" = "order_id",
* "label" = "order_number",
...
...
modules/payment/commerce_payment.install
View file @
c5ef8cd8
...
...
@@ -5,6 +5,7 @@
* Install, update and uninstall functions for the commerce_payment module.
*/
use
Drupal\commerce\CommerceContentEntityStorageSchema
;
use
Drupal\commerce_payment
\
Entity\PaymentMethod
;
use
Drupal\commerce_payment
\
Event\PaymentEvent
;
use
Drupal\Core\Field\BaseFieldDefinition
;
...
...
@@ -145,3 +146,23 @@ function commerce_payment_update_8206() {
->
setDisplayConfigurable
(
'view'
,
TRUE
);
$entity_definition_update
->
installFieldStorageDefinition
(
'avs_response_code_label'
,
'commerce_payment'
,
'commerce_payment'
,
$storage_definition
);
}
/**
* Ensure new field indexes on the payment and payment method entities.
*/
function
commerce_payment_update_8207
()
{
$entity_type_manager
=
\
Drupal
::
entityTypeManager
();
$definition_update_manager
=
\
Drupal
::
entityDefinitionUpdateManager
();
// Get the current payment entity type definition, ensure the storage schema
// class is set.
$entity_type
=
$entity_type_manager
->
getDefinition
(
'commerce_payment'
)
->
setHandlerClass
(
'storage_schema'
,
CommerceContentEntityStorageSchema
::
class
);
// Regenerate entity type indexes.
$definition_update_manager
->
updateEntityType
(
$entity_type
);
$entity_type
=
$entity_type_manager
->
getDefinition
(
'commerce_payment_method'
)
->
setHandlerClass
(
'storage_schema'
,
CommerceContentEntityStorageSchema
::
class
);
$definition_update_manager
->
updateEntityType
(
$entity_type
);
}
modules/payment/src/Entity/Payment.php
View file @
c5ef8cd8
...
...
@@ -29,6 +29,7 @@ use Drupal\Core\Field\BaseFieldDefinition;
* "event" = "Drupal\commerce_payment\Event\PaymentEvent",
* "list_builder" = "Drupal\commerce_payment\PaymentListBuilder",
* "storage" = "Drupal\commerce_payment\PaymentStorage",
* "storage_schema" = "Drupal\commerce\CommerceContentEntityStorageSchema",
* "form" = {
* "operation" = "Drupal\commerce_payment\Form\PaymentOperationForm",
* "delete" = "Drupal\Core\Entity\ContentEntityDeleteForm",
...
...
@@ -40,6 +41,9 @@ use Drupal\Core\Field\BaseFieldDefinition;
* },
* base_table = "commerce_payment",
* admin_permission = "administer commerce_payment",
* field_indexes = {
* "remote_id"
* },
* entity_keys = {
* "id" = "payment_id",
* "bundle" = "type",
...
...
modules/payment/src/Entity/PaymentMethod.php
View file @
c5ef8cd8
...
...
@@ -31,6 +31,7 @@ use Drupal\profile\Entity\ProfileInterface;
* "list_builder" = "Drupal\commerce_payment\PaymentMethodListBuilder",
* "storage" = "Drupal\commerce_payment\PaymentMethodStorage",
* "views_data" = "Drupal\commerce\CommerceEntityViewsData",
* "storage_schema" = "Drupal\commerce\CommerceContentEntityStorageSchema",
* "form" = {
* "edit" = "Drupal\commerce_payment\Form\PaymentMethodEditForm",
* "delete" = "Drupal\commerce_payment\Form\PaymentMethodDeleteForm"
...
...
@@ -41,6 +42,9 @@ use Drupal\profile\Entity\ProfileInterface;
* },
* base_table = "commerce_payment_method",
* admin_permission = "administer commerce_payment_method",
* field_indexes = {
* "remote_id"
* },
* entity_keys = {
* "id" = "method_id",
* "uuid" = "uuid",
...
...
modules/product/commerce_product.install
View file @
c5ef8cd8
...
...
@@ -5,6 +5,7 @@
* Install, update and uninstall functions for the Product module.
*/
use
Drupal\commerce\CommerceContentEntityStorageSchema
;
use
Drupal\commerce_product
\
Entity\Product
;
use
Drupal\commerce_product
\
Entity\ProductVariation
;
use
Drupal\Core\Field\BaseFieldDefinition
;
...
...
@@ -267,3 +268,19 @@ function commerce_product_update_8210() {
$definition_update_manager
->
updateFieldStorageDefinition
(
$storage_definition
);
}
}
/**
* Ensure new field indexes on the product variation entity.
*/
function
commerce_product_update_8211
()
{
$entity_type_manager
=
\
Drupal
::
entityTypeManager
();
$definition_update_manager
=
\
Drupal
::
entityDefinitionUpdateManager
();
// Get the current product variation entity type definition, ensure the
// storage schema class is set.
$entity_type
=
$entity_type_manager
->
getDefinition
(
'commerce_product_variation'
)
->
setHandlerClass
(
'storage_schema'
,
CommerceContentEntityStorageSchema
::
class
);
// Regenerate entity type indexes.
$definition_update_manager
->
updateEntityType
(
$entity_type
);
}
modules/product/src/Entity/ProductVariation.php
View file @
c5ef8cd8
...
...
@@ -32,6 +32,7 @@ use Symfony\Component\Routing\Exception\RouteNotFoundException;
* handlers = {
* "event" = "Drupal\commerce_product\Event\ProductVariationEvent",
* "storage" = "Drupal\commerce_product\ProductVariationStorage",
* "storage_schema" = "Drupal\commerce\CommerceContentEntityStorageSchema",
* "access" = "Drupal\commerce_product\ProductVariationAccessControlHandler",
* "permission_provider" = "Drupal\commerce_product\ProductVariationPermissionProvider",
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
...
...
@@ -53,6 +54,10 @@ use Symfony\Component\Routing\Exception\RouteNotFoundException;
* "translation" = "Drupal\content_translation\ContentTranslationHandler"
* },
* admin_permission = "administer commerce_product",
* fieldable = TRUE,
* field_indexes = {
* "sku"
* },
* translatable = TRUE,
* translation = {
* "content_translation" = {
...
...
modules/promotion/commerce_promotion.install
View file @
c5ef8cd8
...
...
@@ -5,6 +5,7 @@
* Install, update and uninstall functions for the commerce_promotion module.
*/
use
Drupal\commerce\CommerceContentEntityStorageSchema
;
use
Drupal\Core\Field\BaseFieldDefinition
;
/**
...
...
@@ -160,3 +161,19 @@ function commerce_promotion_update_8205() {
$entity_definition_update
->
installFieldStorageDefinition
(
'usage_limit_customer'
,
'commerce_promotion'
,
'commerce_promotion'
,
$storage_definition
);
$entity_definition_update
->
installFieldStorageDefinition
(
'usage_limit_customer'
,
'commerce_promotion_coupon'
,
'commerce_promotion'
,
$storage_definition
);
}
/**
* Ensure new field indexes on the coupon entity.
*/
function
commerce_promotion_update_8206
()
{
$entity_type_manager
=
\
Drupal
::
entityTypeManager
();
$definition_update_manager
=
\
Drupal
::
entityDefinitionUpdateManager
();
// Get the current coupon entity type definition, ensure the storage schema
// class is set.
$entity_type
=
$entity_type_manager
->
getDefinition
(
'commerce_promotion_coupon'
)
->
setHandlerClass
(
'storage_schema'
,
CommerceContentEntityStorageSchema
::
class
);
// Regenerate entity type indexes.
$definition_update_manager
->
updateEntityType
(
$entity_type
);
}
modules/promotion/src/Entity/Coupon.php
View file @
c5ef8cd8
...
...
@@ -24,6 +24,7 @@ use Drupal\Core\Entity\EntityTypeInterface;
* "event" = "Drupal\commerce_promotion\Event\CouponEvent",
* "list_builder" = "Drupal\commerce_promotion\CouponListBuilder",
* "storage" = "Drupal\commerce_promotion\CouponStorage",
* "storage_schema" = "Drupal\commerce\CommerceContentEntityStorageSchema",
* "access" = "Drupal\commerce_promotion\CouponAccessControlHandler",
* "views_data" = "Drupal\commerce\CommerceEntityViewsData",
* "form" = {
...
...
@@ -40,6 +41,9 @@ use Drupal\Core\Entity\EntityTypeInterface;
* },
* base_table = "commerce_promotion_coupon",
* admin_permission = "administer commerce_promotion",
* field_indexes = {
* "code"
* },
* entity_keys = {
* "id" = "id",
* "label" = "code",
...
...
src/CommerceContentEntityStorageSchema.php
0 → 100644
View file @
c5ef8cd8
<?php
namespace
Drupal\commerce
;
use
Drupal\Core\Entity\EntityTypeInterface
;
use
Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema
;
use
Drupal\Core\Field\FieldStorageDefinitionInterface
;
/**
* Defines a schema handler that supports defining base field indexes.
*/
class
CommerceContentEntityStorageSchema
extends
SqlContentEntityStorageSchema
{
/**
* {@inheritdoc}
*/
public
function
onEntityTypeUpdate
(
EntityTypeInterface
$entity_type
,
EntityTypeInterface
$original
)
{
parent
::
onEntityTypeUpdate
(
$entity_type
,
$original
);
// ::onEntityTypeUpdate will only populate new indexes if the entity has
// a change on being translatable, revisionable, or a field change.
// @see https://www.drupal.org/project/drupal/issues/3005447
$entity_schema
=
$this
->
getEntitySchema
(
$entity_type
,
TRUE
);
$schema_table
=
$entity_type
->
getDataTable
()
?:
$entity_type
->
getBaseTable
();
$schema_indexes
=
$entity_schema
[
$schema_table
][
'indexes'
];
foreach
(
$schema_indexes
as
$index_name
=>
$index_fields
)
{
if
(
!
$this
->
database
->
schema
()
->
indexExists
(
$schema_table
,
$index_name
))
{
$this
->
database
->
schema
()
->
addIndex
(
$schema_table
,
$index_name
,
$index_fields
,
$entity_schema
[
$schema_table
]);
}
}
}
/**
* {@inheritdoc}
*/
protected
function
getSharedTableFieldSchema
(
FieldStorageDefinitionInterface
$storage_definition
,
$table_name
,
array
$column_mapping
)
{
$schema
=
parent
::
getSharedTableFieldSchema
(
$storage_definition
,
$table_name
,
$column_mapping
);
$entity_type
=
$this
->
entityTypeManager
->
getDefinition
(
$storage_definition
->
getTargetEntityTypeId
());
$field_indexes
=
$entity_type
->
get
(
'field_indexes'
);
foreach
(
$field_indexes
as
$field_name
)
{
if
(
$field_name
==
$storage_definition
->
getName
())
{
$this
->
addSharedTableFieldIndex
(
$storage_definition
,
$schema
);
}
}
return
$schema
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment