Skip to content

Commit

Permalink
Dev: cleaning on update controller and update model
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Mar 1, 2016
1 parent 503c0d1 commit b7fd28e
Show file tree
Hide file tree
Showing 2 changed files with 142 additions and 129 deletions.
90 changes: 44 additions & 46 deletions application/controllers/admin/update.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if (! defined('BASEPATH')) exit('No direct script access allowed');
/*
* LimeSurvey
* Copyright (C) 2007-2011 The LimeSurvey Project Team / Carsten Schmitz
Expand Down Expand Up @@ -87,7 +87,7 @@ public function getbothbuttons()
*/
public function getwelcome()
{
if(Permission::model()->hasGlobalPermission('superadmin'))
if (Permission::model()->hasGlobalPermission('superadmin'))
{
// We get the update key in the database. If it's empty, getWelcomeMessage will return subscription
$updateKey = getGlobalSetting("update_key");
Expand All @@ -108,10 +108,10 @@ public function getwelcome()
*/
public function checkLocalErrors()
{
if(Permission::model()->hasGlobalPermission('superadmin'))
if (Permission::model()->hasGlobalPermission('superadmin'))
{
// We use request rather than post, because this step can be called by url by displayComfortStep.js
if( isset($_REQUEST['destinationBuild']) )
if (isset($_REQUEST['destinationBuild']) )
{
$destinationBuild = $_REQUEST['destinationBuild'];
$access_token = $_REQUEST['access_token'];
Expand All @@ -135,33 +135,32 @@ public function checkLocalErrors()
*/
public function changeLog()
{
if(Permission::model()->hasGlobalPermission('superadmin'))
if (Permission::model()->hasGlobalPermission('superadmin'))
{

// We use request rather than post, because this step can be called by url by displayComfortStep.js
if( isset($_REQUEST['destinationBuild']) )
if (isset($_REQUEST['destinationBuild']) )
{

$destinationBuild = $_REQUEST['destinationBuild'];
$access_token = $_REQUEST['access_token'];

// We get the change log from the ComfortUpdate server
$updateModel = new UpdateForm();
$changelog = $updateModel->getChangeLog( $destinationBuild );
// We get the change log from the ComfortUpdate server
$updateModel = new UpdateForm();
$changelog = $updateModel->getChangeLog( $destinationBuild );

if( $changelog->result )
{
$aData['errors'] = FALSE;
$aData['changelogs'] = $changelog;
$aData['html_from_server'] = $changelog->html;
$aData['destinationBuild'] = $destinationBuild;
$aData['access_token'] = $access_token;
}
else
{
return $this->_renderError($changelog);
}
return $this->controller->renderPartial('update/updater/steps/_change_log', $aData, false, false);
if ($changelog->result )
{
$aData['errors'] = FALSE;
$aData['changelogs'] = $changelog;
$aData['html_from_server'] = $changelog->html;
$aData['destinationBuild'] = $destinationBuild;
$aData['access_token'] = $access_token;
}
else
{
return $this->_renderError($changelog);
}
return $this->controller->renderPartial('update/updater/steps/_change_log', $aData, false, false);
}
return $this->_renderErrorString("unknown_destination_build");
}
Expand All @@ -174,10 +173,10 @@ public function changeLog()
*/
public function fileSystem()
{
if(Permission::model()->hasGlobalPermission('superadmin'))
if (Permission::model()->hasGlobalPermission('superadmin'))
{

if( isset($_REQUEST['destinationBuild']))
if (isset($_REQUEST['destinationBuild']))
{
$tobuild = $_REQUEST['destinationBuild'];
$access_token = $_REQUEST['access_token'];
Expand All @@ -186,9 +185,8 @@ public function fileSystem()
$updateModel = new UpdateForm();
$changedFiles = $updateModel->getChangedFiles($tobuild);

if( $changedFiles->result )
if ($changedFiles->result )
{
//TODO : clean that
$aData = $updateModel->getFileStatus($changedFiles->files);

$aData['html_from_server'] = ( isset($changedFiles->html) )?$changedFiles->html:'';
Expand All @@ -211,21 +209,21 @@ public function fileSystem()
*/
public function backup()
{
if(Permission::model()->hasGlobalPermission('superadmin'))
if (Permission::model()->hasGlobalPermission('superadmin'))
{
if(Yii::app()->request->getPost('destinationBuild'))
if (Yii::app()->request->getPost('destinationBuild'))
{
$destinationBuild = Yii::app()->request->getPost('destinationBuild');
$access_token = $_REQUEST['access_token'];
$access_token = $_REQUEST['access_token'];

if(Yii::app()->request->getPost('datasupdateinfo'))
if (Yii::app()->request->getPost('datasupdateinfo'))
{
$updateinfos= unserialize ( base64_decode( ( Yii::app()->request->getPost('datasupdateinfo') )));

$updateModel = new UpdateForm();
$backupInfos = $updateModel->backupFiles($updateinfos);

if( $backupInfos->result )
if ($backupInfos->result )
{
$dbBackupInfos = $updateModel->backupDb($destinationBuild);
// If dbBackup fails, it will just provide a warning message : backup manually
Expand Down Expand Up @@ -270,21 +268,21 @@ function step4()
$destinationBuild = Yii::app()->request->getPost('destinationBuild');
$access_token = $_REQUEST['access_token'];

if( Yii::app()->request->getPost('datasupdateinfo') )
if ( Yii::app()->request->getPost('datasupdateinfo') )
{
$updateinfos = unserialize ( base64_decode( ( Yii::app()->request->getPost('datasupdateinfo') )));

// this is the last step - Download the zip file, unpack it and replace files accordingly
$updateModel = new UpdateForm();
$file = $updateModel->downloadUpdateFile($access_token, $destinationBuild);

if( $file->result )
if ($file->result )
{
$unzip = $updateModel->unzipUpdateFile();
if( $unzip->result )
if ($unzip->result )
{
$remove = $updateModel->removeDeletedFiles($updateinfos);
if( $remove->result )
if ($remove->result )
{
// Should never bug (version.php is checked before))
$updateModel->updateVersion($destinationBuild);
Expand Down Expand Up @@ -338,21 +336,21 @@ public function updateUpdater()
{
if (Permission::model()->hasGlobalPermission('superadmin'))
{
if( Yii::app()->request->getPost('destinationBuild') )
if ( Yii::app()->request->getPost('destinationBuild') )
{
$destinationBuild = Yii::app()->request->getPost('destinationBuild');
$updateModel = new UpdateForm();

$localChecks = $updateModel->getLocalChecksForUpdater();

if( $localChecks->result )
if ($localChecks->result )
{
$file = $updateModel->downloadUpdateUpdaterFile($destinationBuild);

if( $file->result )
if ($file->result )
{
$unzip = $updateModel->unzipUpdateUpdaterFile();
if( $unzip->result )
if ($unzip->result )
{
$updateModel->removeTmpFile('update_updater.zip');
$updateModel->removeTmpFile('comfort_updater_cookie.txt');
Expand Down Expand Up @@ -404,14 +402,14 @@ public function submitkey()

if (Permission::model()->hasGlobalPermission('superadmin'))
{
if( Yii::app()->request->getPost('keyid') )
if ( Yii::app()->request->getPost('keyid') )
{
// We trim it, just in case user added a space...
$submittedUpdateKey = trim(Yii::app()->request->getPost('keyid'));

$updateModel = new UpdateForm();
$check = $updateModel->checkUpdateKeyonServer($submittedUpdateKey);
if( $check->result )
if ($check->result )
{
// If the key is validated by server, we update the local database with this key
$updateKey = $updateModel->setUpdateKey($submittedUpdateKey);
Expand All @@ -437,7 +435,7 @@ public function submitkey()
public function db($continue = null)
{
Yii::app()->loadHelper("update/update");
if(isset($continue) && $continue=="yes")
if (isset($continue) && $continue=="yes")
{
$aViewUrls['output'] = CheckForDBUpgrades($continue);
$aData['display']['header'] = false;
Expand Down Expand Up @@ -489,7 +487,7 @@ private function _getButtons($crosscheck)

// TODO : if no update available, set session about it...

if( $serverAnswer->result )
if ($serverAnswer->result )
{
unset($serverAnswer->result);
return $this->controller->renderPartial('//admin/update/check_updates/update_buttons/_updatesavailable', array('updateInfos' => $serverAnswer), false, false);
Expand All @@ -505,11 +503,11 @@ private function _getButtons($crosscheck)
*/
private function _renderWelcome($serverAnswer)
{
if( $serverAnswer->result )
if ($serverAnswer->result )
{
// Available views (in /admin/update/welcome/ )
$views = array('welcome', 'subscribe', 'key_updated', 'updater_update');
if( in_array($serverAnswer->view, $views) )
if (in_array($serverAnswer->view, $views) )
{
return $this->controller->renderPartial('//admin/update/updater/welcome/_'.$serverAnswer->view, array('serverAnswer' => $serverAnswer), false, false);
}
Expand Down

0 comments on commit b7fd28e

Please sign in to comment.