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
    • Event Recordings
      Recordings from SugarU Live Webinars and Sugar Market Academy
    • 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 Prepare Rector for Customizations
  • Dev Blog
  • Answers & Best Practices
  • Developer On-boarding
  • Dev Tutorials
  • Developer Events
  • Event Recaps
  • Members
  • Developer Suggestions
  • Sub-Groups
  • More
  • Cancel
  • New
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

Prepare Rector for Customizations

If you are looking to make your customizations, not packaged in an MLP, compatible with different versions of PHP, this guide is for you.

You will take your customization code and add to the Sugar instance where Rector is and git has been initialized.

You need to have a inventory of your assets to create your git/rector config.

Prerequisites:

  • Basic Setup
  • Customization Assets Inventory (file path of your assets)
  • A vanila instance if you don't have an inventory

Create your Customization Inventory

If you already have your customization inventory, great! you can skip this section.

There are a few different ways of achieving the same result, we are going to use a vanilla instance as our basis for git comparison, and your current "deployed" instance with your code installed in the filesystem.

In your vanilla instance, you will follow the steps from our Basic Setup and have git init and commit.

Once you have that in place, (git status should return empty results), you are good to go on copying all the files from your deployed instance to the vanilla one.

sh-3.2$ cp -rf /path/to/current/sugar/* /path/to/vanila/sugar/


* it is important to have the exact same version of Sugar, otherwise, you'll have "noise" in the vendors folder and other files that aren't necessarily your custom code but Sugar release-related files and those can be ignored if found.

After it has been copied over, execute git status commands to get your customization inventory:

sh-3.2$ git status
On branch main
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        modules/FD_SignupFraudDetection/
        modules/FD_TransactionFraudDetect/

nothing added to commit but untracked files present (use "git add" to track)

Prepare your Rector config

Copy the paths, and paste them into the rector.php config file that was generated in the previous step, replacing the default paths in $rectorConfig->paths([ array like this (you can ignore some of the files, like *ext.php and *orderMapping.php):

    $rectorConfig->paths([
        __DIR__ . '/modules/FD_SignupFraudDetection/',
        __DIR__ . '/modules/FD_TransactionFraudDetect/',
    ]);

* Please, notice the '/' after __DIR__ constant usage. It is required as __DIR__ does not have a trailing slash.

Modify the rector.php config file to upgrade the code to the newest supported PHP version (in our case, 8.3):

Specify PHP 8.3 as your phpVersion:

$rectorConfig->phpVersion(PhpVersion::PHP_83);

If you'd like to have only the incompatible rules between PHP 7.4 to PHP 8.3, you can use the following:

    $rectorConfig->rules([
        AddParamBasedOnParentClassMethodRector::class,
        SetStateToStaticRector::class,
        ArrayKeyExistsOnPropertyRector::class,
        ExportToReflectionFunctionRector::class,
        FilterVarToAddSlashesRector::class,
        MbStrrposEncodingArgumentPositionRector::class,
        MoneyFormatToNumberFormatRector::class,
        RealToFloatTypeCastRector::class,
        RestoreDefaultNullToNullableTypePropertyRector::class,
        StringifyStrNeedlesRector::class,
        GetClassOnNullRector::class,
        ListEachRector::class,
        ReplaceEachAssignmentWithKeyCurrentRector::class,
        ParseStrWithResultArgumentRector::class,
        StringifyDefineRector::class,
        WhileEachToForeachRector::class,
        ConsistentImplodeRector::class,
        CurlyToSquareBracketArrayStringRector::class,
        StaticCallOnNonStaticToInstanceCallRector::class,
    ]);

Add safeCount rule to your config if you are in a supported Sugar version

<?php
...
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;
...
return static function (RectorConfig $rectorConfig): void {
...
    $rectorConfig->ruleWithConfiguration(RenameFunctionRector::class, [
        'count' => 'safeCount',
    ]);
...

Full config file example (incompatibilities only)

By following those steps, you should have a rector.php similar to this to run incompatible rules between PHP 7.4 to PHP 8.3:

<?php
declare(strict_types=1);

use Rector\CodingStyle\Rector\FuncCall\ConsistentImplodeRector;
use Rector\Php72\Rector\Assign\ListEachRector;
use Rector\Php72\Rector\Assign\ReplaceEachAssignmentWithKeyCurrentRector;
use Rector\Php72\Rector\FuncCall\GetClassOnNullRector;
use Rector\Php72\Rector\FuncCall\ParseStrWithResultArgumentRector;
use Rector\Php72\Rector\FuncCall\StringifyDefineRector;
use Rector\Php72\Rector\While_\WhileEachToForeachRector;
use Rector\Php73\Rector\FuncCall\StringifyStrNeedlesRector;
use Rector\Php74\Rector\Double\RealToFloatTypeCastRector;
use Rector\Php74\Rector\FuncCall\ArrayKeyExistsOnPropertyRector;
use Rector\Php74\Rector\FuncCall\FilterVarToAddSlashesRector;
use Rector\Php74\Rector\FuncCall\MbStrrposEncodingArgumentPositionRector;
use Rector\Php74\Rector\FuncCall\MoneyFormatToNumberFormatRector;
use Rector\Php74\Rector\Property\RestoreDefaultNullToNullableTypePropertyRector;
use Rector\Php74\Rector\StaticCall\ExportToReflectionFunctionRector;
use Rector\Php80\Rector\ClassMethod\AddParamBasedOnParentClassMethodRector;
use Rector\Php80\Rector\ClassMethod\SetStateToStaticRector;
use Rector\Config\RectorConfig;
use Rector\ValueObject\PhpVersion;
use Rector\Php74\Rector\ArrayDimFetch\CurlyToSquareBracketArrayStringRector;
use Rector\Caching\ValueObject\Storage\MemoryCacheStorage;
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;
use Rector\Php70\Rector\StaticCall\StaticCallOnNonStaticToInstanceCallRector;


return static function (RectorConfig $rectorConfig): void {
    $rectorConfig->paths([
        __DIR__ . '/modules/FD_SignupFraudDetection/',
        __DIR__ . '/modules/FD_TransactionFraudDetect/',
    ]);

    $rectorConfig->cacheClass(MemoryCacheStorage::class);
    $rectorConfig->disableParallel();
    $rectorConfig->phpVersion(PhpVersion::PHP_83);

    $rectorConfig->rules([
        AddParamBasedOnParentClassMethodRector::class,
        SetStateToStaticRector::class,
        ArrayKeyExistsOnPropertyRector::class,
        ExportToReflectionFunctionRector::class,
        FilterVarToAddSlashesRector::class,
        MbStrrposEncodingArgumentPositionRector::class,
        MoneyFormatToNumberFormatRector::class,
        RealToFloatTypeCastRector::class,
        RestoreDefaultNullToNullableTypePropertyRector::class,
        StringifyStrNeedlesRector::class,
        GetClassOnNullRector::class,
        ListEachRector::class,
        ReplaceEachAssignmentWithKeyCurrentRector::class,
        ParseStrWithResultArgumentRector::class,
        StringifyDefineRector::class,
        WhileEachToForeachRector::class,
        ConsistentImplodeRector::class,
        CurlyToSquareBracketArrayStringRector::class,
        StaticCallOnNonStaticToInstanceCallRector::class,
    ]);
    $rectorConfig->ruleWithConfiguration(RenameFunctionRector::class, [
        'count' => 'safeCount',
    ]);
};

You can move on to the Execution Phase:

  • Execute Rector
  • Share
  • History
  • More
  • Cancel
  • Sign in to reply
  • Sergej Keterling
    Sergej Keterling 11 months ago in reply to Rafael Fernandes

    Hi Rafael Fernandes ,

    I don't want to bother you, but is there anything new? :)

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More Actions
    • Cancel
  • Rafael Fernandes
    Rafael Fernandes over 1 year ago in reply to Sergej Keterling

    we will get to those versions when all of our PHP8.2 efforts are completed, keep you posted when we update them to the latest rector.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More Actions
    • Cancel
  • Sergej Keterling
    Sergej Keterling over 1 year ago in reply to Rafael Fernandes

    Hi Rafael Fernandes ,

    Thank you for your feedback.

    Rectror has released the first stable version 1.0.0. this year, I have tested it with the latest version 1.0.2, but I had to exclude some classes earlier with 0.18.1 too, because they were missing. There are even more problems with version 1.0.2 with this configs.

    Sugar 14 will support php 8.3, that's why I asked about it.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More Actions
    • Cancel
  • Rafael Fernandes
    Rafael Fernandes over 1 year ago in reply to Sergej Keterling

    Hi S. Keterling,

    which version are you using? we are using 0.18.1 as stated in our Setup guide.

    at the moment we are still working with PHP8.2 and I'm sure at some point we will update our configs for PHP8.3 but not yet.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More Actions
    • Cancel
  • Sergej Keterling
    Sergej Keterling over 1 year ago in reply to Sergej Keterling

    Rafael Fernandes 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More Actions
    • Cancel
  • Sergej Keterling
    Sergej Keterling over 1 year ago

    Hello, will these configs also be adapted for the current rector versions, because it is no longer compatible? Will the config for PHP 8.3 also be available?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More Actions
    • Cancel
Related
Recommended