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 Reply Children
  • 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();
            }
        }
    }