Skip to content

Commit 84f640e

Browse files
vsorokayurio
authored andcommitted
BAP-13382: Unpredictable data sorting on Calls grid (#6791)
- Fix issues in ORDER BY modification and move it to AST walker - Fix indexes (add ID to the end)
1 parent 08e57aa commit 84f640e

File tree

22 files changed

+207
-31
lines changed

22 files changed

+207
-31
lines changed

Diff for: src/OroCRM/Bundle/AccountBundle/Entity/Account.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
/**
2323
* @ORM\Entity()
24-
* @ORM\Table(name="orocrm_account", indexes={@ORM\Index(name="account_name_idx", columns={"name"})})
24+
* @ORM\Table(name="orocrm_account", indexes={@ORM\Index(name="account_name_idx", columns={"name", "id"})})
2525
* @ORM\HasLifecycleCallbacks()
2626
* @Oro\Loggable
2727
* @Config(

Diff for: src/OroCRM/Bundle/AccountBundle/Migrations/Schema/OroCRMAccountBundleInstaller.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function setAttachmentExtension(AttachmentExtension $attachmentExtension)
8080
*/
8181
public function getMigrationVersion()
8282
{
83-
return 'v1_11';
83+
return 'v1_11_1';
8484
}
8585

8686
/**
@@ -157,7 +157,7 @@ protected function createOrocrmAccountTable(Schema $schema, QueryBag $queries)
157157
$table->addIndex(['user_owner_id'], 'IDX_7166D3719EB185F9', []);
158158
$table->addIndex(['organization_id'], 'IDX_7166D37132C8A3DE', []);
159159
$table->addIndex(['default_contact_id'], 'IDX_7166D371AF827129', []);
160-
$table->addIndex(['name'], 'account_name_idx', []);
160+
$table->addIndex(['name', 'id'], 'account_name_idx', []);
161161

162162
$queries->addPostQuery(new AccountNameExprIndexQuery());
163163
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace OroCRM\Bundle\AccountBundle\Migrations\Schema\v1_11_1;
4+
5+
use Doctrine\DBAL\Schema\Schema;
6+
7+
use Oro\Bundle\MigrationBundle\Migration\Migration;
8+
use Oro\Bundle\MigrationBundle\Migration\QueryBag;
9+
10+
class UpdateIndexes implements Migration
11+
{
12+
/**
13+
* {@inheritdoc}
14+
*/
15+
public function up(Schema $schema, QueryBag $queries)
16+
{
17+
$table = $schema->getTable('orocrm_account');
18+
$indexName = 'account_name_idx';
19+
$indexColumns = ['name', 'id'];
20+
if ($table->hasIndex($indexName) && $table->getIndex($indexName)->getColumns() !== $indexColumns) {
21+
$table->dropIndex($indexName);
22+
$table->addIndex($indexColumns, $indexName);
23+
}
24+
}
25+
}

Diff for: src/OroCRM/Bundle/CaseBundle/Entity/CaseEntity.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
/**
2121
* @ORM\Entity
2222
* @ORM\Table(
23-
* name="orocrm_case"
23+
* name="orocrm_case",
24+
* indexes={@ORM\Index(name="case_reported_at_idx",columns={"reportedAt", "id"})}
2425
* )
2526
* @ORM\HasLifecycleCallbacks()
2627
* @Oro\Loggable

Diff for: src/OroCRM/Bundle/CaseBundle/Migrations/Schema/OroCRMCaseBundleInstaller.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class OroCRMCaseBundleInstaller implements
4242
*/
4343
public function getMigrationVersion()
4444
{
45-
return 'v1_9';
45+
return 'v1_10';
4646
}
4747

