Skip to content

Commit

Permalink
Fixed issue #8263: Admin whith ability to update can not update
Browse files Browse the repository at this point in the history
Dev: don't break on error
Dev: if there are an error in files backup : surely there are error at step4
Fixed issue: any user can update
  • Loading branch information
Shnoulle committed Oct 20, 2013
1 parent d486502 commit 8c9302c
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 36 deletions.
4 changes: 3 additions & 1 deletion application/controllers/admin/checkintegrity.php
Expand Up @@ -28,7 +28,9 @@ public function __construct($controller, $id)
parent::__construct($controller, $id);

if (Yii::app()->session['USER_RIGHT_CONFIGURATOR'] != 1) {
die();
$clang = $this->getController()->lang;
Yii::app()->session['flashmessage'] = $clang->gT("You do not have sufficient rights to access this page.");
$this->getController()->redirect($this->getController()->createUrl("/admin/"));
}

Yii::app()->loadHelper('database');
Expand Down
57 changes: 45 additions & 12 deletions application/controllers/admin/update.php
Expand Up @@ -21,6 +21,17 @@
*/
class update extends Survey_Common_Action
{
function __construct($controller, $id)
{
parent::__construct($controller, $id);

if (Yii::app()->session['USER_RIGHT_CONFIGURATOR'] != 1) {
$clang = $this->getController()->lang;
Yii::app()->session['flashmessage'] = $clang->gT("You do not have sufficient rights to access this page.");
$this->getController()->redirect($this->getController()->createUrl("/admin/"));
}
}

/**
* Default Controller Action
*/
Expand Down Expand Up @@ -236,7 +247,6 @@ function step3()
}

$aData['updateinfo'] = $updateinfo;

// okay, updateinfo now contains all necessary updateinformation
// Create DB and file backups now

Expand All @@ -259,10 +269,12 @@ function step3()
$v_list = $archive->add($filestozip, PCLZIP_OPT_REMOVE_PATH, $publicdir);

if ($v_list == 0) {
die("Error : ".$archive->errorInfo(true));
$aFileBackup= array('class'=>'error','text'=>sprintf($clang->gt("Error on file backup: %s"),$archive->errorInfo(true)));
}
$aData['sFilesArchive']=$tempdir.DIRECTORY_SEPARATOR.'LimeSurvey_files_backup_'.$basefilename.'.zip';

else{
$aFileBackup= array('class'=>'success','text'=>sprintf($clang->gt("File backup created: %s"),$tempdir.DIRECTORY_SEPARATOR.'LimeSurvey_files_backup_'.$basefilename.'.zip'));
}
$aData['aFileBackup']=$aFileBackup;
$aData['databasetype'] = $aDatabasetype;

//TODO: Yii provides no function to backup the database. To be done after dumpdb is ported
Expand All @@ -274,17 +286,38 @@ function step3()
$dfilename = $tempdir.DIRECTORY_SEPARATOR."LimeSurvey_database_backup_".$basefilename.".sql.gz";

outputDatabase('',false,$sfilename);

$archive = new PclZip($dfilename);
$v_list = $archive->add(array($sfilename), PCLZIP_OPT_REMOVE_PATH, $tempdir,PCLZIP_OPT_ADD_TEMP_FILE_ON);
unlink($sfilename);
if ($v_list == 0) {
die("Error : ".$archive->errorInfo(true));
// Before try to zip: test size of file
if( is_file($sfilename) && filesize($sfilename))
{
$archive = new PclZip($dfilename);
$v_list = $archive->add(array($sfilename), PCLZIP_OPT_REMOVE_PATH, $tempdir,PCLZIP_OPT_ADD_TEMP_FILE_ON);
unlink($sfilename);
if ($v_list == 0) {
$aSQLBackup=array('class'=>'warning','text'=>$clang->gt("Unable to backup your database for unknow reason. Before proceeding please backup your database using a backup tool!"));
}
else
{
$aSQLBackup=array('class'=>'success','text'=>sprintf($clang->gT('DB backup created: %s'),htmlspecialchars($dfilename)));
}
}
else
{
$aSQLBackup=array('class'=>'warning','text'=>$clang->gt("Unable to backup your database for unknow reason. Before proceeding please backup your database using a backup tool!"));
}
$aData['sSQLArchive']=$dfilename;
}
}

