Skip to content

Commit

Permalink
Dev: Added version config and fixed DBUpdate on login
Browse files Browse the repository at this point in the history
git-svn-id: file:///Users/Shitiz/Downloads/lssvn/source/limesurvey_yii@11802 b72ed6b6-b9f8-46b5-92b4-906544132732
  • Loading branch information
Gaurav Narula committed Dec 29, 2011
1 parent 17602dc commit 8ea167c
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 48 deletions.
2 changes: 2 additions & 0 deletions application/config/version.php
Expand Up @@ -16,4 +16,6 @@
$config['dbversionnumber'] = 153;
$config['buildnumber'] = '';

return $config;

?>
2 changes: 1 addition & 1 deletion application/controllers/AdminController.php
Expand Up @@ -105,7 +105,7 @@ public function run($action)
{
$usrow = getGlobalSetting('DBVersion');
if ((int) $usrow < Yii::app()->getConfig('dbversionnumber') && $action != 'update' && $action != 'authentication')
$this->redirect($this->createUrl('update/db'));
$this->redirect($this->createUrl('/admin/update/db'));
}

if ($action != "update" && $action != "db")
Expand Down
23 changes: 14 additions & 9 deletions application/controllers/admin/update.php
Expand Up @@ -35,16 +35,13 @@ public function run()
$actions = array_keys($_GET);
$_GET['method'] = $action = (!empty($actions[0])) ? $actions[0] : '';

echo $this->getController()->_getAdminHeader(false, true);

if (!empty($action)) {
$this->$action($_GET[$action]);
}
else
{
$this->index();
}
echo $this->getController()->_getAdminFooter("http://docs.limesurvey.org", $this->getController()->lang->gT("LimeSurvey online manual"), true);
}
}

/**
Expand Down Expand Up @@ -80,7 +77,7 @@ function index($subaction = null)
$data['changelog'] = isset($changelog) ? $changelog : '';
$data['httperror'] = isset($httperror) ? $httperror : '';

$this->getController()->render('/admin/update/update', $data);
$this->_renderHtml('/admin/update/update', $data);
}

private function _getChangelog($buildnumber, $updaterversion, $updatekey)
Expand Down Expand Up @@ -153,7 +150,7 @@ function step2()
$data['error'] = $error;
$data['updateinfo'] = $updateinfo;
$data['readonlyfiles'] = $readonlyfiles;
$this->getController()->render('/admin/update/step2', $data);
$this->_renderHtml('/admin/update/step2', $data);
}

private function _getReadOnlyFiles($updateinfo)
Expand Down Expand Up @@ -303,7 +300,7 @@ function step3()
write_file($tempdir.'/'.$sfilename.".gz", $backup);
}
}
$this->getController()->render('/admin/update/step3', $data);
$this->_renderHtml('/admin/update/step3', $data);
}


Expand Down Expand Up @@ -432,7 +429,7 @@ function step4()
setGlobalSetting('updateavailable','0');
setGlobalSetting('updatebuild','');
setGlobalSetting('updateversion','');
$this->getController()->render('/admin/update/step4', $data);
$this->_renderHtml('/admin/update/step4', $data);
}

private function _RunUpdaterUpdate()
Expand Down Expand Up @@ -565,7 +562,15 @@ function db($subaction = null)
{
echo CheckForDBUpgrades();
}
echo self::_getAdminFooter("http://docs.limesurvey.org", $clang->gT("LimeSurvey online manual"), true);
echo $this->getController()->_getAdminFooter("http://docs.limesurvey.org", $clang->gT("LimeSurvey online manual"), true);
}

private function _renderHtml($path, $data)
{
echo $this->getController()->_getAdminHeader(false, true);
$this->getController()->render($path, $data);
echo $this->getController()->_getAdminFooter("http://docs.limesurvey.org", $this->getController()->lang->gT("LimeSurvey online manual"), true);

}

}
3 changes: 2 additions & 1 deletion application/core/LSYii_Application.php
Expand Up @@ -39,8 +39,9 @@ public function __construct($config = null)
// Load the default and environmental settings from different files into self.
$app_config = require(APPPATH . '/config/application.php');
$ls_config = require(APPPATH . '/config/lsconfig.php');
$version_config = require(APPPATH . '/config/version.php');

$settings = array_merge($app_config, $ls_config);
$settings = array_merge($app_config, $ls_config, $version_config);
foreach ($settings as $key => $value)
$this->setConfig($key, $value);
}
Expand Down
44 changes: 23 additions & 21 deletions application/helpers/common_helper.php
Expand Up @@ -5623,32 +5623,32 @@ function removeBOM($str=""){
function GetUpdateInfo()
{
//require_once($homedir."/classes/http/http.php");
$CI =& get_instance();
$CI->load->library('admin/http/http','http');
Yii::import('application.libraries.admin.http.http');
$http = new http;

$CI->http->timeout=0;
$CI->http->data_timeout=0;
$CI->http->user_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
$CI->http->GetRequestArguments("http://update.limesurvey.org?build=".Yii::app()->getConfig("buildnumber"),$arguments);
$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?build=".Yii::app()->getConfig("buildnumber"),$arguments);

$updateinfo=false;
$error=$CI->http->Open($arguments);
$error=$CI->http->SendRequest($arguments);
$error=$http->Open($arguments);
$error=$http->SendRequest($arguments);

$CI->http->ReadReplyHeaders($headers);
$http->ReadReplyHeaders($headers);


if($error=="") {
$body=''; $full_body='';
for(;;){
$error = $CI->http->ReadReplyBody($body,10000);
$error = $http->ReadReplyBody($body,10000);
if($error != "" || strlen($body)==0) break;
$full_body .= $body;
}
$updateinfo=json_decode($full_body,true);
if ($CI->http->response_status!='200')
if ($http->response_status!='200')
{
$updateinfo['errorcode']=$CI->http->response_status;
$updateinfo['errorcode']=$http->response_status;
$updateinfo['errorhtml']=$full_body;
}
}
Expand All @@ -5657,7 +5657,7 @@ function GetUpdateInfo()
$updateinfo['errorcode']=$error;
$updateinfo['errorhtml']=$error;
}
unset( $CI->http );
unset( $http );
return $updateinfo;
}

Expand Down Expand Up @@ -7691,7 +7691,8 @@ function modify_database($sqlfile='', $sqlstring='')
global $modifyoutput;

//require_once($homedir."/classes/core/sha256.php");
Yii::app()->loadLibrary('admin/sha256');
Yii::app()->loadLibrary('admin/sha256','sha256');
$sha256 = new sha256;
$success = true; // Let's be optimistic
$modifyoutput='';

Expand Down Expand Up @@ -7723,22 +7724,23 @@ function modify_database($sqlfile='', $sqlstring='')
$command .= $line;
$command = str_replace('prefix_', Yii::app()->db->tablePrefix, $command); // Table prefixes
$command = str_replace('$defaultuser', Yii::app()->getConfig('defaultuser'), $command);
$command = str_replace('$defaultpass', Yii::app()->sha256->hashing(Yii::app()->getConfig('defaultpass')), $command);
$command = str_replace('$defaultpass', $sha256->hashing(Yii::app()->getConfig('defaultpass')), $command);
$command = str_replace('$siteadminname', $siteadminname, $command);
$command = str_replace('$siteadminemail', $siteadminemail, $command);
$command = str_replace('$defaultlang', Yii::app()->getConfig('defaultlang'), $command);
$command = str_replace('$sessionname', 'ls'.sRandomChars(20,'123456789'), $command);
$command = str_replace('$databasetabletype', Yii::app()->db->getDriverName(), $command);

if (!Yii::app()->db->createCommand($command)->query()) { //Checked
try
{ Yii::app()->db->createCommand($command)->query(); //Checked
$command=htmlspecialchars($command);
$modifyoutput .="<br />".sprintf($clang->gT("SQL command failed: %s"),"<span style='font-size:10px;'>".$command."</span>","<span style='color:#ee0000;font-size:10px;'></span><br/>");
$success = false;
$modifyoutput .=". ";
}
else
{
catch(CDbException $e)
{
$command=htmlspecialchars($command);
$modifyoutput .=". ";
$modifyoutput .="<br />".sprintf($clang->gT("SQL command failed: %s"),"<span style='font-size:10px;'>".$command."</span>","<span style='color:#ee0000;font-size:10px;'></span><br/>");
$success = false;
}

$command = '';
Expand Down
14 changes: 7 additions & 7 deletions application/helpers/update/update_helper.php
Expand Up @@ -24,8 +24,8 @@ function CheckForDBUpgrades($subaction = null)
$dbversionnumber = Yii::app()->getConfig('dbversionnumber');
$currentDBVersion=GetGlobalSetting('DBVersion');
$dbprefix = Yii::app()->db->tablePrefix;
//$usertemplaterootdir = Yii::app()->getConfig('usertemplaterootdir');
//$standardtemplaterootdir = Yii::app()->getConfig('standardtemplaterootdir');
$usertemplaterootdir = Yii::app()->getConfig('usertemplaterootdir');
$standardtemplaterootdir = Yii::app()->getConfig('standardtemplaterootdir');
if (intval($dbversionnumber)>intval($currentDBVersion))
{
if(isset($subaction) && $subaction=="continue")
Expand All @@ -40,9 +40,9 @@ function CheckForDBUpgrades($subaction = null)
//$tables = $connect->getSchema()->getTableNames();
db_upgrade_all(intval($currentDBVersion));
db_upgrade(intval($currentDBVersion));
Yii::app()->db->createCommand()->update($dbprefix.'settings_global', array('stg_value' => intval($dbversionnumber)), array('stg_name' => 'DBVersion'));
Yii::app()->db->createCommand()->update($dbprefix.'settings_global', array('stg_value' => intval($dbversionnumber)), 'stg_name = \'DBVersion\'');
echo "<br />".sprintf($clang->gT("Database has been successfully upgraded to version %s"),$dbversionnumber);
echo "<br /><a href='".site_url("admin")."'>".$clang->gT("Back to main menu")."</a></div>";
echo "<br /><a href='".Yii::app()->createUrl("admin")."'>".$clang->gT("Back to main menu")."</a></div>";
}
else {
ShowDBUpgradeNotice();
Expand All @@ -59,12 +59,12 @@ function ShowDBUpgradeNotice() {
echo $clang->gT('Please verify the following information before continuing with the database upgrade:').'<ul>';
echo "<li><b>" .$clang->gT('Database type') . ":</b> " . Yii::app()->db->getDriverName() . "</li>";
echo "<li><b>" .$clang->gT('Database name') . ":</b> " . getDBConnectionStringProperty('dbname') . "</li>";
echo "<li><b>" .$clang->gT('Table prefix') . ":</b> " . Yii::app()->tablePrefix . "</li>";
echo "<li><b>" .$clang->gT('Table prefix') . ":</b> " . Yii::app()->db->tablePrefix . "</li>";
echo "<li><b>" .$clang->gT('Site name') . ":</b> " . Yii::app()->getConfig("sitename") . "</li>";
echo "<li><b>" .$clang->gT('Root URL') . ":</b> " . site_url() . "</li>";
echo "<li><b>" .$clang->gT('Root URL') . ":</b> " . Yii::app()->createUrl('') . "</li>";
echo '</ul>';
echo "<br />";
echo "<a href='".site_url("admin/update/db/continue")."'>" . $clang->gT('Click here to continue') . "</a>";
echo "<a href='".Yii::app()->createUrl("admin/update/db/continue")."'>" . $clang->gT('Click here to continue') . "</a>";
echo "<br />";
echo '</div>';
}
Expand Down
19 changes: 11 additions & 8 deletions application/helpers/update/upgrade-all_helper.php
Expand Up @@ -21,6 +21,8 @@ function db_upgrade_all($oldversion) {
/// This function does anything necessary to upgrade
/// older versions to match current functionality
global $modifyoutput, $dbprefix, $usertemplaterootdir, $standardtemplaterootdir;
$usertemplaterootdir = Yii::app()->getConfig('usertemplaterootdir');
$standardtemplaterootdir = Yii::app()->getConfig('standardtemplaterootdir');
$clang = Yii::app()->lang;
echo str_pad($clang->gT('The LimeSurvey database is being upgraded').' ('.date('Y-m-d H:i:s').')',14096).".<br /><br />". $clang->gT('Please be patient...')."<br /><br />\n";

Expand Down Expand Up @@ -69,14 +71,14 @@ function db_upgrade_all($oldversion) {
$fields = array(
'relevance' => 'TEXT'
);
Yii::app()->db->schema->addColumn('{{questions}}',$fields);
Yii::app()->db->schema->addColumn('{{questions}}','relevance','TEXT');
}
if ($oldversion < 151)
{
$fields = array(
'randomization_group' => 'VARCHAR(20) NOT NULL default \'\''
);
Yii::app()->db->schema->addColumn('{{groups}}',$fields);
Yii::app()->db->schema->addColumn('{{groups}}','randomization_group','VARCHAR(20) NOT NULL default \'\'');
}
if ($oldversion < 152)
{
Expand Down Expand Up @@ -107,15 +109,15 @@ function upgrade_question_attributes148()
$sDBPrefix=Yii::app()->db->tablePrefix;
$sSurveyQuery = "SELECT sid FROM {$sDBPrefix}surveys";
$oSurveyResult = db_execute_assoc($sSurveyQuery);
foreach ( $oSurveyResult->result_array() as $aSurveyRow)
foreach ( $oSurveyResult->readAll() as $aSurveyRow)
{
$surveyid=$aSurveyRow['sid'];
$languages=array_merge(array(GetBaseLanguageFromSurveyID($surveyid)), GetAdditionalLanguagesFromSurveyID($surveyid));

$sAttributeQuery = "select q.qid,attribute,value from {$sDBPrefix}question_attributes qa , {$sDBPrefix}questions q where q.qid=qa.qid and sid={$surveyid}";
$oAttributeResult = db_execute_assoc($sAttributeQuery);
$aAllAttributes=questionAttributes(true);
foreach ( $oAttributeResult->result_array() as $aAttributeRow)
foreach ( $oAttributeResult->readAll() as $aAttributeRow)
{
if (isset($aAllAttributes[$aAttributeRow['attribute']]['i18n']) && $aAllAttributes[$aAttributeRow['attribute']]['i18n'])
{
Expand All @@ -133,16 +135,17 @@ function upgrade_question_attributes148()
function upgrade_survey_table145()
{
global $modifyoutput, $connect;
$sSurveyQuery = "SELECT * FROM ".db_table_name('surveys')." where notification<>'0'";
$sDBPrefix = Yii::app()->db->tablePrefix;
$sSurveyQuery = "SELECT * FROM ".$sDBPrefix.'surveys'." where notification<>'0'";
$oSurveyResult = db_execute_assoc($sSurveyQuery);
foreach ( $oSurveyResult->result_array() as $aSurveyRow )
foreach ( $oSurveyResult->readAll() as $aSurveyRow )
{
if ($aSurveyRow['notification']=='1' && trim($aSurveyRow['adminemail'])!='')
{
$aEmailAddresses=explode(';',$aSurveyRow['adminemail']);
$sAdminEmailAddress=$aEmailAddresses[0];
$sEmailnNotificationAddresses=implode(';',$aEmailAddresses);
$sSurveyUpdateQuery= "update ".db_table_name('surveys')." set adminemail='{$sAdminEmailAddress}', emailnotificationto='{$sEmailnNotificationAddresses}' where sid=".$aSurveyRow['sid'];
$sSurveyUpdateQuery= "update ".$sDBPrefix.'surveys'." set adminemail='{$sAdminEmailAddress}', emailnotificationto='{$sEmailnNotificationAddresses}' where sid=".$aSurveyRow['sid'];
$connect->execute($sSurveyUpdateQuery);
}
else
Expand All @@ -158,7 +161,7 @@ function upgrade_survey_table145()
$connect->execute($sSurveyUpdateQuery);
}
}
$sSurveyQuery = "SELECT * FROM ".db_table_name('surveys_languagesettings');
$sSurveyQuery = "SELECT * FROM ".$sDBPrefix.'surveys_languagesettings';
$oSurveyResult = Yii::app()->db->createCommand($sSurveyQuery)->queryAll();
foreach ( $oSurveyResult as $aSurveyRow )
{
Expand Down
2 changes: 1 addition & 1 deletion application/helpers/update/upgrade-mysql_helper.php
Expand Up @@ -555,7 +555,7 @@ function db_upgrade($oldversion) {
modify_database("","ALTER TABLE `prefix_users` CHANGE `superadmin` `superadmin` tinyint(1) NOT NULL default '0' AFTER `delete_user`"); echo $modifyoutput; flush();@ob_flush();
modify_database("","ALTER TABLE `prefix_users` CHANGE `htmleditormode` `htmleditormode` varchar(7) collate utf8_unicode_ci default 'default'"); echo $modifyoutput; flush();@ob_flush();
modify_database("","ALTER TABLE `prefix_users` CHANGE `dateformat` `dateformat` int(10) unsigned NOT NULL default '1'"); echo $modifyoutput; flush();@ob_flush();
modify_database("","ALTER TABLE `prefix_users` DROP INDEX `email`;");
//modify_database("","ALTER TABLE `prefix_users` DROP INDEX `email`;");

modify_database("","UPDATE `prefix_user_groups` SET `name`='' where `name` is null;"); echo $modifyoutput; flush();@ob_flush();
modify_database("","ALTER TABLE `prefix_user_groups` CHANGE `name` `name` varchar(20) collate utf8_unicode_ci NOT NULL"); echo $modifyoutput; flush();@ob_flush();
Expand Down

0 comments on commit 8ea167c

Please sign in to comment.