initial commit

This commit is contained in:
greggy
2025-10-06 23:52:38 +02:00
parent ad46abd2ba
commit ba8483bec2
17 changed files with 505 additions and 92 deletions

View File

@@ -9,5 +9,8 @@
"Entity\\": "src/Entity/",
"Repository\\": "src/Repository/"
}
},
"require-dev": {
"doctrine/migrations": "^3.9"
}
}

27
migrations-cli.php Normal file
View File

@@ -0,0 +1,27 @@
#!/usr/bin/env php
<?php
require_once 'vendor/autoload.php';
use Doctrine\Migrations\Tools\Console\Command;
use Symfony\Component\Console\Application;
$dependencyFactory = require 'migrations-config.php';
$cli = new Application('Doctrine Migrations');
$cli->setCatchExceptions(true);
$cli->addCommands([
new Command\DiffCommand($dependencyFactory),
new Command\ExecuteCommand($dependencyFactory),
new Command\GenerateCommand($dependencyFactory),
new Command\LatestCommand($dependencyFactory),
new Command\ListCommand($dependencyFactory),
new Command\MigrateCommand($dependencyFactory),
new Command\RollupCommand($dependencyFactory),
new Command\StatusCommand($dependencyFactory),
new Command\SyncMetadataCommand($dependencyFactory),
new Command\VersionCommand($dependencyFactory),
]);
$cli->run();

11
migrations-config.php Normal file
View File

@@ -0,0 +1,11 @@
<?php
require_once 'doctrine-config.php';
use Doctrine\Migrations\Configuration\EntityManager\ExistingEntityManager;
use Doctrine\Migrations\Configuration\Migration\PhpFile;
use Doctrine\Migrations\DependencyFactory;
$config = new PhpFile('migrations.php');
return DependencyFactory::fromEntityManager($config, new ExistingEntityManager($entityManager));

22
migrations.php Normal file
View File

@@ -0,0 +1,22 @@
<?php
return [
'table_storage' => [
'table_name' => 'doctrine_migration_versions',
'version_column_name' => 'version',
'version_column_length' => 191,
'executed_at_column_name' => 'executed_at',
'execution_time_column_name' => 'execution_time',
],
'migrations_paths' => [
'Migrations' => __DIR__ . '/migrations',
],
'all_or_nothing' => true,
'transactional' => true,
'check_database_platform' => true,
'organize_migrations' => 'none',
'connection' => null,
'em' => null,
];

View File

@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
namespace Migrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20251006214042 extends AbstractMigration
{
public function getDescription(): string
{
return 'Initial schema with default data';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE kampagnen (id INT AUTO_INCREMENT NOT NULL, is_fb TINYINT(1) NOT NULL, is_tr TINYINT(1) NOT NULL, is_mail TINYINT(1) NOT NULL, dest_url VARCHAR(255) NOT NULL, mailtext LONGTEXT DEFAULT NULL, img VARCHAR(255) DEFAULT NULL, linktext VARCHAR(255) DEFAULT NULL, ma SMALLINT NOT NULL, reload SMALLINT NOT NULL, dateCreated DATETIME NOT NULL, dateModified DATETIME NOT NULL, user_id INT DEFAULT NULL, INDEX IDX_37572FC6A76ED395 (user_id), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE reloadsperre (id INT AUTO_INCREMENT NOT NULL, reload_bis DATETIME NOT NULL, ip VARCHAR(45) NOT NULL, dateCreated DATETIME NOT NULL, kampagne_id INT NOT NULL, user_id INT NOT NULL, INDEX IDX_B6A62B2AACE19231 (kampagne_id), INDEX IDX_B6A62B2AA76ED395 (user_id), INDEX idx_kampagne_user (kampagne_id, user_id), INDEX idx_reload_bis (reload_bis), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE users (id INT AUTO_INCREMENT NOT NULL, username VARCHAR(100) NOT NULL, email VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, rolle ENUM(\'user\', \'admin\', \'werbenetzwerk\'), createdAt DATETIME NOT NULL, werbenetzwerk_id INT DEFAULT NULL, INDEX IDX_1483A5E948B23AFC (werbenetzwerk_id), PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('CREATE TABLE werbenetzwerk (id INT AUTO_INCREMENT NOT NULL, umrechnungskurs DOUBLE PRECISION NOT NULL, eigenanteil_prozent SMALLINT UNSIGNED NOT NULL, date_updated DATETIME DEFAULT NULL, PRIMARY KEY (id)) DEFAULT CHARACTER SET utf8mb4');
$this->addSql('ALTER TABLE kampagnen ADD CONSTRAINT FK_37572FC6A76ED395 FOREIGN KEY (user_id) REFERENCES users (id)');
$this->addSql('ALTER TABLE reloadsperre ADD CONSTRAINT FK_B6A62B2AACE19231 FOREIGN KEY (kampagne_id) REFERENCES kampagnen (id)');
$this->addSql('ALTER TABLE reloadsperre ADD CONSTRAINT FK_B6A62B2AA76ED395 FOREIGN KEY (user_id) REFERENCES users (id)');
$this->addSql('ALTER TABLE users ADD CONSTRAINT FK_1483A5E948B23AFC FOREIGN KEY (werbenetzwerk_id) REFERENCES werbenetzwerk (id)');
// Default data - Werbenetzwerk
$this->addSql('INSERT INTO werbenetzwerk (umrechnungskurs, eigenanteil_prozent, date_updated) VALUES (0.0000000022, 25, NOW())');
// Default data - Users
$this->addSql('INSERT INTO users (username, email, password, rolle, createdAt) VALUES ("admin", "admin@example.com", "$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi", "admin", NOW())');
$this->addSql('INSERT INTO users (username, email, password, rolle, createdAt) VALUES ("testuser1", "testuser1@example.com", "$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi", "user", NOW())');
$this->addSql('INSERT INTO users (username, email, password, rolle, createdAt) VALUES ("testuser2", "testuser2@example.com", "$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi", "user", NOW())');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE kampagnen DROP FOREIGN KEY FK_37572FC6A76ED395');
$this->addSql('ALTER TABLE reloadsperre DROP FOREIGN KEY FK_B6A62B2AACE19231');
$this->addSql('ALTER TABLE reloadsperre DROP FOREIGN KEY FK_B6A62B2AA76ED395');
$this->addSql('ALTER TABLE users DROP FOREIGN KEY FK_1483A5E948B23AFC');
$this->addSql('DROP TABLE kampagnen');
$this->addSql('DROP TABLE reloadsperre');
$this->addSql('DROP TABLE users');
$this->addSql('DROP TABLE werbenetzwerk');
}
}

View File

@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace Migrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20251006214520 extends AbstractMigration
{
public function getDescription(): string
{
return 'Change IP column to VARBINARY(16) for efficient storage';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE reloadsperre CHANGE ip ip VARBINARY(16) NOT NULL');
$this->addSql('ALTER TABLE users CHANGE rolle rolle ENUM(\'user\', \'admin\', \'werbenetzwerk\')');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE reloadsperre CHANGE ip ip VARCHAR(45) NOT NULL');
$this->addSql('ALTER TABLE users CHANGE rolle rolle ENUM(\'user\', \'admin\', \'werbenetzwerk\') DEFAULT NULL');
}
}

View File

@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace Migrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20251006214635 extends AbstractMigration
{
public function getDescription(): string
{
return 'Change IP column to INT UNSIGNED for IPv4 storage (4 bytes)';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE reloadsperre CHANGE ip ip INT UNSIGNED NOT NULL');
$this->addSql('ALTER TABLE users CHANGE rolle rolle ENUM(\'user\', \'admin\', \'werbenetzwerk\')');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE reloadsperre CHANGE ip ip VARBINARY(16) NOT NULL');
$this->addSql('ALTER TABLE users CHANGE rolle rolle ENUM(\'user\', \'admin\', \'werbenetzwerk\') DEFAULT NULL');
}
}

View File

@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace Migrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20251006214741 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add ON DELETE actions to foreign keys';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE kampagnen DROP FOREIGN KEY `FK_37572FC6A76ED395`');
$this->addSql('ALTER TABLE kampagnen ADD CONSTRAINT FK_37572FC6A76ED395 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE SET NULL');
$this->addSql('ALTER TABLE reloadsperre DROP FOREIGN KEY `FK_B6A62B2AA76ED395`');
$this->addSql('ALTER TABLE reloadsperre DROP FOREIGN KEY `FK_B6A62B2AACE19231`');
$this->addSql('ALTER TABLE reloadsperre ADD CONSTRAINT FK_B6A62B2AA76ED395 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE reloadsperre ADD CONSTRAINT FK_B6A62B2AACE19231 FOREIGN KEY (kampagne_id) REFERENCES kampagnen (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE users DROP FOREIGN KEY `FK_1483A5E948B23AFC`');
$this->addSql('ALTER TABLE users CHANGE rolle rolle ENUM(\'user\', \'admin\', \'werbenetzwerk\')');
$this->addSql('ALTER TABLE users ADD CONSTRAINT FK_1483A5E948B23AFC FOREIGN KEY (werbenetzwerk_id) REFERENCES werbenetzwerk (id) ON DELETE SET NULL');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE kampagnen DROP FOREIGN KEY FK_37572FC6A76ED395');
$this->addSql('ALTER TABLE kampagnen ADD CONSTRAINT `FK_37572FC6A76ED395` FOREIGN KEY (user_id) REFERENCES users (id)');
$this->addSql('ALTER TABLE reloadsperre DROP FOREIGN KEY FK_B6A62B2AACE19231');
$this->addSql('ALTER TABLE reloadsperre DROP FOREIGN KEY FK_B6A62B2AA76ED395');
$this->addSql('ALTER TABLE reloadsperre ADD CONSTRAINT `FK_B6A62B2AACE19231` FOREIGN KEY (kampagne_id) REFERENCES kampagnen (id)');
$this->addSql('ALTER TABLE reloadsperre ADD CONSTRAINT `FK_B6A62B2AA76ED395` FOREIGN KEY (user_id) REFERENCES users (id)');
$this->addSql('ALTER TABLE users DROP FOREIGN KEY FK_1483A5E948B23AFC');
$this->addSql('ALTER TABLE users CHANGE rolle rolle ENUM(\'user\', \'admin\', \'werbenetzwerk\') DEFAULT NULL');
$this->addSql('ALTER TABLE users ADD CONSTRAINT `FK_1483A5E948B23AFC` FOREIGN KEY (werbenetzwerk_id) REFERENCES werbenetzwerk (id)');
}
}

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace Migrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20251006214859 extends AbstractMigration
{
public function getDescription(): string
{
return 'Change kampagne FK to RESTRICT (kampagne must exist)';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE reloadsperre DROP FOREIGN KEY `FK_B6A62B2AACE19231`');
$this->addSql('ALTER TABLE reloadsperre ADD CONSTRAINT FK_B6A62B2AACE19231 FOREIGN KEY (kampagne_id) REFERENCES kampagnen (id) ON DELETE RESTRICT');
$this->addSql('ALTER TABLE users CHANGE rolle rolle ENUM(\'user\', \'admin\', \'werbenetzwerk\')');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE reloadsperre DROP FOREIGN KEY FK_B6A62B2AACE19231');
$this->addSql('ALTER TABLE reloadsperre ADD CONSTRAINT `FK_B6A62B2AACE19231` FOREIGN KEY (kampagne_id) REFERENCES kampagnen (id) ON DELETE CASCADE');
$this->addSql('ALTER TABLE users CHANGE rolle rolle ENUM(\'user\', \'admin\', \'werbenetzwerk\') DEFAULT NULL');
}
}

66
seed-kampagnen.php Normal file
View File

@@ -0,0 +1,66 @@
<?php
// seed-kampagnen.php - Beispiel-Kampagnen einfügen
require_once 'doctrine-config.php';
use Entity\Kampagne;
use Entity\User;
try {
// Prüfen ob bereits Kampagnen vorhanden sind
$existingData = $entityManager->getRepository(Kampagne::class)->findAll();
if (count($existingData) > 0) {
echo "Kampagnen sind bereits vorhanden. Überspringe Seed.\n";
exit(0);
}
// User für Zuweisung holen
$users = $entityManager->getRepository(User::class)->findAll();
if (count($users) === 0) {
echo "Keine User gefunden. Bitte erst User anlegen.\n";
exit(1);
}
// 10 Beispiel-Kampagnen erstellen
$kampagnenData = [
['is_fb' => true, 'is_tr' => false, 'is_mail' => false, 'dest_url' => 'https://example.com/promo1', 'linktext' => 'Super Angebot 1', 'ma' => 5, 'reload' => 24],
['is_fb' => false, 'is_tr' => true, 'is_mail' => false, 'dest_url' => 'https://example.com/promo2', 'linktext' => 'Mega Deal 2', 'ma' => 3, 'reload' => 12],
['is_fb' => true, 'is_tr' => true, 'is_mail' => false, 'dest_url' => 'https://example.com/promo3', 'linktext' => 'Exklusiv Angebot 3', 'ma' => 10, 'reload' => 48],
['is_fb' => false, 'is_tr' => false, 'is_mail' => true, 'dest_url' => 'https://example.com/promo4', 'linktext' => 'Newsletter Special 4', 'ma' => 2, 'reload' => 6, 'mailtext' => 'Hallo, schau dir unser tolles Angebot an!'],
['is_fb' => true, 'is_tr' => false, 'is_mail' => true, 'dest_url' => 'https://example.com/promo5', 'linktext' => 'Combo Deal 5', 'ma' => 7, 'reload' => 36, 'mailtext' => 'Exklusive Kombination nur für dich!'],
['is_fb' => false, 'is_tr' => true, 'is_mail' => false, 'dest_url' => 'https://example.com/promo6', 'linktext' => 'Traffic Boost 6', 'ma' => 4, 'reload' => 18],
['is_fb' => true, 'is_tr' => true, 'is_mail' => true, 'dest_url' => 'https://example.com/promo7', 'linktext' => 'All-in-One 7', 'ma' => 15, 'reload' => 72, 'mailtext' => 'Maximale Reichweite mit allen Kanälen!'],
['is_fb' => false, 'is_tr' => false, 'is_mail' => false, 'dest_url' => 'https://example.com/promo8', 'linktext' => 'Basic Campaign 8', 'ma' => 1, 'reload' => 3],
['is_fb' => true, 'is_tr' => false, 'is_mail' => false, 'dest_url' => 'https://example.com/promo9', 'linktext' => 'Facebook Power 9', 'ma' => 8, 'reload' => 24],
['is_fb' => false, 'is_tr' => true, 'is_mail' => true, 'dest_url' => 'https://example.com/promo10', 'linktext' => 'Traffic + Mail 10', 'ma' => 6, 'reload' => 30, 'mailtext' => 'Doppelte Power für deine Kampagne!'],
];
$userIndex = 0;
foreach ($kampagnenData as $data) {
$kampagne = new Kampagne();
$kampagne->setIsFb($data['is_fb']);
$kampagne->setIsTr($data['is_tr']);
$kampagne->setIsMail($data['is_mail']);
$kampagne->setDestUrl($data['dest_url']);
$kampagne->setLinktext($data['linktext']);
$kampagne->setMa($data['ma']);
$kampagne->setReload($data['reload']);
if (isset($data['mailtext'])) {
$kampagne->setMailtext($data['mailtext']);
}
// User rotierend zuweisen
$kampagne->setUser($users[$userIndex % count($users)]);
$userIndex++;
$entityManager->persist($kampagne);
}
$entityManager->flush();
echo "10 Beispiel-Kampagnen wurden erfolgreich eingefügt.\n";
} catch (\Exception $e) {
echo "Fehler beim Einfügen der Daten: " . $e->getMessage() . "\n";
}

View File

@@ -1,30 +0,0 @@
<?php
// seed-werbenetzwerk.php - Default-Daten für Werbenetzwerk einfügen
require_once 'doctrine-config.php';
use Entity\Werbenetzwerk;
try {
// Prüfen ob bereits Daten vorhanden sind
$existingData = $entityManager->getRepository(Werbenetzwerk::class)->findAll();
if (count($existingData) > 0) {
echo "Werbenetzwerk-Daten sind bereits vorhanden. Überspringe Seed.\n";
exit(0);
}
// Default-Daten einfügen
$werbenetzwerk = new Werbenetzwerk();
$werbenetzwerk->setWerbenetzwerk('ADC');
$werbenetzwerk->setName('AdCity.eu');
$werbenetzwerk->setUmrechnungskurs(0.0000000022);
$werbenetzwerk->setEigenanteilProzent(25);
$entityManager->persist($werbenetzwerk);
$entityManager->flush();
echo "Default-Werbenetzwerk 'ADC' wurde erfolgreich eingefügt.\n";
} catch (\Exception $e) {
echo "Fehler beim Einfügen der Daten: " . $e->getMessage() . "\n";
}

31
setup-database.php Normal file
View File

@@ -0,0 +1,31 @@
<?php
// setup-database.php - Komplettes Datenbank-Setup mit Migrations
require_once 'config.php';
try {
// Datenbank neu erstellen
$pdo = new PDO("mysql:host=$databaseHost", $databaseUser, $databasePassword);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec("DROP DATABASE IF EXISTS $databaseDatabase");
$pdo->exec("CREATE DATABASE $databaseDatabase CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci");
echo "✓ Datenbank '$databaseDatabase' wurde neu erstellt.\n";
// Migrations ausführen
echo "\n";
passthru('php migrations-cli.php migrations:migrate --no-interaction', $returnCode);
if ($returnCode === 0) {
echo "\n✓ Datenbank-Setup erfolgreich abgeschlossen!\n";
echo "\nStandardbenutzer:\n";
echo "- admin / admin123 (Rolle: admin)\n";
echo "- testuser1 / test123 (Rolle: user)\n";
echo "- testuser2 / test123 (Rolle: user)\n";
} else {
echo "\n✗ Fehler beim Ausführen der Migrations.\n";
exit(1);
}
} catch (PDOException $e) {
echo "✗ Fehler: " . $e->getMessage() . "\n";
exit(1);
}

View File

@@ -41,12 +41,8 @@ class Kampagne
#[ORM\Column(type: 'smallint')]
private int $reload = 0;
#[ORM\ManyToOne(targetEntity: Werbenetzwerk::class)]
#[ORM\JoinColumn(name: 'werbenetzwerk_id', referencedColumnName: 'werbenetzwerk', nullable: true)]
private ?Werbenetzwerk $werbenetzwerk = null;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: true)]
#[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
private ?User $user = null;
#[ORM\Column(type: 'datetime')]
@@ -183,17 +179,6 @@ class Kampagne
return $this->dateModified;
}
public function getWerbenetzwerk(): ?Werbenetzwerk
{
return $this->werbenetzwerk;
}
public function setWerbenetzwerk(?Werbenetzwerk $werbenetzwerk): self
{
$this->werbenetzwerk = $werbenetzwerk;
return $this;
}
public function getUser(): ?User
{
return $this->user;

View File

@@ -0,0 +1,96 @@
<?php
namespace Entity;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity]
#[ORM\Table(name: 'reloadsperre')]
#[ORM\Index(name: 'idx_kampagne_user', columns: ['kampagne_id', 'user_id'])]
#[ORM\Index(name: 'idx_reload_bis', columns: ['reload_bis'])]
#[ORM\HasLifecycleCallbacks]
class Reloadsperre
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\ManyToOne(targetEntity: Kampagne::class)]
#[ORM\JoinColumn(name: 'kampagne_id', referencedColumnName: 'id', nullable: false, onDelete: 'RESTRICT')]
private Kampagne $kampagne;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
private User $user;
#[ORM\Column(type: 'datetime')]
private \DateTimeInterface $reload_bis;
#[ORM\Column(type: 'integer', options: ['unsigned' => true])]
private int $ip;
#[ORM\Column(type: 'datetime')]
private \DateTimeInterface $dateCreated;
#[ORM\PrePersist]
public function setDateCreatedValue(): void
{
$this->dateCreated = new \DateTime();
}
// Getters and Setters
public function getId(): ?int
{
return $this->id;
}
public function getKampagne(): Kampagne
{
return $this->kampagne;
}
public function setKampagne(Kampagne $kampagne): self
{
$this->kampagne = $kampagne;
return $this;
}
public function getUser(): User
{
return $this->user;
}
public function setUser(User $user): self
{
$this->user = $user;
return $this;
}
public function getReloadBis(): \DateTimeInterface
{
return $this->reload_bis;
}
public function setReloadBis(\DateTimeInterface $reload_bis): self
{
$this->reload_bis = $reload_bis;
return $this;
}
public function getIp(): string
{
return long2ip($this->ip);
}
public function setIp(string $ip): self
{
$this->ip = ip2long($ip);
return $this;
}
public function getDateCreated(): \DateTimeInterface
{
return $this->dateCreated;
}
}

