From be165bdf4531b436c826c08d7b4b53087f79ae5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=BE=D0=BC=D0=B0=D0=BD=20=D0=93=D1=80=D0=B8=D0=BD?= =?UTF-8?q?=D1=8C=D0=BA=D0=BE?= Date: Sun, 10 Jul 2022 18:54:30 +0000 Subject: [PATCH] Revert "Update core/SQL_DUMPS/users.sql, core/bootstrap.php, core/migrations/000002_users.sql" This reverts commit f5aa2e57f8a15af4cd91d5b6c23ddcae665de6ff --- core/SQL_DUMPS/users.sql | 4 +- core/bootstrap.php | 28 ++++++++++- core/migrations/000002_users.sql | 4 +- core/partizan.php | 80 ++++++++++++++++++++++++++++++++ test.php | 30 ++++++++++++ 5 files changed, 141 insertions(+), 5 deletions(-) create mode 100644 core/partizan.php create mode 100644 test.php diff --git a/core/SQL_DUMPS/users.sql b/core/SQL_DUMPS/users.sql index 388b212..6cb516e 100644 --- a/core/SQL_DUMPS/users.sql +++ b/core/SQL_DUMPS/users.sql @@ -14,7 +14,7 @@ CREATE TABLE `users` DEFAULT CHARSET = utf8; INSERT INTO `users` (`id`, `login`, `password`, `name`, `email`, `image_id`, `token`, `last_active`, `date_created`, `date_updated`) -VALUES (1, 'admin', 'c7e82c3d2bed998ea1f4c1aca09c282b', 'Роман Гринько', 'rsgrinko@yandex.ru', 18, 'RG1819-1000-77EB-8F7A-9B112FB69D3A0', +VALUES (1, 'admin', '5321ef98bd96cccf03f50979fdd8c893', 'Роман Гринько', 'rsgrinko@yandex.ru', 18, 'RG1819-1000-77EB-8F7A-9B112FB69D3A0', '1657051585', '2022-06-17 16:18:56', NULL), (2, 'a.kirilcev', 'c7e82c3d2bed998ea1f4c1aca09c282b', 'Александр Кирильцев', 'a.kirilcev@it-tula.ru', 20, 'RG17DE-1000-26FC-837F-8F9C47E643970', '1655471459', '2022-06-17 16:18:56', NULL), @@ -26,4 +26,4 @@ ALTER TABLE `users` ALTER TABLE `users` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT = 25; -COMMIT; +COMMIT; \ No newline at end of file diff --git a/core/bootstrap.php b/core/bootstrap.php index e9b6b77..4daa2ec 100644 --- a/core/bootstrap.php +++ b/core/bootstrap.php @@ -11,6 +11,32 @@ } date_default_timezone_set('Europe/Moscow'); + require_once __DIR__ . '/../vendor/autoload.php'; + \Sentry\init( + [ + 'dsn' => 'https://8657ac1a900c44e5bc51714bb4c00dbb@o1303100.ingest.sentry.io/6541634', + 'error_types' => E_ALL & ~E_NOTICE, + ] + ); + + Sentry\configureScope(function (Sentry\State\Scope $sentryScope) { + $sentryScope->setExtra('user_id', $_SESSION['id'] ?? ''); + $sentryScope->setExtra('user_login', $_SESSION['login'] ?? ''); + $sentryScope->setExtra('user_token', $_SESSION['token'] ?? ''); + }); + /* + try { + $this->functionFailsForSure(); + } catch (\Throwable $exception) { + \Sentry\captureException($exception); + } + + // OR + + \Sentry\captureLastError(); + */ + + ob_start(function ($buffer) { try { Template::set('CLEAR_CACHE_LINK_NAME', 'Сброс файлового кэша'); @@ -101,4 +127,4 @@ if (defined('USE_ROUTER') && USE_ROUTER === true) { Router::execute(); die(); - } + } \ No newline at end of file diff --git a/core/migrations/000002_users.sql b/core/migrations/000002_users.sql index 7b4fd62..6950284 100644 --- a/core/migrations/000002_users.sql +++ b/core/migrations/000002_users.sql @@ -14,7 +14,7 @@ CREATE TABLE if not exists `users` DEFAULT CHARSET = utf8; INSERT INTO `users` (`id`, `login`, `password`, `name`, `email`, `image_id`, `token`, `last_active`, `date_created`, `date_updated`) -VALUES (1, 'admin', 'c7e82c3d2bed998ea1f4c1aca09c282b', 'Роман Гринько', 'rsgrinko@yandex.ru', 18, 'RG1819-1000-77EB-8F7A-9B112FB69D3A0', +VALUES (1, 'admin', '5321ef98bd96cccf03f50979fdd8c893', 'Роман Гринько', 'rsgrinko@yandex.ru', 18, 'RG1819-1000-77EB-8F7A-9B112FB69D3A0', '1657051585', '2022-06-17 16:18:56', NULL), (2, 'a.kirilcev', 'c7e82c3d2bed998ea1f4c1aca09c282b', 'Александр Кирильцев', 'a.kirilcev@it-tula.ru', 20, 'RG17DE-1000-26FC-837F-8F9C47E643970', '1655471459', '2022-06-17 16:18:56', NULL), @@ -26,4 +26,4 @@ ALTER TABLE `users` ALTER TABLE `users` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT = 25; -COMMIT; +COMMIT; \ No newline at end of file diff --git a/core/partizan.php b/core/partizan.php new file mode 100644 index 0000000..b23ccd7 --- /dev/null +++ b/core/partizan.php @@ -0,0 +1,80 @@ +query('set names utf8'); + if (!$query) + throw new Exception($errorMessage); + else + return $conn; + } + } + + function getMigrationFiles($conn) { + $sqlFolder = 'migrations/'; + $allFiles = glob($sqlFolder . '*.sql'); + + $query = sprintf('show tables from `%s` like "%s"', DB_NAME, DB_TABLE_VERSIONS); + $data = $conn->query($query); + $firstMigration = !$data->num_rows; + + if ($firstMigration) { + return $allFiles; + } + + $versionsFiles = []; + $query = sprintf('select `name` from `%s`', DB_TABLE_VERSIONS); + $data = $conn->query($query)->fetch_all(MYSQLI_ASSOC); + foreach ($data as $row) { + array_push($versionsFiles, $sqlFolder . $row['name']); + } + return array_diff($allFiles, $versionsFiles); + } + + + function migrate($conn, $file) { + $command = sprintf('mysql -u%s -p%s -h %s -D %s < %s', DB_USER, DB_PASSWORD, DB_HOST, DB_NAME, $file); + shell_exec($command); + $baseName = basename($file); + $query = sprintf('insert into `%s` (`name`) values("%s")', DB_TABLE_VERSIONS, $baseName); + $conn->query($query); + } + + $conn = connectDB(); + $files = getMigrationFiles($conn); + if (empty($files)) { + echo 'Ваша база данных в актуальном состоянии.'; + } else { + echo 'Начинаем миграцию...' . PHP_EOL; + + // Накатываем миграцию для каждого файла + foreach ($files as $file) { + migrate($conn, $file); + // Выводим название выполненного файла + echo basename($file) . PHP_EOL; + } + + echo PHP_EOL . 'Миграция завершена.'; + } + + + + break; + default: + echo 'Неизвестная команда' . PHP_EOL; + break; + } \ No newline at end of file diff --git a/test.php b/test.php new file mode 100644 index 0000000..a404b25 --- /dev/null +++ b/test.php @@ -0,0 +1,30 @@ +> /dev/null 2>&1'; + passthru($handler); + $currentRunThread = (int)exec('ps -awx | grep \'test.php\' | grep -v \'grep\' | wc -l'); + echo 'Now running: ' . $currentRunThread . PHP_EOL; + } + } else { + $res = (new TelegramSender(TELEGRAM_BOT_TOKEN))->setChat(TELEGRAM_NOTIFICATION_CHANNEL)->sendMessage('Start proc #' . $argv[1]); + Log::logToFile(json_encode($res, JSON_UNESCAPED_UNICODE), 'test.log', $argv[1]); + sleep(rand(2, 10)); + $res = (new TelegramSender(TELEGRAM_BOT_TOKEN))->setChat(TELEGRAM_NOTIFICATION_CHANNEL)->sendMessage('End proc #' . $argv[1]); + Log::logToFile(json_encode($res, JSON_UNESCAPED_UNICODE), 'test.log', $argv[1]); + } +