Skip to content

Commit

Permalink
Fixed issue: Updater not showing new updates
Browse files Browse the repository at this point in the history
  • Loading branch information
c-schmitz committed Oct 30, 2012
1 parent 7765858 commit 10d4c17
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 54 deletions.
6 changes: 3 additions & 3 deletions application/controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,9 @@ public function _showadminmenu($surveyid = false)
Yii::app()->session['flashmessage'] = $clang->gT("Warning: You are still using the default password ('password'). Please change your password and re-login again.");
}

$data['showupdate'] = (Yii::app()->session['USER_RIGHT_SUPERADMIN'] == 1 && Yii::app()->getConfig("updatelastcheck")>0 && Yii::app()->getConfig("updateavailable")==1 && Yii::app()->getConfig("updatable") );
$data['updateversion'] = Yii::app()->getConfig("updateversion");
$data['updatebuild'] = Yii::app()->getConfig("updatebuild");
$data['showupdate'] = (Yii::app()->session['USER_RIGHT_SUPERADMIN'] == 1 && getGlobalSetting("updatelastcheck")>0 && getGlobalSetting("updateavailable")==1 && Yii::app()->getConfig("updatable") );
$data['updateversion'] = getGlobalSetting("updateversion");
$data['updatebuild'] = getGlobalSetting("updatebuild");
$data['surveyid'] = $surveyid;
$data['iconsize'] = Yii::app()->getConfig('adminthemeiconsize');
$data['sImageURL'] = Yii::app()->getConfig('adminimageurl');
Expand Down
16 changes: 11 additions & 5 deletions application/controllers/admin/globalsettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public function showphpinfo()
}
}

public function updatecheck()
{
updateCheck();
$this->getController()->redirect('admin/globalsettings');
}

