Error in determineIfUpgrade function #4362

Open
opened 2026-02-20 16:16:34 -05:00 by deekerman · 0 comments
Owner

Originally created by @babington-andy on GitHub (Aug 6, 2020).

Issue

When installing a module package the upgrade wizard checks whether this is an upgrade using the determineIfUpgrade function in modules/Administration/UpgradeHistory.php, it does so by checking the upgrade_history table, fetching all rows matching the id_name of the package...

$query = "SELECT id, version FROM " . $this->table_name . " WHERE id_name = '$id_name' ORDER BY date_entered DESC";
$result = $this->db->query($query);

It then loops through all of the returned rows checking if the current row is a greater version than the previous row ($temp_version)...

while ($row = $this->db->fetchByAssoc($result)) {
    if (!$this->is_right_version_greater(explode('.', $row['version']), explode('.', $temp_version))) {
        $temp_version = $row['version'];
        $id = $row['id'];
    }
}//end while

...if the current row version is NOT greater, it sets the $temp_version to the current row version and checks against the next row.

This behaviour is incorrect, it should set the $temp_version to the current row version if the current row version IS greater than the previous row.

Expected Behavior

A package being installed that is an upgrade should be identified and treated as an upgrade.

Actual Behavior

A package being installed that is an upgrade is not identified as an upgrade, and is treated as a new package.

Possible Fix

The code block indicated above should be changed to the following (remove the !)...

while ($row = $this->db->fetchByAssoc($result)) {
    if ($this->is_right_version_greater(explode('.', $row['version']), explode('.', $temp_version))) {
        $temp_version = $row['version'];
        $id = $row['id'];
    }
}//end while

Steps to Reproduce

  1. Create a simple package containing a file called testfile1.php with a manifest such as...
$manifest = array(
    0 =>
    array(
        'acceptable_sugar_versions' =>
        array(
            0 => '6.5.25',
        ),
    ),
    1 =>
    array(
        'acceptable_sugar_flavors' =>
        array(
            0 => 'CE',
            1 => 'PRO',
            2 => 'ENT',
        ),
    ),
    'readme' => '',
    'key' => 'examplepackage',
    'author' => '',
    'description' => '',
    'icon' => '',
    'is_uninstallable' => true,
    'name' => 'Example Package',
    'published_date' => '2020-08-01 01:00:00',
    'type' => 'module',
    'version' => '0.1.2',
    'remove_tables' => 'prompt',
);

$installdefs = array(
    'id' => 'examplepackage',
    'copy' => array(
        array(
            'from' => '<basepath>/testfile1.php',
            'to' => 'custom/testfile1.php',
        ),
    ),
);
  1. Install the package
  2. Create an upgrade to the package containing a file called testfile2.php with a manifest like this...
$manifest = array(
    0 =>
    array(
        'acceptable_sugar_versions' =>
        array(
            0 => '6.5.25',
        ),
    ),
    1 =>
    array(
        'acceptable_sugar_flavors' =>
        array(
            0 => 'CE',
            1 => 'PRO',
            2 => 'ENT',
        ),
    ),
    'readme' => '',
    'key' => 'examplepackage',
    'author' => '',
    'description' => '',
    'icon' => '',
    'is_uninstallable' => true,
    'name' => 'Example Package',
    'published_date' => '2020-08-01 02:00:00',
    'type' => 'module',
    'version' => '0.1.3',
    'remove_tables' => 'prompt',
);

$installdefs = array(
    'id' => 'examplepackage',
);

$upgrade_manifest = array(
    'upgrade_paths' => array(
        '0.1.2' => array(
            'id' => 'examplepackage',
            'copy' => array(
                array(
                    'from' => '<basepath>/testfile2.php',
                    'to' => 'custom/testfile2.php',
                ),
            ),
        ),
    ),
);
  1. Install the upgrade package
  2. Confirm that testfile2.php did not get uploaded to custom/testfile2.php

Context

This bug affected me when trying to upgrade a package I had installed

Your Environment

  • SuiteCRM Version used: 7.11.12
  • Browser name and version: Firefox 78.0.2 (64-bit)
  • Environment name and version (e.g. MySQL, PHP 7): MariaDB 10.3.7, PHP 7.3
  • Operating System and version: Centos 7.8
