function step4() { $clang = $this->getController()->lang; $buildnumber = Yii::app()->getConfig("buildnumber"); $tempdir = Yii::app()->getConfig("tempdir"); $updatebuild = getGlobalSetting("updatebuild"); $rootdir = Yii::app()->getConfig("rootdir"); $publicdir = Yii::app()->getConfig("publicdir"); $tempdir = Yii::app()->getConfig("tempdir"); $aDatabasetype = Yii::app()->db->getDriverName(); // Request the list with changed files from the server $aData = array(); if (!isset(Yii::app()->session['updateinfo'])) { if ($updateinfo['error'] == 1) { } } else { $updateinfo = Yii::app()->session['updateinfo']; } // this is the last step - Download the zip file, unpack it and replace files accordingly // Create DB and file backups now $downloaderror = false; Yii::import('application.libraries.admin.http.httpRequestIt'); $http = new httpRequestIt(); $http->proxy_host_name = Yii::app()->getConfig("proxy_host_name", ""); $http->proxy_host_port = Yii::app()->getConfig("proxy_host_port", 80); // Allow redirects $http->follow_redirect = 1; /* Connection timeout */ $http->timeout = 0; /* Data transfer timeout */ $http->data_timeout = 0; $http->user_agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"; $http->GetRequestArguments($this->getProtocol() . "update.limesurvey.org/updates/download/{$updateinfo['downloadid']}", $arguments); $http->RestoreCookies(Yii::app()->session['updatesession']); $error = $http->Open($arguments); $error = $http->SendRequest($arguments); $http->ReadReplyHeaders($headers); if ($headers['content-type'] == 'text/html') { @unlink($tempdir . '/update.zip'); } else { if ($error == '') { $body = ''; $pFile = fopen($tempdir . '/update.zip', 'w'); for (;;) { $error = $http->ReadReplyBody($body, 100000); if ($error != "" || strlen($body) == 0) { break; } fwrite($pFile, $body); } fclose($pFile); } else { print $error; } } //Now unzip the new files over the existing ones. $new_files = false; if (file_exists($tempdir . '/update.zip')) { Yii::app()->loadLibrary("admin/pclzip"); $archive = new PclZip($tempdir . '/update.zip'); if ($archive->extract(PCLZIP_OPT_PATH, $rootdir . '/', PCLZIP_OPT_REPLACE_NEWER) == 0) { die("Error : " . $archive->errorInfo(true)); } else { $new_files = true; unlink($tempdir . '/update.zip'); } } else { $downloaderror = true; } // Now remove all files that are to be deleted according to update process // This happens after unzipping foreach ($updateinfo['files'] as $afile) { if ($afile['type'] == 'D' && file_exists($rootdir . $afile['file'])) { if (is_file($rootdir . $afile['file'])) { @unlink($rootdir . $afile['file']); } else { rmdirr($rootdir . $afile['file']); } } } $aData['new_files'] = $new_files; $aData['downloaderror'] = $downloaderror; // PclTraceDisplay(); // Now we have to update version.php if (!$downloaderror) { @ini_set('auto_detect_line_endings', true); $versionlines = file($rootdir . '/application/config/version.php'); $handle = fopen($rootdir . '/application/config/version.php', "w"); foreach ($versionlines as $line) { if (strpos($line, 'buildnumber') !== false) { $line = '$config[\'buildnumber\'] = ' . Yii::app()->session['updateinfo']['toversion'] . ';' . "\r\n"; } fwrite($handle, $line); } fclose($handle); } setGlobalSetting('updateavailable', '0'); setGlobalSetting('updatebuild', ''); setGlobalSetting('updateversions', ''); // We redirect here because the files might have been overwritten earlier // and classes may have been changed that would be needed in the view Yii::app()->session['installlstep4b'] = $aData; Yii::app()->getController()->redirect(array('/admin/update/sa/step4b')); }