From a211996200d6f87942358ebc3c7e745e9bc67e5c Mon Sep 17 00:00:00 2001 From: Carsten Schmitz Date: Tue, 25 Sep 2012 10:08:41 +0200 Subject: [PATCH] Fixed issue: ComfortUpdate not working --- application/config/config-defaults.php | 6 + application/config/version.php | 4 +- application/controllers/AdminController.php | 1 - application/controllers/admin/dumpdb.php | 159 +-------------- .../controllers/admin/globalsettings.php | 2 + .../controllers/admin/remotecontrol.php | 4 +- application/controllers/admin/update.php | 127 ++++++------ application/core/LSYii_Application.php | 30 +-- application/helpers/admin/backupdb_helper.php | 193 ++++++++++++++++++ application/helpers/globalsettings_helper.php | 8 +- application/views/admin/update/step2.php | 4 +- application/views/admin/update/step3.php | 54 +++-- application/views/admin/update/step4.php | 2 +- application/views/admin/update/update.php | 12 +- 14 files changed, 316 insertions(+), 290 deletions(-) create mode 100644 application/helpers/admin/backupdb_helper.php diff --git a/application/config/config-defaults.php b/application/config/config-defaults.php index 1132e96ede1..83efbbb00c5 100644 --- a/application/config/config-defaults.php +++ b/application/config/config-defaults.php @@ -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) diff --git a/application/config/version.php b/application/config/version.php index 6019257d997..0340aeb3aba 100644 --- a/application/config/version.php +++ b/application/config/version.php @@ -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; diff --git a/application/controllers/AdminController.php b/application/controllers/AdminController.php index e252e57432e..367cd22a4b3 100644 --- a/application/controllers/AdminController.php +++ b/application/controllers/AdminController.php @@ -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; diff --git a/application/controllers/admin/dumpdb.php b/application/controllers/admin/dumpdb.php index d6b94624897..f964c56c253 100644 --- a/application/controllers/admin/dumpdb.php +++ b/application/controllers/admin/dumpdb.php @@ -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; - } -} +} \ No newline at end of file diff --git a/application/controllers/admin/globalsettings.php b/application/controllers/admin/globalsettings.php index 55c9f75eedc..e5dc0fed3a6 100644 --- a/application/controllers/admin/globalsettings.php +++ b/application/controllers/admin/globalsettings.php @@ -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']); diff --git a/application/controllers/admin/remotecontrol.php b/application/controllers/admin/remotecontrol.php index 0032116c59d..c68c8de0709 100644 --- a/application/controllers/admin/remotecontrol.php +++ b/application/controllers/admin/remotecontrol.php @@ -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'); diff --git a/application/controllers/admin/update.php b/application/controllers/admin/update.php index 6395dd9c19a..734c5b38804 100644 --- a/application/controllers/admin/update.php +++ b/application/controllers/admin/update.php @@ -9,10 +9,7 @@ * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * See COPYRIGHT.php for copyright notices and details. -* -* $Id$ */ -list(,$updaterversion)=explode(' ','$Rev: 11155 $'); // this is updated by subversion so don't change this string /** * Update Controller @@ -24,19 +21,19 @@ */ class update extends Survey_Common_Action { - /** * Default Controller Action */ - function index($subaction = null) + function index($sSubAction = null) { - global $updaterversion; $this->_RunUpdaterUpdate(); $clang = $this->getController()->lang; - $buildnumber = Yii::app()->getConfig("buildnumber"); + $iCurrentBuildnumber = Yii::app()->getConfig("buildnumber"); $tempdir = Yii::app()->getConfig("tempdir"); - $updatekey = $this->_getUpdateKey($subaction); + $iDestinationBuild= Yii::app()->getConfig("updatebuild"); + + $updatekey = $this->_getUpdateKey($sSubAction); $error = false; if ( $updatekey != '' ) { @@ -47,7 +44,7 @@ function index($subaction = null) $error = true; } - list($httperror, $changelog, $cookies) = $this->_getChangelog($buildnumber, $updaterversion, $updatekey); + list($httperror, $changelog, $cookies) = $this->_getChangelog($iCurrentBuildnumber, $iDestinationBuild, $updatekey); } $aData['error'] = $error; @@ -59,9 +56,19 @@ function index($subaction = null) $this->_renderWrappedTemplate('update', 'update', $aData); } + private function _getChangedFiles($buildnumber, $updaterversion, $updatekey) + { + $http = new http; + $httperror = $this->_requestChangedFiles($http, $buildnumber, $updaterversion, $updatekey); + + if ($httperror != '') { + return array($httperror, null); + } + return $this->_readChangelog($http); + } + private function _getChangelog($buildnumber, $updaterversion, $updatekey) { - Yii::app()->loadLibrary('admin/http/http'); $http = new http; $httperror = $this->_requestChangelog($http, $buildnumber, $updaterversion, $updatekey); @@ -97,13 +104,27 @@ private function _requestChangelog(http $http, $buildnumber, $updaterversion, $u return $http->SendRequest($arguments); } + + private function _requestChangedFiles(http $http, $buildnumber, $updaterversion, $updatekey) + { + $http->timeout = 0; + $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/update/' . $buildnumber . '/' . $updaterversion . '/' . $updatekey, $arguments); + + $http->Open($arguments); + + return $http->SendRequest($arguments); + } + - private function _getUpdateKey($subaction) + private function _getUpdateKey($sSubAction) { $updatekey = Yii::app()->getConfig("updatekey"); - if ($subaction == 'keyupdate') { + if ($sSubAction == 'keyupdate') { $updatekey = sanitize_paranoid_string($_POST['updatekey']); setGlobalSetting('updatekey', $updatekey); + Yii::app()->setConfig("updatekey", $updatekey); return $updatekey; } return $updatekey; @@ -117,20 +138,18 @@ function step2() $updatebuild = Yii::app()->getConfig("updatebuild"); $updatekey = Yii::app()->getConfig("updatekey"); - list($error, $updateinfo, $cookies) = $this->_getChangelog($buildnumber, $updatebuild, $updatekey); - $readonlyfiles = $this->_getReadOnlyFiles($updateinfo); - + list($error, $updateinfo, $cookies) = $this->_getChangedFiles($buildnumber, $updatebuild, $updatekey); + $aData = $this->_getFileStatus($updateinfo); Yii::app()->session['updateinfo'] = $updateinfo; Yii::app()->session['updatesession'] = $cookies; $aData['error'] = $error; $aData['updateinfo'] = $updateinfo; - $aData['readonlyfiles'] = $readonlyfiles; $this->_renderWrappedTemplate('update', 'step2', $aData); } - private function _getReadOnlyFiles($updateinfo) + private function _getFileStatus($updateinfo) { // okay, updateinfo now contains all necessary updateinformation // Now check if the existing files have the mentioned checksum @@ -148,7 +167,10 @@ private function _getReadOnlyFiles($updateinfo) { $this->_checkFile($afile, $rootdir, $readonlyfiles, $existingfiles, $modifiedfiles); } - return $readonlyfiles; + return array('readonlyfiles'=>$readonlyfiles, + 'modifiedfiles'=>$modifiedfiles, + 'existingfiles'=>$existingfiles) + ; } private function _checkFile($file, $rootdir, &$readonlyfiles, &$existingfiles, &$modifiedfiles) @@ -198,7 +220,6 @@ function step3() $updatekey = Yii::app()->getConfig("updatekey"); $updatebuild = Yii::app()->getConfig("updatebuild"); //$_POST=$this->input->post(); - Yii::app()->loadLibrary('admin/http/http'); $rootdir = Yii::app()->getConfig("rootdir"); $publicdir = Yii::app()->getConfig("publicdir"); $tempdir = Yii::app()->getConfig("tempdir"); @@ -224,7 +245,7 @@ function step3() // okay, updateinfo now contains all necessary updateinformation // Create DB and file backups now - $basefilename = date("YmdHis-").md5(uniqid(rand(), true)); + $basefilename = dateShift(date("Y-m-d H:i:s"), "Y-m-d", Yii::app()->getConfig('timeadjust')).'_'.md5(uniqid(rand(), true)); //Now create a backup of the files to be delete or modified $filestozip=array(); @@ -237,46 +258,35 @@ function step3() } } - Yii::app()->loadLibrary("admin/pclzip/pclzip",array('p_zipname' => $tempdir.DIRECTORY_SEPARATOR.'files-'.$basefilename.'.zip')); - $archive = $this->pclzip; + Yii::app()->loadLibrary("admin/pclzip/pclzip"); + $archive = new PclZip($tempdir.DIRECTORY_SEPARATOR.'LimeSurvey_files_backup_'.$basefilename.'.zip'); $v_list = $archive->add($filestozip, PCLZIP_OPT_REMOVE_PATH, $publicdir); if ($v_list == 0) { die("Error : ".$archive->errorInfo(true)); } + $aData['sFilesArchive']=$tempdir.DIRECTORY_SEPARATOR.'LimeSurvey_files_backup_'.$basefilename.'.zip'; $aData['databasetype'] = $aDatabasetype; //TODO: Yii provides no function to backup the database. To be done after dumpdb is ported if (in_array($aDatabasetype, array('mysql', 'mysqli'))) { - $this->load->dbutil(); - $this->load->helper("string"); if ((in_array($aDatabasetype, array('mysql', 'mysqli'))) && Yii::app()->getConfig('demoMode') != true) { - $tables = $this->db->list_tables(); - foreach ($tables as $table) - { - if ($this->db->dbprefix==substr($table, 0, strlen($this->db->dbprefix))) - { - $lstables[] = $table; - } + Yii::app()->loadHelper("admin/backupdb"); + $sfilename = $tempdir.DIRECTORY_SEPARATOR."backup_db_".randomChars(20)."_".dateShift(date("Y-m-d H:i:s"), "Y-m-d", Yii::app()->getConfig('timeadjust')).".sql"; + $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); + unlink($sfilename); + if ($v_list == 0) { + die("Error : ".$archive->errorInfo(true)); } - $sfilename = "backup_db_".random_string('unique')."_".dateShift(date("Y-m-d H:i:s"), "Y-m-d", Yii::app()->getConfig('timeadjust')).".sql"; - $dfilename = "LimeSurvey_".$this->db->database."_dump_".dateShift(date("Y-m-d H:i:s"), "Y-m-d", Yii::app()->getConfig('timeadjust')).".sql.gz"; - $prefs = array( - 'format' => 'zip', // gzip, zip, txt - // File name - NEEDED ONLY WITH ZIP FILES - 'filename' => $sfilename, - 'tables' => $lstables, - 'add_drop' => TRUE, // Whether to add DROP TABLE statements to backup file - 'add_insert' => TRUE, // Whether to add INSERT data to backup file - 'newline' => "\n" // Newline character used in backup file - ); - $this->dbutil->backup($prefs); - $backup =& $this->dbutil->backup(); - $this->load->helper('file'); - write_file($tempdir.'/'.$sfilename.".gz", $backup); + $aData['sSQLArchive']=$dfilename; } } @@ -291,7 +301,7 @@ function step4() $tempdir = Yii::app()->getConfig("tempdir"); $updatekey = Yii::app()->getConfig("updatekey"); $updatebuild = Yii::app()->getConfig("updatebuild"); - Yii::app()->loadLibrary('admin/http/http'); + $rootdir = Yii::app()->getConfig("rootdir"); $publicdir = Yii::app()->getConfig("publicdir"); $tempdir = Yii::app()->getConfig("tempdir"); @@ -368,8 +378,8 @@ function step4() //Now unzip the new files over the existing ones. $new_files = false; if (file_exists($tempdir.'/update.zip')){ - Yii::app()->loadLibrary("admin/pclzip/pclzip",array('p_zipname' => $tempdir.'/update.zip')); - $archive = $this->pclzip; + Yii::app()->loadLibrary("admin/pclzip/pclzip"); + $archive = new PclZip($tempdir.'/update.zip'); if ($archive->extract(PCLZIP_OPT_PATH, $rootdir.'/', PCLZIP_OPT_REPLACE_NEWER)== 0) { die("Error : ".$archive->errorInfo(true)); } @@ -399,7 +409,7 @@ function step4() { if(strpos($line,'buildnumber')!==false) { - $line='$config[\'buildnumber\']'." = '{Yii::app()->session['updateinfo']['toversion']}';\r\n"; + $line='$config[\'buildnumber\'] = '.Yii::app()->session['updateinfo']['toversion'].';'."\r\n"; } fwrite($handle,$line); } @@ -415,12 +425,10 @@ function step4() private function _RunUpdaterUpdate() { - //global $homedir, $debug, $updaterversion; - global $updaterversion; $clang = $this->getController()->lang; $versionnumber = Yii::app()->getConfig("versionnumber"); + $buildnumber = Yii::app()->getConfig("buildnumber"); $tempdir = Yii::app()->getConfig("tempdir"); - Yii::app()->loadLibrary('admin/http/http'); $http=new http; @@ -429,7 +437,7 @@ private function _RunUpdaterUpdate() /* 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=$updaterversion",$arguments); + $http->GetRequestArguments("http://update.limesurvey.org?updaterbuild={$buildnumber}",$arguments); $updateinfo=false; $error=$http->Open($arguments); @@ -458,16 +466,13 @@ private function _RunUpdaterUpdate() $updateinfo['errorhtml']=$error; } unset( $http ); - if ((int)$updateinfo['UpdaterRevision']<=$updaterversion) + if ((int)$updateinfo['UpdaterRevision']<=$buildnumber) { + // There is no newer updater version on the server return true; } - if (!is_writable($tempdir)) - { - $error=true; - } - if (!is_writable(APPPATH.DIRECTORY_SEPARATOR.'controllers'.DIRECTORY_SEPARATOR.'admin'.DIRECTORY_SEPARATOR.'update.php')) + if (!is_writable($tempdir) || !is_writable(APPPATH.DIRECTORY_SEPARATOR.'controllers'.DIRECTORY_SEPARATOR.'admin'.DIRECTORY_SEPARATOR.'update.php')) { $error=true; } @@ -485,7 +490,7 @@ private function _RunUpdaterUpdate() /* 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/$updaterversion",$arguments); + $http->GetRequestArguments("http://update.limesurvey.org/updates/downloadupdater/{$this->updaterversion}",$arguments); $httperror=$http->Open($arguments); $httperror=$http->SendRequest($arguments); diff --git a/application/core/LSYii_Application.php b/application/core/LSYii_Application.php index 94f46dfc1e8..fd8df04f704 100644 --- a/application/core/LSYii_Application.php +++ b/application/core/LSYii_Application.php @@ -12,12 +12,11 @@ */ /** -* Implements global registry and config +* Implements global config */ class LSYii_Application extends CWebApplication { protected $config = array(); - protected $registry = array(); public $lang = null; /** @@ -69,7 +68,7 @@ public function loadLibrary($library) } /** - * Sets a configuration variable into the registry + * Sets a configuration variable into the config * * @access public * @param string $name @@ -99,7 +98,7 @@ public function loadConfig($file) } /** - * Returns a config variable from the registry + * Returns a config variable from the config * * @access public * @param string $name @@ -110,18 +109,6 @@ public function getConfig($name) return isset($this->config[$name]) ? $this->config[$name] : false; } - /** - * Sets a configuration variable into the registry - * - * @access public - * @param string $name - * @param mixed $value - * @return void - */ - public function setRegistry($name, $value) - { - $this->registry[$name] = $value; - } /** * For future use, cache the language app wise as well. @@ -135,15 +122,4 @@ public function setLang(Limesurvey_lang $lang) $this->lang = $lang; } - /** - * Returns a config variable from the registry - * - * @access public - * @param string $name - * @return mixed - */ - public function getRegistry($name) - { - return isset($this->registry[$name]) ? $this->registry[$name] : false; - } } diff --git a/application/helpers/admin/backupdb_helper.php b/application/helpers/admin/backupdb_helper.php new file mode 100644 index 00000000000..d7ed4cb6110 --- /dev/null +++ b/application/helpers/admin/backupdb_helper.php @@ -0,0 +1,193 @@ +getConfig('allowexportalldb'); + + $sOutput=_outputDBDescription($sDbName, $bAllowExportAllDb); + if ($bEchoOutput) + { + echo $sOutput; + } + if (!is_null($sFileName)) + { + $oFile=fopen($sFileName,'w'); + fwrite($oFile,$sOutput); + } + _outputDBData($bAllowExportAllDb, $bEchoOutput, $sFileName, $oFile); + if (!is_null($sFileName)) + { + fclose($oFile); + } + + } + + function _outputDBDescription($sDbName, $bAllowExportAllDb) + { + $sOutput= '--' . "\n"; + $sOutput.= '-- LimeSurvey Database Dump of `' . $sDbName . '`' . "\n"; + if (!$bAllowExportAllDb) { + $sOutput= '-- Only prefixed tables with: ' . Yii::app()->db->tablePrefix . "\n"; + } + $sOutput.= '-- Date of Dump: ' . dateShift(date('d-M-Y'), 'd-M-Y', Yii::app()->getConfig('timeadjust')) . "\n"; + $sOutput.= '--' . "\n"; + return $sOutput; + } + + function _outputDBData($bAllowExportAllDb, $bEchoOutput, $sFileName, $oFile) + { + $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))) { + $sOutput=_outputTableDescription($sTableName); + $sOutput.=_outputTableData($sTableName, $oTableData); + if ($bEchoOutput) + { + echo $sOutput; + } + if (!is_null($sFileName)) + { + fwrite($oFile,$sOutput); + } + } + } + } + + /** + * Outputs the table structure in sql format + */ + function _outputTableDescription($sTableName) + { + $sOutput= "\n".'-- --------------------------------------------------------'."\n\n"; + $sOutput.= '--'."\n"; + $sOutput.= '-- Table structure for table `'.$sTableName.'`'."\n"; + $sOutput.= '--'."\n\n"; + $sOutput.= 'DROP TABLE IF EXISTS `'.$sTableName.'`;'."\n"; + + $aCreateTable = Yii::app()->db->createCommand('SHOW CREATE TABLE '.Yii::app()->db->quoteTableName($sTableName))->queryRow(); + $sOutput.= $aCreateTable['Create Table'].';'."\n\n"; + return $sOutput; + } + + /** + * Outputs the table data in sql format + */ + function _outputTableData($sTableName, $oTableData) + { + $sOutput= '--'."\n"; + $sOutput.= '-- Dumping data for table `'.$sTableName.'`'."\n"; + $sOutput.= '--'."\n\n"; + + $iNbRecords = _countNumberOfEntries($sTableName); + if ($iNbRecords > 0) { + $iMaxNbRecords = _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(); + + $sOutput.=_outputRecords($sTableName, $aFieldNames, $aRecords); + + } + $sOutput.= "\n"; + } + return $sOutput; + } + + function _outputRecords($sTableName, $aFieldNames, $aRecords) + { + $i=0; + $sOutput=''; + foreach ($aRecords as $aRecord) + { + if ($i==0){ + $sOutput.= 'INSERT INTO `' . $sTableName . "` VALUES\n"; + } + $sOutput.= '('; + foreach ($aFieldNames as $sFieldName) + { + + if (isset($aRecord[$sFieldName]) && !is_null($aRecord[$sFieldName])) { + $sValue= addslashes($aRecord[$sFieldName]); + $sValue = preg_replace("#\n#", "\\n", $sValue); + $sOutput.= '"' . $sValue . '"'; + } + else + { + $sOutput.= 'NULL'; + } + + if (end($aFieldNames) != $sFieldName) { + $sOutput.= ', '; + } + } + $i++; + if ($i==200 || (end($aRecords) == $aRecord)) + { + $sOutput.= ');' . "\n"; + $i=0; + } + else + { + $sOutput.= '),' . "\n"; + } + } + return $sOutput; + } + + function _countNumberOfEntries($sTableName) + { + $aNumRows = Yii::app()->db->createCommand('SELECT COUNT(*) FROM ' . Yii::app()->db->quoteTableName($sTableName))->queryRow(); + $iNumRows = $aNumRows['COUNT(*)']; + return $iNumRows; + } + + function _getMaxNbRecords() + { + $iMaxRecords = (int)Yii::app()->getConfig('maxdumpdbrecords'); + if ($iMaxRecords < 1) { + $iMaxRecords = 2500; + return $iMaxRecords; // default + } + return $iMaxRecords; + } + + + /** + * Get the database name + */ + 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; + } + \ No newline at end of file diff --git a/application/helpers/globalsettings_helper.php b/application/helpers/globalsettings_helper.php index c8aa41a437b..61e588713cd 100644 --- a/application/helpers/globalsettings_helper.php +++ b/application/helpers/globalsettings_helper.php @@ -32,15 +32,13 @@ function injectglobalsettings() //$$setting['stg_name']=$setting['stg_value']; Yii::app()->setConfig($setting->getAttribute('stg_name'), $setting->getAttribute('stg_value')); } - - Yii::app()->setRegistry($setting->getAttribute('stg_name'), $setting->getAttribute('stg_value')); } } } function getGlobalSetting($settingname) { - $dbvalue = Yii::app()->getRegistry($settingname); + $dbvalue = Yii::app()->getConfig($settingname); if ($dbvalue === false) { @@ -48,7 +46,7 @@ function getGlobalSetting($settingname) if ($dbvalue === null) { - Yii::app()->setRegistry($settingname, null); + Yii::app()->setConfig($settingname, null); $dbvalue = ''; } else @@ -88,8 +86,6 @@ function setGlobalSetting($settingname, $settingvalue) $record->save(); } - Yii::app()->setRegistry($settingname,$settingvalue); - Yii::app()->setConfig($settingname, $settingvalue); } diff --git a/application/views/admin/update/step2.php b/application/views/admin/update/step2.php index 2a952f1fea7..210e1e764cc 100644 --- a/application/views/admin/update/step2.php +++ b/application/views/admin/update/step2.php @@ -50,7 +50,7 @@ { echo '
  • '.htmlspecialchars($existingfile['file']).'
  • '; } - echo ''; + echo '
    '; } if (count($modifiedfiles)>0) @@ -63,7 +63,7 @@ { echo '
  • '.htmlspecialchars($modifiedfile['file']).'
  • '; } - echo ''; + echo '
    '; } if (count($readonlyfiles)>0) diff --git a/application/views/admin/update/step3.php b/application/views/admin/update/step3.php index 722267d65d2..4e83995b836 100644 --- a/application/views/admin/update/step3.php +++ b/application/views/admin/update/step3.php @@ -1,38 +1,36 @@ +
    gT('ComfortUpdate step %s'),'3'); ?>
    +

    eT('Creating DB & file backup')?>


    '.sprintf($clang->gT('ComfortUpdate step %s'),'3').'
    '; -echo '

    '.$clang->gT('Creating DB & file backup').'

    '; - -if (!isset( Yii::app()->session['updateinfo'])) -{ - $clang->eT('On requesting the update information from limesurvey.org there has been an error:').'
    '; - - if ($updateinfo['error']==1) + if (!isset( Yii::app()->session['updateinfo'])) { - $clang->eT('Your update key is invalid and was removed. ').'
    '; + $clang->eT('On requesting the update information from limesurvey.org there has been an error:').'
    '; + + if ($updateinfo['error']==1) + { + $clang->eT('Your update key is invalid and was removed. ').'
    '; + } + else + $clang->eT('On requesting the update information from limesurvey.org there has been an error:').'
    '; } - else - $clang->eT('On requesting the update information from limesurvey.org there has been an error:').'
    '; -} -$clang->eT('Creating file backup... ').'
    '; + $clang->eT('Creating file backup... ').'
    '; -echo "".$clang->gT('File backup created:').' '.htmlspecialchars($tempdir.DIRECTORY_SEPARATOR.'files-'.$basefilename.'.zip').'

    '; + echo "".$clang->gT('File backup created:').' '.htmlspecialchars($sFilesArchive).'

    '; -if ($databasetype=='mysql' || $databasetype=='mysqli') -{ - $clang->eT('Creating database backup... ').'
    '; - echo "".$clang->gT('DB backup created:')." ".htmlspecialchars($tempdir.DIRECTORY_SEPARATOR.'db-'.$basefilename.'.sql').'

    '; -} -else -{ - echo "".$clang->gT('No DB backup created:').'
    '.$clang->gT('Database backup functionality is currently not available for your database type. Before proceeding please backup your database using a backup tool!').'


    '; -} + if ($databasetype=='mysql' || $databasetype=='mysqli') + { + $clang->eT('Creating database backup... ').'
    '; + echo "".$clang->gT('DB backup created:')." ".htmlspecialchars($sSQLArchive).'

    '; + } + else + { + echo "".$clang->gT('No DB backup created:').'
    '.$clang->gT('Database backup functionality is currently not available for your database type. Before proceeding please backup your database using a backup tool!').'


    '; + } -$clang->eT('Please check any problems above and then proceed to the final step.'); -echo "

    "; -echo '
    '; + $clang->eT('Please check any problems above and then proceed to the final step.'); + echo "

    "; + echo ''; ?> diff --git a/application/views/admin/update/step4.php b/application/views/admin/update/step4.php index 026ddbdd5fa..6ec63d445fa 100644 --- a/application/views/admin/update/step4.php +++ b/application/views/admin/update/step4.php @@ -28,7 +28,7 @@ $clang->eT('Please check any problems above - update was done.').'
    '; } -echo "

    "; +echo "

    "; echo ''; ?> diff --git a/application/views/admin/update/update.php b/application/views/admin/update/update.php index 099141304ce..1fff1cc9e65 100644 --- a/application/views/admin/update/update.php +++ b/application/views/admin/update/update.php @@ -1,15 +1,15 @@ '.$clang->gT('Welcome to the ComfortUpdate').'

    '; -$clang->eT('The LimeSurvey ComfortUpdate is an easy procedure to quickly update to the latest version of LimeSurvey.').'
    '; -$clang->eT('The following steps will be done by this update:').'

    '; echo '

    '.$clang->gT('Checking basic requirements...').'

    '; if ($updatekey==''){ - $clang->eT('You need an update key to run the comfort update. During the beta test of this update feature the key "LIMESURVEYUPDATE" can be used.'); - echo "
    '; + $clang->eT('You need an update key to run the ComfortUpdate. During the beta test of this update feature the key "LIMESURVEYUPDATE" can be used.'); + echo "

    '; echo '
    '; } else @@ -26,7 +26,7 @@ echo "
  • ".sprintf($clang->gT("Version file is not writable (%s). Please set according file permissions."),APPPATH.'config/version.php')."
  • "; $error=true; } - echo '

    '.$clang->gT('Change log').'

    '; + echo '

    '.$clang->gT('Change log').'

    '; if($httperror=="") { echo '';