Skip to content

Commit

Permalink
Fixed issue #09890 : broken survey can break admin page if debug is set
Browse files Browse the repository at this point in the history
Dev: test if defaultlanguage exist : send an alert if not
Dev: send user to check integrity if there are error
Dev: add an alert if 1st part of checkintegrity fix somethyning
Dev: update notifications to allow alert-info
  • Loading branch information
Shnoulle committed Feb 11, 2016
1 parent e98a950 commit 01bf5fc
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 44 deletions.
33 changes: 24 additions & 9 deletions application/controllers/admin/checkintegrity.php
Expand Up @@ -331,6 +331,8 @@ private function _deleteConditions(array $conditions, array $aData)
*/
protected function _checkintegrity()
{
/* Find is some fix is done */
$bDirectlyFixed=false;
// Delete survey permissions if the user does not exist
$oCriteria = new CDbCriteria;
$oCriteria->join = 'LEFT JOIN {{users}} u ON {{permissions}}.uid=u.uid';
Expand All @@ -340,7 +342,10 @@ protected function _checkintegrity()
$oCriteria->join = 'USING {{users}} u';
$oCriteria->condition = '{{permissions}}.uid=u.uid AND (u.uid IS NULL)';
}
Permission::model()->deleteAll($oCriteria);
if(Permission::model()->deleteAll($oCriteria))
{
$bDirectlyFixed=true;
}

// Delete survey permissions if the survey does not exist
$oCriteria = new CDbCriteria;
Expand All @@ -351,19 +356,22 @@ protected function _checkintegrity()
$oCriteria->join = 'USING {{surveys}} s';
$oCriteria->condition = "{{permissions}}.entity_id=s.sid AND (s.sid IS NULL AND entity='survey')";
}
Permission::model()->deleteAll($oCriteria);

if(Permission::model()->deleteAll($oCriteria))
{
$bDirectlyFixed=true;
}

// Deactivate surveys that have a missing response table
$surveys = Survey::model()->findAll();
foreach ($surveys as $survey)
$oSurveys = Survey::model()->findAll();
foreach ($oSurveys as $oSurvey)
{
if ($survey['active']=='Y' && !tableExists("{{survey_{$survey['sid']}}}"))
if ($oSurvey->active=='Y' && !tableExists("{{survey_{$oSurvey->sid}}}"))
{
Survey::model()->updateByPk($survey['sid'],array('active'=>'N'));
Survey::model()->updateByPk($survey->sid,array('active'=>'N'));
$bDirectlyFixed=true;
}
}
unset($surveys);
unset($oSurveys);



Expand All @@ -390,6 +398,7 @@ protected function _checkintegrity()
$sNewTable = "old_survey_{$iSurveyID}_{$sDate}";
try {
$deactivateresult = Yii::app()->db->createCommand()->renameTable("{{{$sOldTable}}}", "{{{$sNewTable}}}");
$bDirectlyFixed=true;
} catch (CDbException $e) {
die ('Couldn\'t make backup of the survey table. Please try again. The database reported the following error:<br />' . htmlspecialchars($e) . '<br />');
}
Expand All @@ -409,6 +418,7 @@ protected function _checkintegrity()
$sNewTable = "old_tokens_{$iSurveyID}_{$sDate}";
try {
$deactivateresult = Yii::app()->db->createCommand()->renameTable("{{{$sOldTable}}}", "{{{$sNewTable}}}");
$bDirectlyFixed=true;
} catch (CDbException $e) {
die ('Couldn\'t make backup of the survey table. Please try again. The database reported the following error:<br />' . htmlspecialchars($e) . '<br />');
}
Expand Down Expand Up @@ -568,6 +578,7 @@ protected function _checkintegrity()
foreach ($insertdata as $k => $v)
$oLanguageSettings->$k = $v;
$usresult=$oLanguageSettings->save();
$bDirectlyFixed=true;
}
}
}
Expand Down Expand Up @@ -778,7 +789,11 @@ protected function _checkintegrity()
// the token table and remove if it doesn't.


/* TODO */
/* Show a alert message is some fix is done */
if($bDirectlyFixed)
{
Yii::app()->setFlashMessage(gT("Some needed fix are already done."),'info');
}

return $aDelete;
}
Expand Down
14 changes: 13 additions & 1 deletion application/helpers/common_helper.php
Expand Up @@ -216,7 +216,19 @@ function getSurveyList($returnarray=false, $surveyid=false)
$surveynames = array();
foreach ($surveyidresult as $result)
{
$surveynames[] = array_merge($result->attributes, $result->defaultlanguage->attributes);
if(!empty($result->defaultlanguage))
{
$surveynames[] = array_merge($result->attributes, $result->defaultlanguage->attributes);
}
elseif(empty($bCheckIntegrity))
{
$bCheckIntegrity=true;
Yii::app()->setFlashMessage(
sprintf(gT("One or more surveys seem broken, you must %s of the LimeSurvey database."),
CHtml::link(gT('check data integrity'),array("admin/checkintegrity"))
),
'error');
}
}

$cached = $surveynames;
Expand Down
52 changes: 18 additions & 34 deletions application/views/admin/notifications/notifications.php
@@ -1,38 +1,22 @@
<div id="notif-container" class="col-lg-12 content-right" style="z-index: 10100">
<?php foreach($aMessage as $message):?>
<?php if(!isset($message['type'])): ?>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span >&times;</span></button>
<?php echo $message['message'];?>
</div>
<?php else: ?>

<?php if($message['type']=="success"): ?>
<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span >&times;</span></button>
<?php echo $message['message'];?>
</div>
<?php elseif($message['type']=="error"):?>
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span >&times;</span></button>
<?php echo $message['message'];?>
</div>
<?php elseif($message['type']=="warning"):?>
<div class="alert alert-warning alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span >&times;</span></button>
<?php echo $message['message'];?>
</div>
<?php else:?>

<div class="alert alert-success alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span >&times;</span></button>
<?php echo $message['message'];?>
</div>

<?php endif;?>


<?php endif;?>

<?php
if(isset($message['type']) && in_array($message['type'],array('error','success','danger','warning','info')))
{
$sType=$message['type'];
if($sType=='error')
{
$sType='danger';
}
}
else
{
$sType='success';
}
echo CHtml::tag("div",array('class'=>"alert alert-{$sType} alert-dismissible",'role'=>'alert'),false,false);
echo CHtml::htmlButton("<span >&times;</span>",array('type'=>'button','class'=>'close','data-dismiss'=>'alert','aria-label'=>gT("Close")));
echo $message['message'];
echo CHtml::closeTag("div");
?>
<?php endforeach;?>
</div>

0 comments on commit 01bf5fc

Please sign in to comment.