4848
/**
@@ -138,6 +138,7 @@ protected function createOrocrmCaseTable(Schema $schema)
138138
$table->addIndex(['related_account_id'], 'IDX_AB3BAC1E11A6570A', []);
139139
$table->addIndex(['source_name'], 'IDX_AB3BAC1E5FA9FB05', []);
140140
$table->addIndex(['priority_name'], 'IDX_AB3BAC1E965BD3DF', []);
141+
$table->addIndex(['reportedAt', 'id'], 'case_reported_at_idx', []);
141142
}
142143

143144
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace OroCRM\Bundle\CaseBundle\Migrations\Schema\v1_10;
4+
5+
use Doctrine\DBAL\Schema\Schema;
6+
7+
use Oro\Bundle\MigrationBundle\Migration\Migration;
8+
use Oro\Bundle\MigrationBundle\Migration\QueryBag;
9+
10+
class UpdateIndexes implements Migration
11+
{
12+
/**
13+
* {@inheritdoc}
14+
*/
15+
public function up(Schema $schema, QueryBag $queries)
16+
{
17+
$table = $schema->getTable('orocrm_case');
18+
$indexName = 'case_reported_at_idx';
19+
$indexColumns = ['reportedAt', 'id'];
20+
if ($table->hasIndex($indexName)) {
21+
if ($table->getIndex($indexName)->getColumns() !== $indexColumns) {
22+
$table->dropIndex($indexName);
23+
$table->addIndex($indexColumns, $indexName);
24+
}
25+
} else {
26+
$table->addIndex($indexColumns, $indexName);
27+
}
28+
}
29+
}

Diff for: src/OroCRM/Bundle/ContactBundle/Entity/Contact.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* @ORM\Table(
3434
* name="orocrm_contact",
3535
* indexes={
36-
* @ORM\Index(name="contact_name_idx",columns={"last_name", "first_name"}),
36+
* @ORM\Index(name="contact_name_idx",columns={"last_name", "first_name", "id"}),
3737
* @ORM\Index(name="contact_updated_at_idx",columns={"updatedAt"}),
3838
* }
3939
* )

Diff for: src/OroCRM/Bundle/ContactBundle/Migrations/Schema/OroCRMContactBundleInstaller.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function setAttachmentExtension(AttachmentExtension $attachmentExtension)
7373
*/
7474
public function getMigrationVersion()
7575
{
76-
return 'v1_14';
76+
return 'v1_15';
7777
}
7878

7979
/**
@@ -151,7 +151,7 @@ protected function createOrocrmContactTable(Schema $schema)
151151
$table->addIndex(['reports_to_contact_id'], 'IDX_403263EDF27EBC1E', []);
152152
$table->addIndex(['created_by_user_id'], 'IDX_403263ED7D182D95', []);
153153
$table->addIndex(['updated_by_user_id'], 'IDX_403263ED2793CC5E', []);
154-
$table->addIndex(['last_name', 'first_name'], 'contact_name_idx', []);
154+
$table->addIndex(['last_name', 'first_name', 'id'], 'contact_name_idx', []);
155155
$table->addIndex(['updatedAt'], 'contact_updated_at_idx', []);
156156
}
157157

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace OroCRM\Bundle\ContactBundle\Migrations\Schema\v1_15;
4+
5+
use Doctrine\DBAL\Schema\Schema;
6+
7+
use Oro\Bundle\MigrationBundle\Migration\Migration;
8+
use Oro\Bundle\MigrationBundle\Migration\QueryBag;
9+
10+
class UpdateIndexes implements Migration
11+
{
12+
/**
13+
* {@inheritdoc}
14+
*/
15+
public function up(Schema $schema, QueryBag $queries)
16+
{
17+
$table = $schema->getTable('orocrm_contact');
18+
$indexName = 'contact_name_idx';
19+
$indexColumns = ['last_name', 'first_name', 'id'];
20+
if ($table->hasIndex($indexName) && $table->getIndex($indexName)->getColumns() !== $indexColumns) {
21+
$table->dropIndex($indexName);
22+
$table->addIndex($indexColumns, $indexName);
23+
}
24+
}
25+
}

