Skip to content

Commit f7cccae

Browse files
Refactor project structure and implement Nix development shell
- Moved all public-facing files to a `public/` directory for better organization. - Renamed assets and relocated them to the `public/assets` directory. - Replaced custom PHP implementations for database and routing with environment-aware includes. - Converted database initialization logic into `php/pdo.php`. - Introduced `shell.nix` for setting up a Nix development shell with `php85` and Composer. - Updated Docker configuration to adapt to new folder structure. - Replaced generic MySQL image with version `9.7`. - Adjusted `compose.debug.yaml` and Apache settings for the new directory layout.
1 parent 9f9799a commit f7cccae

32 files changed

Lines changed: 131 additions & 213 deletions

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use nix

compose.debug.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
services:
22
mysql:
33
container_name: mysql_dev
4-
image: mysql
5-
command: --default-authentication-plugin=mysql_native_password
4+
image: mysql:9.7
65
environment:
76
MYSQL_ROOT_PASSWORD: test
87
MYSQL_DATABASE: test
@@ -15,6 +14,8 @@ services:
1514
- "8080:80"
1615
volumes:
1716
- ./:/var/www/
17+
depends_on:
18+
- mysql
1819
environment:
1920
MYSQL_HOST: mysql_dev
2021
MYSQL_DATABASE: test

debug.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ RUN chown -R www-data:www-data /var/www
3939
COPY docker/start-apache /usr/local/bin
4040

4141
ENV APP_PATH=/var/www
42+
COPY docker/000-default.conf /etc/apache2/sites-available/000-default.conf
4243

4344
CMD ["start-apache"]

docker/000-default.conf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<VirtualHost *:80>
22
ServerAdmin webmaster@localhost
3-
DocumentRoot /var/www
3+
DocumentRoot /var/www/public
44

5-
<Directory /var/www>
5+
<Directory /var/www/public>
66
Options Indexes FollowSymLinks
77
AllowOverride All
88
Require all granted

impressum.html

Lines changed: 0 additions & 85 deletions
This file was deleted.

pdo.php

Lines changed: 0 additions & 87 deletions
This file was deleted.

php/devmarkt.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
include_once('../pdo.php');
2+
include_once('pdo.php');
33
include_once('login.inc.php');
44
include_once('token.inc.php');
55
include_once('request.inc.php');

php/pdo.php

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,87 @@
11
<?php
2-
include_once(getenv("APP_PATH") . '/pdo.php');
2+
session_start();
3+
error_reporting(E_ALL ^ E_DEPRECATED);
4+
$base_url = getenv("BOT_BASE_URI");
5+
$devmarkt_anfragen = getenv("GUILD_DEVMARKT_REQUEST_CHANNEL");
6+
$devmarkt = getenv("GUILD_DEVMARKT_CHANNEL");
7+
$guild_id = getenv("GUILD_ID");
8+
$moderator_id = getenv("GUILD_MOD_ID");
9+
$redirect_uri = getenv("BOT_REDIRECT_URI");
10+
11+
class MySQL
12+
{
13+
14+
private $host, $database, $username, $password;
15+
16+
private $pdo;
17+
18+
public function __construct()
19+
{
20+
21+
$this->host = getenv("MYSQL_HOST");
22+
$this->database = getenv("MYSQL_DATABASE");
23+
$this->username = getenv("MYSQL_USER");
24+
$this->password = getenv("MYSQL_PASSWORD");
25+
$options = array(
26+
PDO::ATTR_ERRMODE => PDO::ERRMODE_SILENT,
27+
PDO::ATTR_PERSISTENT => false,
28+
);
29+
$this->pdo = new PDO('mysql:host=' . $this->host . ';dbname=' . $this->database, $this->username, $this->password, $options);
30+
$this->loadTables();
31+
32+
}
33+
34+
public function loadTables()
35+
{
36+
37+
$pdoConnection = $this->getPDO();
38+
39+
$stmt = 'CREATE TABLE IF NOT EXISTS `dc_users` ( `id` INT NOT NULL AUTO_INCREMENT , `discord_id` VARCHAR(255) NOT NULL , `auth_code` VARCHAR(255) NOT NULL , `refresh_code` VARCHAR(255) NOT NULL , `rang` VARCHAR(50) NOT NULL , `login_token` VARCHAR(255),`blocked` BOOLEAN, `thread` VARCHAR(200) NULL DEFAULT NULL, PRIMARY KEY (`id`)) ENGINE = InnoDB;';
40+
$qry = $pdoConnection->prepare($stmt);
41+
$qry->execute();
42+
43+
$stmt1 = 'CREATE TABLE `anfragen` ( `id` INT NOT NULL AUTO_INCREMENT , `by_discord_id` VARCHAR(255) NOT NULL , `title` VARCHAR(100) NOT NULL , `type` VARCHAR(20) NOT NULL , `description` VARCHAR(' . getenv("MAX_DESCRIPTION_SIZE") . ') NOT NULL , `link` VARCHAR(100) NOT NULL , `req_id` VARCHAR(100) NOT NULL , `status` VARCHAR(100) NOT NULL , `processed_by` VARCHAR(100) NOT NULL ,`message_id` VARCHAR(100),`date` VARCHAR(100),`date_processed` VARCHAR(100),`color` VARCHAR(100),`reason` VARCHAR(500),`options` VARCHAR(200), PRIMARY KEY (`id`)) ENGINE = InnoDB;';
44+
$qry1 = $pdoConnection->prepare($stmt1);
45+
$qry1->execute();
46+
47+
}
48+
49+
public function getPDO()
50+
{
51+
52+
return $this->pdo;
53+
54+
}
55+
56+
public function close()
57+
{
58+
59+
$this->pdo->close();
60+
61+
}
62+
63+
public function query($qry)
64+
{
65+
return $this->pdo->query($qry);
66+
67+
}
68+
69+
public function inTable($table, $column, $user)
70+
{
71+
72+
$pdoConnection = $this->pdo;
73+
74+
$stmt = "SELECT * FROM `" . $table . "` WHERE `" . $column . "`=:user";
75+
$qry = $pdoConnection->prepare($stmt);
76+
$qry->bindParam(":user", $user);
77+
$qry->execute();
78+
79+
if ($qry->fetchColumn() == 0) {
80+
return false;
81+
}
82+
return true;
83+
}
84+
85+
}
86+
87+
?>

0 commit comments

Comments
 (0)