Sugar 8 Pro to Enterprise Conversion Upgrade fails - Duplicate entry into SugarFavorites

So I'm currently working on upgrading our SugarCRM instance.

Before proceeding with the rest of the upgrades, I need to convert from Pro to Enterprise.

When applying the upgrade, I see this error in UpgradeWizard.log

Wed, 30 Aug 2023 19:12:27 +0000 [Upgrader] - Starting script 6_SharableDashboards
Wed, 30 Aug 2023 19:12:27 +0000 [Upgrader] - ERROR: Exception: An exception occurred while executing 'INSERT INTO sugarfavorites (id, name, date_entered, date_modified, modified_user_id, created_by, description, deleted, module, record_id, assigned_user_id) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)' with params ["098fee45e1e7041684fa96f0f459c8a3", null, "2023-08-30 19:12:27", "2023-08-30 19:12:27", "1", "1", null, 0, "Dashboards", "3fc434e6-9b6d-357a-0759-576936d6ca5e", "1"]:
Duplicate entry '098fee45e1e7041684fa96f0f459c8a3' for key 'PRIMARY'
Wed, 30 Aug 2023 19:12:27 +0000 [Upgrader] - Finished script 6_SharableDashboards
Wed, 30 Aug 2023 19:12:27 +0000 [Upgrader] - ERROR: Post-upgrade stage failed! Error executing post scripts


I'm not sure what the purpose of this script is, but I checked the 7.9.4 -> 8.0 upgrader for 6_SharableDashboards.php and I see the exact same file there. So I'm wondering if anyone has run into this issue before and what they might have done to fix it.

Seems like I have no choice but to try to modify the upgrader to remove this script?


Parents
  • I don't think the error refers to the 6_SharableDashboards

    The Error is on the post-upgrade stage which, in my experience, is often related to a problem with file permissions and the final QRR that each upgrade goes through.

    Check this guideline on File Permissions and rerun the silent upgrader with the continue option (-S continue) or rerun the upgrade wizard to finish the upgrade.

    FrancescaS

    PS. Also check what other ERROR lines you have, it looks like you have an issue with a duplicate entry for primary key in your sugarfavorites table. (just 2 lines up from the last)

  • I think the error is in the post upgrade script that  is referencing. It's not clear why this script would need to run on a Pro to Ent conversion as I don't recall there being any additional functionality to dashboard sharing introduced in Enterprise.

    Josh,

    What results do you get from running the following queries on your Pro 8.0 instance?

    SELECT count(*) FROM sugarfavorites WHERE module = 'Dashboards' AND deleted = '0';
    SELECT * FROM sugarfavorites WHERE id = '098fee45e1e7041684fa96f0f459c8a3';

    Chris

  • I get 334 for the count query and I get 1 result back for the 2nd query.

    For reference, we are trying to get from 7.8.22 to present. (Yes, I'm aware of the number of versions we'll have to go)

    The upgrade prior to this one (7.9.4 -> 8.0.0) contains this exact same script.

    Here is a copy of the 6_ShareableDashboards.php script as well. which is present in both of these packages:
    located in modules/Dashboards/upgrade/scripts/post/6_ShareableDashboards.php in both packages.

    -SugarPro-Upgrade-7.9.4.0-to-8.0.0
    -SugarPro-to-SugarEnt-Conversion-8.0.0

    <?php
    /*
     * Your installation or use of this SugarCRM file is subject to the applicable
     * terms available at
     * http://support.sugarcrm.com/Resources/Master_Subscription_Agreements/.
     * If you do not agree to all of the applicable terms or do not have the
     * authority to bind the entity as an authorized representative, then do not
     * install or use this SugarCRM file.
     *
     * Copyright (C) SugarCRM Inc. All rights reserved.
     */
    
    /**
     * Class SugarUpgradeSharableDashboards
     *
     * This upgrader runs for each user, and then each user's dashboard. It contains
     * the upgrade requirements for sharable dashboards, including:
     *  Favorite assignment
     *  Team assignment
     */
    class SugarUpgradeSharableDashboards extends UpgradeScript
    {
        public $order = 6900;
        public $type = self::UPGRADE_DB;
        public function run()
        {
            if (version_compare($this->from_version, '7.10', '>=')) {
                return;
            }
    
            $this->updateTeams();
            $this->addToFavorites();
        }
    
        private function updateTeams()
        {
            $conn = $this->db->getConnection();
    
            $select = $conn->executeQuery('
                SELECT DISTINCT d.assigned_user_id AS used_id, t.id AS team_id
                FROM dashboards d
                INNER JOIN teams t
                ON t.associated_user_id = d.assigned_user_id
                AND t.deleted = 0
                WHERE d.deleted = 0
            ');
    
            $update = $conn->prepare('
                UPDATE dashboards
                SET team_id = ?,
                team_set_id = ?
                WHERE assigned_user_id = ?
            ');
    
            while (($row = $select->fetch())) {
                $teamId = $row['team_id'];
                $userId = $row['used_id'];
    
                // Handle team assignment
                $teamSetId = (new TeamSet())->addTeams([$teamId]);
                $update->execute([$teamId, $teamSetId, $userId]);
            }
        }
    
        private function addToFavorites()
        {
            $stmt = $this->db->getConnection()->executeQuery('
                SELECT dashboards.id, dashboards.assigned_user_id
                FROM dashboards
                WHERE dashboards.deleted = 0
            ');
    
            while (($row = $stmt->fetch())) {
                $userId = $row['assigned_user_id'];
                $dashboardId = $row['id'];
    
                // Add the dashboard to the user's favorites
                $favId = SugarFavorites::generateGUID('Dashboards', $dashboardId, $userId);
    
                $fav = BeanFactory::newBean('SugarFavorites');
                $fav->id = $favId;
                $fav->module = 'Dashboards';
                $fav->record_id = $dashboardId;
                $fav->created_by = $userId;
                $fav->assigned_user_id = $userId;
                $fav->modified_user_id = $userId;
                $fav->new_with_id = true;
                $fav->update_modified_by = false;
                $fav->set_created_by = false;
                $fav->save();
            }
        }
    }

  • Thanks for confirming the query results,  . The script being present in the 7.9.4.0 to 8.0.0 upgrade package makes sense because 8.0 is where shareable dashboards were released as a feature. I don't think the script was intended to be in the 8.0 conversion package since it would have already run for anyone performing that conversion as you have found. 

    I confirmed the 6_ShareableDashboards script is not in the 9.0 Pro-to-Ent conversion package, so I think the best course of action is to upgrade Pro 8.0 to 9.0 and then perform the conversion there rather than manually modifying the conversion package for 8.0.

    Chris

  • That seems like a good plan! 

    However, my downloads manager only shows the Sugar Enterprise upgrades for each version under "Upgrade Packages". Perhaps support will need to send me the pro upgrades? Or do I need to use the silent upgrades?

    Looks like I can go:
    8.0.0 -> 8.0.3 -> 8.0.8 -> 9.0.5

  • The Silent Upgrade is just the package to run the upgrade via command line, you will still need the PRO upgrade files from Support.

    FrancescaS

Reply Children
No Data