При неудаче в запросе к БД валидные данные сохраняются в yaml-файл (script.php)
This commit is contained in:
@ -70,6 +70,17 @@ final class ContingentManager
|
||||
return $specializations;
|
||||
}
|
||||
|
||||
public function getOrgs(Database $db) : array
|
||||
{
|
||||
$sql = 'SELECT DISTINCT org_id FROM sveden_education_contingent';
|
||||
$org = $db->selectQuery($sql);
|
||||
$orgs = [];
|
||||
foreach ($org as $o) {
|
||||
$orgs[] = $o['org_id'];
|
||||
}
|
||||
return $orgs;
|
||||
}
|
||||
|
||||
public function buildURL(string $url): string
|
||||
{
|
||||
// Строит -> https://<base_uri>/sveden/education/
|
||||
|
@ -52,16 +52,15 @@ class ContingentParser
|
||||
{
|
||||
$data = $this->parse();
|
||||
$records = array();
|
||||
|
||||
if ($data == null) return [];
|
||||
|
||||
// var_dump($data['eduName']->item(0));
|
||||
// exit(0);
|
||||
|
||||
$equel = $data['eduName']->length;
|
||||
$equal = $data['eduName']->length;
|
||||
foreach ($data as $field) {
|
||||
if ($field->length == 0) {
|
||||
return [];
|
||||
}
|
||||
if ($field->length != $equel) {
|
||||
if ($field->length != $equal) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ use App\Library\DatabaseConfig;
|
||||
use App\Library\Logger;
|
||||
use PDOException;
|
||||
use PDO;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
class Database
|
||||
{
|
||||
private PDO $pdo;
|
||||
@ -66,7 +67,10 @@ class Database
|
||||
}
|
||||
$stmt->execute();
|
||||
Logger::log(self::$logFile, "Запрос выполнен успешно!");
|
||||
} catch (PDOException $e) {
|
||||
} catch (PDOException $e) {
|
||||
// При ошибке запроса сохраняем валидные данные в yaml-файл
|
||||
$yaml = Yaml::dump($params);
|
||||
file_put_contents(__DIR__ . '/not-recorded-in-db.yaml', $yaml);
|
||||
$message = "Ошибка запроса:" . $e->getMessage();
|
||||
Logger::log(self::$logFile, $message);
|
||||
}
|
||||
|
Reference in New Issue
Block a user