upgrade_connectors();
logThis('End upgrade_connectors', $path);
//Unlink files that have been removed
if (function_exists('unlinkUpgradeFiles')) {
    unlinkUpgradeFiles($sugar_version, $path);
}
if (function_exists('rebuildSprites') && function_exists('imagecreatetruecolor')) {
    rebuildSprites(true);
}
//Patch for bug57431 : Module name isn't updated in portal layout editor
updateRenamedModulesLabels();
//setup forecast defualt settings
if (version_compare($sugar_version, '6.7.0', '<')) {
    require_once clean_path($unzip_dir . '/scripts/upgrade_utils.php');
    require_once $unzip_dir . '/' . $zip_from_dir . '/modules/Forecasts/ForecastsDefaults.php';
    ForecastsDefaults::setupForecastSettings(true, $sugar_version, getUpgradeVersion());
    ForecastsDefaults::upgradeColumns();
    // do the config update to add the 'support' platform to any config with the category of 'portal'
    updatePortalConfigToContainPlatform();
}
// Bug 57216 - Upgrade wizard dying on metadata upgrader because needed files were
// already called but news needed to replace them. This moves the metadata upgrader
// later in the process - rgonzalez
logThis('Checking for mobile/portal metadata upgrade...');
// 6.6 metadata enhancements for portal and wireless, should only be
// handled for upgrades FROM pre-6.6 to a version POST 6.6 and MUST be
// handled AFTER inclusion of the upgrade package files
if (!didThisStepRunBefore('commit', 'upgradePortalMobileMetadata')) {
    if (version_compare($sugar_version, '6.6.0', '<')) {
        if (file_exists('modules/UpgradeWizard/SidecarUpdate/SidecarMetaDataUpgrader.php')) {
            set_upgrade_progress('commit', 'in_progress', 'upgradePortalMobileMetadata', 'in_progress');
     require_once 'modules/UpgradeWizard/SugarMerge/SugarMerge.php';
     $merger = new SugarMerge($zipBasePath);
     $merger->mergeAll();
     set_upgrade_progress('end', 'in_progress', 'threewaymerge', 'done');
 }
 ///////////////////////////////////////////////////////////////////////////////
 ////	COPY NEW FILES INTO TARGET INSTANCE
 if (!didThisStepRunBefore('commit', 'commitCopyNewFiles')) {
     set_upgrade_progress('commit', 'in_progress', 'commitCopyNewFiles', 'in_progress');
     $split = commitCopyNewFiles($unzip_dir, $zip_from_dir);
     $copiedFiles = $split['copiedFiles'];
     $skippedFiles = $split['skippedFiles'];
     set_upgrade_progress('commit', 'in_progress', 'commitCopyNewFiles', 'done');
 }
 require_once clean_path($unzip_dir . '/scripts/upgrade_utils.php');
 $new_sugar_version = getUpgradeVersion();
 $origVersion = substr(preg_replace("/[^0-9]/", "", $sugar_version), 0, 3);
 $destVersion = substr(preg_replace("/[^0-9]/", "", $new_sugar_version), 0, 3);
 $siv_varset_1 = setSilentUpgradeVar('origVersion', $origVersion);
 $siv_varset_2 = setSilentUpgradeVar('destVersion', $destVersion);
 $siv_write = writeSilentUpgradeVars();
 if (!$siv_varset_1 || !$siv_varset_2 || !$siv_write) {
     logThis("Error with silent upgrade variables: origVersion write success is ({$siv_varset_1}) " . "-- destVersion write success is ({$siv_varset_2}) -- " . "writeSilentUpgradeVars success is ({$siv_write}) -- " . "path to cache dir is ({$GLOBALS['sugar_config']['cache_dir']})", $path);
 }
 require_once 'modules/DynamicFields/templates/Fields/TemplateText.php';
 ///////////////////////////////////////////////////////////////////////////////
 ///    RELOAD NEW DEFINITIONS
 global $ACLActions, $beanList, $beanFiles;
 include 'modules/ACLActions/actiondefs.php';
 include 'include/modules.php';
 /////////////////////////////////////////////
function post_install()
{
    global $unzip_dir;
    global $sugar_config;
    global $sugar_version;
    global $path;
    global $_SESSION;
    if (!isset($_SESSION['sqlSkippedQueries'])) {
        $_SESSION['sqlSkippedQueries'] = array();
    }
    initialize_session_vars();
    if (!isset($unzip_dir) || $unzip_dir == null) {
        $unzip_dir = $_SESSION['unzip_dir'];
    }
    _logThis('Entered post_install function.', $path);
    $self_dir = "{$unzip_dir}/scripts";
    ///////////////////////////////////////////////////////////////////////////
    ////	PUT DATABASE UPGRADE SCRIPT HANDLING HERE
    $new_sugar_version = getUpgradeVersion();
    $post_action = status_post_install_action('sql_query');
    if ($post_action != null) {
        if ($post_action != 'done') {
            //continue from where left in previous run
            runSqlFiles($sugar_version, $new_sugar_version, 'sql_query', $post_action);
            $currProg['sql_query'] = 'done';
            post_install_progress($currProg, 'set');
        }
    } else {
        //never ran before
        runSqlFiles($sugar_version, $new_sugar_version, 'sql_query');
        $currProg['sql_query'] = 'done';
        post_install_progress($currProg, 'set');
    }
    genericFunctions();
    upgradeDbAndFileVersion($new_sugar_version);
    //Remove jssource/src_files sub-directories if they still exist
    $jssource_dirs = array('jssource/src_files/include/javascript/ext-2.0', 'jssource/src_files/include/javascript/ext-1.1.1', 'jssource/src_files/include/javascript/yui');
    foreach ($jssource_dirs as $js_dir) {
        if (file_exists($js_dir)) {
            _logThis("Remove {$js_dir} directory");
            rmdir_recursive($js_dir);
            _logThis("Finished removing {$js_dir} directory");
        }
    }
}