else
{
$aSQLBackup=array('class'=>'warning','text'=>$clang->gT('Database backup functionality is currently not available for your database type. Before proceeding please backup your database using a backup tool!'));
}
$aData['aSQLBackup']=$aSQLBackup;
if($aFileBackup['class']=="success" && $aSQLBackup['class']=="success") {
$aData['result']="success";
}elseif($aFileBackup['class']=="error" || $aSQLBackup['class']=="error") {
$aData['result']="error";
}else{
$aData['result']="warning";
}
$this->_renderWrappedTemplate('update', 'step3', $aData);
}

Expand Down
45 changes: 22 additions & 23 deletions application/views/admin/update/step3.php
@@ -1,5 +1,7 @@
<div class="header ui-widget-header"><?php sprintf($clang->gT('ComfortUpdate step %s'),'3'); ?></div><div class="updater-background">
<h3><?php $clang->eT('Creating DB & file backup')?></h3><br>
<div class="header ui-widget-header"><?php sprintf($clang->gT('ComfortUpdate step %s'),'3'); ?></div>
<div class="updater-background">
<h3><?php $clang->eT('Creating DB & file backup')?></h3>
<div class='messagebox ui-corner-all'>
<?php
if (!isset( Yii::app()->session['updateinfo']))
{
Expand All @@ -12,25 +14,22 @@
else
$clang->eT('On requesting the update information from limesurvey.org there has been an error:').'<br />';
}
?>
<?php if($result=="success") { ?>
<div class='successheader'><?php $clang->eT("Success"); ?></div>
<?php }elseif ($result=="warning" ) { ?>
<div class='warningheader'><?php $clang->eT("Warning"); ?></div>
<?php }else{ ?>
<div class='errorheader'><?php $clang->eT("Failed"); ?></div>
<?php } ?>
<div class="<?php echo $aFileBackup['class']; ?>title"> <?php $clang->eT('Creating file backup... '); ?></div>
<p><?php echo $aFileBackup['text']; ?></p>


$clang->eT('Creating file backup... ').'<br />';

echo "<span class='successtitle'>".$clang->gT('File backup created:').' '.htmlspecialchars($sFilesArchive).'</span><br /><br />';

if ($databasetype=='mysql' || $databasetype=='mysqli')
{
$clang->eT('Creating database backup... ').'<br />';
echo "<span class='successtitle'>".$clang->gT('DB backup created:')." ".htmlspecialchars($sSQLArchive).'</span><br /><br />';
}
else
{
echo "<span class='warningtitle'>".$clang->gT('No DB backup created:').'<br />'.$clang->gT('Database backup functionality is currently not available for your database type. Before proceeding please backup your database using a backup tool!').'</span><br /><br />';
}

$clang->eT('Please check any problems above and then proceed to the final step.');
echo "<p><button onclick=\"window.open('".Yii::app()->getController()->createUrl("admin/update/sa/step4/")."', '_top')\" ";
echo ">".sprintf($clang->gT('Proceed to step %s'),'4')."</button></p>";
echo '</div>';

?>
<div class="<?php echo $aFileBackup['class']; ?>title"> <?php $clang->eT('Creating database backup...'); ?></div>
<p class="<?php echo $aSQLBackup['class']; ?>"><?php echo $aSQLBackup['text']; ?></p>
<p class="information"><?php $clang->eT('Please check any problems above and then proceed to the final step.'); ?>
<?php echo "<p><a class='button' href='".Yii::app()->getController()->createUrl("admin/update/sa/step4/")."'>
".sprintf($clang->gT('Proceed to step %s'),'4') ."</a></p>";
?>
</div>
</div>

0 comments on commit 8c9302c

Please sign in to comment.