Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Sarun Mungthanya
SpnPatch-Laravel
Commits
91c3b2e5
Commit
91c3b2e5
authored
Dec 06, 2024
by
Sarun Mungthanya
Browse files
issue update patch exchangerate
parent
fb353ee1
Changes
2
Hide whitespace changes
Inline
Side-by-side
app/Http/Controllers/SmartUpdateController.php
View file @
91c3b2e5
...
...
@@ -130,7 +130,7 @@ class SmartUpdateController extends Controller
'uId'
=>
$request
->
input
(
'MUID'
),
'uCode'
=>
$request
->
input
(
'MUCODE'
),
])
->
render
();
echo
iconv
(
"UTF-8"
,
"TIS-620"
,
$htmlContent
);
}
public
function
queryToSimpleTable
(
$query
,
$numberSortOpt
=
"YES"
,
$columnSortOpt
=
"YES"
,
$colorPack
=
[
'#DDDDDD'
,
'#F2F2F2'
,
'#FFFFFF'
,
'#F2F2FF'
],
$noCodeIfEmpty
=
"NO"
)
...
...
@@ -220,7 +220,6 @@ class SmartUpdateController extends Controller
'message'
=>
'Version Incompatible.'
,
]);
}
if
(
!
empty
(
$patchDetails
->
PATCHCODE_SERVER
))
{
$ptid
=
static
::
extractPtid
(
$patchDetails
->
PATCHCODE_SERVER
);
$pacthFiles
=
TabPatchFile
::
where
(
"ptid"
,
$ptid
)
->
get
();
...
...
@@ -231,9 +230,11 @@ class SmartUpdateController extends Controller
$max
=
count
(
$pacthFiles
);
$checkDeployemnt
=
strpos
(
$patchDetails
->
PATCHCODE_SERVER
,
'file_exists("deployment/".$VERSION'
);
$folder
=
static
::
extractVersion
(
$patchDetails
->
PATCHCODE_SERVER
);
$checkExchangeRate
=
strpos
(
$patchDetails
->
PATCHCODE_SERVER
,
'center_conf_exchangerate'
);
if
(
$checkDeployemnt
!==
false
)
{
$folder
=
static
::
extractVersion
(
$patchDetails
->
PATCHCODE_SERVER
);
$DOUPGRADE
=
"N"
;
if
(
!
empty
(
$folder
))
{
if
(
Storage
::
exists
(
"deployment/"
.
$folder
))
{
...
...
@@ -257,17 +258,42 @@ class SmartUpdateController extends Controller
$file_name_0
=
''
;
$file_data_0
=
''
;
}
$patchCodeServer
=
str_replace
(
'Query2Var'
,
'static::Query2Var'
,
$patchDetails
->
PATCHCODE_SERVER
);
$patchCodeServer
=
str_replace
(
'Query2SQL'
,
'static::Query2SQL'
,
$patchCodeServer
);
if
(
$checkExchangeRate
!==
false
)
{
$codeEval
=
strpos
(
$patchDetails
->
PATCHCODE_SERVER
,
'//import'
);
if
(
$codeEval
!==
false
)
{
$result
=
substr
(
$patchDetails
->
PATCHCODE_SERVER
,
0
,
$codeEval
);
}
eval
(
$result
);
$sourceTable
=
'center_conf_exchangerate'
;
$destinationTable
=
'conf_exchangerate'
;
$conditionColumn
=
'exdate'
;
$conditionValue
=
$MONTH
;
$additionalColumns
=
[
'amenddate'
=>
$UPDATECODE
,
'usrname'
=>
''
];
$resultImport
=
static
::
generateInsertSQLWithCount
(
$sourceTable
,
$destinationTable
,
$conditionColumn
,
$conditionValue
,
$additionalColumns
);
$serverchk
=
$resultImport
[
"total"
];
$SQL1
=
$resultImport
[
"sql"
];
$sourceTable
=
'center_conf_exchangerate_export'
;
$destinationTable
=
'conf_exchangerate_export'
;
$resultExport
=
static
::
generateInsertSQLWithCount
(
$sourceTable
,
$destinationTable
,
$conditionColumn
,
$conditionValue
,
$additionalColumns
);
$serverchk
=
$resultImport
[
"total"
];
$SQL2
=
$resultImport
[
"sql"
];
}
$patchCode
=
$patchDetails
->
PATCHCODE
;
$patchCode
=
str_replace
(
'updatePatchFile("$$file_name_0", "$$file_data_0");'
,
''
,
$patchCode
);
$patchCode
=
str_replace
(
'$'
,
'#'
,
$patchCode
);
$patchCode
=
str_replace
(
'##'
,
'$'
,
$patchCode
);
eval
(
'$patchCode=<<<EOF2'
.
chr
(
13
)
.
$patchCode
.
chr
(
13
)
.
'EOF2;'
.
chr
(
13
));
$patchCode
=
str_replace
(
'#'
,
'$'
,
$patchCode
);
if
(
isset
(
$mode
)
&&
$mode
===
'AUTO'
)
{
$pid
=
DB
::
table
(
'conf_server_pendding as t0'
)
->
join
(
'conf_smartupdate as t1'
,
't0.PatchID'
,
'='
,
't1.PID'
)
...
...
@@ -546,4 +572,63 @@ class SmartUpdateController extends Controller
}
return
null
;
}
public
static
function
generateInsertSQLWithCount
(
$sourceTable
,
$destinationTable
,
$conditionColumn
,
$conditionValue
,
$additionalColumns
)
{
// Fetch data from the source table based on the condition
$rows
=
DB
::
table
(
$sourceTable
)
->
where
(
$conditionColumn
,
'like'
,
$conditionValue
)
->
get
();
// Check if rows exist
if
(
$rows
->
isEmpty
())
{
return
[
'total'
=>
0
,
'sql'
=>
''
];
}
// Detect the database type
$dbType
=
config
(
'database.default'
);
$quoteL
=
$dbType
===
'sqlsrv'
?
'['
:
'`'
;
$quoteR
=
$dbType
===
'sqlsrv'
?
']'
:
'`'
;
$insertStatements
=
[];
foreach
(
$rows
as
$row
)
{
$values
=
[];
// Include all columns from the row dynamically
foreach
((
array
)
$row
as
$column
=>
$value
)
{
// Escape single quotes for MSSQL and MySQL
$escapedValue
=
str_replace
(
"'"
,
"''"
,
$value
);
// Handle special MSSQL cases, e.g., default datetime
if
(
$escapedValue
===
'0000-00-00 00:00:00'
)
{
$escapedValue
=
'2000-01-01 00:00:00'
;
}
$values
[]
=
"'
$escapedValue
'"
;
}
// Append additional columns (e.g., `amenddate`) dynamically
foreach
(
$additionalColumns
as
$key
=>
$value
)
{
$escapedValue
=
str_replace
(
"'"
,
"''"
,
$value
);
$values
[]
=
"'
$escapedValue
'"
;
}
// Create the INSERT statement
$columns
=
array_keys
((
array
)
$row
);
$columns
=
array_merge
(
$columns
,
array_keys
(
$additionalColumns
));
$quotedColumns
=
array_map
(
fn
(
$col
)
=>
$quoteL
.
$col
.
$quoteR
,
$columns
);
$insertStatements
[]
=
"INSERT INTO
$quoteL$destinationTable$quoteR
("
.
implode
(
', '
,
$quotedColumns
)
.
") VALUES ("
.
implode
(
', '
,
$values
)
.
");"
;
}
// Combine all statements into a single string
return
[
'total'
=>
$rows
->
count
(),
'sql'
=>
implode
(
"
\n
"
,
$insertStatements
)
];
}
}
app/Http/Livewire/Pages/Exchangerate/ExchangerateUpload.php
View file @
91c3b2e5
...
...
@@ -236,7 +236,7 @@ class ExchangerateUpload extends Component
// Using Eloquent to get the data
$patchFiles
=
DB
::
table
(
'tab_patch_file'
)
->
where
(
'ptid'
,
$next_PID
)
->
get
();
$PATCHCODE_SERVER
=
"
$a
=1;
\n
"
;
$PATCHCODE_SERVER
=
'
$a=1;\n
'
;
foreach
(
$patchFiles
as
$index
=>
$file
)
{
$PATCHCODE_SERVER
.
=
"
\$
file_name_
{
$index
}
=
\"
{
$file
->
file_name
}
\"
;
\n
"
;
$PATCHCODE_SERVER
.
=
"
\$
file_data_
{
$index
}
=
\"
{
$file
->
file_data
}
\"
;
\n
"
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment