function is_server_version_greater($left, $right)
{
    if (count($left) == 0 && count($right) == 0) {
        return false;
    } else {
        if (count($left) == 0 || count($right) == 0) {
            return true;
        } else {
            if ($left[0] == $right[0]) {
                array_shift($left);
                array_shift($right);
                return is_server_version_greater($left, $right);
            } else {
                if ($left[0] < $right[0]) {
                    return true;
                } else {
                    return false;
                }
            }
        }
    }
}
Ejemplo n.º 2
0
function get_required_upgrades($session, $client_upgrade_history, $client_version)
{
    // files might be big
    global $sugar_config;
    $error = new SoapError();
    if (!validate_authenticated($session)) {
        $error->set_error('invalid_login');
        return array('upgrade_history_list' => array(), 'error' => $error->get_soap_array());
    }
    global $current_user;
    $upgrade_history = new UpgradeHistory();
    $installeds = $upgrade_history->getAllOrderBy('date_entered ASC');
    $history = array();
    $client_ver = explode('.', $client_version);
    foreach ($installeds as $installed) {
        $installed_ver = explode('.', $installed->version);
        if (count($installed_ver) >= 3) {
            if (is_server_version_greater($client_ver, $installed_ver) == true) {
                $found = false;
                foreach ($client_upgrade_history as $client_history) {
                    if ($client_history['md5'] == $installed->md5sum) {
                        $found = true;
                        break;
                    }
                }
                if (!$found) {
                    //now check to be sure that this is available as an offline client upgrade
                    $manifest_file = getManifest($installed->filename);
                    if (is_file($manifest_file)) {
                        require_once $manifest_file;
                        if (!isset($manifest['offline_client_applicable']) || $manifest['offline_client_applicable'] == true || $manifest['offline_client_applicable'] == 'true') {
                            $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());
                        }
                    }
                }
            }
        }
    }
    return array('upgrade_history_list' => $history, 'error' => $error->get_soap_array());
}