Originally created by @babington-andy on GitHub (Aug 6, 2020). #### Issue When installing a module package the upgrade wizard checks whether this is an upgrade using the determineIfUpgrade function in modules/Administration/UpgradeHistory.php, it does so by checking the upgrade_history table, fetching all rows matching the id_name of the package... ``` $query = "SELECT id, version FROM " . $this->table_name . " WHERE id_name = '$id_name' ORDER BY date_entered DESC"; $result = $this->db->query($query); ``` It then loops through all of the returned rows checking if the current row is a greater version than the previous row ($temp_version)... ``` while ($row = $this->db->fetchByAssoc($result)) { if (!$this->is_right_version_greater(explode('.', $row['version']), explode('.', $temp_version))) { $temp_version = $row['version']; $id = $row['id']; } }//end while ``` ...if the current row version is NOT greater, it sets the $temp_version to the current row version and checks against the next row. This behaviour is incorrect, it should set the $temp_version to the current row version if the current row version IS greater than the previous row. #### Expected Behavior A package being installed that is an upgrade should be identified and treated as an upgrade. #### Actual Behavior A package being installed that is an upgrade is not identified as an upgrade, and is treated as a new package. #### Possible Fix The code block indicated above should be changed to the following (remove the !)... ``` while ($row = $this->db->fetchByAssoc($result)) { if ($this->is_right_version_greater(explode('.', $row['version']), explode('.', $temp_version))) { $temp_version = $row['version']; $id = $row['id']; } }//end while ``` #### Steps to Reproduce <!--- Provide a link to a live example, or an unambiguous set of steps to --> <!--- reproduce this bug include code to reproduce, if relevant --> 1. Create a simple package containing a file called testfile1.php with a manifest such as... ``` $manifest = array( 0 => array( 'acceptable_sugar_versions' => array( 0 => '6.5.25', ), ), 1 => array( 'acceptable_sugar_flavors' => array( 0 => 'CE', 1 => 'PRO', 2 => 'ENT', ), ), 'readme' => '', 'key' => 'examplepackage', 'author' => '', 'description' => '', 'icon' => '', 'is_uninstallable' => true, 'name' => 'Example Package', 'published_date' => '2020-08-01 01:00:00', 'type' => 'module', 'version' => '0.1.2', 'remove_tables' => 'prompt', ); $installdefs = array( 'id' => 'examplepackage', 'copy' => array( array( 'from' => '<basepath>/testfile1.php', 'to' => 'custom/testfile1.php', ), ), ); ``` 2. Install the package 3. Create an upgrade to the package containing a file called testfile2.php with a manifest like this... ``` $manifest = array( 0 => array( 'acceptable_sugar_versions' => array( 0 => '6.5.25', ), ), 1 => array( 'acceptable_sugar_flavors' => array( 0 => 'CE', 1 => 'PRO', 2 => 'ENT', ), ), 'readme' => '', 'key' => 'examplepackage', 'author' => '', 'description' => '', 'icon' => '', 'is_uninstallable' => true, 'name' => 'Example Package', 'published_date' => '2020-08-01 02:00:00', 'type' => 'module', 'version' => '0.1.3', 'remove_tables' => 'prompt', ); $installdefs = array( 'id' => 'examplepackage', ); $upgrade_manifest = array( 'upgrade_paths' => array( '0.1.2' => array( 'id' => 'examplepackage', 'copy' => array( array( 'from' => '<basepath>/testfile2.php', 'to' => 'custom/testfile2.php', ), ), ), ), ); ``` 4. Install the upgrade package 5. Confirm that testfile2.php did not get uploaded to custom/testfile2.php #### Context This bug affected me when trying to upgrade a package I had installed #### Your Environment * SuiteCRM Version used: 7.11.12 * Browser name and version: Firefox 78.0.2 (64-bit) * Environment name and version (e.g. MySQL, PHP 7): MariaDB 10.3.7, PHP 7.3 * Operating System and version: Centos 7.8
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/SuiteCRM-SuiteCRM#4362
No description provided.