From e63be43639cce51c8e71b00b95e3bd659fb73625 Mon Sep 17 00:00:00 2001 From: igor Date: Sat, 11 Oct 2025 16:49:46 +0200 Subject: [PATCH] pridany Maintenance pre modul TPsoft\DBmodel, pridane poznamky, pridana konfiguracia pre DEV a PROD, --- backend/src/Init.php | 21 ++-------- backend/src/Maintenance.php | 81 +++++++++++++++++++++++++++++++++++++ doc/notes.txt | 21 ++++++++++ frontend/.env.development | 1 + frontend/.env.production | 1 + 5 files changed, 108 insertions(+), 17 deletions(-) create mode 100644 backend/src/Maintenance.php create mode 100644 doc/notes.txt create mode 100644 frontend/.env.development create mode 100644 frontend/.env.production diff --git a/backend/src/Init.php b/backend/src/Init.php index bc4c5a9..c13bc55 100644 --- a/backend/src/Init.php +++ b/backend/src/Init.php @@ -4,6 +4,7 @@ require __DIR__ . '/../vendor/autoload.php'; use \Exception; use \TPsoft\DBmodel\DBmodel; +use \TPsoft\BugreportBackend\Maintenance; global $dbh; @@ -14,20 +15,6 @@ if (Configuration::DB_TYPE == 'mysql') { } else { throw new Exception('Unknown database type'); } -/* -$dbh->tables = [ - 'reports' => [ - 'name' => 'reports', - 'primary_key_name' => 'report_id', - 'allow_attributes' => [ - 'report_id' => 'varchar()', - 'report_title' => 'varchar()', - 'report_description' => 'varchar()', - 'report_status' => 'varchar()', - 'report_group' => 'varchar()', - 'report_priority' => 'varchar()', - 'created_dt' => 'varchar()', - ], - ], -]; -*/ \ No newline at end of file + +$maintenance = new Maintenance($dbh); +$maintenance->database(); diff --git a/backend/src/Maintenance.php b/backend/src/Maintenance.php new file mode 100644 index 0000000..ed2dca1 --- /dev/null +++ b/backend/src/Maintenance.php @@ -0,0 +1,81 @@ +existsTable('options')) { + $this->checkDBTable('options', ' + `key` VARCHAR(255) NOT NULL PRIMARY KEY, + `value` VARCHAR(255) NOT NULL + '); + $this->dbver(1); + } + $dbver = $this->dbver(); + if ($dbver == 1) { + $this->checkDBTable('reports', ' + `report_id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + `report_title` varchar(255) DEFAULT NULL, + `report_description` text DEFAULT NULL, + `report_status` int(11) DEFAULT NULL, + `report_group` varchar(255) NOT NULL, + `report_priority` int(11) DEFAULT NULL, + `ordnum` int(11) DEFAULT NULL, + `created_dt` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP + '); + $this->dbver(2); + $dbver = 2; + } + if ($dbver == 2) { + $this->checkDBTable('attachments', ' + `attachment_id` INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, + `report_id` int(11) NOT NULL, + `attachment_type` varchar(255) DEFAULT NULL, + `attachment_content` text DEFAULT NULL, + `created_dt` datetime DEFAULT NULL, + `updated_dt` datetime DEFAULT NULL + '); + $this->dbver(3); + $dbver = 3; + } + } + + protected function settings(string $key, ?string $value = null): string|false + { + if (is_null($value)) { + return $this->dbh->getOne(sprintf('SELECT `value` FROM `options` WHERE `key` = %s', $this->dbh->quote($key))); + } else { + $db_type = $this->dbh->getDBtype(); + switch ($db_type) { + case 'mysql': + return $this->dbh->query(sprintf( + 'INSERT INTO `options` (`key`, `value`) VALUES (%s, %s) ON DUPLICATE KEY UPDATE `value` = %s', + $this->dbh->quote($key), + $this->dbh->quote($value), + $this->dbh->quote($value) + )) !== false; + break; + case 'sqlite': + return $this->dbh->query(sprintf( + 'INSERT INTO `options` (`key`, `value`) VALUES (%s, %s) ON CONFLICT(`key`) DO UPDATE SET `value` = %s', + $this->dbh->quote($key), + $this->dbh->quote($value), + $this->dbh->quote($value) + )) !== false; + break; + default: + new \Exception('Unknown DB type: ' . $db_type); + return false; + break; + } + } + } + + protected function dbver(?string $ver = null) + { + return $this->settings('version', $ver); + } +} diff --git a/doc/notes.txt b/doc/notes.txt new file mode 100644 index 0000000..a3d8153 --- /dev/null +++ b/doc/notes.txt @@ -0,0 +1,21 @@ +projekt/ +│ +├── backend/ # PHP časť (API, logika, DB) +│ ├── public/ # root pre webserver (index.php, assets) +│ │ └── index.php +│ ├── src/ # zdrojový PHP kód (kontroléry, modely, služby) +│ ├── vendor/ # Composer balíčky (gitignore!) +│ ├── composer.json +│ └── composer.lock +│ +├── frontend/ # Vue časť +│ ├── src/ # Vue komponenty, views, store +│ ├── public/ # statické súbory (favicon, index.html template) +│ ├── dist/ # build výstup (gitignore!) → deploy do backend/public +│ ├── package.json +│ ├── package-lock.json +│ └── vite.config.js / vue.config.js +│ +├── docker/ (voliteľné) # ak používaš Docker (Nginx, PHP-FPM, Node build) +│ +└── README.md diff --git a/frontend/.env.development b/frontend/.env.development new file mode 100644 index 0000000..3b5dd93 --- /dev/null +++ b/frontend/.env.development @@ -0,0 +1 @@ +VITE_BACKENDAPI_URL="https://192.168.0.101/BugReport/backend/public/API.php" diff --git a/frontend/.env.production b/frontend/.env.production new file mode 100644 index 0000000..10dc79f --- /dev/null +++ b/frontend/.env.production @@ -0,0 +1 @@ +VITE_BACKENDAPI_URL="/API.php"