Use old Quotes module

Introduction

After upgrading one instance of SugarCRM from version 7 to version 8 I wanted to use old Quotes module instead of the new one. Because a lot of modification on Quotes module I didn’t want to upgrade to a new one.

As you know Quotes module moved from BWC to Sidecar in version 7.9. So I created this post to help anyone who needs to do a similar thing with Quotes module. Or if you want to do it with some other module. This principle could be used.




How to…

You need to have a copy of old Quotes, so make a copy of this folders:

/sugar/custom/modules/Quotes/
/sugar/custom/Extension/modules/Quotes/
/sugar/modules/Quotes/

After upgrading to version 8 I replaced above folders with the old ones. But that is not enough, you need to tell SugarCRM that this module is BWC, not Sidecar. To do that create a new file and specify Quotes as BWC module. So, create the file in /sugar/custom/Extension/application/Ext/Include/modules.php and add code from the snippet below.

<?php
$bwcModules[] = 'Quotes';

If you don’t do the last step then all links to Quotes would be linked to Sidecar version instead of the BWC.

To use the old Quotes module just do Quick repair and rebuild. But when doing so many customizations I prefer to do the repair through a console. To do that navigate in your console to sugar folder of your project and execute the following command.

/Applications/MAMP/bin/php/php7.12/bin/php -f repair.php

Note that I am using Mac, on other OS it can be different. Also, I am using PHP version 7.12. I prefer this because I would see immediately results and all errors in the console.




Corrections

Depending on your customization it is possible that you would get more errors or bugs when trying to use old Quotes module or any other.

Database

First that I got was an error on the database key in the Quotes table.

In /sugar/modules/Quotes/vardefs.php ‘quote_num’ field had a unique index that couldn’t be applied to the new database. Previously it was ‘fields’ => array(‘quote_num’, ‘system_id’) but now we have only quote_num as unique index.

So you can change it directly here because after all modifications this module is not upgrade safe anymore.

array(
            'name' => 'quote_num',
            'type' => 'unique',
            'fields' => array('quote_num',)
            'fields' => array(
                'quote_num',
            ),
        ),
Reports

As Reports module was also changed to Sidecar we need to change the links to it in Quotes code. In this case, I wanted to use new Reports too, so this was fine for me. Link can be changed directly in Quotes module /sugar/modules/Quotes/clients/base/menus/header/header.php but I have already customized menu so I changed it in custom directory /sugar/custom/modules/Quotes/clients/base/menus/header/header.php

Note that the last approach is better, it is always preferred to do changes in the custom folder not at the actual module.

array(
        'route' => '#Reports?filterModule=' . $module_name,
        'label' =>'LNK_QUOTE_REPORTS',
        'acl_action'=>'list',
        'acl_module' => 'Reports',
        'icon' => 'fa-bar-chart-o',
    ),

As you can see the link is set to Sidecar, previous was ‘route’=>’#bwc/index.php?module=Reports&action=index&view=quotes&query=true&report_module=Quotes’




Layout

For some modules, the layout can be a problem. I didn’t have problems on Quotes layout but after upgrading from SugarCRM 7 to SugarCRM 8 I had problems with the layout of Leads, Cases etc. Problem is easy to solve. In SugarCRM 8 layout has been changed and if you make customization of it then it would probably break. Custom layout for record view is defined in the file /sugar/custom/modules/{MODULE_NAME}/clients/base/layouts/record/record.php similar is for list view. Just copy default record.php layout to it and add your modifications. Here is an example of a default record.php layout in SugarCRM 8.

$viewdefs[$module_name]['base']['layout']['record'] = array(
    'components' => array(
        array(
            'layout' => array(
                'type' => 'default',
                'name' => 'sidebar',
                'components' => array(
                    array(
                        'layout' => array(
                            'type' => 'base',
                            'name' => 'main-pane',
                            'css_class' => 'main-pane span8',
                            'components' => array(
                                array(
                                    'view' => 'record',
                                    'primary' => true,
                                ),
                                array(
                                    'layout' => 'extra-info',
                                ),
                                array(
                                    'view' => 'mint-panel',
                                ),
                                array(
                                    'layout' => array(
                                        'type' => 'filterpanel',
                                        'last_state' => array(
                                            'id' => 'record-filterpanel',
                                            'defaults' => array(
                                                'toggle-view' => 'subpanels',
                                            ),
                                        ),
                                        'refresh_button' => true,
                                        'availableToggles' => array(
                                            array(
                                                'name' => 'subpanels',
                                                'icon' => 'fa-table',
                                                'label' => 'LBL_DATA_VIEW',
                                            ),
                                            array(
                                                'name' => 'list',
                                                'icon' => 'fa-table',
                                                'label' => 'LBL_LISTVIEW',
                                            ),
                                            array(
                                                'name' => 'activitystream',
                                                'icon' => 'fa-clock-o',
                                                'label' => 'LBL_ACTIVITY_STREAM',
                                            ),
                                        ),
                                        'components' => array(
                                            array(
                                                'layout' => 'filter',
                                                'xmeta' => array(
                                                    'layoutType' => '',
                                                ),
                                                'loadModule' => 'Filters',
                                            ),
                                            array(
                                                'view' => 'filter-rows',
                                            ),
                                            array(
                                                'view' => 'filter-actions',
                                            ),
                                            array(
                                                'layout' => 'activitystream',
                                                'context' =>
                                                    array(
                                                        'module' => 'Activities',
                                                    ),
                                            ),
                                            array(
                                                'layout' => 'subpanels',
                                            ),
                                        ),
                                    ),
                                ),
                            ),
                        ),
                    ),
                    array(
                        'layout' => array(
                            'type' => 'base',
                            'name' => 'dashboard-pane',
                            'css_class' => 'dashboard-pane',
                            'components' => array(
                                array(
                                    'layout' => array(
                                        'type' => 'dashboard',
                                        'last_state' => array(
                                            'id' => 'last-visit',
                                        )
                                    ),
                                    'context' => array(
                                        'forceNew' => true,
                                        'module' => 'Home',
                                    ),
                                    'loadModule' => 'Dashboards',
                                ),
                            ),
                        ),
                    ),
                    array(
                        'layout' => array(
                            'type' => 'base',
                            'name' => 'preview-pane',
                            'css_class' => 'preview-pane',
                            'components' => array(
                                array(
                                    'layout' => 'preview',
                                ),
                            ),
                        ),
                    ),
                ),
            ),
        ),
    ),
);
Other

I didn’t have much more problems. But there were some bugs in modified PHP files mostly related to the new PHP version. For that just take a look at your PHP error log file and sugarcrm.log

Conclusion

This was an example of how to use old Quotes module. This can be applied to any BWC module that you want to use instead Sidecar. Just note that you need to know which modules are related so maybe you will need to change more than one module if it not working properly. I luckily didn’t had that kind of problems with Quote module.

If you liked this post, check other our posts too. For instance our post here about extending module class.

Also check our YouTube channel here.

Marko Vucak Author

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *