Commit 657b13e4 authored by Chanon.u's avatar Chanon.u
Browse files

Merge branch 'sprint1' of...

Merge branch 'sprint1' of https://idemo.netbay.co.th/gitlab/sarun.netbay/spnpatch-laravel into sprint1
parents 80268886 1971e4b2
......@@ -46,7 +46,7 @@ class MasterFileController extends Controller
if ($request->createPatch) {
$sqlPackAll = $this->readTxt($filePath, $formatData, $fileFormat, $request->limit, $request->noLimit);
$this->processPatches($sqlPackAll, $fileFormat, $request->genWithSmartUpdate ,$request->noLimit);
$this->processPatches($sqlPackAll, $fileFormat, $request->genWithSmartUpdate, $request->noLimit);
$message .= 'Patch master file created successfully. ';
}
......@@ -95,7 +95,7 @@ class MasterFileController extends Controller
]);
}
function processPatches($sqlPackAll, $fileFormat, $genSpnSmartUpdateDecode ,$noLimit)
function processPatches($sqlPackAll, $fileFormat, $genSpnSmartUpdateDecode, $noLimit)
{
$uid = auth()->user()->id;
$pLevel = "Critical";
......@@ -113,7 +113,14 @@ class MasterFileController extends Controller
if ($countSql != 1 && !$noLimit) {
$partPatch = 'Part ' . $part++;
}
$tis620_encoded = iconv('UTF-8', 'TIS-620', var_export($sqlPack, true));
// $utf8_encoded = mb_convert_encoding(var_export($sqlPack, true), 'UTF-8', 'auto');
// $utf8_encoded = mb_convert_encoding(var_export($sqlPack, true), 'UTF-8', 'auto');
$tis620_encoded = iconv('UTF-8', 'Windows-874',var_export($sqlPack, true));
// $tis620_encoded = var_export($sqlPack, true);
// dd($tis620_encoded);
$ALL64 = base64_encode(gzcompress($tis620_encoded));
......@@ -126,8 +133,8 @@ class MasterFileController extends Controller
}
$patchCode .= $updatedecode;
$patchCode .= "eval('\$SQL='.".'$ALLVAR.";");'."\n";
$patchCode .= $this->generatePatchCode($countSql , $i__);
$patchCode .= "eval('\$SQL='." . '$ALLVAR.";");' . "\n";
$patchCode .= $this->generatePatchCode($countSql, $i__);
if ($noLimit && ($i__ == $countSql - 1)) {
$this->savePatch($patchCode, $nameFormat, $day, $month, $year, $partPatch, $pLevel, $pDesc, $uid, $pApproveDate);
......@@ -138,7 +145,7 @@ class MasterFileController extends Controller
}
private function generatePatchCode($countSql , $i__)
private function generatePatchCode($countSql, $i__)
{
$patchCode = '';
$patchCode .= '$insert=$SQL["insert"];' . "\n";
......@@ -168,13 +175,14 @@ class MasterFileController extends Controller
$patchCode .= 'unset($update);' . "\n";
$patchCode .= 'unset($select);' . "\n";
$patchCode .= 'unset($select2);' . "\n";
$patchCode .= '$PRINT_ .= date("h:i:s")." Process '.($i__+1).' / ' . $countSql . ' Successful Update $succ data(s) (Added = $succ2) from $CountSQL_.</br>";' . "\n";
$patchCode .= '$PRINT_ .= date("h:i:s")." Process ' . ($i__ + 1) . ' / ' . $countSql . ' Successful Update $succ data(s) (Added = $succ2) from $CountSQL_.</br>";' . "\n";
return $patchCode;
}
private function savePatch($patchCode, $nameformat, $day, $month, $year, $partPatch, $PLEVEL, $PDESC, $UID, $PAPPROVEDATE)
{
$patchCode .= '$PRINTOUT=$PRINT_;' . "\n";
$patchCode .= '$PATCH_STATUS="OK";' . "\n";
// $patchCode = str_replace("'", "''", $patchCode);
......@@ -197,25 +205,26 @@ class MasterFileController extends Controller
DB::table('conf_smartupdate')->insert($data);
}
private function readTxt($filePath, $formatData, $ac, $limit = 10000 , $noLimit = false)
private function readTxt($filePath, $formatData, $ac, $limit = 10000, $noLimit = true)
{
// header("Content-Type: text/html; charset=TIS-620");
ini_set('memory_limit', '-1');
$sqlPackAll = [];
$sqlPack = [];
$count = 0;
$fileHandle = fopen($filePath, "r");
while (!feof($fileHandle)) {
$sqlPack = [];
$text = fgets($fileHandle);
// try {
// $text = iconv('TIS-620', 'UTF-8', $text);
// } catch (\Throwable $th) {
$encoding = mb_detect_encoding($text, ['UTF-8', 'ISO-8859-1', 'ASCII' ,'TIS-620'], true);
$text = iconv($encoding, 'UTF-8', $text);
try {
$text = iconv('TIS-620', 'UTF-8', $text);
// }
} catch (\Throwable $th) {
$encoding = mb_detect_encoding($text, ['UTF-8', 'ISO-8859-1', 'ASCII'], true);
$text = iconv('Windows-874', 'UTF-8', $text);
}
$X = $Y = $Z = 0;
......@@ -233,6 +242,7 @@ class MasterFileController extends Controller
$type = (int) filter_var($type, FILTER_SANITIZE_NUMBER_INT);
$fieldValue = mb_substr($text, $Y, $type, 'UTF-8');
// $fieldValue = substr($text, $Y, $type);
$Y += $type;
if ($fieldFormat['FORMAT'] === 'date') {
......@@ -242,8 +252,8 @@ class MasterFileController extends Controller
$primaryKeyConditions[] = $primaryKey['FILD'] . " = '" . trim($fieldValue) . "'";
}
$select2[] = " WHERE ".implode(' AND ', $primaryKeyConditions);
$select[] = "SELECT * FROM " . $formatData['database'] . " ". " WHERE ".implode(' AND ', $primaryKeyConditions);
$select2[] = " WHERE " . implode(' AND ', $primaryKeyConditions);
$select[] = "SELECT * FROM " . $formatData['database'] . " " . " WHERE " . implode(' AND ', $primaryKeyConditions);
$insertFields = [];
......@@ -259,7 +269,7 @@ class MasterFileController extends Controller
$type = (int) filter_var($type, FILTER_SANITIZE_NUMBER_INT);
$fieldValue = mb_substr($text, $X, $type, 'UTF-8');
// $fieldValue = substr($text, $Y, $type);
$X += $type;
if ($fieldFormat['FORMAT'] === 'date') {
$fieldValue = $this->convertDate($fieldValue);
......@@ -270,7 +280,7 @@ class MasterFileController extends Controller
$insertValues[] = "'" . str_replace("'", "''", trim($fieldValue)) . "'";
}
$insert[] = "INSERT INTO " . $formatData['database'] . " (". implode(',', $insertFields) . ") VALUES (" . implode(',', $insertValues) . ")";
$insert[] = "INSERT INTO " . $formatData['database'] . " (" . implode(',', $insertFields) . ") VALUES (" . implode(',', $insertValues) . ")";
$update[] = $this->generateUpdateQuery($formatData['format'], $text, $Z, $formatData['primary_key']);
......@@ -280,18 +290,18 @@ class MasterFileController extends Controller
'select' => $select,
'select2' => $select2,
'DATABASE' => $formatData['database'],
'counter' => $count+=1
'counter' => $count += 1
];
if ($count > $limit) {
$sqlPackAll[]=$sqlPack;
if ($count >= $limit && !$noLimit) {
$sqlPackAll[] = $sqlPack;
$count = 0;
unset($sqlPack);
}
}
fclose($fileHandle);
$sqlPackAll[] = $sqlPack;
return $sqlPackAll;
}
private function generateUpdateQuery($formatData, $text, &$Z, $primaryKeys)
......@@ -306,7 +316,7 @@ class MasterFileController extends Controller
$type = (int) $type + 1;
}
$type = (int) filter_var($type, FILTER_SANITIZE_NUMBER_INT);
$fieldValue = mb_substr($text, $Z, $type, 'UTF-8');
$fieldValue = mb_substr($text, $Z, $type);
$Z += $type;
if ($fieldFormat['FORMAT'] === 'date') {
......@@ -324,4 +334,5 @@ class MasterFileController extends Controller
return $update;
}
}
......@@ -122,14 +122,16 @@ class SmartUpdateController extends Controller
->where('TaskDate', '<', now())
->update(['TaskStatus' => 1]);
echo view('smartupdate.patch_update', [
$htmlContent = view('smartupdate.patch_update', [
'serverKeyClient' => $serverKeyClient,
'pendingUpdates' => $pendingUpdates,
'clientVersion' => $clientVersion,
'cannotUpdateAll' => $cannotUpdateAll,
'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")
{
......@@ -306,7 +308,7 @@ class SmartUpdateController extends Controller
echo base64_encode($patchCode);
} else {
echo base64_encode('$PATCH_STATUS="DONE";');
echo base64_encode('$PATCH_STATUS="EMPTY PATCHCODE SERVER";');
}
}
......
<head>
<title>Patch Updates</title>
<link rel="stylesheet" type="text/css" href="css/ui-darkness/jquery-ui-1.8.12.custom.css">
<script src="core/resource/sortTable.js"></script>
......@@ -132,7 +133,7 @@
@foreach ($pendingUpdates as $update)
<tr>
<td>{{ $update->PatchDate }}</td>
<td>{{ $update->Title }}</td>
<td>{{ $update->Title }} </td>
<td>{{ $update->Level }}</td>
<td>{{ $update->Description }}</td>
<td style="text-align: center;">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment