SugarClub
SugarClub
  • User
  • Site
  • Search
  • User
  • Groups & Discussions
    Groups & Discussions
    • Product Forums
      Product-focused Q&A, discussions, best practices, fixes, and help
      Product Forums
      • Sugar Market
      • Sugar Sell & Enterprise
      • Sugar Serve
      • sales-i
    • User Groups
      Professional, Industry, Language
    • Get Involved
      Learn how to become a Raving Fan
    • Social Club
      Live, interactive, virtual meetups with other Sugar customers and Sugar’s Subject Matter experts!
    • Leadership Lounge
      Network with fellow organizational leaders, ask questions, and share insights
    • Developers
      Visit DevClub, the SugarClub group for Sugar Developers
      Developers
      • DevClub
      • Mobile Developers
      • Developer Builds
        Supplemental access level required. Inquiries: developers@sugarcrm.com
    • Additional Groups (Access Required)
      Groups that require special access will be displayed here. Contact sugarclub@sugarcrm.com for assistance. Click here to see all groups
      Additional Groups (Access Required)
      • SugarCloud Platform
  • Product Information
    Product Information
    • Release Central
      Find release-specific content to prepare for your next Sugar update
    • Documentation & Resources
      Looking to expand your Sugar knowledge? Explore our in-depth documentation and other helpful resources!
    • Product Update Blogs
      Updates about each Sugar product
    • Customer Stories »
      Case Studies by SugarCRM
  • Training & Certification
    Training & Certification
    • Training & Certification Home
      Live & On-Demand classes, Quick Videos, Sugar Certifications, and more!
    • Quick Videos
      Short videos about using Sugar
    • My SugarU Dashboard »
    • SugarU News & Updates
  • Adoption
    Adoption
    • Grow Adoption Framework
      Get started on your adoption journey and review the adoption resources from SugarCRM
  • Calendar
  • News
    News
    • Sugar News
    • SugarCRM.com News »
    • Dev Blog
    • SugarCRM Marketplace Blog
  • Help
    Help
    • Welcome to Sugar!
      New to Sugar? Get started here!
    • SugarClub Help & Instructions
      Learn more about SugarClub and find answers to questions about this site
    • New to SugarClub?
      Start your community journey here
    • Technical Support
      Sugar's support resources
      Technical Support
      • Case Portal »
        Access the SugarCRM Case Portal
      • Working with Sugar Support »
        Find out more about engaging with the SugarCRM Support team
      • SugarCloud Information
        Find information about SugarCloud service updates and site status. Contact sugarclub@sugarcrm.com to request access
  • More from Sugar
    More from Sugar
    • DevClub
    • PartnerClub
    • Support
    • SugarOutfitters Marketplace
    • sugarcrm.com
  • DevClub
  • PartnerClub
  • Support
  • Marketplace
  • sugarcrm.com
DevClub
DevClub
Dev Tutorials Executing Rector
Click here to join this group and curate your SugarClub experience.
  • +On-Boarding Framework
  • +Customization Guides
  • +Modern UI Technical Guide
  • -Automated PHP Compatibility Tool
    • Rector Basic Setup
    • Prepare Rector for MLP/Addon
    • Prepare Rector for Customizations
    • Executing Rector
    • Keeping Compatibility
    • Troubleshooting Rector
    • PHP 7.4 Warnings to PHP8.2 Errors
  • +Customization Best Practices in Sugar
  • How to write code for SugarCloud webinar Q&A
  • HOW TO: enforce ACL on Tags
  • Remove custom fields created via package installation
  • Sugar Developer Tools
  • Tutorial:  How to register custom platforms in Sugar instances via Platform extension
  • Adding a google reCAPTCHA in a Web-to-Lead form
  • Sugar Developer Blog Style Guide

Executing Rector

Now that you have your Rector properly configured with your customization, either via MLP or custom code you can continue with a dry-run or run rector automatically.

Dry-run Rector

Dry-run gives you the opportunity to see what Rector has found and will execute/change before it actually does it on your behalf.

it's time to dry-run rector by executing the following command.

Fullscreen
1
/path/to/sugar/vendor/rector/rector/bin/rector/bin/rector process --clear-cache --dry-run > php83.diff
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
/path/to/sugar/vendor/rector/rector/bin/rector/bin/rector process --clear-cache --dry-run > php83.diff

