pridany Maintenance pre modul TPsoft\DBmodel,

pridane poznamky,
pridana konfiguracia pre DEV a PROD,
This commit is contained in:
2025-10-11 16:49:46 +02:00
parent 995e0e40a5
commit e63be43639
5 changed files with 108 additions and 17 deletions

View File

@ -4,6 +4,7 @@ require __DIR__ . '/../vendor/autoload.php';
use \Exception; use \Exception;
use \TPsoft\DBmodel\DBmodel; use \TPsoft\DBmodel\DBmodel;
use \TPsoft\BugreportBackend\Maintenance;
global $dbh; global $dbh;
@ -14,20 +15,6 @@ if (Configuration::DB_TYPE == 'mysql') {
} else { } else {
throw new Exception('Unknown database type'); throw new Exception('Unknown database type');
} }
/*
$dbh->tables = [ $maintenance = new Maintenance($dbh);
'reports' => [ $maintenance->database();
'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()',
],
],
];
*/

View File

@ -0,0 +1,81 @@
<?php
namespace TPsoft\BugreportBackend;
class Maintenance extends \TPsoft\DBmodel\Maintenance
{
public function database()
{
if (!$this->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);
}
}

21
doc/notes.txt Normal file
View File

@ -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

View File

@ -0,0 +1 @@
VITE_BACKENDAPI_URL="https://192.168.0.101/BugReport/backend/public/API.php"

1
frontend/.env.production Normal file
View File

@ -0,0 +1 @@
VITE_BACKENDAPI_URL="/API.php"