Add optional images to slides
Slides (except YouTube) can carry one image. Uploads are validated, rotated by EXIF orientation, scaled to 1600 px and stored as WebP outside webroot, which also strips camera metadata. Images have an alt text (or are marked decorative) and a layout: top, side or full screen (content slides). Files are removed after the commit when a slide is deleted or its image is replaced, with the poll, and `bin/cake images_cleanup` sweeps leftovers. Duplicated slides get their own file. Docker image gains gd with WebP. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
8c7818ee40
commit
a395b50894
30 files changed
+1705
-11
No files matched your search
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
use Migrations\BaseMigration;
|
||||
|
||||
/**
|
||||
* One optional image per slide. The (scaled) file lives in the upload directory, see
|
||||
* \App\Service\ImageService; the table only holds its random file name and how to show it.
|
||||
*/
|
||||
class AddImageToSlides extends BaseMigration
|
||||
{
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
$table = $this->table('slides');
|
||||
$columns = [
|
||||
// file name inside the poll's upload directory (null = no image)
|
||||
'image' => ['string', ['null' => true, 'default' => null, 'limit' => 40]],
|
||||
// alternative text, '' = purely decorative image
|
||||
'image_alt' => ['string', ['null' => true, 'default' => null, 'limit' => 255]],
|
||||
// top | side | full (null = default of the slide type)
|
||||
'image_layout' => ['string', ['null' => true, 'default' => null, 'limit' => 8]],
|
||||
'image_width' => ['integer', ['null' => true, 'default' => null]],
|
||||
'image_height' => ['integer', ['null' => true, 'default' => null]],
|
||||
];
|
||||
$changed = false;
|
||||
foreach ($columns as $name => [$type, $options]) {
|
||||
if (!$table->hasColumn($name)) {
|
||||
$table->addColumn($name, $type, $options);
|
||||
$changed = true;
|
||||
}
|
||||
}
|
||||
if ($changed) {
|
||||
$table->update();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
$table = $this->table('slides');
|
||||
foreach (['image', 'image_alt', 'image_layout', 'image_width', 'image_height'] as $name) {
|
||||
if ($table->hasColumn($name)) {
|
||||
$table->removeColumn($name);
|
||||
}
|
||||
}
|
||||
$table->update();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user