Example #1
0
function commitPatch($unlink = false, $type = 'patch')
{
    require_once 'ModuleInstall/ModuleInstaller.php';
    require_once 'include/entryPoint.php';
    global $mod_strings;
    global $base_upgrade_dir;
    global $base_tmp_upgrade_dir;
    global $db;
    $GLOBALS['db'] = $db;
    $errors = array();
    $files = array();
    global $current_user;
    $current_user = new User();
    $current_user->is_admin = '1';
    $old_mod_strings = $mod_strings;
    if (is_dir($base_upgrade_dir)) {
        $files = findAllFiles("{$base_upgrade_dir}/{$type}", $files);
        $mi = new ModuleInstaller();
        $mi->silent = true;
        $mod_strings = return_module_language('en', "Administration");
        foreach ($files as $file) {
            if (!preg_match('#.*\\.zip\\$#', $file)) {
                continue;
            }
            // handle manifest.php
            $target_manifest = remove_file_extension($file) . '-manifest.php';
            include $target_manifest;
            $unzip_dir = mk_temp_dir($base_tmp_upgrade_dir);
            unzip($file, $unzip_dir);
            if (file_exists("{$unzip_dir}/scripts/pre_install.php")) {
                require_once "{$unzip_dir}/scripts/pre_install.php";
                pre_install();
            }
            if (isset($manifest['copy_files']['from_dir']) && $manifest['copy_files']['from_dir'] != "") {
                $zip_from_dir = $manifest['copy_files']['from_dir'];
            }
            $source = "{$unzip_dir}/{$zip_from_dir}";
            $dest = getcwd();
            copy_recursive($source, $dest);
            if (file_exists("{$unzip_dir}/scripts/post_install.php")) {
                require_once "{$unzip_dir}/scripts/post_install.php";
                post_install();
            }
            $new_upgrade = new UpgradeHistory();
            $new_upgrade->filename = $file;
            $new_upgrade->md5sum = md5_file($file);
            $new_upgrade->type = $manifest['type'];
            $new_upgrade->version = $manifest['version'];
            $new_upgrade->status = "installed";
            //$new_upgrade->author        = $manifest['author'];
            $new_upgrade->name = $manifest['name'];
            $new_upgrade->description = $manifest['description'];
            $serial_manifest = array();
            $serial_manifest['manifest'] = isset($manifest) ? $manifest : '';
            $serial_manifest['installdefs'] = isset($installdefs) ? $installdefs : '';
            $serial_manifest['upgrade_manifest'] = isset($upgrade_manifest) ? $upgrade_manifest : '';
            $new_upgrade->manifest = base64_encode(serialize($serial_manifest));
            $new_upgrade->save();
            unlink($file);
        }
        //rof
    }
    //fi
    $mod_strings = $old_mod_strings;
}
     $errors = commitMakeBackupFiles($rest_dir, $install_file, $unzip_dir, $zip_from_dir, array());
     set_upgrade_progress('commit', 'in_progress', 'commitMakeBackupFiles', 'done');
 }
 //Need to make sure we have the matching copy of SetValueAction for static/instance method matching
 if (file_exists("include/Expressions/Actions/SetValueAction.php")) {
     require_once "include/Expressions/Actions/SetValueAction.php";
 }
 ///////////////////////////////////////////////////////////////////////////////
 ////	HANDLE PREINSTALL SCRIPTS
 if (empty($errors)) {
     $file = "{$unzip_dir}/" . constant('SUGARCRM_PRE_INSTALL_FILE');
     if (is_file($file)) {
         include $file;
         if (!didThisStepRunBefore('commit', 'pre_install')) {
             set_upgrade_progress('commit', 'in_progress', 'pre_install', 'in_progress');
             pre_install();
             set_upgrade_progress('commit', 'in_progress', 'pre_install', 'done');
         }
     }
 }
 //Clean smarty from cache
 $cachedir = sugar_cached('smarty');
 if (is_dir($cachedir)) {
     $allModFiles = array();
     $allModFiles = findAllFiles($cachedir, $allModFiles);
     foreach ($allModFiles as $file) {
         //$file_md5_ref = str_replace(clean_path(getcwd()),'',$file);
         if (file_exists($file)) {
             unlink($file);
         }
     }
function get_required_upgrades($soapclient, $session)
{
    global $sugar_config, $sugar_version;
    require_once 'vendor/nusoap//nusoap.php';
    $errors = array();
    $upgrade_history = new UpgradeHistory();
    $upgrade_history->disable_row_level_security = true;
    $installeds = $upgrade_history->getAllOrderBy('date_entered ASC');
    $history = array();
    require_once 'soap/SoapError.php';
    $error = new SoapError();
    foreach ($installeds as $installed) {
        $history[] = array('id' => $installed->id, 'filename' => $installed->filename, 'md5' => $installed->md5sum, 'type' => $installed->type, 'status' => $installed->status, 'version' => $installed->version, 'date_entered' => $installed->date_entered, 'error' => $error->get_soap_array());
    }
    $result = $soapclient->call('get_required_upgrades', array('session' => $session, 'client_upgrade_history' => $history, 'client_version' => $sugar_version));
    $tempdir_parent = create_cache_directory("disc_client");
    $temp_dir = tempnam($tempdir_parent, "sug");
    sugar_mkdir($temp_dir, 0775);
    $upgrade_installed = false;
    if (empty($soapclient->error_str) && $result['error']['number'] == 0) {
        foreach ($result['upgrade_history_list'] as $upgrade) {
            $file_result = $soapclient->call('get_encoded_file', array('session' => $session, 'filename' => $upgrade['filename']));
            if (empty($soapclient->error_str) && $result['error']['number'] == 0) {
                if ($file_result['md5'] == $upgrade['md5']) {
                    $newfile = write_encoded_file($file_result, $temp_dir);
                    unzip($newfile, $temp_dir);
                    global $unzip_dir;
                    $unzip_dir = $temp_dir;
                    if (file_exists("{$temp_dir}/manifest.php")) {
                        require_once "{$temp_dir}/manifest.php";
                        global $manifest_arr;
                        $manifest_arr = $manifest;
                        if (!isset($manifest['offline_client_applicable']) || $manifest['offline_client_applicable'] == true || $manifest['offline_client_applicable'] == 'true') {
                            if (file_exists("{$temp_dir}/scripts/pre_install.php")) {
                                require_once "{$temp_dir}/scripts/pre_install.php";
                                pre_install();
                            }
                            if (isset($manifest['copy_files']['from_dir']) && $manifest['copy_files']['from_dir'] != "") {
                                $zip_from_dir = $manifest['copy_files']['from_dir'];
                            }
                            $source = "{$temp_dir}/{$zip_from_dir}";
                            $dest = getcwd();
                            copy_recursive($source, $dest);
                            if (file_exists("{$temp_dir}/scripts/post_install.php")) {
                                require_once "{$temp_dir}/scripts/post_install.php";
                                post_install();
                            }
                            //save newly installed upgrade
                            $new_upgrade = new UpgradeHistory();
                            $new_upgrade->filename = $upgrade['filename'];
                            $new_upgrade->md5sum = $upgrade['md5'];
                            $new_upgrade->type = $upgrade['type'];
                            $new_upgrade->version = $upgrade['version'];
                            $new_upgrade->status = "installed";
                            $new_upgrade->save();
                            $upgrade_installed = true;
                        }
                    }
                }
            }
        }
    }
    return $upgrade_installed;
}