From e6f7012c5cf145f28ba0eae77e178fa8cf4cd749 Mon Sep 17 00:00:00 2001 From: Yurii Muratov Date: Wed, 1 Feb 2017 11:39:10 +0200 Subject: [PATCH 1/3] CRM-6860: Change opportunities datagrid. Change enum joins (#7138) --- .../Bundle/SalesBundle/Resources/config/datagrid.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OroCRM/Bundle/SalesBundle/Resources/config/datagrid.yml b/src/OroCRM/Bundle/SalesBundle/Resources/config/datagrid.yml index 21cd35d18fb..ebefd445cd5 100644 --- a/src/OroCRM/Bundle/SalesBundle/Resources/config/datagrid.yml +++ b/src/OroCRM/Bundle/SalesBundle/Resources/config/datagrid.yml @@ -21,7 +21,7 @@ datagrid: - o.probability - o.budgetAmount - o.closeRevenue - - s.id as status + - IDENTITY(o.status) as status - CONCAT_WS(' ', contactAlias.firstName, contactAlias.lastName) as contactName - contactAlias.id as contact - closeReason.label as closeReasonLabel @@ -36,7 +36,6 @@ datagrid: join: left: - { join: o.contact, alias: contactAlias } - - { join: o.status, alias: s } - { join: o.closeReason, alias: closeReason } - { join: contactAlias.emails, alias: email, conditionType: WITH, condition: 'email.primary = true' } - { join: o.dataChannel, alias: channel } @@ -87,9 +86,10 @@ datagrid: label: orocrm.sales.opportunity.probability.label frontend_type: percent status: - frontend_type: select + context: + enum_code: opportunity_status + frontend_type: enum label: orocrm.sales.opportunity.status.label - choices: "@oro_entity_extend.enum_value_provider->getEnumChoicesByCode('opportunity_status')" primaryEmail: label: orocrm.contact.email.label ownerName: From ccdedc5905e4fdd3fabc0b4191500c1f22a2b78e Mon Sep 17 00:00:00 2001 From: Vova Soroka Date: Fri, 3 Feb 2017 01:14:08 +0200 Subject: [PATCH 2/3] BAP-13382: Unpredictable data sorting on Calls grid. Revert from 1.10 due to BC breaks --- .../Bundle/AccountBundle/Entity/Account.php | 2 +- .../Schema/OroCRMAccountBundleInstaller.php | 4 +- .../Schema/v1_11_1/UpdateIndexes.php | 25 ----------- .../Bundle/CaseBundle/Entity/CaseEntity.php | 3 +- .../Schema/OroCRMCaseBundleInstaller.php | 3 +- .../Migrations/Schema/v1_10/UpdateIndexes.php | 29 ------------- .../Bundle/ContactBundle/Entity/Contact.php | 2 +- .../Schema/OroCRMContactBundleInstaller.php | 4 +- .../Migrations/Schema/v1_15/UpdateIndexes.php | 25 ----------- .../ContactUsBundle/Entity/ContactRequest.php | 2 +- .../Schema/OroCRMContactUsBundleInstaller.php | 4 +- .../Schema/v1_10_1/UpdateIndexes.php | 25 ----------- .../Bundle/MagentoBundle/Entity/Cart.php | 2 +- .../Bundle/MagentoBundle/Entity/Customer.php | 2 +- .../Bundle/MagentoBundle/Entity/Order.php | 4 +- .../Schema/OroCRMMagentoBundleInstaller.php | 8 ++-- .../Schema/v1_41_5/UpdateIndexes.php | 41 ------------------- .../NewsletterSubscriberControllerTest.php | 10 +++-- src/OroCRM/Bundle/SalesBundle/Entity/Lead.php | 2 +- .../Bundle/SalesBundle/Entity/Opportunity.php | 2 +- .../Schema/OroCRMSalesBundleInstaller.php | 4 +- .../Schema/v1_25_7/UpdateIndexes.php | 33 --------------- 22 files changed, 30 insertions(+), 206 deletions(-) delete mode 100644 src/OroCRM/Bundle/AccountBundle/Migrations/Schema/v1_11_1/UpdateIndexes.php delete mode 100644 src/OroCRM/Bundle/CaseBundle/Migrations/Schema/v1_10/UpdateIndexes.php delete mode 100644 src/OroCRM/Bundle/ContactBundle/Migrations/Schema/v1_15/UpdateIndexes.php delete mode 100644 src/OroCRM/Bundle/ContactUsBundle/Migrations/Schema/v1_10_1/UpdateIndexes.php delete mode 100644 src/OroCRM/Bundle/MagentoBundle/Migrations/Schema/v1_41_5/UpdateIndexes.php delete mode 100644 src/OroCRM/Bundle/SalesBundle/Migrations/Schema/v1_25_7/UpdateIndexes.php diff --git a/src/OroCRM/Bundle/AccountBundle/Entity/Account.php b/src/OroCRM/Bundle/AccountBundle/Entity/Account.php index 7c317f8636d..8ac5a7528e7 100644 --- a/src/OroCRM/Bundle/AccountBundle/Entity/Account.php +++ b/src/OroCRM/Bundle/AccountBundle/Entity/Account.php @@ -21,7 +21,7 @@ /** * @ORM\Entity() - * @ORM\Table(name="orocrm_account", indexes={@ORM\Index(name="account_name_idx", columns={"name", "id"})}) + * @ORM\Table(name="orocrm_account", indexes={@ORM\Index(name="account_name_idx", columns={"name"})}) * @ORM\HasLifecycleCallbacks() * @Oro\Loggable * @Config( diff --git a/src/OroCRM/Bundle/AccountBundle/Migrations/Schema/OroCRMAccountBundleInstaller.php b/src/OroCRM/Bundle/AccountBundle/Migrations/Schema/OroCRMAccountBundleInstaller.php index 6b4a95058aa..0e7e0178a60 100644 --- a/src/OroCRM/Bundle/AccountBundle/Migrations/Schema/OroCRMAccountBundleInstaller.php +++ b/src/OroCRM/Bundle/AccountBundle/Migrations/Schema/OroCRMAccountBundleInstaller.php @@ -80,7 +80,7 @@ public function setAttachmentExtension(AttachmentExtension $attachmentExtension) */ public function getMigrationVersion() { - return 'v1_11_1'; + return 'v1_11'; } /** @@ -157,7 +157,7 @@ protected function createOrocrmAccountTable(Schema $schema, QueryBag $queries) $table->addIndex(['user_owner_id'], 'IDX_7166D3719EB185F9', []); $table->addIndex(['organization_id'], 'IDX_7166D37132C8A3DE', []); $table->addIndex(['default_contact_id'], 'IDX_7166D371AF827129', []); - $table->addIndex(['name', 'id'], 'account_name_idx', []); + $table->addIndex(['name'], 'account_name_idx', []); $queries->addPostQuery(new AccountNameExprIndexQuery()); } diff --git a/src/OroCRM/Bundle/AccountBundle/Migrations/Schema/v1_11_1/UpdateIndexes.php b/src/OroCRM/Bundle/AccountBundle/Migrations/Schema/v1_11_1/UpdateIndexes.php deleted file mode 100644 index e2a32da2cd1..00000000000 --- a/src/OroCRM/Bundle/AccountBundle/Migrations/Schema/v1_11_1/UpdateIndexes.php +++ /dev/null @@ -1,25 +0,0 @@ -getTable('orocrm_account'); - $indexName = 'account_name_idx'; - $indexColumns = ['name', 'id']; - if ($table->hasIndex($indexName) && $table->getIndex($indexName)->getColumns() !== $indexColumns) { - $table->dropIndex($indexName); - $table->addIndex($indexColumns, $indexName); - } - } -} diff --git a/src/OroCRM/Bundle/CaseBundle/Entity/CaseEntity.php b/src/OroCRM/Bundle/CaseBundle/Entity/CaseEntity.php index db02a228d01..6b4750e3690 100644 --- a/src/OroCRM/Bundle/CaseBundle/Entity/CaseEntity.php +++ b/src/OroCRM/Bundle/CaseBundle/Entity/CaseEntity.php @@ -20,8 +20,7 @@ /** * @ORM\Entity * @ORM\Table( - * name="orocrm_case", - * indexes={@ORM\Index(name="case_reported_at_idx",columns={"reportedAt", "id"})} + * name="orocrm_case" * ) * @ORM\HasLifecycleCallbacks() * @Oro\Loggable diff --git a/src/OroCRM/Bundle/CaseBundle/Migrations/Schema/OroCRMCaseBundleInstaller.php b/src/OroCRM/Bundle/CaseBundle/Migrations/Schema/OroCRMCaseBundleInstaller.php index 7dd95265b1b..b4d7b3668c5 100644 --- a/src/OroCRM/Bundle/CaseBundle/Migrations/Schema/OroCRMCaseBundleInstaller.php +++ b/src/OroCRM/Bundle/CaseBundle/Migrations/Schema/OroCRMCaseBundleInstaller.php @@ -42,7 +42,7 @@ class OroCRMCaseBundleInstaller implements */ public function getMigrationVersion() { - return 'v1_10'; + return 'v1_9'; } /** @@ -138,7 +138,6 @@ protected function createOrocrmCaseTable(Schema $schema) $table->addIndex(['related_account_id'], 'IDX_AB3BAC1E11A6570A', []); $table->addIndex(['source_name'], 'IDX_AB3BAC1E5FA9FB05', []); $table->addIndex(['priority_name'], 'IDX_AB3BAC1E965BD3DF', []); - $table->addIndex(['reportedAt', 'id'], 'case_reported_at_idx', []); } /** diff --git a/src/OroCRM/Bundle/CaseBundle/Migrations/Schema/v1_10/UpdateIndexes.php b/src/OroCRM/Bundle/CaseBundle/Migrations/Schema/v1_10/UpdateIndexes.php deleted file mode 100644 index 1be3954acff..00000000000 --- a/src/OroCRM/Bundle/CaseBundle/Migrations/Schema/v1_10/UpdateIndexes.php +++ /dev/null @@ -1,29 +0,0 @@ -getTable('orocrm_case'); - $indexName = 'case_reported_at_idx'; - $indexColumns = ['reportedAt', 'id']; - if ($table->hasIndex($indexName)) { - if ($table->getIndex($indexName)->getColumns() !== $indexColumns) { - $table->dropIndex($indexName); - $table->addIndex($indexColumns, $indexName); - } - } else { - $table->addIndex($indexColumns, $indexName); - } - } -} diff --git a/src/OroCRM/Bundle/ContactBundle/Entity/Contact.php b/src/OroCRM/Bundle/ContactBundle/Entity/Contact.php index 05a8efaf17c..599f4b2ba3d 100644 --- a/src/OroCRM/Bundle/ContactBundle/Entity/Contact.php +++ b/src/OroCRM/Bundle/ContactBundle/Entity/Contact.php @@ -33,7 +33,7 @@ * @ORM\Table( * name="orocrm_contact", * indexes={ - * @ORM\Index(name="contact_name_idx",columns={"last_name", "first_name", "id"}), + * @ORM\Index(name="contact_name_idx",columns={"last_name", "first_name"}), * @ORM\Index(name="contact_updated_at_idx",columns={"updatedAt"}), * } * ) diff --git a/src/OroCRM/Bundle/ContactBundle/Migrations/Schema/OroCRMContactBundleInstaller.php b/src/OroCRM/Bundle/ContactBundle/Migrations/Schema/OroCRMContactBundleInstaller.php index dfdc5fa0134..8ca61d78787 100644 --- a/src/OroCRM/Bundle/ContactBundle/Migrations/Schema/OroCRMContactBundleInstaller.php +++ b/src/OroCRM/Bundle/ContactBundle/Migrations/Schema/OroCRMContactBundleInstaller.php @@ -73,7 +73,7 @@ public function setAttachmentExtension(AttachmentExtension $attachmentExtension) */ public function getMigrationVersion() { - return 'v1_15'; + return 'v1_14'; } /** @@ -151,7 +151,7 @@ protected function createOrocrmContactTable(Schema $schema) $table->addIndex(['reports_to_contact_id'], 'IDX_403263EDF27EBC1E', []); $table->addIndex(['created_by_user_id'], 'IDX_403263ED7D182D95', []); $table->addIndex(['updated_by_user_id'], 'IDX_403263ED2793CC5E', []); - $table->addIndex(['last_name', 'first_name', 'id'], 'contact_name_idx', []); + $table->addIndex(['last_name', 'first_name'], 'contact_name_idx', []); $table->addIndex(['updatedAt'], 'contact_updated_at_idx', []); } diff --git a/src/OroCRM/Bundle/ContactBundle/Migrations/Schema/v1_15/UpdateIndexes.php b/src/OroCRM/Bundle/ContactBundle/Migrations/Schema/v1_15/UpdateIndexes.php deleted file mode 100644 index cc026557e41..00000000000 --- a/src/OroCRM/Bundle/ContactBundle/Migrations/Schema/v1_15/UpdateIndexes.php +++ /dev/null @@ -1,25 +0,0 @@ -getTable('orocrm_contact'); - $indexName = 'contact_name_idx'; - $indexColumns = ['last_name', 'first_name', 'id']; - if ($table->hasIndex($indexName) && $table->getIndex($indexName)->getColumns() !== $indexColumns) { - $table->dropIndex($indexName); - $table->addIndex($indexColumns, $indexName); - } - } -} diff --git a/src/OroCRM/Bundle/ContactUsBundle/Entity/ContactRequest.php b/src/OroCRM/Bundle/ContactUsBundle/Entity/ContactRequest.php index 7babcc13b26..7b4f84461e9 100644 --- a/src/OroCRM/Bundle/ContactUsBundle/Entity/ContactRequest.php +++ b/src/OroCRM/Bundle/ContactUsBundle/Entity/ContactRequest.php @@ -22,7 +22,7 @@ * @ORM\Entity * @ORM\Table( * name="orocrm_contactus_request", - * indexes={@ORM\Index(name="request_create_idx",columns={"created_at", "id"})} + * indexes={@ORM\Index(name="request_create_idx",columns={"created_at"})} * ) * * @Config( diff --git a/src/OroCRM/Bundle/ContactUsBundle/Migrations/Schema/OroCRMContactUsBundleInstaller.php b/src/OroCRM/Bundle/ContactUsBundle/Migrations/Schema/OroCRMContactUsBundleInstaller.php index e8f86df7b72..04dd1e46742 100644 --- a/src/OroCRM/Bundle/ContactUsBundle/Migrations/Schema/OroCRMContactUsBundleInstaller.php +++ b/src/OroCRM/Bundle/ContactUsBundle/Migrations/Schema/OroCRMContactUsBundleInstaller.php @@ -34,7 +34,7 @@ public function setActivityExtension(ActivityExtension $activityExtension) */ public function getMigrationVersion() { - return 'v1_10_1'; + return 'v1_10'; } /** @@ -117,7 +117,7 @@ protected function createOrocrmContactusRequestTable(Schema $schema) $table->addIndex(['opportunity_id'], 'IDX_342872E89A34590F', []); $table->addIndex(['lead_id'], 'IDX_342872E855458D', []); $table->addIndex(['workflow_step_id'], 'IDX_342872E871FE882C', []); - $table->addIndex(['created_at', 'id'], 'request_create_idx', []); + $table->addIndex(['created_at'], 'request_create_idx', []); } diff --git a/src/OroCRM/Bundle/ContactUsBundle/Migrations/Schema/v1_10_1/UpdateIndexes.php b/src/OroCRM/Bundle/ContactUsBundle/Migrations/Schema/v1_10_1/UpdateIndexes.php deleted file mode 100644 index 4204349da70..00000000000 --- a/src/OroCRM/Bundle/ContactUsBundle/Migrations/Schema/v1_10_1/UpdateIndexes.php +++ /dev/null @@ -1,25 +0,0 @@ -getTable('orocrm_contactus_request'); - $indexName = 'request_create_idx'; - $indexColumns = ['created_at', 'id']; - if ($table->hasIndex($indexName) && $table->getIndex($indexName)->getColumns() !== $indexColumns) { - $table->dropIndex($indexName); - $table->addIndex($indexColumns, $indexName); - } - } -} diff --git a/src/OroCRM/Bundle/MagentoBundle/Entity/Cart.php b/src/OroCRM/Bundle/MagentoBundle/Entity/Cart.php index a95ca26218e..7611876890c 100644 --- a/src/OroCRM/Bundle/MagentoBundle/Entity/Cart.php +++ b/src/OroCRM/Bundle/MagentoBundle/Entity/Cart.php @@ -30,7 +30,7 @@ * @ORM\Table(name="orocrm_magento_cart", * indexes={ * @ORM\Index(name="magecart_origin_idx", columns={"origin_id"}), - * @ORM\Index(name="magecart_updated_idx", columns={"updatedAt", "id"}), + * @ORM\Index(name="magecart_updated_idx", columns={"updatedAt"}), * @ORM\Index(name="magecart_payment_details_idx", columns={"payment_details"}), * @ORM\Index(name="status_name_items_qty_idx", columns={"status_name", "items_qty"}) * }, diff --git a/src/OroCRM/Bundle/MagentoBundle/Entity/Customer.php b/src/OroCRM/Bundle/MagentoBundle/Entity/Customer.php index 2cad5deedda..fa456666260 100644 --- a/src/OroCRM/Bundle/MagentoBundle/Entity/Customer.php +++ b/src/OroCRM/Bundle/MagentoBundle/Entity/Customer.php @@ -35,7 +35,7 @@ * uniqueConstraints={@ORM\UniqueConstraint(name="magecustomer_oid_cid_unq", columns={"origin_id", "channel_id"})}, * indexes={ * @ORM\Index(name="magecustomer_name_idx",columns={"first_name", "last_name"}), - * @ORM\Index(name="magecustomer_rev_name_idx",columns={"last_name", "first_name", "id"}), + * @ORM\Index(name="magecustomer_rev_name_idx",columns={"last_name", "first_name"}), * @ORM\Index(name="magecustomer_email_guest_idx",columns={"email"}) * } * ) diff --git a/src/OroCRM/Bundle/MagentoBundle/Entity/Order.php b/src/OroCRM/Bundle/MagentoBundle/Entity/Order.php index c0e9f1604d1..cb48882b88c 100644 --- a/src/OroCRM/Bundle/MagentoBundle/Entity/Order.php +++ b/src/OroCRM/Bundle/MagentoBundle/Entity/Order.php @@ -12,6 +12,8 @@ use Oro\Bundle\UserBundle\Entity\User; use Oro\Bundle\AddressBundle\Entity\AddressType; use Oro\Bundle\AddressBundle\Entity\AbstractTypedAddress; +use Oro\Bundle\WorkflowBundle\Entity\WorkflowItem; +use Oro\Bundle\WorkflowBundle\Entity\WorkflowStep; use Oro\Bundle\LocaleBundle\Model\FirstNameInterface; use Oro\Bundle\LocaleBundle\Model\LastNameInterface; @@ -26,7 +28,7 @@ * @ORM\HasLifecycleCallbacks * @ORM\Table(name="orocrm_magento_order", * indexes={ - * @ORM\Index(name="mageorder_created_idx",columns={"created_at", "id"}) + * @ORM\Index(name="mageorder_created_idx",columns={"created_at"}) * }, * uniqueConstraints={ * @ORM\UniqueConstraint(name="unq_increment_id_channel_id", columns={"increment_id", "channel_id"}) diff --git a/src/OroCRM/Bundle/MagentoBundle/Migrations/Schema/OroCRMMagentoBundleInstaller.php b/src/OroCRM/Bundle/MagentoBundle/Migrations/Schema/OroCRMMagentoBundleInstaller.php index 2bc8834f276..11e5df358a7 100644 --- a/src/OroCRM/Bundle/MagentoBundle/Migrations/Schema/OroCRMMagentoBundleInstaller.php +++ b/src/OroCRM/Bundle/MagentoBundle/Migrations/Schema/OroCRMMagentoBundleInstaller.php @@ -110,7 +110,7 @@ public function setVisitEventAssociationExtension(VisitEventAssociationExtension */ public function getMigrationVersion() { - return 'v1_41_5'; + return 'v1_41_4'; } /** @@ -336,7 +336,7 @@ protected function createOrocrmMagentoOrderTable(Schema $schema) $table->addIndex(['data_channel_id'], 'IDX_4D09F305BDC09B73', []); $table->addIndex(['organization_id'], 'IDX_4D09F30532C8A3DE', []); $table->setPrimaryKey(['id']); - $table->addIndex(['created_at', 'id'], 'mageorder_created_idx', []); + $table->addIndex(['created_at'], 'mageorder_created_idx', []); $table->addUniqueIndex(['increment_id', 'channel_id'], 'unq_increment_id_channel_id'); } @@ -427,7 +427,7 @@ protected function createOrocrmMagentoCustomerTable(Schema $schema) $table->addIndex(['organization_id'], 'IDX_2A61EE7D32C8A3DE', []); $table->setPrimaryKey(['id']); $table->addIndex(['first_name', 'last_name'], 'magecustomer_name_idx', []); - $table->addIndex(['last_name', 'first_name', 'id'], 'magecustomer_rev_name_idx', []); + $table->addIndex(['last_name', 'first_name'], 'magecustomer_rev_name_idx', []); $table->addIndex(['email'], 'magecustomer_email_guest_idx', []); $table->addUniqueIndex(['origin_id', 'channel_id'], 'magecustomer_oid_cid_unq'); } @@ -714,7 +714,7 @@ protected function createOrocrmMagentoCartTable(Schema $schema) $table->addIndex(['organization_id'], 'IDX_96661A8032C8A3DE', []); $table->setPrimaryKey(['id']); $table->addIndex(['origin_id'], 'magecart_origin_idx', []); - $table->addIndex(['updatedAt', 'id'], 'magecart_updated_idx', []); + $table->addIndex(['updatedAt'], 'magecart_updated_idx', []); $table->addIndex(['payment_details'], 'magecart_payment_details_idx', []); $table->addIndex(['status_name', 'items_qty'], 'status_name_items_qty_idx', []); $table->addUniqueIndex(['origin_id', 'channel_id'], 'unq_cart_origin_id_channel_id'); diff --git a/src/OroCRM/Bundle/MagentoBundle/Migrations/Schema/v1_41_5/UpdateIndexes.php b/src/OroCRM/Bundle/MagentoBundle/Migrations/Schema/v1_41_5/UpdateIndexes.php deleted file mode 100644 index 759f8e0bcc2..00000000000 --- a/src/OroCRM/Bundle/MagentoBundle/Migrations/Schema/v1_41_5/UpdateIndexes.php +++ /dev/null @@ -1,41 +0,0 @@ -getTable('orocrm_magento_cart'); - $indexName = 'magecart_updated_idx'; - $indexColumns = ['updatedAt', 'id']; - if ($table->hasIndex($indexName) && $table->getIndex($indexName)->getColumns() !== $indexColumns) { - $table->dropIndex($indexName); - $table->addIndex($indexColumns, $indexName); - } - - $table = $schema->getTable('orocrm_magento_order'); - $indexName = 'mageorder_created_idx'; - $indexColumns = ['created_at', 'id']; - if ($table->hasIndex($indexName) && $table->getIndex($indexName)->getColumns() !== $indexColumns) { - $table->dropIndex($indexName); - $table->addIndex($indexColumns, $indexName); - } - - $table = $schema->getTable('orocrm_magento_customer'); - $indexName = 'magecustomer_rev_name_idx'; - $indexColumns = ['last_name', 'first_name', 'id']; - if ($table->hasIndex($indexName) && $table->getIndex($indexName)->getColumns() !== $indexColumns) { - $table->dropIndex($indexName); - $table->addIndex($indexColumns, $indexName); - } - } -} diff --git a/src/OroCRM/Bundle/MagentoBundle/Tests/Functional/Controller/NewsletterSubscriberControllerTest.php b/src/OroCRM/Bundle/MagentoBundle/Tests/Functional/Controller/NewsletterSubscriberControllerTest.php index 9d2a91217a2..fde61c24d9e 100644 --- a/src/OroCRM/Bundle/MagentoBundle/Tests/Functional/Controller/NewsletterSubscriberControllerTest.php +++ b/src/OroCRM/Bundle/MagentoBundle/Tests/Functional/Controller/NewsletterSubscriberControllerTest.php @@ -2,6 +2,8 @@ namespace OroCRM\Bundle\MagentoBundle\Tests\Functional\Controller; +use Doctrine\ORM\EntityManager; + use Oro\Bundle\ImportExportBundle\Job\JobExecutor; use Oro\Bundle\ImportExportBundle\Job\JobResult; use OroCRM\Bundle\MagentoBundle\Entity\NewsletterSubscriber; @@ -106,8 +108,8 @@ public function gridProvider() 'gridFilters' => [], 'assert' => [ 'channelName' => 'Magento channel', - 'email' => 'subscriber3@example.com', - 'status' => 'Unsubscribed', + 'email' => 'subscriber@example.com', + 'status' => 'Subscribed', 'customerName' => 'John Doe', 'customerEmail' => 'test@example.com' ], @@ -122,8 +124,8 @@ public function gridProvider() ], 'assert' => [ 'channelName' => 'Magento channel', - 'email' => 'subscriber3@example.com', - 'status' => 'Unsubscribed', + 'email' => 'subscriber@example.com', + 'status' => 'Subscribed', 'customerName' => 'John Doe', 'customerEmail' => 'test@example.com' ], diff --git a/src/OroCRM/Bundle/SalesBundle/Entity/Lead.php b/src/OroCRM/Bundle/SalesBundle/Entity/Lead.php index cecd10ddef2..d34275bc5b6 100644 --- a/src/OroCRM/Bundle/SalesBundle/Entity/Lead.php +++ b/src/OroCRM/Bundle/SalesBundle/Entity/Lead.php @@ -32,7 +32,7 @@ * * @ORM\Table( * name="orocrm_sales_lead", - * indexes={@ORM\Index(name="lead_created_idx",columns={"createdAt", "id"})} + * indexes={@ORM\Index(name="lead_created_idx",columns={"createdAt"})} * ) * @ORM\Entity(repositoryClass="OroCRM\Bundle\SalesBundle\Entity\Repository\LeadRepository") * @ORM\HasLifecycleCallbacks() diff --git a/src/OroCRM/Bundle/SalesBundle/Entity/Opportunity.php b/src/OroCRM/Bundle/SalesBundle/Entity/Opportunity.php index a4b5f7f158e..469433c039c 100644 --- a/src/OroCRM/Bundle/SalesBundle/Entity/Opportunity.php +++ b/src/OroCRM/Bundle/SalesBundle/Entity/Opportunity.php @@ -23,7 +23,7 @@ * @ORM\Table( * name="orocrm_sales_opportunity", * indexes={ - * @ORM\Index(name="opportunity_created_idx",columns={"created_at", "id"}), + * @ORM\Index(name="opportunity_created_idx",columns={"created_at"}), * @ORM\Index( * name="opportunities_by_status_idx", * columns={"organization_id","status_id","close_revenue","budget_amount","created_at"} diff --git a/src/OroCRM/Bundle/SalesBundle/Migrations/Schema/OroCRMSalesBundleInstaller.php b/src/OroCRM/Bundle/SalesBundle/Migrations/Schema/OroCRMSalesBundleInstaller.php index 729a0917f77..33126d7fc9e 100644 --- a/src/OroCRM/Bundle/SalesBundle/Migrations/Schema/OroCRMSalesBundleInstaller.php +++ b/src/OroCRM/Bundle/SalesBundle/Migrations/Schema/OroCRMSalesBundleInstaller.php @@ -198,7 +198,7 @@ protected function createOrocrmSalesOpportunityTable(Schema $schema) $table->addColumn('notes', 'text', ['notnull' => false]); $table->addColumn('closed_at', 'datetime', ['notnull' => false]); $table->addIndex(['contact_id'], 'idx_c0fe4aace7a1254a', []); - $table->addIndex(['created_at', 'id'], 'opportunity_created_idx', []); + $table->addIndex(['created_at'], 'opportunity_created_idx', []); $table->addUniqueIndex(['workflow_item_id'], 'uniq_c0fe4aac1023c4ee'); $table->addIndex(['user_owner_id'], 'idx_c0fe4aac9eb185f9', []); $table->addIndex(['lead_id'], 'idx_c0fe4aac55458d', []); @@ -331,7 +331,7 @@ protected function createOrocrmSalesLeadTable(Schema $schema) $table->addIndex(['user_owner_id'], 'idx_73db46339eb185f9', []); $table->addIndex(['customer_id'], 'IDX_73DB46339395C3F3', []); $table->addIndex(['data_channel_id'], 'IDX_73DB4633BDC09B73', []); - $table->addIndex(['createdat', 'id'], 'lead_created_idx', []); + $table->addIndex(['createdat'], 'lead_created_idx', []); $table->addIndex(['contact_id'], 'idx_73db4633e7a1254a', []); $table->setPrimaryKey(['id']); $table->addIndex(['workflow_step_id'], 'idx_73db463371fe882c', []); diff --git a/src/OroCRM/Bundle/SalesBundle/Migrations/Schema/v1_25_7/UpdateIndexes.php b/src/OroCRM/Bundle/SalesBundle/Migrations/Schema/v1_25_7/UpdateIndexes.php deleted file mode 100644 index 47caa2d9cd7..00000000000 --- a/src/OroCRM/Bundle/SalesBundle/Migrations/Schema/v1_25_7/UpdateIndexes.php +++ /dev/null @@ -1,33 +0,0 @@ -getTable('orocrm_sales_lead'); - $indexName = 'lead_created_idx'; - $indexColumns = ['createdAt', 'id']; - if ($table->hasIndex($indexName) && $table->getIndex($indexName)->getColumns() !== $indexColumns) { - $table->dropIndex($indexName); - $table->addIndex($indexColumns, $indexName); - } - - $table = $schema->getTable('orocrm_sales_opportunity'); - $indexName = 'opportunity_created_idx'; - $indexColumns = ['created_at', 'id']; - if ($table->hasIndex($indexName) && $table->getIndex($indexName)->getColumns() !== $indexColumns) { - $table->dropIndex($indexName); - $table->addIndex($indexColumns, $indexName); - } - } -} From 46f7ec19837ce786625e5ec85d26288be204045d Mon Sep 17 00:00:00 2001 From: Pavel Usachev Date: Fri, 3 Feb 2017 12:53:19 +0200 Subject: [PATCH 3/3] =?UTF-8?q?CRM-6669:=20Widget=20=E2=80=9CCampaigns=20B?= =?UTF-8?q?y=20Close=20Revenue=20=E2=80=9D:=20Total=20for=20campaign=20ar?= =?UTF-8?q?=E2=80=A6=20(#7009)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * CRM-6669: Widget “Campaigns By Close Revenue ”: Total for campaign are shown incorrectly for “today” date range. - fixed sql query for filter campaigns with close revenue more than 0 - added functional test for null opportunity close revenue --- .../Entity/Repository/CampaignRepository.php | 1 + .../Dashboard/CampaignByCloseRevenueTest.php | 48 +++++++++++ ...oadCampaignByCloseRevenueWidgetFixture.php | 79 ++++++++++++++----- 3 files changed, 109 insertions(+), 19 deletions(-) diff --git a/src/OroCRM/Bundle/CampaignBundle/Entity/Repository/CampaignRepository.php b/src/OroCRM/Bundle/CampaignBundle/Entity/Repository/CampaignRepository.php index 00ca8e2ab80..17d2f04c330 100644 --- a/src/OroCRM/Bundle/CampaignBundle/Entity/Repository/CampaignRepository.php +++ b/src/OroCRM/Bundle/CampaignBundle/Entity/Repository/CampaignRepository.php @@ -153,6 +153,7 @@ public function getCampaignsByCloseRevenueQB($opportunitiesAlias) ->join('OroCRMSalesBundle:Lead', 'lead', 'WITH', 'lead.campaign = campaign') ->join('lead.opportunities', $opportunitiesAlias) ->where(sprintf('%s.status=\'won\'', $opportunitiesAlias)) + ->andWhere(sprintf('%s.closeRevenue>0', $opportunitiesAlias)) ->orderBy('closeRevenue', 'DESC') ->groupBy('campaign.name'); diff --git a/src/OroCRM/Bundle/SalesBundle/Tests/Functional/Dashboard/CampaignByCloseRevenueTest.php b/src/OroCRM/Bundle/SalesBundle/Tests/Functional/Dashboard/CampaignByCloseRevenueTest.php index d278cd9ce1b..6155574149e 100644 --- a/src/OroCRM/Bundle/SalesBundle/Tests/Functional/Dashboard/CampaignByCloseRevenueTest.php +++ b/src/OroCRM/Bundle/SalesBundle/Tests/Functional/Dashboard/CampaignByCloseRevenueTest.php @@ -49,6 +49,7 @@ public function testDateRangeAllTypeFilter($requestData) $this->assertNotEmpty($crawler->html()); $chartData = $this->getChartData($crawler); + //If we have data for chart we need only first campaign if ($chartData) { $chartData = reset($chartData); @@ -61,6 +62,53 @@ public function testDateRangeAllTypeFilter($requestData) ); } + /** + * @dataProvider widgetConfigureProvider + * @array $requestData + */ + public function testFilterCampaignByNullCloseRevenue(array $requestData) + { + $this->configureWidget($this->widget, $requestData['widgetConfig']); + + $crawler = $this->client->request( + 'GET', + $this->getUrl( + 'orocrm_campaign_dashboard_campaigns_by_close_revenue_chart', + [ + 'widget' => 'campaigns_by_close_revenue', + '_widgetId' => $this->widget->getId() + ] + ) + ); + $response = $this->client->getResponse(); + $this->assertEquals($response->getStatusCode(), 200, "Failed in getting widget view !"); + $this->assertNotEmpty($crawler->html()); + + $chartData = $this->getChartData($crawler); + + $this->assertCount( + $requestData['expectedCampaignCount'], + $chartData, + "Opportunity with null or 0 close revenue is presented" + ); + } + + public function widgetConfigureProvider() + { + return [ + 'Closed lost opportunities' => [ + [ + 'widgetConfig' => [ + 'campaigns_by_close_revenue[dateRange][part]' => 'value', + 'campaigns_by_close_revenue[dateRange][type]' => AbstractDateFilterType::TYPE_ALL_TIME, + ], + 'expectedResult' => 200, // 2 opportunities * $100 + 'expectedCampaignCount' => 1 // Opportunity with test campaign have null close revenue + ], + ], + ]; + } + /** * @return array */ diff --git a/src/OroCRM/Bundle/SalesBundle/Tests/Functional/Fixture/LoadCampaignByCloseRevenueWidgetFixture.php b/src/OroCRM/Bundle/SalesBundle/Tests/Functional/Fixture/LoadCampaignByCloseRevenueWidgetFixture.php index 1d749d004c6..45b8e63eab4 100644 --- a/src/OroCRM/Bundle/SalesBundle/Tests/Functional/Fixture/LoadCampaignByCloseRevenueWidgetFixture.php +++ b/src/OroCRM/Bundle/SalesBundle/Tests/Functional/Fixture/LoadCampaignByCloseRevenueWidgetFixture.php @@ -26,27 +26,50 @@ class LoadCampaignByCloseRevenueWidgetFixture extends AbstractFixture private $opportunityCount = 0; - protected function createLead() - { + /** + * @param string $name + * @param Campaign $campaign + * @param string $referenceName + * + * @return Lead + */ + protected function createLead( + $name, + Campaign $campaign, + $referenceName = null + ) { $lead = new Lead(); - $lead->setName('Lead name'); + $lead->setName($name); $lead->setOrganization($this->organization); - $lead->setCampaign($this->getReference('default_campaign')); + $lead->setCampaign($campaign); $this->em->persist($lead); $this->em->flush(); - $this->setReference('default_lead', $lead); + + ($referenceName === null ) ?: $this->setReference($referenceName, $lead); + + return $lead; } - protected function createOpportunity($createdAt, $status) - { + /** + * @param \DateTime $createdAt + * @param string $status + * @param Lead $lead + * @param int $closeRevenue + */ + protected function createOpportunity( + $createdAt, + $status, + Lead $lead, + $closeRevenue = null + ) { $className = ExtendHelper::buildEnumValueClassName(Opportunity::INTERNAL_STATUS_CODE); $opportunityStatus = $this->em->getRepository($className)->find(ExtendHelper::buildEnumValueId($status)); $opportunity = new Opportunity(); $opportunity->setName(sprintf('Test Opportunity #%d', ++$this->opportunityCount)); $opportunity->setStatus($opportunityStatus); - $opportunity->setLead($this->getReference('default_lead')); - $opportunity->setCloseRevenue(100); + $opportunity->setLead($lead); + ($closeRevenue === null ) ?: $opportunity->setCloseRevenue($closeRevenue); $opportunity->setOrganization($this->organization); $this->em->persist($opportunity); @@ -54,28 +77,48 @@ protected function createOpportunity($createdAt, $status) $this->em->flush(); } - protected function createCampaign() + /** + * @param string $name + * @param string $code + * @param string $reference + * + * @return Campaign + */ + protected function createCampaign($name, $code, $reference = null) { $campaign = new Campaign(); - $campaign->setName('Campaign'); - $campaign->setCode('cmp'); + $campaign->setName($name); + $campaign->setCode($code); $campaign->setOrganization($this->organization); $campaign->setReportPeriod(Campaign::PERIOD_MONTHLY); $this->em->persist($campaign); $this->em->flush(); - $this->setReference('default_campaign', $campaign); + + ($reference === null) ?: $this->setReference($reference, $campaign); + + return $campaign; } protected function createOpportunities() { $createdAt = new \DateTime('2016-12-28 12:03:10', new \DateTimeZone('UTC')); + + $defaultCampaign = $this->createCampaign('Default campaing', 'cmt'); + $anotherCampaign = $this->createCampaign('Another campaing', 'test'); + + $defaultLead = $this->createLead('Default Lead', $defaultCampaign); + $anotherLead = $this->createLead('Another Lead', $anotherCampaign); + // Every opportunity has value of $100 - $this->createOpportunity($createdAt, 'won'); - $this->createOpportunity($createdAt, 'in_progress'); - $this->createOpportunity($createdAt, 'lost'); + $this->createOpportunity($createdAt, 'won', $defaultLead, 100); + $this->createOpportunity($createdAt, 'in_progress', $defaultLead, 100); + $this->createOpportunity($createdAt, 'lost', $defaultLead, 100); + + //This opportunity without close revenue + $this->createOpportunity($createdAt, 'won', $anotherLead); $createdAt->add(new \DateInterval('P1D')); - $this->createOpportunity($createdAt, 'won'); + $this->createOpportunity($createdAt, 'won', $defaultLead, 100); } /** @@ -85,8 +128,6 @@ public function load(ObjectManager $manager) { $this->organization = $manager->getRepository('OroOrganizationBundle:Organization')->getFirst(); $this->em = $manager; - $this->createCampaign(); - $this->createLead(); $this->createOpportunities(); $dashboard = new Dashboard(); $dashboard->setName('dashboard');