Diff for: src/OroCRM/Bundle/ContactUsBundle/Entity/ContactRequest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* @ORM\Entity
2323
* @ORM\Table(
2424
* name="orocrm_contactus_request",
25-
* indexes={@ORM\Index(name="request_create_idx",columns={"created_at"})}
25+
* indexes={@ORM\Index(name="request_create_idx",columns={"created_at", "id"})}
2626
* )
2727
*
2828
* @Config(

Diff for: src/OroCRM/Bundle/ContactUsBundle/Migrations/Schema/OroCRMContactUsBundleInstaller.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function setActivityExtension(ActivityExtension $activityExtension)
3434
*/
3535
public function getMigrationVersion()
3636
{
37-
return 'v1_10';
37+
return 'v1_10_1';
3838
}
3939

4040
/**
@@ -117,7 +117,7 @@ protected function createOrocrmContactusRequestTable(Schema $schema)
117117
$table->addIndex(['opportunity_id'], 'IDX_342872E89A34590F', []);
118118
$table->addIndex(['lead_id'], 'IDX_342872E855458D', []);
119119
$table->addIndex(['workflow_step_id'], 'IDX_342872E871FE882C', []);
120-
$table->addIndex(['created_at'], 'request_create_idx', []);
120+
$table->addIndex(['created_at', 'id'], 'request_create_idx', []);
121121
}
122122

123123

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace OroCRM\Bundle\ContactUsBundle\Migrations\Schema\v1_10_1;
4+
5+
use Doctrine\DBAL\Schema\Schema;
6+
7+
use Oro\Bundle\MigrationBundle\Migration\Migration;
8+
use Oro\Bundle\MigrationBundle\Migration\QueryBag;
9+
10+
class UpdateIndexes implements Migration
11+
{
12+
/**
13+
* {@inheritdoc}
14+
*/
15+
public function up(Schema $schema, QueryBag $queries)
16+
{
17+
$table = $schema->getTable('orocrm_contactus_request');
18+
$indexName = 'request_create_idx';
19+
$indexColumns = ['created_at', 'id'];
20+
if ($table->hasIndex($indexName) && $table->getIndex($indexName)->getColumns() !== $indexColumns) {
21+
$table->dropIndex($indexName);
22+
$table->addIndex($indexColumns, $indexName);
23+
}
24+
}
25+
}

Diff for: src/OroCRM/Bundle/MagentoBundle/Entity/Cart.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* @ORM\Table(name="orocrm_magento_cart",
3131
* indexes={
3232
* @ORM\Index(name="magecart_origin_idx", columns={"origin_id"}),
33-
* @ORM\Index(name="magecart_updated_idx", columns={"updatedAt"}),
33+
* @ORM\Index(name="magecart_updated_idx", columns={"updatedAt", "id"}),
3434
* @ORM\Index(name="magecart_payment_details_idx", columns={"payment_details"}),
3535
* @ORM\Index(name="status_name_items_qty_idx", columns={"status_name", "items_qty"})
3636
* },

Diff for: src/OroCRM/Bundle/MagentoBundle/Entity/Customer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* uniqueConstraints={@ORM\UniqueConstraint(name="magecustomer_oid_cid_unq", columns={"origin_id", "channel_id"})},
3636
* indexes={
3737
* @ORM\Index(name="magecustomer_name_idx",columns={"first_name", "last_name"}),
38-
* @ORM\Index(name="magecustomer_rev_name_idx",columns={"last_name", "first_name"}),
38+
* @ORM\Index(name="magecustomer_rev_name_idx",columns={"last_name", "first_name", "id"}),
3939
* @ORM\Index(name="magecustomer_email_guest_idx",columns={"email"})
4040
* }
4141
* )

Diff for: src/OroCRM/Bundle/MagentoBundle/Entity/Order.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
use Oro\Bundle\UserBundle\Entity\User;
1313
use Oro\Bundle\AddressBundle\Entity\AddressType;
1414
use Oro\Bundle\AddressBundle\Entity\AbstractTypedAddress;
15-
use Oro\Bundle\WorkflowBundle\Entity\WorkflowItem;
16-
use Oro\Bundle\WorkflowBundle\Entity\WorkflowStep;
1715
use Oro\Bundle\LocaleBundle\Model\FirstNameInterface;
1816
use Oro\Bundle\LocaleBundle\Model\LastNameInterface;
1917

