1843200
  .   �_’I|¥‰ÓMjqØ‚¦ð¬÷a–Ðz¾””ÔD¨ 	Å +�zà¦-ÿÀ      File not found.
  #   ˆl–Ãa¾”ªClÊq@†ãNÜTÅ£Ã„_¿Á *˜    #!/usr/local/cpanel/3rdparty/bin/perl

#                                      Copyright 2026 WebPros International, LLC
#                                                           All rights reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited.

package scripts::mass_change_php_setting;

use cPstrict;
use Getopt::Long;

use Cpanel::Config::userdata ();
use Cpanel::PackMan          ();
use Cpanel::PHP::Config      ();
use Cpanel::PHP::Vhosts      ();
use Cpanel::ProgLang         ();
use Cpanel::SafeRun::Object  ();
use Cpanel::WebServer        ();

sub usage ( $err_msg = undef ) {

    if ( defined $err_msg ) {
        say "Error: $err_msg\n";
    }

    print <<"END_MESSAGE";
Usage: $0 <php_from> <php_to> [--dryrun|-d] [--verbose|-v]
Change all users with PHP version set to <php_from> to <php_to>.
Arguments:
  <php_to>      The PHP version to change to (e.g. ea-php74)
  <php_from>    The PHP version to change from (e.g. ea-php73)
Options:
  --dryrun, -d  Show what would be changed, but do not make any changes.
  --verbose, -v Show detailed output of the changes being made.

Note:
    This *will* restart the webserver.
    This *will* restart any PHP-FPM services that are affected by the change.

**IMPORTANT NOTE**
If php_from is the system default, the system default will be changed to php_to.

Example:
    $0 ea-php73 ea-php74 --verbose

See also: /usr/local/cpanel/scripts/show_php_settings

    show_php_settings allows you to see the current PHP settings for all users and domains.

END_MESSAGE
    if ( defined $err_msg ) {
        return 1;
    }

    return 0;
}

our %package_cache;

sub _does_the_package_exist ($package) {

    if ( !%package_cache ) {
        my $packman = Cpanel::PackMan->instance();
        my $sys     = $packman->sys();
        my @array   = $packman->list( state => 'installed' );
        %package_cache = map { $_ => 1 } @array;
    }

    return 1 if ( exists $package_cache{$package} );
    return 0;
}

sub script ( $php_from, $php_to, $dryrun = 0, $verbose = 0 ) {

    unless ( defined $php_to && defined $php_from ) {
        return usage("Both <php_from> and <php_to> arguments are required.");
    }

    # Dryrun implies verbose
    $verbose = 1 if $dryrun;

    say "Changing PHP setting from '$php_from' to '$php_to'" if $verbose;
    say "(Dry run mode)"                                     if $dryrun;

    # Check and make sure both versions are valid.
    # The format is xx-phpYY where YY is the version number without the dot.
    # Nothing else is permitted

    foreach my $ver ( $php_from, $php_to ) {
        unless ( $ver =~ m/^[a-z]{2,}-php[0-9]{2}$/ ) {
            die "Invalid PHP version format: '$ver'. Expected format is 'xx-phpYY' where YY is the version number without the dot.\n";
        }
    }

    if ( !_does_the_package_exist($php_from) ) {
        die "The specified 'from' PHP version package '$php_from' is not installed on the system.\n";
    }

    if ( !_does_the_package_exist($php_to) ) {
        die "The specified 'to' PHP version package '$php_to' is not installed on the system.\n";
    }

    my $php                = Cpanel::ProgLang->new( 'type' => 'php' );
    my $system_php_version = $php->get_system_default_package();
    my $changed_default    = 0;
    my $made_changes       = 0;

    # Let's check to see if anything will change or not.

    if ( $system_php_version eq $php_from ) {
        $changed_default++;
        $made_changes++;
    }

    my @users = Cpanel::Config::userdata::load_user_list();

    my $versions = Cpanel::PHP::Vhosts::get_php_vhost_versions_from_php_config( Cpanel::PHP::Config::get_php_config_for_users( \@users ) );

    foreach my $domain (@$versions) {
        my $user        = $domain->{account};
        my $vhost       = $domain->{vhost};
        my $current_ver = $domain->{version}