private function _displaySettings()
{
Yii::app()->loadHelper('surveytranslator');
Expand All @@ -69,12 +75,12 @@ private function _displaySettings()
$data[$key] = $row;
}
$data['thisupdatecheckperiod'] = getGlobalSetting('updatecheckperiod');
$data['updatelastcheck'] = Yii::app()->getConfig("updatelastcheck");
$data['updateavailable'] = (Yii::app()->getConfig("updateavailable") && Yii::app()->getConfig("updatable"));
$data['updatelastcheck'] = getGlobalSetting("updatelastcheck");
$data['updateavailable'] = (getGlobalSetting("updateavailable") && Yii::app()->getConfig("updatable"));
$data['updatable'] = Yii::app()->getConfig("updatable");
$data['updateinfo'] = Yii::app()->getConfig("updateinfo");
$data['updatebuild'] = Yii::app()->getConfig("updatebuild");
$data['updateversion'] = Yii::app()->getConfig("updateversion");
$data['updateinfo'] = getGlobalSetting("updateinfo");
$data['updatebuild'] = getGlobalSetting("updatebuild");
$data['updateversion'] = getGlobalSetting("updateversion");
$data['allLanguages'] = getLanguageData(false, Yii::app()->session['adminlang']);
if (trim(Yii::app()->getConfig('restrictToLanguages')) == '') {
$data['restrictToLanguages'] = array_keys($data['allLanguages']);
Expand Down
91 changes: 48 additions & 43 deletions application/controllers/admin/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ class update extends Survey_Common_Action
function index($sSubAction = null)
{
$this->_RunUpdaterUpdate();
Yii::import('application.libraries.admin.http.httpRequest');

$clang = $this->getController()->lang;
$iCurrentBuildnumber = Yii::app()->getConfig("buildnumber");
$tempdir = Yii::app()->getConfig("tempdir");
$iDestinationBuild= Yii::app()->getConfig("updatebuild");
$iDestinationBuild= getGlobalSetting("updatebuild");

$updatekey = $this->_getUpdateKey($sSubAction);
$error = false;
Expand All @@ -58,7 +59,8 @@ function index($sSubAction = null)

private function _getChangedFiles($buildnumber, $updaterversion, $updatekey)
{
$http = new http;
Yii::import('application.libraries.admin.http.httpRequest');
$http = new httpRequest;
$httperror = $this->_requestChangedFiles($http, $buildnumber, $updaterversion, $updatekey);

if ($httperror != '') {
Expand All @@ -69,7 +71,8 @@ private function _getChangedFiles($buildnumber, $updaterversion, $updatekey)

private function _getChangelog($buildnumber, $updaterversion, $updatekey)
{
$http = new http;
Yii::import('application.libraries.admin.http.httpRequest');
$http = new httpRequest;
$httperror = $this->_requestChangelog($http, $buildnumber, $updaterversion, $updatekey);

if ($httperror != '') {
Expand All @@ -78,7 +81,7 @@ private function _getChangelog($buildnumber, $updaterversion, $updatekey)
return $this->_readChangelog($http);
}

private function _readChangelog(http $http)
private function _readChangelog(httpRequest $http)
{
$szLines = '';
$szResponse = '';
Expand All @@ -93,7 +96,7 @@ private function _readChangelog(http $http)
}
}

private function _requestChangelog(http $http, $buildnumber, $updaterversion, $updatekey)
private function _requestChangelog(httpRequest $http, $buildnumber, $updaterversion, $updatekey)
{
$http->timeout = 0;
$http->data_timeout = 0;
Expand All @@ -104,8 +107,8 @@ private function _requestChangelog(http $http, $buildnumber, $updaterversion, $u

return $http->SendRequest($arguments);
}

private function _requestChangedFiles(http $http, $buildnumber, $updaterversion, $updatekey)
private function _requestChangedFiles(httpRequest $http, $buildnumber, $updaterversion, $updatekey)
{
$http->timeout = 0;
$http->data_timeout = 0;
Expand All @@ -120,7 +123,7 @@ private function _requestChangedFiles(http $http, $buildnumber, $updaterversion,

private function _getUpdateKey($sSubAction)
{
$updatekey = Yii::app()->getConfig("updatekey");
$updatekey = getGlobalSetting("updatekey");
if ($sSubAction == 'keyupdate') {
$updatekey = sanitize_paranoid_string($_POST['updatekey']);
setGlobalSetting('updatekey', $updatekey);
Expand All @@ -133,10 +136,11 @@ private function _getUpdateKey($sSubAction)

function step2()
{

$clang = $this->getController()->lang;
$buildnumber = Yii::app()->getConfig("buildnumber");
$updatebuild = Yii::app()->getConfig("updatebuild");
$updatekey = Yii::app()->getConfig("updatekey");
$updatebuild = getGlobalSetting("updatebuild");
$updatekey =getGlobalSetting("updatekey");

list($error, $updateinfo, $cookies) = $this->_getChangedFiles($buildnumber, $updatebuild, $updatekey);
$aData = $this->_getFileStatus($updateinfo);
Expand Down Expand Up @@ -217,16 +221,15 @@ function step3()
$clang = $this->getController()->lang;
$buildnumber = Yii::app()->getConfig("buildnumber");
$tempdir = Yii::app()->getConfig("tempdir");
$updatekey = Yii::app()->getConfig("updatekey");
$updatebuild = Yii::app()->getConfig("updatebuild");
$updatekey = getGlobalSetting("updatekey");
$updatebuild = getGlobalSetting("updatebuild");
//$_POST=$this->input->post();
$rootdir = Yii::app()->getConfig("rootdir");
$publicdir = Yii::app()->getConfig("publicdir");
$tempdir = Yii::app()->getConfig("tempdir");
$aDatabasetype = Yii::app()->db->getDriverName();
$aData = array('clang' => $clang);
// Request the list with changed files from the server
$updatekey=getGlobalSetting('updatekey');

if (!isset( Yii::app()->session['updateinfo']))
{
Expand Down Expand Up @@ -299,15 +302,14 @@ function step4()
$clang = $this->getController()->lang;
$buildnumber = Yii::app()->getConfig("buildnumber");
$tempdir = Yii::app()->getConfig("tempdir");
$updatekey = Yii::app()->getConfig("updatekey");
$updatebuild = Yii::app()->getConfig("updatebuild");
$updatekey = getGlobalSetting("updatekey");
$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
$updatekey=getGlobalSetting('updatekey');
$aData = array('clang' => $clang);

if (!isset( Yii::app()->session['updateinfo']))
Expand All @@ -325,7 +327,8 @@ function step4()
// Create DB and file backups now

$downloaderror=false;
$http=new http;
Yii::import('application.libraries.admin.http.httpRequest');
$http=new httpRequest;

// Allow redirects
$http->follow_redirect=1;
Expand Down Expand Up @@ -430,33 +433,34 @@ private function _RunUpdaterUpdate()
$buildnumber = Yii::app()->getConfig("buildnumber");
$tempdir = Yii::app()->getConfig("tempdir");

$http=new http;

Yii::import('application.libraries.admin.http.httpRequest');
$oHTTPRequest=new httpRequest;

/* Connection timeout */
$http->timeout=0;
$oHTTPRequest->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("http://update.limesurvey.org?updaterbuild={$buildnumber}",$arguments);
$oHTTPRequest->data_timeout=0;
$oHTTPRequest->user_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
$oHTTPRequest->GetRequestArguments("http://update.limesurvey.org?updaterbuild={$buildnumber}",$arguments);

$updateinfo=false;
$error=$http->Open($arguments);
$error=$http->SendRequest($arguments);
$error=$oHTTPRequest->Open($arguments);
$error=$oHTTPRequest->SendRequest($arguments);

$http->ReadReplyHeaders($headers);
$oHTTPRequest->ReadReplyHeaders($headers);


if($error=="") {
$body=''; $full_body='';
for(;;){
$error = $http->ReadReplyBody($body,10000);
$error = $oHTTPRequest->ReadReplyBody($body,10000);
if($error != "" || strlen($body)==0) break;
$full_body .= $body;
}
$updateinfo=json_decode($full_body,true);
if ($http->response_status!='200')
if ($oHTTPRequest->response_status!='200')
{
$updateinfo['errorcode']=$http->response_status;
$updateinfo['errorcode']=$oHTTPRequest->response_status;
$updateinfo['errorhtml']=$full_body;
}
}
Expand All @@ -465,7 +469,7 @@ private function _RunUpdaterUpdate()
$updateinfo['errorcode']=$error;
$updateinfo['errorhtml']=$error;
}
unset( $http );
unset( $oHTTPRequest );
if ((int)$updateinfo['UpdaterRevision']<=$buildnumber)
{
// There is no newer updater version on the server
Expand All @@ -481,34 +485,35 @@ private function _RunUpdaterUpdate()
// Create DB and file backups now

$downloaderror=false;
$http=new http;
Yii::import('application.libraries.admin.http.httpRequest');
$oHTTPRequest=new httpRequest;

// Allow redirects
$http->follow_redirect=1;
$oHTTPRequest->follow_redirect=1;
/* Connection timeout */
$http->timeout=0;
$oHTTPRequest->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("http://update.limesurvey.org/updates/downloadupdater/{$this->updaterversion}",$arguments);
$oHTTPRequest->data_timeout=0;
$oHTTPRequest->user_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
$oHTTPRequest->GetRequestArguments("http://update.limesurvey.org/updates/downloadupdater/{$this->updaterversion}",$arguments);

$httperror=$http->Open($arguments);
$httperror=$http->SendRequest($arguments);
$http->ReadReplyHeaders($headers);
$oHTTPRequesterror=$oHTTPRequest->Open($arguments);
$oHTTPRequesterror=$oHTTPRequest->SendRequest($arguments);
$oHTTPRequest->ReadReplyHeaders($headers);
if ($headers['content-type']=='text/html')
{
@unlink($tempdir.'/updater.zip');
}
elseif($httperror=='') {
elseif($oHTTPRequesterror=='') {
$body=''; $full_body='';
for(;;){
$httperror = $http->ReadReplyBody($body,100000);
if($httperror != "" || strlen($body)==0) break;
$oHTTPRequesterror = $oHTTPRequest->ReadReplyBody($body,100000);
if($oHTTPRequesterror != "" || strlen($body)==0) break;
$full_body .= $body;
}
file_put_contents($tempdir.'/updater.zip',$full_body);
}
$aData['httperror'] = $httperror;
$aData['httperror'] = $oHTTPRequesterror;

//Now unzip the new updater over the existing ones.
if (file_exists($tempdir.'/updater.zip')){
Expand Down
4 changes: 2 additions & 2 deletions application/helpers/common_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4433,8 +4433,8 @@ function removeBOM($str=""){
function getUpdateInfo()
{
//require_once($homedir."/classes/http/http.php");
Yii::import('application.libraries.admin.http.http');
$http = new http;
Yii::import('application.libraries.admin.http.httpRequest');
$http=new httpRequest;

$http->timeout=0;
$http->data_timeout=0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
*/

class http
class httpRequest
{
var $host_name="";
var $host_port=0;
Expand Down

0 comments on commit 10d4c17

Please sign in to comment.