Dry run produces a very detailed output file (if you spooled it off to a file) containing the diff and the list of rector rules that were applied to make your code compatible with PHP 8.2 (which we configured it to)

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
1 file with changes
===================
1) custom/Extension/application/Ext/Include/BuildingBlock_HelloWorldDashlet.php:0
---------- begin diff ----------
@@ @@
<?php
//WARNING: The contents of this file are auto-generated
- $this->ss->assign("current_users", count($active_users));
- $this->ss->assign("user_count_param", "user_count: '".count($active_users)."'");
+ $this->ss->assign("current_users", is_countable($active_users) ? count($active_users) : 0);
+ $this->ss->assign("user_count_param", "user_count: '".(is_countable($active_users) ? count($active_users) : 0)."'");
?>
----------- end diff -----------
Applied rules:
* AddDefaultValueForUndefinedVariableRector (https://github.com/vimeo/psalm/blob/29b70442b11e3e66113935a2ee22e165a70c74a4/docs/fixing_code.md#possiblyundefinedvariable)
* CountOnNullRector (https://3v4l.org/Bndc9)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1 file with changes
===================

1) custom/Extension/application/Ext/Include/BuildingBlock_HelloWorldDashlet.php:0

    ---------- begin diff ----------
@@ @@
 <?php 
  //WARNING: The contents of this file are auto-generated
- $this->ss->assign("current_users", count($active_users));
- $this->ss->assign("user_count_param", "user_count: '".count($active_users)."'");
+ $this->ss->assign("current_users", is_countable($active_users) ? count($active_users) : 0);
+ $this->ss->assign("user_count_param", "user_count: '".(is_countable($active_users) ? count($active_users) : 0)."'");
  
 ?>
    ----------- end diff -----------

Applied rules:
 * AddDefaultValueForUndefinedVariableRector (https://github.com/vimeo/psalm/blob/29b70442b11e3e66113935a2ee22e165a70c74a4/docs/fixing_code.md#possiblyundefinedvariable)
 * CountOnNullRector (https://3v4l.org/Bndc9)

 [OK] 1 file would have changed (dry-run) by Rector                                                                     

Execute Rector

If your dry-run is clear or you are ready to let Rector auto-update your code, now it's time to get a second git commit to "clear" the system so we know exactly what rector has done to our system.

Prepare Git

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
sh-3.2$ git status
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: config_override.php
modified: custom/application/Ext/Include/modules.ext.php
Untracked files:
(use "git add <file>..." to include in what will be committed)
custom/Extension/application/Ext/Include/BuildingBlock_HelloWorldDashlet.php
custom/Extension/application/Ext/Include/orderMapping.php
custom/clients/
custom/modules/ActivityStream/
custom/modules/Forecasts/Ext/clients/
custom/modules/pmse_Project/
no changes added to commit (use "git add" and/or "git commit -a")
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
sh-3.2$ git status
On branch main
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   config_override.php
        modified:   custom/application/Ext/Include/modules.ext.php

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        custom/Extension/application/Ext/Include/BuildingBlock_HelloWorldDashlet.php
        custom/Extension/application/Ext/Include/orderMapping.php
        custom/clients/
        custom/modules/ActivityStream/
        custom/modules/Forecasts/Ext/clients/
        custom/modules/pmse_Project/

no changes added to commit (use "git add" and/or "git commit -a")

Commit

Fullscreen
1
2
3
sh-3.2$ git add . && git commit -am "Before Rector"
[master 33a18416] Before Rector
422 files changed, 96500 insertions(+)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
sh-3.2$ git add . && git commit -am "Before Rector"
[master 33a18416] Before Rector
 422 files changed, 96500 insertions(+)

Execute

Run the rector process once again, but without --dry-run and --clear-cache options as the cache is up to date (the process should look like this):

Fullscreen
1
2
➜ sugar git:(master) /path/to/sugar/vendor/rector/rector/bin/rector/bin/rector process
10/30 [▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░] 33%
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
➜  sugar git:(master) /path/to/sugar/vendor/rector/rector/bin/rector/bin/rector process                                           
 10/30 [▓▓▓▓▓▓▓▓▓░░░░░░░░░░░░░░░░░░░]  33%
 
* This may take time, depending on the complexity of the code. In some cases, this can take more than an hour.

After Execution (Git diff)

Once finished, Rector will provide a similar report to the dry-run, but now those files have actually been modified in the filesystem.
By executing git status you should see all the changes ready to work on PHP 8.3 (or depending on the config you specified)
Fullscreen
1
2
3
4
5
6
7
8
sh-3.2$ git status
On branch main
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: custom/Extension/application/Ext/Include/BuildingBlock_HelloWorldDashlet.php
no changes added to commit (use "git add" and/or "git commit -a")
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
sh-3.2$ git status
On branch main
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   custom/Extension/application/Ext/Include/BuildingBlock_HelloWorldDashlet.php

no changes added to commit (use "git add" and/or "git commit -a")
Congratulations, you now have your code compatible with PHP 8.3.

You can now commit your new code as follows:

Fullscreen
1
2
3
sh-3.2$ git add . && git commit -am "PHP 8.3 upgrade refactor"
[master 7ad3bf22] PHP 8.3 upgrade refactor
1 files changed, 1 insertions(+), 1 deletions(-)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
sh-3.2$ git add . && git commit -am "PHP 8.3 upgrade refactor"
[master 7ad3bf22] PHP 8.3 upgrade refactor
 1 files changed, 1 insertions(+), 1 deletions(-)

You can move on to the Keeping Compatibility Phase:

  • Keeping Compatibility
  • 0 comments
  • 0 members are here
  • Sign in to reply
Related
Recommended