test data before use

This commit is contained in:
Aliberk Sandıkçı 2024-01-08 19:05:46 +03:00
parent 041b6a2634
commit 412bcc1035
Signed by: asandikci
GPG key ID: 25C67A03B5666BC1
2 changed files with 36 additions and 3 deletions

View file

@ -106,12 +106,28 @@
<script> <script>
function updateData() { function updateData() {
xmlHttp = new XMLHttpRequest(); xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var response = xmlHttp.responseText
if (response.includes("parseError") ){
console.error("VERİLER YANLIŞ ŞEKİLDE GİRİLMİŞ, GÖTÜNÜ SİKEYİM KELO");
console.warn(response);
} else if (response.includes("fileError")){
console.error("VERİ DOSYASI SUNUCUDA BULUNAMADI, SUNUCUYU KONTROL EDİNİZ");
console.warn(response);
} else if (response.includes("success")) {
console.info("VERİLER BAŞARIYLA GÜNCELLENDİ")
} else {
console.warn("VERİ GÜNCELLENİRKEN BİR HATA OLUŞTU, SAYFAYI YENİLEMEYİ DENEYİN");
}
}
};
params = "updateData=yes"; params = "updateData=yes";
xmlHttp.open("POST", "src/server.php", true); xmlHttp.open("POST", "src/server.php", true);
xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); xmlHttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xmlHttp.send(params); xmlHttp.send(params);
flag = true; flag = true;
return "UPDATED DATA FROM SERVER!" return;
} }
</script> </script>
<script> <script>

View file

@ -10,13 +10,29 @@ $parser = new Toml();
$dock_local_test = 1; $dock_local_test = 1;
# Fetch Remote data and update data.toml (running each 10 min with cronjob) # Fetch Remote data and update data.toml (running each 10 min with cronjob)
function testData($toml)
{
global $parser;
try {
$array = $parser::Parse($toml);
} catch (Exception $e) {
$ans = 'Caught exception: ' . $e->getMessage() . "\n";
return $ans;
}
return 0;
}
function updateRemoteData() function updateRemoteData()
{ {
global $DATAACCESS_TOKEN; global $DATAACCESS_TOKEN;
global $APP_NAME; global $APP_NAME;
$string = file_get_contents("https://git.aliberksandikci.com.tr/api/v1/repos/ifl/YurdleBackend/raw/data.toml?access_token=" . $DATAACCESS_TOKEN); $string = file_get_contents("https://git.aliberksandikci.com.tr/api/v1/repos/ifl/YurdleBackend/raw/data.toml?access_token=" . $DATAACCESS_TOKEN);
if ($string === FALSE) { if ($string === FALSE) {
echo "Could not read the file."; echo "fileError: Could not read the file or could not get the file from server";
return;
} else if (testData($string) != 0) {
echo "parseError: " . testData($string);
return;
} else { } else {
$file = __DIR__ . "/../data.toml"; $file = __DIR__ . "/../data.toml";
file_put_contents($file, $string, LOCK_EX); file_put_contents($file, $string, LOCK_EX);
@ -25,6 +41,7 @@ function updateRemoteData()
chown("$file", $APP_NAME); chown("$file", $APP_NAME);
parseTOML(); // not necessary parseTOML(); // not necessary
echo "success";
} }