View File

@@ -22,6 +22,13 @@ class User
#[ORM\Column(type: 'string', length: 255)]
private string $password;
#[ORM\Column(type: 'string', columnDefinition: "ENUM('user', 'admin', 'werbenetzwerk')")]
private string $rolle = 'user';
#[ORM\ManyToOne(targetEntity: Werbenetzwerk::class)]
#[ORM\JoinColumn(name: 'werbenetzwerk_id', referencedColumnName: 'id', nullable: true, onDelete: 'SET NULL')]
private ?Werbenetzwerk $werbenetzwerk = null;
#[ORM\Column(type: 'datetime')]
private \DateTime $createdAt;
@@ -79,4 +86,39 @@ class User
$this->createdAt = $createdAt;
return $this;
}
public function getRolle(): string
{
return $this->rolle;
}
public function setRolle(string $rolle): self
{
if (!in_array($rolle, ['user', 'admin', 'werbenetzwerk'])) {
throw new \InvalidArgumentException('Rolle muss "user", "admin" oder "werbenetzwerk" sein');
}
$this->rolle = $rolle;
return $this;
}
public function isAdmin(): bool
{
return $this->rolle === 'admin';
}
public function isWerbenetzwerk(): bool
{
return $this->rolle === 'werbenetzwerk';
}
public function getWerbenetzwerk(): ?Werbenetzwerk
{
return $this->werbenetzwerk;
}
public function setWerbenetzwerk(?Werbenetzwerk $werbenetzwerk): self
{
$this->werbenetzwerk = $werbenetzwerk;
return $this;
}
}

View File

@@ -10,11 +10,9 @@ use Doctrine\ORM\Mapping as ORM;
class Werbenetzwerk
{
#[ORM\Id]
#[ORM\Column(type: 'string', length: 5)]
private string $werbenetzwerk;
#[ORM\Column(type: 'text')]
private string $name;
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Column(type: 'float')]
private float $umrechnungskurs;
@@ -33,26 +31,9 @@ class Werbenetzwerk
}
// Getters and Setters
public function getWerbenetzwerk(): string
public function getId(): ?int
{
return $this->werbenetzwerk;
}
public function setWerbenetzwerk(string $werbenetzwerk): self
{
$this->werbenetzwerk = $werbenetzwerk;
return $this;
}
public function getName(): string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
return $this->id;
}
public function getUmrechnungskurs(): float

View File

@@ -1,22 +0,0 @@
<?php
// update-schema.php - Datenbank-Schema aktualisieren
require_once 'doctrine-config.php';
use Doctrine\ORM\Tools\SchemaTool;
$classes = [
$entityManager->getClassMetadata('Entity\User'),
$entityManager->getClassMetadata('Entity\Kampagne'),
$entityManager->getClassMetadata('Entity\Werbenetzwerk'),
];
$schemaTool = new SchemaTool($entityManager);
try {
// Schema updaten
$schemaTool->updateSchema($classes);
echo "Database schema updated successfully!\n";
} catch (\Exception $e) {
echo "Error updating schema: " . $e->getMessage() . "\n";
}