Add image support for car brands and models
Phase 3 of the dashboard roadmap. Adds brands.image_path and car_models.image_path, following the exact same pattern as the existing gallery cover-image columns: Schema.php (create + additive migration), the export/import wiring (TABLE_COLUMNS + IMAGE_COLUMNS, so the files survive an export/import round-trip), orphaned-file cleanup via the Phase 1 Uploads helper (including brand deletes, which cascade-delete their models), and an ImageUploadField in both admin pages with a thumbnail column in the tables. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
5a56fec2c7
commit
b2b7e0a8d6
11 changed files with 145 additions and 39 deletions
|
|
@ -1,8 +1,9 @@
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
import { api } from '../../api/client.js';
|
import { api } from '../../api/client.js';
|
||||||
|
import ImageUploadField from '../../components/ImageUploadField.jsx';
|
||||||
|
|
||||||
const emptyForm = { name: '', sort_order: 0 };
|
const emptyForm = { name: '', image_path: '', sort_order: 0 };
|
||||||
|
|
||||||
export default function Brands() {
|
export default function Brands() {
|
||||||
const [brands, setBrands] = useState([]);
|
const [brands, setBrands] = useState([]);
|
||||||
|
|
@ -18,7 +19,7 @@ export default function Brands() {
|
||||||
|
|
||||||
const startEdit = (brand) => {
|
const startEdit = (brand) => {
|
||||||
setEditingId(brand.id);
|
setEditingId(brand.id);
|
||||||
setForm({ name: brand.name, sort_order: brand.sort_order });
|
setForm({ name: brand.name, image_path: brand.image_path || '', sort_order: brand.sort_order });
|
||||||
};
|
};
|
||||||
|
|
||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
|
|
@ -56,6 +57,7 @@ export default function Brands() {
|
||||||
<table className="w-full text-left text-sm">
|
<table className="w-full text-left text-sm">
|
||||||
<thead className="bg-neutral-50 text-neutral-500 dark:bg-neutral-900 dark:text-neutral-400">
|
<thead className="bg-neutral-50 text-neutral-500 dark:bg-neutral-900 dark:text-neutral-400">
|
||||||
<tr>
|
<tr>
|
||||||
|
<th className="px-4 py-2">Bild</th>
|
||||||
<th className="px-4 py-2">Name</th>
|
<th className="px-4 py-2">Name</th>
|
||||||
<th className="px-4 py-2">Sortierung</th>
|
<th className="px-4 py-2">Sortierung</th>
|
||||||
<th className="px-4 py-2 text-right">Aktionen</th>
|
<th className="px-4 py-2 text-right">Aktionen</th>
|
||||||
|
|
@ -64,6 +66,13 @@ export default function Brands() {
|
||||||
<tbody className="divide-y divide-neutral-100 dark:divide-neutral-800">
|
<tbody className="divide-y divide-neutral-100 dark:divide-neutral-800">
|
||||||
{brands.map((brand) => (
|
{brands.map((brand) => (
|
||||||
<tr key={brand.id} className="bg-white dark:bg-neutral-950">
|
<tr key={brand.id} className="bg-white dark:bg-neutral-950">
|
||||||
|
<td className="px-4 py-2">
|
||||||
|
{brand.image_path ? (
|
||||||
|
<img src={brand.image_path} alt="" className="h-10 w-10 rounded-md object-cover" />
|
||||||
|
) : (
|
||||||
|
<span className="flex h-10 w-10 items-center justify-center rounded-md bg-neutral-100 text-xs text-neutral-400 dark:bg-neutral-800">–</span>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
<td className="px-4 py-2 font-medium text-neutral-800 dark:text-neutral-100">
|
<td className="px-4 py-2 font-medium text-neutral-800 dark:text-neutral-100">
|
||||||
<Link to={`/marken/${brand.slug}`} target="_blank" className="hover:text-brand-500">
|
<Link to={`/marken/${brand.slug}`} target="_blank" className="hover:text-brand-500">
|
||||||
{brand.name}
|
{brand.name}
|
||||||
|
|
@ -77,7 +86,7 @@ export default function Brands() {
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
{brands.length === 0 && (
|
{brands.length === 0 && (
|
||||||
<tr><td colSpan={3} className="px-4 py-6 text-center text-neutral-400">Noch keine Marken angelegt.</td></tr>
|
<tr><td colSpan={4} className="px-4 py-6 text-center text-neutral-400">Noch keine Marken angelegt.</td></tr>
|
||||||
)}
|
)}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
@ -95,6 +104,11 @@ export default function Brands() {
|
||||||
className="w-full rounded-md border border-neutral-300 bg-white px-3 py-2 text-sm dark:border-neutral-700 dark:bg-neutral-900"
|
className="w-full rounded-md border border-neutral-300 bg-white px-3 py-2 text-sm dark:border-neutral-700 dark:bg-neutral-900"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<ImageUploadField
|
||||||
|
value={form.image_path}
|
||||||
|
onChange={(path) => setForm({ ...form, image_path: path })}
|
||||||
|
label="Bild (optional)"
|
||||||
|
/>
|
||||||
<div>
|
<div>
|
||||||
<label className="mb-1 block text-sm font-medium text-neutral-700 dark:text-neutral-300">Sortierung</label>
|
<label className="mb-1 block text-sm font-medium text-neutral-700 dark:text-neutral-300">Sortierung</label>
|
||||||
<input
|
<input
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
import { useEffect, useMemo, useState } from 'react';
|
import { useEffect, useMemo, useState } from 'react';
|
||||||
import { api } from '../../api/client.js';
|
import { api } from '../../api/client.js';
|
||||||
|
import ImageUploadField from '../../components/ImageUploadField.jsx';
|
||||||
|
|
||||||
const emptyForm = { name: '', brand_id: '', sort_order: 0 };
|
const emptyForm = { name: '', brand_id: '', image_path: '', sort_order: 0 };
|
||||||
|
|
||||||
export default function Models() {
|
export default function Models() {
|
||||||
const [models, setModels] = useState([]);
|
const [models, setModels] = useState([]);
|
||||||
|
|
@ -25,7 +26,12 @@ export default function Models() {
|
||||||
|
|
||||||
const startEdit = (model) => {
|
const startEdit = (model) => {
|
||||||
setEditingId(model.id);
|
setEditingId(model.id);
|
||||||
setForm({ name: model.name, brand_id: model.brand_id, sort_order: model.sort_order });
|
setForm({
|
||||||
|
name: model.name,
|
||||||
|
brand_id: model.brand_id,
|
||||||
|
image_path: model.image_path || '',
|
||||||
|
sort_order: model.sort_order,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const resetForm = () => {
|
const resetForm = () => {
|
||||||
|
|
@ -83,6 +89,7 @@ export default function Models() {
|
||||||
<table className="w-full text-left text-sm">
|
<table className="w-full text-left text-sm">
|
||||||
<thead className="bg-neutral-50 text-neutral-500 dark:bg-neutral-900 dark:text-neutral-400">
|
<thead className="bg-neutral-50 text-neutral-500 dark:bg-neutral-900 dark:text-neutral-400">
|
||||||
<tr>
|
<tr>
|
||||||
|
<th className="px-4 py-2">Bild</th>
|
||||||
<th className="px-4 py-2">Marke</th>
|
<th className="px-4 py-2">Marke</th>
|
||||||
<th className="px-4 py-2">Modell</th>
|
<th className="px-4 py-2">Modell</th>
|
||||||
<th className="px-4 py-2 text-right">Aktionen</th>
|
<th className="px-4 py-2 text-right">Aktionen</th>
|
||||||
|
|
@ -91,6 +98,13 @@ export default function Models() {
|
||||||
<tbody className="divide-y divide-neutral-100 dark:divide-neutral-800">
|
<tbody className="divide-y divide-neutral-100 dark:divide-neutral-800">
|
||||||
{filteredModels.map((model) => (
|
{filteredModels.map((model) => (
|
||||||
<tr key={model.id} className="bg-white dark:bg-neutral-950">
|
<tr key={model.id} className="bg-white dark:bg-neutral-950">
|
||||||
|
<td className="px-4 py-2">
|
||||||
|
{model.image_path ? (
|
||||||
|
<img src={model.image_path} alt="" className="h-10 w-10 rounded-md object-cover" />
|
||||||
|
) : (
|
||||||
|
<span className="flex h-10 w-10 items-center justify-center rounded-md bg-neutral-100 text-xs text-neutral-400 dark:bg-neutral-800">–</span>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
<td className="px-4 py-2">{model.brand_name}</td>
|
<td className="px-4 py-2">{model.brand_name}</td>
|
||||||
<td className="px-4 py-2 font-medium text-neutral-800 dark:text-neutral-100">{model.name}</td>
|
<td className="px-4 py-2 font-medium text-neutral-800 dark:text-neutral-100">{model.name}</td>
|
||||||
<td className="px-4 py-2 text-right">
|
<td className="px-4 py-2 text-right">
|
||||||
|
|
@ -100,7 +114,7 @@ export default function Models() {
|
||||||
</tr>
|
</tr>
|
||||||
))}
|
))}
|
||||||
{filteredModels.length === 0 && (
|
{filteredModels.length === 0 && (
|
||||||
<tr><td colSpan={3} className="px-4 py-6 text-center text-neutral-400">
|
<tr><td colSpan={4} className="px-4 py-6 text-center text-neutral-400">
|
||||||
{models.length === 0 ? 'Noch keine Modelle angelegt.' : 'Keine Modelle für diese Marke.'}
|
{models.length === 0 ? 'Noch keine Modelle angelegt.' : 'Keine Modelle für diese Marke.'}
|
||||||
</td></tr>
|
</td></tr>
|
||||||
)}
|
)}
|
||||||
|
|
@ -132,6 +146,11 @@ export default function Models() {
|
||||||
className="w-full rounded-md border border-neutral-300 bg-white px-3 py-2 text-sm dark:border-neutral-700 dark:bg-neutral-900"
|
className="w-full rounded-md border border-neutral-300 bg-white px-3 py-2 text-sm dark:border-neutral-700 dark:bg-neutral-900"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<ImageUploadField
|
||||||
|
value={form.image_path}
|
||||||
|
onChange={(path) => setForm({ ...form, image_path: path })}
|
||||||
|
label="Bild (optional)"
|
||||||
|
/>
|
||||||
<div>
|
<div>
|
||||||
<label className="mb-1 block text-sm font-medium text-neutral-700 dark:text-neutral-300">Sortierung</label>
|
<label className="mb-1 block text-sm font-medium text-neutral-700 dark:text-neutral-300">Sortierung</label>
|
||||||
<input
|
<input
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ const SECTIONS = [
|
||||||
{
|
{
|
||||||
key: 'catalog',
|
key: 'catalog',
|
||||||
label: 'Fahrzeug-Katalog',
|
label: 'Fahrzeug-Katalog',
|
||||||
hint: 'Marken, Modelle, Pakete, Produkte, Upgrades',
|
hint: 'Marken, Modelle (inkl. Bilder), Pakete, Produkte, Upgrades',
|
||||||
tables: ['brands', 'car_models', 'packages', 'package_products', 'package_upgrades'],
|
tables: ['brands', 'car_models', 'packages', 'package_products', 'package_upgrades'],
|
||||||
},
|
},
|
||||||
{ key: 'services', label: 'Leistungen', hint: 'Die Leistungen-Übersicht', tables: ['services'] },
|
{ key: 'services', label: 'Leistungen', hint: 'Die Leistungen-Übersicht', tables: ['services'] },
|
||||||
|
|
|
||||||
12
hifi/api/database/migration_brand_model_images.sql
Normal file
12
hifi/api/database/migration_brand_model_images.sql
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
USE hifi_shop;
|
||||||
|
|
||||||
|
-- Bild pro Automarke und Modell (z.B. Logo bzw. Fahrzeugfoto), analog zu den bereits
|
||||||
|
-- bestehenden Bild-Spalten bei der Bildergalerie. Additiv, nichts wird geloescht.
|
||||||
|
-- Hinweis: Auf der Live-Seite reicht stattdessen ein Klick auf "Datenbankstruktur aktualisieren"
|
||||||
|
-- unter Admin-Panel -> Einstellungen -> Datenbank.
|
||||||
|
|
||||||
|
ALTER TABLE brands
|
||||||
|
ADD COLUMN IF NOT EXISTS image_path VARCHAR(255) NULL AFTER slug;
|
||||||
|
|
||||||
|
ALTER TABLE car_models
|
||||||
|
ADD COLUMN IF NOT EXISTS image_path VARCHAR(255) NULL AFTER slug;
|
||||||
|
|
@ -92,6 +92,7 @@ CREATE TABLE brands (
|
||||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
name VARCHAR(100) NOT NULL,
|
name VARCHAR(100) NOT NULL,
|
||||||
slug VARCHAR(120) NOT NULL UNIQUE,
|
slug VARCHAR(120) NOT NULL UNIQUE,
|
||||||
|
image_path VARCHAR(255) NULL,
|
||||||
sort_order INT NOT NULL DEFAULT 0,
|
sort_order INT NOT NULL DEFAULT 0,
|
||||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
|
|
@ -102,6 +103,7 @@ CREATE TABLE car_models (
|
||||||
brand_id INT NOT NULL,
|
brand_id INT NOT NULL,
|
||||||
name VARCHAR(100) NOT NULL,
|
name VARCHAR(100) NOT NULL,
|
||||||
slug VARCHAR(150) NOT NULL,
|
slug VARCHAR(150) NOT NULL,
|
||||||
|
image_path VARCHAR(255) NULL,
|
||||||
sort_order INT NOT NULL DEFAULT 0,
|
sort_order INT NOT NULL DEFAULT 0,
|
||||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,14 @@ namespace App\Controllers;
|
||||||
use App\Config\Database;
|
use App\Config\Database;
|
||||||
use App\Support\Http;
|
use App\Support\Http;
|
||||||
use App\Support\Slug;
|
use App\Support\Slug;
|
||||||
|
use App\Support\Uploads;
|
||||||
|
|
||||||
class BrandController
|
class BrandController
|
||||||
{
|
{
|
||||||
public static function index(): void
|
public static function index(): void
|
||||||
{
|
{
|
||||||
$stmt = Database::connection()->query(
|
$stmt = Database::connection()->query(
|
||||||
'SELECT id, name, slug, sort_order FROM brands ORDER BY sort_order, name'
|
'SELECT id, name, slug, image_path, sort_order FROM brands ORDER BY sort_order, name'
|
||||||
);
|
);
|
||||||
Http::send($stmt->fetchAll());
|
Http::send($stmt->fetchAll());
|
||||||
}
|
}
|
||||||
|
|
@ -27,9 +28,14 @@ class BrandController
|
||||||
$slug = Slug::make($name);
|
$slug = Slug::make($name);
|
||||||
$db = Database::connection();
|
$db = Database::connection();
|
||||||
$stmt = $db->prepare(
|
$stmt = $db->prepare(
|
||||||
'INSERT INTO brands (name, slug, sort_order) VALUES (?, ?, ?)'
|
'INSERT INTO brands (name, slug, image_path, sort_order) VALUES (?, ?, ?, ?)'
|
||||||
);
|
);
|
||||||
$stmt->execute([$name, $slug, (int) ($body['sort_order'] ?? 0)]);
|
$stmt->execute([
|
||||||
|
$name,
|
||||||
|
$slug,
|
||||||
|
trim($body['image_path'] ?? '') ?: null,
|
||||||
|
(int) ($body['sort_order'] ?? 0),
|
||||||
|
]);
|
||||||
|
|
||||||
Http::send(['id' => (int) $db->lastInsertId(), 'name' => $name, 'slug' => $slug], 201);
|
Http::send(['id' => (int) $db->lastInsertId(), 'name' => $name, 'slug' => $slug], 201);
|
||||||
}
|
}
|
||||||
|
|
@ -43,24 +49,50 @@ class BrandController
|
||||||
Http::error('Name erforderlich', 422);
|
Http::error('Name erforderlich', 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$newImagePath = trim($body['image_path'] ?? '') ?: null;
|
||||||
$db = Database::connection();
|
$db = Database::connection();
|
||||||
|
$oldStmt = $db->prepare('SELECT image_path FROM brands WHERE id = ?');
|
||||||
|
$oldStmt->execute([$id]);
|
||||||
|
$oldImagePath = $oldStmt->fetchColumn();
|
||||||
|
|
||||||
$stmt = $db->prepare(
|
$stmt = $db->prepare(
|
||||||
'UPDATE brands SET name = ?, slug = ?, sort_order = ? WHERE id = ?'
|
'UPDATE brands SET name = ?, slug = ?, image_path = ?, sort_order = ? WHERE id = ?'
|
||||||
);
|
);
|
||||||
$stmt->execute([
|
$stmt->execute([
|
||||||
$name,
|
$name,
|
||||||
Slug::make($name),
|
Slug::make($name),
|
||||||
|
$newImagePath,
|
||||||
(int) ($body['sort_order'] ?? 0),
|
(int) ($body['sort_order'] ?? 0),
|
||||||
$id,
|
$id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
Uploads::deleteIfOrphaned($oldImagePath ?: null, $newImagePath);
|
||||||
|
|
||||||
Http::send(['ok' => true]);
|
Http::send(['ok' => true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function destroy(array $params): void
|
public static function destroy(array $params): void
|
||||||
{
|
{
|
||||||
$stmt = Database::connection()->prepare('DELETE FROM brands WHERE id = ?');
|
$id = (int) $params['id'];
|
||||||
$stmt->execute([(int) $params['id']]);
|
$db = Database::connection();
|
||||||
|
|
||||||
|
$oldStmt = $db->prepare('SELECT image_path FROM brands WHERE id = ?');
|
||||||
|
$oldStmt->execute([$id]);
|
||||||
|
$oldImagePath = $oldStmt->fetchColumn();
|
||||||
|
|
||||||
|
// ON DELETE CASCADE raeumt car_models in der DB mit auf - deren Bilddateien vorher
|
||||||
|
// einsammeln, danach sind die Zeilen (und Pfade) weg.
|
||||||
|
$modelImagesStmt = $db->prepare('SELECT image_path FROM car_models WHERE brand_id = ?');
|
||||||
|
$modelImagesStmt->execute([$id]);
|
||||||
|
$modelImages = $modelImagesStmt->fetchAll(\PDO::FETCH_COLUMN);
|
||||||
|
|
||||||
|
$stmt = $db->prepare('DELETE FROM brands WHERE id = ?');
|
||||||
|
$stmt->execute([$id]);
|
||||||
|
|
||||||
|
foreach ([$oldImagePath, ...$modelImages] as $path) {
|
||||||
|
Uploads::deleteIfOrphaned($path ?: null, null);
|
||||||
|
}
|
||||||
|
|
||||||
Http::send(['ok' => true]);
|
Http::send(['ok' => true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,14 @@ namespace App\Controllers;
|
||||||
use App\Config\Database;
|
use App\Config\Database;
|
||||||
use App\Support\Http;
|
use App\Support\Http;
|
||||||
use App\Support\Slug;
|
use App\Support\Slug;
|
||||||
|
use App\Support\Uploads;
|
||||||
|
|
||||||
class ModelController
|
class ModelController
|
||||||
{
|
{
|
||||||
public static function index(): void
|
public static function index(): void
|
||||||
{
|
{
|
||||||
$stmt = Database::connection()->query(
|
$stmt = Database::connection()->query(
|
||||||
'SELECT m.id, m.name, m.slug, m.sort_order, m.brand_id, b.name AS brand_name, b.slug AS brand_slug
|
'SELECT m.id, m.name, m.slug, m.image_path, m.sort_order, m.brand_id, b.name AS brand_name, b.slug AS brand_slug
|
||||||
FROM car_models m JOIN brands b ON b.id = m.brand_id
|
FROM car_models m JOIN brands b ON b.id = m.brand_id
|
||||||
ORDER BY b.name, m.sort_order, m.name'
|
ORDER BY b.name, m.sort_order, m.name'
|
||||||
);
|
);
|
||||||
|
|
@ -30,12 +31,13 @@ class ModelController
|
||||||
|
|
||||||
$db = Database::connection();
|
$db = Database::connection();
|
||||||
$stmt = $db->prepare(
|
$stmt = $db->prepare(
|
||||||
'INSERT INTO car_models (brand_id, name, slug, sort_order) VALUES (?, ?, ?, ?)'
|
'INSERT INTO car_models (brand_id, name, slug, image_path, sort_order) VALUES (?, ?, ?, ?, ?)'
|
||||||
);
|
);
|
||||||
$stmt->execute([
|
$stmt->execute([
|
||||||
$brandId,
|
$brandId,
|
||||||
$name,
|
$name,
|
||||||
Slug::make($name),
|
Slug::make($name),
|
||||||
|
trim($body['image_path'] ?? '') ?: null,
|
||||||
(int) ($body['sort_order'] ?? 0),
|
(int) ($body['sort_order'] ?? 0),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
@ -53,24 +55,43 @@ class ModelController
|
||||||
Http::error('Name und Marke erforderlich', 422);
|
Http::error('Name und Marke erforderlich', 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
$stmt = Database::connection()->prepare(
|
$newImagePath = trim($body['image_path'] ?? '') ?: null;
|
||||||
'UPDATE car_models SET brand_id = ?, name = ?, slug = ?, sort_order = ? WHERE id = ?'
|
$db = Database::connection();
|
||||||
|
$oldStmt = $db->prepare('SELECT image_path FROM car_models WHERE id = ?');
|
||||||
|
$oldStmt->execute([$id]);
|
||||||
|
$oldImagePath = $oldStmt->fetchColumn();
|
||||||
|
|
||||||
|
$stmt = $db->prepare(
|
||||||
|
'UPDATE car_models SET brand_id = ?, name = ?, slug = ?, image_path = ?, sort_order = ? WHERE id = ?'
|
||||||
);
|
);
|
||||||
$stmt->execute([
|
$stmt->execute([
|
||||||
$brandId,
|
$brandId,
|
||||||
$name,
|
$name,
|
||||||
Slug::make($name),
|
Slug::make($name),
|
||||||
|
$newImagePath,
|
||||||
(int) ($body['sort_order'] ?? 0),
|
(int) ($body['sort_order'] ?? 0),
|
||||||
$id,
|
$id,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
Uploads::deleteIfOrphaned($oldImagePath ?: null, $newImagePath);
|
||||||
|
|
||||||
Http::send(['ok' => true]);
|
Http::send(['ok' => true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function destroy(array $params): void
|
public static function destroy(array $params): void
|
||||||
{
|
{
|
||||||
$stmt = Database::connection()->prepare('DELETE FROM car_models WHERE id = ?');
|
$id = (int) $params['id'];
|
||||||
$stmt->execute([(int) $params['id']]);
|
$db = Database::connection();
|
||||||
|
|
||||||
|
$oldStmt = $db->prepare('SELECT image_path FROM car_models WHERE id = ?');
|
||||||
|
$oldStmt->execute([$id]);
|
||||||
|
$oldImagePath = $oldStmt->fetchColumn();
|
||||||
|
|
||||||
|
$stmt = $db->prepare('DELETE FROM car_models WHERE id = ?');
|
||||||
|
$stmt->execute([$id]);
|
||||||
|
|
||||||
|
Uploads::deleteIfOrphaned($oldImagePath ?: null, null);
|
||||||
|
|
||||||
Http::send(['ok' => true]);
|
Http::send(['ok' => true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,8 @@ class SettingsController
|
||||||
// Exporte aus älteren/neueren Versionen (mit weniger/mehr Spalten) importiert
|
// Exporte aus älteren/neueren Versionen (mit weniger/mehr Spalten) importiert
|
||||||
// werden können (fehlende Spalten bekommen einfach ihren DB-Standardwert).
|
// werden können (fehlende Spalten bekommen einfach ihren DB-Standardwert).
|
||||||
private const TABLE_COLUMNS = [
|
private const TABLE_COLUMNS = [
|
||||||
'brands' => ['id', 'name', 'slug', 'sort_order', 'created_at', 'updated_at'],
|
'brands' => ['id', 'name', 'slug', 'image_path', 'sort_order', 'created_at', 'updated_at'],
|
||||||
'car_models' => ['id', 'brand_id', 'name', 'slug', 'sort_order', 'created_at', 'updated_at'],
|
'car_models' => ['id', 'brand_id', 'name', 'slug', 'image_path', 'sort_order', 'created_at', 'updated_at'],
|
||||||
'packages' => ['id', 'car_model_id', 'name', 'slug', 'description', 'markup_type', 'markup_value', 'icon_name', 'tagline', 'price_text', 'is_featured', 'sort_order', 'created_at', 'updated_at'],
|
'packages' => ['id', 'car_model_id', 'name', 'slug', 'description', 'markup_type', 'markup_value', 'icon_name', 'tagline', 'price_text', 'is_featured', 'sort_order', 'created_at', 'updated_at'],
|
||||||
'package_products' => ['id', 'package_id', 'source_url', 'name_override', 'scraped_name', 'scraped_price', 'scraped_currency', 'scraped_image_url', 'price_updated_at', 'scrape_status', 'scrape_error', 'sort_order', 'created_at', 'updated_at'],
|
'package_products' => ['id', 'package_id', 'source_url', 'name_override', 'scraped_name', 'scraped_price', 'scraped_currency', 'scraped_image_url', 'price_updated_at', 'scrape_status', 'scrape_error', 'sort_order', 'created_at', 'updated_at'],
|
||||||
'package_upgrades' => ['id', 'package_id', 'name', 'description', 'price', 'sort_order', 'created_at', 'updated_at'],
|
'package_upgrades' => ['id', 'package_id', 'name', 'description', 'price', 'sort_order', 'created_at', 'updated_at'],
|
||||||
|
|
@ -77,6 +77,8 @@ class SettingsController
|
||||||
'gallery_brands' => 'cover_image_path',
|
'gallery_brands' => 'cover_image_path',
|
||||||
'gallery_projects' => 'cover_image_path',
|
'gallery_projects' => 'cover_image_path',
|
||||||
'gallery_photos' => 'image_path',
|
'gallery_photos' => 'image_path',
|
||||||
|
'brands' => 'image_path',
|
||||||
|
'car_models' => 'image_path',
|
||||||
];
|
];
|
||||||
|
|
||||||
// Kein const, da abhängig von der Umgebung (base_path unterscheidet sich
|
// Kein const, da abhängig von der Umgebung (base_path unterscheidet sich
|
||||||
|
|
|
||||||
|
|
@ -109,6 +109,7 @@ class Schema
|
||||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
name VARCHAR(100) NOT NULL,
|
name VARCHAR(100) NOT NULL,
|
||||||
slug VARCHAR(120) NOT NULL UNIQUE,
|
slug VARCHAR(120) NOT NULL UNIQUE,
|
||||||
|
image_path VARCHAR(255) NULL,
|
||||||
sort_order INT NOT NULL DEFAULT 0,
|
sort_order INT NOT NULL DEFAULT 0,
|
||||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
|
|
@ -119,6 +120,7 @@ class Schema
|
||||||
brand_id INT NOT NULL,
|
brand_id INT NOT NULL,
|
||||||
name VARCHAR(100) NOT NULL,
|
name VARCHAR(100) NOT NULL,
|
||||||
slug VARCHAR(150) NOT NULL,
|
slug VARCHAR(150) NOT NULL,
|
||||||
|
image_path VARCHAR(255) NULL,
|
||||||
sort_order INT NOT NULL DEFAULT 0,
|
sort_order INT NOT NULL DEFAULT 0,
|
||||||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
|
@ -346,6 +348,7 @@ class Schema
|
||||||
'id' => 'INT AUTO_INCREMENT PRIMARY KEY',
|
'id' => 'INT AUTO_INCREMENT PRIMARY KEY',
|
||||||
'name' => 'VARCHAR(100) NOT NULL',
|
'name' => 'VARCHAR(100) NOT NULL',
|
||||||
'slug' => 'VARCHAR(120) NOT NULL',
|
'slug' => 'VARCHAR(120) NOT NULL',
|
||||||
|
'image_path' => 'VARCHAR(255) NULL',
|
||||||
'sort_order' => 'INT NOT NULL DEFAULT 0',
|
'sort_order' => 'INT NOT NULL DEFAULT 0',
|
||||||
'created_at' => 'DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP',
|
'created_at' => 'DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP',
|
||||||
'updated_at' => 'DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
|
'updated_at' => 'DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
|
||||||
|
|
@ -355,6 +358,7 @@ class Schema
|
||||||
'brand_id' => 'INT NOT NULL',
|
'brand_id' => 'INT NOT NULL',
|
||||||
'name' => 'VARCHAR(100) NOT NULL',
|
'name' => 'VARCHAR(100) NOT NULL',
|
||||||
'slug' => 'VARCHAR(150) NOT NULL',
|
'slug' => 'VARCHAR(150) NOT NULL',
|
||||||
|
'image_path' => 'VARCHAR(255) NULL',
|
||||||
'sort_order' => 'INT NOT NULL DEFAULT 0',
|
'sort_order' => 'INT NOT NULL DEFAULT 0',
|
||||||
'created_at' => 'DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP',
|
'created_at' => 'DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP',
|
||||||
'updated_at' => 'DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
|
'updated_at' => 'DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP',
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -43,7 +43,7 @@
|
||||||
"sameAs": ["https://www.youtube.com/@hifiplanet2812"]
|
"sameAs": ["https://www.youtube.com/@hifiplanet2812"]
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<script type="module" crossorigin src="/assets/index-DSPSdxQO.js"></script>
|
<script type="module" crossorigin src="/assets/index-CQBq4yeF.js"></script>
|
||||||
<link rel="modulepreload" crossorigin href="/assets/lucide-icons-66ioQXWI.js">
|
<link rel="modulepreload" crossorigin href="/assets/lucide-icons-66ioQXWI.js">
|
||||||
<link rel="stylesheet" crossorigin href="/assets/index-Cvi6-oeK.css">
|
<link rel="stylesheet" crossorigin href="/assets/index-Cvi6-oeK.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue