-
Notifications
You must be signed in to change notification settings - Fork 988
/
update_helper.php
77 lines (73 loc) · 3.34 KB
/
update_helper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
* LimeSurvey
* Copyright (C) 2007-2011 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* 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.
*
*/
/**
* This functions checks if the databaseversion in the settings table is the same one as required
* If not then the necessary upgrade procedures are run
*/
function CheckForDBUpgrades($subaction = null)
{
$dbversionnumber = Yii::app()->getConfig('dbversionnumber');
$currentDBVersion=GetGlobalSetting('DBVersion');
$usertemplaterootdir = Yii::app()->getConfig('usertemplaterootdir');
$standardtemplaterootdir = Yii::app()->getConfig('standardtemplaterootdir');
if (intval($dbversionnumber)>intval($currentDBVersion))
{
if(isset($subaction) && $subaction=="yes")
{
echo Yii::app()->getController()->_getAdminHeader();
echo "<div style='width:90%; padding:1% 5%;background-color:#eee;'>";
Yii::app()->loadHelper('update/updatedb');
$result=db_upgrade_all(intval($currentDBVersion));
if ($result)
{
$data = "<br />".sprintf(gT("Database has been successfully upgraded to version %s"),$dbversionnumber);
$data .= "<br /><a href='".Yii::app()->getController()->createUrl("/admin")."'>".gT("Back to main menu")."</a></div>";
}
else
{
$data = "<p><a href='".Yii::app()->getController()->createUrl("/admin/databaseupdate/sa/db")."'>".gT("Please fix this error in your database and try again")."</a></p></div>";
}
return $data;
}
else {
return ShowDBUpgradeNotice();
}
}
}
function ShowDBUpgradeNotice() {
//$error=false;
//$sitename = Yii::app()->getConfig('sitename');
return '<div class="messagebox">'
."<div class='header'>".gT('Database upgrade').'</div><p>'
.gT('Please verify the following information before continuing with the database upgrade:').'</p><ul>'
."<li><b>" .gT('Database type') . ":</b> " . Yii::app()->db->getDriverName() . "</li>"
."<li><b>" .gT('Database name') . ":</b> " . getDBConnectionStringProperty('dbname') . "</li>"
."<li><b>" .gT('Table prefix') . ":</b> " . Yii::app()->db->tablePrefix . "</li>"
."<li><b>" .gT('Site name') . ":</b> " . Yii::app()->getConfig("sitename") . "</li>"
."<li><b>" .gT('Root URL') . ":</b> " . Yii::app()->getController()->createUrl('') . "</li>"
.'</ul><br/>'
."<p>"
."<a href='".Yii::app()->getController()->createUrl("admin/databaseupdate/sa/db/continue/yes")."'>" . gT('Click here to continue') . "</a>"
."</p>"
.'</div>';
}
function getDBConnectionStringProperty($sProperty)
{
// Yii doesn't give us a good way to get the database name
preg_match('/'.$sProperty.'=([^;]*)/', Yii::app()->db->getSchema()->getDbConnection()->connectionString, $aMatches);
if ( count($aMatches) === 0 ) {
return null;
}
return $aMatches[1];
}