Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed issue: ComfortUpdate not working
  • Loading branch information
c-schmitz committed Sep 25, 2012
1 parent 6d78481 commit a211996
Show file tree
Hide file tree
Showing 14 changed files with 316 additions and 290 deletions.
6 changes: 6 additions & 0 deletions application/config/config-defaults.php
Expand Up @@ -367,6 +367,12 @@
*/
$config['updatecheckperiod']=7;

/**
* $updatekey - Sets the default update key for the ComfortUpdater
*/
$config['updatekey']='';


/**
* @var $showxquestions string allows you to control whether or not
* {THEREAREXQUESTIONS} is displayed (if it is included in a template)
Expand Down
4 changes: 2 additions & 2 deletions application/config/version.php
Expand Up @@ -12,10 +12,10 @@
*
*/

$config['versionnumber'] = "2.0+";
$config['versionnumber'] = "2.00+";
$config['dbversionnumber'] = 162;
$config['buildnumber'] = '';
$config['updatable'] = false;
$config['updatable'] = true;

return $config;

Expand Down
1 change: 0 additions & 1 deletion application/controllers/AdminController.php
Expand Up @@ -399,7 +399,6 @@ public function _showMessageBox($title,$message,$class="header ui-widget-header"
*/
public function _showadminmenu($surveyid = false)
{
global $homedir, $scriptname, $setfont, $imageurl, $debug, $action, $updatebuild, $updateversion, $updatelastcheck, $databasetype;

$clang = $this->lang;
$data['clang']= $clang;
Expand Down
159 changes: 6 additions & 153 deletions application/controllers/admin/dumpdb.php
Expand Up @@ -45,170 +45,23 @@ function __construct($controller, $id)
*/
public function index()
{
$sDbName = $this->_getDbName();
$this->_outputHeaders($sDbName);
$this->_outputDatabase($sDbName);

$sFileName = 'LimeSurvey_'.$sDbName.'_dump_'.dateShift(date('Y-m-d H:i:s'), 'Y-m-d', Yii::app()->getConfig('timeadjust')).'.sql';
$this->_outputHeaders($sFileName);
Yii::app()->loadHelper("admin/backupdb");
outputDatabase();
exit;
}

/**
* Get the database name
*/
private function _getDbName() {
// Yii doesn't give us a good way to get the database name
preg_match('/dbname=([^;]*)/', Yii::app()->db->getSchema()->getDbConnection()->connectionString, $aMatches);
$sDbName = $aMatches[1];

return $sDbName;
}

/**
* Send the headers so that it is shown as a download
* @param string $sDbName Database Name
*/
private function _outputHeaders($sDbName)
private function _outputHeaders($sFileName)
{
$sFileName = 'LimeSurvey_'.$sDbName.'_dump_'.dateShift(date('Y-m-d H:i:s'), 'Y-m-d', Yii::app()->getConfig('timeadjust')).'.sql';

header('Content-type: application/octet-stream');
header('Content-Disposition: attachment; filename='.$sFileName);
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
}

/**
* Outputs a full dump of the current LimeSurvey database
* @param string $sDbName Database Name
*/
private function _outputDatabase($sDbName)
{
$bAllowExportAllDb = (bool) Yii::app()->getConfig('allowexportalldb');

$this->_outputDBDescription($sDbName, $bAllowExportAllDb);
$this->_outputDBData($bAllowExportAllDb);
}

private function _outputDBDescription($sDbName, $bAllowExportAllDb)
{
echo '--' . "\n";
echo '-- LimeSurvey Database Dump of `' . $sDbName . '`' . "\n";
if (!$bAllowExportAllDb) {
echo '-- Only prefixed tables with: ' . Yii::app()->db->tablePrefix . "\n";
}
echo '-- Date of Dump: ' . dateShift(date('d-M-Y'), 'd-M-Y', Yii::app()->getConfig('timeadjust')) . "\n";
echo '--' . "\n";
}

private function _outputDBData($bAllowExportAllDb)
{
$aTables = Yii::app()->db->getSchema()->getTables();
foreach ($aTables as $sTableName => $oTableData)
{
if ($bAllowExportAllDb && Yii::app()->db->tablePrefix == substr($sTableName, 0, strlen(Yii::app()->db->tablePrefix))) {
$this->_outputTableDescription($sTableName);
$this->_outputTableData($sTableName, $oTableData);
}
}
}

/**
* Outputs the table structure in sql format
*/
private function _outputTableDescription($sTableName)
{
echo "\n".'-- --------------------------------------------------------'."\n\n";
echo '--'."\n";
echo '-- Table structure for table `'.$sTableName.'`'."\n";
echo '--'."\n\n";
echo 'DROP TABLE IF EXISTS `'.$sTableName.'`;'."\n";

$aCreateTable = Yii::app()->db->createCommand('SHOW CREATE TABLE '.Yii::app()->db->quoteTableName($sTableName))->queryRow();
echo $aCreateTable['Create Table'].';'."\n\n";
}

/**
* Outputs the table data in sql format
*/
private function _outputTableData($sTableName, $oTableData)
{
echo '--'."\n";
echo '-- Dumping data for table `'.$sTableName.'`'."\n";
echo '--'."\n\n";

$iNbRecords = $this->_countNumberOfEntries($sTableName);
if ($iNbRecords > 0) {
$iMaxNbRecords = $this->_getMaxNbRecords();
$aFieldNames = array_keys($oTableData->columns);

for ($i = 0; $i < ceil($iNbRecords / $iMaxNbRecords); $i++)
{
$aRecords = Yii::app()->db->createCommand()
->select()
->from($sTableName)
->limit(intval($iMaxNbRecords), ($i != 0 ? ($i * $iMaxNbRecords) + 1 : null))
->query()->readAll();

$aFieldNames = $this->_outputRecords($sTableName, $aFieldNames, $aRecords);

}
echo "\n";
}
}

private function _outputRecords($sTableName, $aFieldNames, $aRecords)
{
$i=0;
foreach ($aRecords as $aRecord)
{
if ($i==0){
echo 'INSERT INTO `' . $sTableName . "` VALUES\n";
}
echo '(';
foreach ($aFieldNames as $sFieldName)
{

if (isset($aRecord[$sFieldName]) && !is_null($aRecord[$sFieldName])) {
$sValue= addslashes($aRecord[$sFieldName]);
$sValue = preg_replace("#\n#", "\\n", $sValue);
echo '"' . $sValue . '"';
}
else
{
echo 'NULL';
}

if (end($aFieldNames) != $sFieldName) {
echo ', ';
}
}
$i++;
if ($i==200 || (end($aRecords) == $aRecord))
{
echo ');' . "\n";
$i=0;
}
else
{
echo '),' . "\n";
}
}
return $aFieldNames;
}

private function _countNumberOfEntries($sTableName)
{
$aNumRows = Yii::app()->db->createCommand('SELECT COUNT(*) FROM ' . Yii::app()->db->quoteTableName($sTableName))->queryRow();
$iNumRows = $aNumRows['COUNT(*)'];
return $iNumRows;
}

private function _getMaxNbRecords()
{
$iMaxRecords = (int)Yii::app()->getConfig('maxdumpdbrecords');
if ($iMaxRecords < 1) {
$iMaxRecords = 2500;
return $iMaxRecords; // default
}
return $iMaxRecords;
}
}
}
2 changes: 2 additions & 0 deletions application/controllers/admin/globalsettings.php
Expand Up @@ -73,6 +73,8 @@ private function _displaySettings()
$data['updateavailable'] = (Yii::app()->getConfig("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['allLanguages'] = getLanguageData(false, Yii::app()->session['adminlang']);
if (trim(Yii::app()->getConfig('restrictToLanguages')) == '') {
$data['restrictToLanguages'] = array_keys($data['allLanguages']);
Expand Down
4 changes: 1 addition & 3 deletions application/controllers/admin/remotecontrol.php
Expand Up @@ -205,9 +205,7 @@ public function get_site_settings($sSessionKey,$sSetttingName)
{
if( Yii::app()->session['USER_RIGHT_SUPERADMIN'] == 1)
{
if (Yii::app()->getRegistry($sSetttingName) !== false)
return Yii::app()->getRegistry($sSetttingName);
elseif (Yii::app()->getConfig($sSetttingName) !== false)
if (Yii::app()->getConfig($sSetttingName) !== false)
return Yii::app()->getConfig($sSetttingName);
else
return array('status' => 'Invalid setting');
Expand Down

0 comments on commit a211996

Please sign in to comment.