forked from webERP-team/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZ_Upgrade_3.04-3.05.php
80 lines (55 loc) · 2.69 KB
/
Z_Upgrade_3.04-3.05.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
78
79
80
<?php
//$PageSecurity = 15;
include('includes/session.php');
$Title = _('Upgrade webERP 3.04 - 3.05');
include('includes/header.php');
prnMsg(_('This script will run perform any modifications to the database required to allow the additional functionality in version 3.05 scripts'),'info');
echo '<p><form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<input type="submit" name="DoUpgrade" value="' . _('Perform Upgrade') . '" />';
echo '</form>';
if ($_POST['DoUpgrade'] == _('Perform Upgrade')){
if ($DBType=='postgres'){
$SQLScriptFile = file('./sql/pg/upgrade3.04-3.05.psql');
} elseif ($DBType ='mysql') { //its a mysql db
$SQLScriptFile = file('./sql/mysql/upgrade3.04-3.05.sql');
}
$ScriptFileEntries = sizeof($SQLScriptFile);
$ErrMsg = _('The script to upgrade the database failed because');
$SQL ='';
$InAFunction = false;
for ($i=0; $i<=$ScriptFileEntries; $i++) {
$SQLScriptFile[$i] = trim($SQLScriptFile[$i]);
if (mb_substr($SQLScriptFile[$i], 0, 2) != '--'
AND mb_substr($SQLScriptFile[$i], 0, 3) != 'USE'
AND mb_strstr($SQLScriptFile[$i],'/*')==FALSE
AND mb_strlen($SQLScriptFile[$i])>1){
$SQL .= ' ' . $SQLScriptFile[$i];
//check if this line kicks off a function definition - pg chokes otherwise
if (mb_substr($SQLScriptFile[$i],0,15) == 'CREATE FUNCTION'){
$InAFunction = true;
}
//check if this line completes a function definition - pg chokes otherwise
if (mb_substr($SQLScriptFile[$i],0,8) == 'LANGUAGE'){
$InAFunction = false;
}
if (mb_strpos($SQLScriptFile[$i],';')>0 AND ! $InAFunction){
$SQL = mb_substr($SQL,0,mb_strlen($SQL)-1);
$result = DB_query($SQL, $ErrMsg);
$SQL='';
}
} //end if its a valid sql line not a comment
} //end of for loop around the lines of the sql script
/*Now run the data conversions required. */
prnMsg(_('Upgrade script to put cost information against GRN records from purchorderdetails records .... please wait'),'info');
$TestAlreadyDoneResult = DB_query('SELECT * FROM grns WHERE stdcostunit<>0');
if (DB_num_rows($TestAlreadyDoneResult)>0){
prnMsg(_('The upgrade script appears to have been run already successfully - there is no need to re-run it'),'info');
include('includes/footer.php');
exit;
}
$UpdateGRNCosts = DB_query('UPDATE grns INNER JOIN purchorderdetails ON grns.podetailitem=purchorderdetails.podetailitem SET grns.stdcostunit = purchorderdetails.stdcostunit');
prnMsg(_('The GRN records have been updated with cost information from purchorderdetails successfully'),'success');
} /*Dont do upgrade */
include('includes/footer.php');
?>