@@ -28,7 +26,7 @@
2826
* @ORM\HasLifecycleCallbacks
2927
* @ORM\Table(name="orocrm_magento_order",
3028
* indexes={
31-
* @ORM\Index(name="mageorder_created_idx",columns={"created_at"})
29+
* @ORM\Index(name="mageorder_created_idx",columns={"created_at", "id"})
3230
* },
3331
* uniqueConstraints={
3432
* @ORM\UniqueConstraint(name="unq_increment_id_channel_id", columns={"increment_id", "channel_id"})

Diff for: src/OroCRM/Bundle/MagentoBundle/Migrations/Schema/OroCRMMagentoBundleInstaller.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function setVisitEventAssociationExtension(VisitEventAssociationExtension
110110
*/
111111
public function getMigrationVersion()
112112
{
113-
return 'v1_41_4';
113+
return 'v1_41_5';
114114
}
115115

116116
/**
@@ -336,7 +336,7 @@ protected function createOrocrmMagentoOrderTable(Schema $schema)
336336
$table->addIndex(['data_channel_id'], 'IDX_4D09F305BDC09B73', []);
337337
$table->addIndex(['organization_id'], 'IDX_4D09F30532C8A3DE', []);
338338
$table->setPrimaryKey(['id']);
339-
$table->addIndex(['created_at'], 'mageorder_created_idx', []);
339+
$table->addIndex(['created_at', 'id'], 'mageorder_created_idx', []);
340340
$table->addUniqueIndex(['increment_id', 'channel_id'], 'unq_increment_id_channel_id');
341341
}
342342

@@ -427,7 +427,7 @@ protected function createOrocrmMagentoCustomerTable(Schema $schema)
427427
$table->addIndex(['organization_id'], 'IDX_2A61EE7D32C8A3DE', []);
428428
$table->setPrimaryKey(['id']);
429429
$table->addIndex(['first_name', 'last_name'], 'magecustomer_name_idx', []);
430-
$table->addIndex(['last_name', 'first_name'], 'magecustomer_rev_name_idx', []);
430+
$table->addIndex(['last_name', 'first_name', 'id'], 'magecustomer_rev_name_idx', []);
431431
$table->addIndex(['email'], 'magecustomer_email_guest_idx', []);
432432
$table->addUniqueIndex(['origin_id', 'channel_id'], 'magecustomer_oid_cid_unq');
433433
}
@@ -714,7 +714,7 @@ protected function createOrocrmMagentoCartTable(Schema $schema)
714714
$table->addIndex(['organization_id'], 'IDX_96661A8032C8A3DE', []);
715715
$table->setPrimaryKey(['id']);
716716
$table->addIndex(['origin_id'], 'magecart_origin_idx', []);
717-
$table->addIndex(['updatedAt'], 'magecart_updated_idx', []);
717+
$table->addIndex(['updatedAt', 'id'], 'magecart_updated_idx', []);
718718
$table->addIndex(['payment_details'], 'magecart_payment_details_idx', []);
719719
$table->addIndex(['status_name', 'items_qty'], 'status_name_items_qty_idx', []);
720720
$table->addUniqueIndex(['origin_id', 'channel_id'], 'unq_cart_origin_id_channel_id');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace OroCRM\Bundle\MagentoBundle\Migrations\Schema\v1_41_5;
4+
5+
use Doctrine\DBAL\Schema\Schema;
6+
7+
use Oro\Bundle\MigrationBundle\Migration\Migration;
8+
use Oro\Bundle\MigrationBundle\Migration\QueryBag;
9+
10+
class UpdateIndexes implements Migration
11+
{
12+
/**
13+
* {@inheritdoc}
14+
*/
15+
public function up(Schema $schema, QueryBag $queries)
16+
{
17+
$table = $schema->getTable('orocrm_magento_cart');
18+
$indexName = 'magecart_updated_idx';
19+
$indexColumns = ['updatedAt', 'id'];
20+
if ($table->hasIndex($indexName) && $table->getIndex($indexName)->getColumns() !== $indexColumns) {
21+
$table->dropIndex($indexName);
22+
$table->addIndex($indexColumns, $indexName);
23+
}
24+
25+
$table = $schema->getTable('orocrm_magento_order');
26+
$indexName = 'mageorder_created_idx';
27+
$indexColumns = ['created_at', 'id'];
28+
if ($table->hasIndex($indexName) && $table->getIndex($indexName)->getColumns() !== $indexColumns) {
29+
$table->dropIndex($indexName);
30+
$table->addIndex($indexColumns, $indexName);
31+
}
32+
33+
$table = $schema->getTable('orocrm_magento_customer');
34+
$indexName = 'magecustomer_rev_name_idx';
35+
$indexColumns = ['last_name', 'first_name', 'id'];
36+
if ($table->hasIndex($indexName) && $table->getIndex($indexName)->getColumns() !== $indexColumns) {
37+
$table->dropIndex($indexName);
38+
$table->addIndex($indexColumns, $indexName);
39+
}
40+
}
41+
}

Diff for: src/OroCRM/Bundle/MagentoBundle/Tests/Functional/Controller/NewsletterSubscriberControllerTest.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace OroCRM\Bundle\MagentoBundle\Tests\Functional\Controller;
44

5-
use Doctrine\ORM\EntityManager;
6-
75
use Oro\Bundle\ImportExportBundle\Job\JobExecutor;
86
use Oro\Bundle\ImportExportBundle\Job\JobResult;
97
use OroCRM\Bundle\MagentoBundle\Entity\NewsletterSubscriber;
@@ -108,8 +106,8 @@ public function gridProvider()
108106
'gridFilters' => [],
109107
'assert' => [
110108
'channelName' => 'Magento channel',
111-
'email' => 'subscriber@example.com',
112-
'status' => 'Subscribed',
109+
'email' => 'subscriber3@example.com',
110+
'status' => 'Unsubscribed',
113111
'customerName' => 'John Doe',
114112
'customerEmail' => '[email protected]'
115113
],
@@ -124,8 +122,8 @@ public function gridProvider()
124122
],
125123
'assert' => [
126124
'channelName' => 'Magento channel',
127-
'email' => 'subscriber@example.com',
128-
'status' => 'Subscribed',
125+
'email' => 'subscriber3@example.com',
126+
'status' => 'Unsubscribed',
129127
'customerName' => 'John Doe',
130128
'customerEmail' => '[email protected]'
131129
],

Diff for: src/OroCRM/Bundle/SalesBundle/Entity/Lead.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*
3333
* @ORM\Table(
3434
* name="orocrm_sales_lead",
35-
* indexes={@ORM\Index(name="lead_created_idx",columns={"createdAt"})}
35+
* indexes={@ORM\Index(name="lead_created_idx",columns={"createdAt", "id"})}
3636
* )
3737
* @ORM\Entity(repositoryClass="OroCRM\Bundle\SalesBundle\Entity\Repository\LeadRepository")
3838
* @ORM\HasLifecycleCallbacks()

Diff for: src/OroCRM/Bundle/SalesBundle/Entity/Opportunity.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* @ORM\Entity(repositoryClass="OroCRM\Bundle\SalesBundle\Entity\Repository\OpportunityRepository")
2323
* @ORM\Table(
2424
* name="orocrm_sales_opportunity",
25-
* indexes={@ORM\Index(name="opportunity_created_idx",columns={"created_at"})}
25+
* indexes={@ORM\Index(name="opportunity_created_idx",columns={"created_at", "id"})}
2626
* )
2727
* @ORM\HasLifecycleCallbacks()
2828
* @Oro\Loggable

0 commit comments

Comments
 (0)