Обновлены настройки Client, дозапись в базу
This commit is contained in:
@ -81,21 +81,12 @@ final class ContingentManager
|
||||
return $orgs;
|
||||
}
|
||||
|
||||
public function buildURL(string $url): string
|
||||
public function buildBaseUri(string $url): string
|
||||
{
|
||||
// Строит -> https://<base_uri>/sveden/education/
|
||||
$offset = strpos($url, '/', strlen('http://'));
|
||||
if ($offset) {
|
||||
$url = substr_replace($url, '', $offset);
|
||||
// Строит -> https://<base_uri>
|
||||
if (strpos($url,'https://') === false && strpos($url,'http://') === false) {
|
||||
$url = "http://$url";
|
||||
}
|
||||
|
||||
$url = "$url/sveden/education/";
|
||||
if (str_contains($url, "http://")) {
|
||||
$url = str_replace("http://","https://", $url);
|
||||
} else {
|
||||
$url = "https://$url";
|
||||
}
|
||||
$url = str_replace("www.","", $url);
|
||||
|
||||
return $url;
|
||||
}
|
||||
@ -130,4 +121,32 @@ final class ContingentManager
|
||||
}
|
||||
return $count ? true : false;
|
||||
}
|
||||
|
||||
public function getExceptionsHtml(string $filename) : array
|
||||
{
|
||||
$errorSites = [];
|
||||
$array = file($filename);
|
||||
for ($i = 0; $i < count($array); $i++) {
|
||||
$arr = explode(' ', $array[$i]);
|
||||
$errorSites[] = $arr[2];
|
||||
}
|
||||
return $errorSites;
|
||||
}
|
||||
|
||||
public function getExceptionsHttpCurl(string $filename) : array
|
||||
{
|
||||
$array = file($filename);
|
||||
$orgHttpError = [];
|
||||
foreach ($array as $str) {
|
||||
$data = explode (' ', $str);
|
||||
if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/", $data[0])
|
||||
&& $data[3] != PHP_EOL) {
|
||||
$orgHttpError[] = $data[2];
|
||||
// $orgHttpError[] = ['org_id' => $data[2], 'site' => $data[3]];
|
||||
}
|
||||
}
|
||||
$orgHttpError = array_unique($orgHttpError);
|
||||
sort($orgHttpError);
|
||||
return $orgHttpError;
|
||||
}
|
||||
}
|
@ -27,15 +27,18 @@ class ContingentParser
|
||||
{
|
||||
libxml_use_internal_errors(true);
|
||||
$dom = new \DOMDocument(
|
||||
encoding: "UTF-8"
|
||||
// encoding: "UTF-8"
|
||||
);
|
||||
$html = mb_convert_encoding(
|
||||
$html,
|
||||
'UTF-8',
|
||||
mb_detect_encoding($html, 'UTF-8, windows-1251')
|
||||
);
|
||||
$html = str_replace('windows-1251','utf-8', $html);
|
||||
$dom->loadHTML($html);
|
||||
if (mb_detect_encoding($html, 'UTF-8, windows-1251') != "UTF-8") {
|
||||
$html = mb_convert_encoding(
|
||||
$html,
|
||||
'UTF-8',
|
||||
mb_detect_encoding($html, 'UTF-8, windows-1251')
|
||||
);
|
||||
$html = str_replace('windows-1251','utf-8', $html);
|
||||
} else {
|
||||
$dom->loadHTML(mb_convert_encoding($html,'HTML-ENTITIES','UTF-8'));
|
||||
}
|
||||
$this->xpath = new \DOMXPath($dom);
|
||||
$this->template = $template;
|
||||
}
|
||||
|
@ -68,18 +68,13 @@ class Database
|
||||
$stmt->execute();
|
||||
Logger::log(self::$logFile, "Запрос выполнен успешно!");
|
||||
} catch (PDOException $e) {
|
||||
// При ошибке запроса сохраняем валидные данные в yaml-файл
|
||||
$yaml = Yaml::dump([$params]);
|
||||
file_put_contents(__DIR__ . '/not-recorded-in-db.yaml', $yaml, FILE_APPEND);
|
||||
$message = "Ошибка запроса:" . $e->getMessage();
|
||||
Logger::log(self::$logFile, $message);
|
||||
// TODO узнать код ошибки
|
||||
// SQLSTATE[HY000]: General error: 2006 MySQL server has gone away
|
||||
// if ($e->getCode() == 0) {
|
||||
// $yaml = Yaml::dump($params);
|
||||
// file_put_contents(__DIR__ . '/not-recorded-in-db.yaml', $yaml);
|
||||
// exit(1);
|
||||
// }
|
||||
// При ошибке запроса сохраняем валидные данные в yaml-файл
|
||||
if ($e->getCode() === "HY000") {
|
||||
$yaml = Yaml::dump($params);
|
||||
file_put_contents(__DIR__ . '/not-recorded-in-db.yaml', $yaml, FILE_APPEND);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user