2026-02-04 23:31:53 +01:00
|
|
|
<?php
|
|
|
|
|
|
2026-02-11 19:28:12 +01:00
|
|
|
namespace MintyPHP\Service\User;
|
2026-02-04 23:31:53 +01:00
|
|
|
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
use MintyPHP\Service\Image\ImageUploadTrait;
|
|
|
|
|
|
2026-02-04 23:31:53 +01:00
|
|
|
class UserAvatarService
|
|
|
|
|
{
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
use ImageUploadTrait;
|
|
|
|
|
|
2026-02-04 23:31:53 +01:00
|
|
|
private const MAX_SIZE = 5242880; // 5 MB
|
|
|
|
|
private const SIZES = [64, 128, 256];
|
|
|
|
|
private const DEFAULT_SIZE = 128;
|
|
|
|
|
|
2026-02-23 12:58:19 +01:00
|
|
|
public function isValidUuid(string $uuid): bool
|
2026-02-04 23:31:53 +01:00
|
|
|
{
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
return self::imageIsValidUuid($uuid);
|
2026-02-04 23:31:53 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-23 12:58:19 +01:00
|
|
|
public function storageBase(): string
|
2026-02-04 23:31:53 +01:00
|
|
|
{
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
return self::imageStorageBase();
|
2026-02-04 23:31:53 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-23 12:58:19 +01:00
|
|
|
public function userDir(string $uuid): string
|
2026-02-04 23:31:53 +01:00
|
|
|
{
|
2026-02-23 12:58:19 +01:00
|
|
|
return $this->storageBase() . '/users/' . $uuid;
|
2026-02-04 23:31:53 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-23 12:58:19 +01:00
|
|
|
public function findAvatarPath(string $uuid, ?int $size = null): ?string
|
2026-02-04 23:31:53 +01:00
|
|
|
{
|
2026-02-23 12:58:19 +01:00
|
|
|
if (!$this->isValidUuid($uuid)) {
|
2026-02-04 23:31:53 +01:00
|
|
|
return null;
|
|
|
|
|
}
|
2026-02-23 12:58:19 +01:00
|
|
|
$dir = $this->userDir($uuid);
|
2026-02-04 23:31:53 +01:00
|
|
|
if (!is_dir($dir)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
if ($size) {
|
2026-02-23 12:58:19 +01:00
|
|
|
$size = $this->normalizeSize($size);
|
|
|
|
|
$variant = $this->findVariantPath($dir, $size);
|
2026-02-04 23:31:53 +01:00
|
|
|
if ($variant) {
|
|
|
|
|
return $variant;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-02-23 12:58:19 +01:00
|
|
|
$defaultVariant = $this->findVariantPath($dir, self::DEFAULT_SIZE);
|
2026-02-04 23:31:53 +01:00
|
|
|
if ($defaultVariant) {
|
|
|
|
|
return $defaultVariant;
|
|
|
|
|
}
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
$original = self::imageFindOriginalPath($dir);
|
2026-02-04 23:31:53 +01:00
|
|
|
return $original ?: null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-23 12:58:19 +01:00
|
|
|
public function hasAvatar(string $uuid): bool
|
2026-02-04 23:31:53 +01:00
|
|
|
{
|
2026-02-23 12:58:19 +01:00
|
|
|
$path = $this->findAvatarPath($uuid);
|
2026-02-04 23:31:53 +01:00
|
|
|
return $path ? is_file($path) : false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-23 12:58:19 +01:00
|
|
|
public function delete(string $uuid): bool
|
2026-02-04 23:31:53 +01:00
|
|
|
{
|
2026-02-23 12:58:19 +01:00
|
|
|
if (!$this->isValidUuid($uuid)) {
|
2026-02-04 23:31:53 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
2026-02-23 12:58:19 +01:00
|
|
|
$dir = $this->userDir($uuid);
|
2026-02-04 23:31:53 +01:00
|
|
|
if (!is_dir($dir)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
$matches = array_merge(
|
|
|
|
|
glob($dir . '/avatar-*.*') ?: [],
|
|
|
|
|
glob($dir . '/avatar.*') ?: [],
|
|
|
|
|
glob($dir . '/original.*') ?: []
|
|
|
|
|
);
|
|
|
|
|
foreach ($matches as $file) {
|
|
|
|
|
if (is_file($file)) {
|
|
|
|
|
@unlink($file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-23 12:58:19 +01:00
|
|
|
public function saveUpload(string $uuid, array $file): array
|
2026-02-04 23:31:53 +01:00
|
|
|
{
|
2026-02-23 12:58:19 +01:00
|
|
|
if (!$this->isValidUuid($uuid)) {
|
2026-02-04 23:31:53 +01:00
|
|
|
return ['ok' => false, 'error' => t('User not found')];
|
|
|
|
|
}
|
|
|
|
|
if (empty($file) || !isset($file['tmp_name'])) {
|
|
|
|
|
return ['ok' => false, 'error' => t('No file uploaded')];
|
|
|
|
|
}
|
|
|
|
|
if (($file['error'] ?? UPLOAD_ERR_NO_FILE) !== UPLOAD_ERR_OK) {
|
|
|
|
|
return ['ok' => false, 'error' => t('Upload failed')];
|
|
|
|
|
}
|
|
|
|
|
if (($file['size'] ?? 0) > self::MAX_SIZE) {
|
|
|
|
|
return ['ok' => false, 'error' => t('File is too large')];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$tmpPath = $file['tmp_name'];
|
2026-02-23 12:58:19 +01:00
|
|
|
$mime = $this->detectMime($tmpPath);
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
$isSvg = self::imageIsSvgUpload($mime, $tmpPath);
|
|
|
|
|
$ext = self::imageExtensionForMime($mime, $isSvg);
|
2026-02-04 23:31:53 +01:00
|
|
|
if (!$ext) {
|
|
|
|
|
return ['ok' => false, 'error' => t('Invalid image file')];
|
|
|
|
|
}
|
2026-03-06 00:44:52 +01:00
|
|
|
// SVG can contain JavaScript — reject files that don't pass the safety check.
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
if ($isSvg && !self::imageIsSafeSvg($tmpPath)) {
|
2026-02-04 23:31:53 +01:00
|
|
|
return ['ok' => false, 'error' => t('Invalid image file')];
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-23 12:58:19 +01:00
|
|
|
$dir = $this->userDir($uuid);
|
2026-02-04 23:31:53 +01:00
|
|
|
if (!is_dir($dir) && !mkdir($dir, 0755, true) && !is_dir($dir)) {
|
|
|
|
|
return ['ok' => false, 'error' => t('Upload failed')];
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-23 12:58:19 +01:00
|
|
|
$this->delete($uuid);
|
2026-02-04 23:31:53 +01:00
|
|
|
$originalPath = $dir . '/original.' . $ext;
|
|
|
|
|
if (!move_uploaded_file($tmpPath, $originalPath)) {
|
|
|
|
|
return ['ok' => false, 'error' => t('Upload failed')];
|
|
|
|
|
}
|
|
|
|
|
@chmod($originalPath, 0644);
|
|
|
|
|
|
2026-03-06 00:44:52 +01:00
|
|
|
// Prefer WebP for variants (better compression); fall back to JPEG if GD lacks WebP support.
|
2026-02-04 23:31:53 +01:00
|
|
|
$variantExt = function_exists('imagewebp') ? 'webp' : 'jpg';
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
if (!$isSvg && self::imageCanResize()) {
|
2026-02-04 23:31:53 +01:00
|
|
|
foreach (self::SIZES as $size) {
|
|
|
|
|
$target = $dir . '/avatar-' . $size . '.' . $variantExt;
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
self::imageResizeAndFit($originalPath, $target, $size, $size, $variantExt);
|
2026-02-04 23:31:53 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ['ok' => true, 'path' => $originalPath, 'mime' => $mime];
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-23 12:58:19 +01:00
|
|
|
public function saveBinary(string $uuid, string $contents, string $mime = ''): array
|
2026-02-04 23:31:53 +01:00
|
|
|
{
|
2026-02-23 12:58:19 +01:00
|
|
|
if (!$this->isValidUuid($uuid)) {
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
return ['ok' => false, 'error' => t('User not found')];
|
2026-02-04 23:31:53 +01:00
|
|
|
}
|
|
|
|
|
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
$size = strlen($contents);
|
|
|
|
|
if ($size <= 0) {
|
|
|
|
|
return ['ok' => false, 'error' => t('Invalid image file')];
|
|
|
|
|
}
|
|
|
|
|
if ($size > self::MAX_SIZE) {
|
|
|
|
|
return ['ok' => false, 'error' => t('File is too large')];
|
2026-02-04 23:31:53 +01:00
|
|
|
}
|
|
|
|
|
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
$tmpPath = tempnam(sys_get_temp_dir(), 'user-avatar-');
|
|
|
|
|
if ($tmpPath === false) {
|
|
|
|
|
return ['ok' => false, 'error' => t('Upload failed')];
|
2026-02-04 23:31:53 +01:00
|
|
|
}
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
if (@file_put_contents($tmpPath, $contents) === false) {
|
|
|
|
|
@unlink($tmpPath);
|
|
|
|
|
return ['ok' => false, 'error' => t('Upload failed')];
|
2026-02-04 23:31:53 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-23 12:58:19 +01:00
|
|
|
$detectedMime = $this->detectMime($tmpPath);
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
if ($detectedMime === 'application/octet-stream') {
|
|
|
|
|
$headerMime = strtolower(trim(explode(';', $mime, 2)[0]));
|
|
|
|
|
if (in_array($headerMime, ['image/jpeg', 'image/png', 'image/webp'], true)) {
|
|
|
|
|
$detectedMime = $headerMime;
|
|
|
|
|
}
|
2026-02-04 23:31:53 +01:00
|
|
|
}
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
$ext = self::imageExtensionForMime($detectedMime, false);
|
|
|
|
|
if (!$ext) {
|
|
|
|
|
@unlink($tmpPath);
|
|
|
|
|
return ['ok' => false, 'error' => t('Invalid image file')];
|
2026-02-04 23:31:53 +01:00
|
|
|
}
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
|
2026-02-23 12:58:19 +01:00
|
|
|
$dir = $this->userDir($uuid);
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
if (!is_dir($dir) && !mkdir($dir, 0755, true) && !is_dir($dir)) {
|
|
|
|
|
@unlink($tmpPath);
|
|
|
|
|
return ['ok' => false, 'error' => t('Upload failed')];
|
2026-02-04 23:31:53 +01:00
|
|
|
}
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
|
2026-02-23 12:58:19 +01:00
|
|
|
$this->delete($uuid);
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
$originalPath = $dir . '/original.' . $ext;
|
2026-03-06 00:44:52 +01:00
|
|
|
// rename() fails across filesystem boundaries (e.g. /tmp → app storage), fall back to copy.
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
if (!@rename($tmpPath, $originalPath)) {
|
|
|
|
|
if (!@copy($tmpPath, $originalPath)) {
|
|
|
|
|
@unlink($tmpPath);
|
|
|
|
|
return ['ok' => false, 'error' => t('Upload failed')];
|
|
|
|
|
}
|
|
|
|
|
@unlink($tmpPath);
|
2026-02-04 23:31:53 +01:00
|
|
|
}
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
@chmod($originalPath, 0644);
|
|
|
|
|
|
|
|
|
|
$variantExt = function_exists('imagewebp') ? 'webp' : 'jpg';
|
|
|
|
|
if (self::imageCanResize()) {
|
|
|
|
|
foreach (self::SIZES as $sizeVariant) {
|
|
|
|
|
$target = $dir . '/avatar-' . $sizeVariant . '.' . $variantExt;
|
|
|
|
|
self::imageResizeAndFit($originalPath, $target, $sizeVariant, $sizeVariant, $variantExt);
|
|
|
|
|
}
|
2026-02-04 23:31:53 +01:00
|
|
|
}
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
|
|
|
|
|
return ['ok' => true, 'path' => $originalPath, 'mime' => $detectedMime];
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-23 12:58:19 +01:00
|
|
|
public function detectMime(string $path): string
|
add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks
- Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists
- Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services
- Add Microsoft OIDC SSO, API token management, and user lifecycle features
- Add swagger-ui vendor integration and OpenAPI spec
- Add production Docker setup and bin/ scripts
- Update composer dependencies, config, templates, and frontend assets throughout
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-22 15:27:35 +01:00
|
|
|
{
|
|
|
|
|
return self::imageDetectMime($path);
|
2026-02-04 23:31:53 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-23 12:58:19 +01:00
|
|
|
private function normalizeSize(int $size): int
|
2026-02-04 23:31:53 +01:00
|
|
|
{
|
|
|
|
|
if (in_array($size, self::SIZES, true)) {
|
|
|
|
|
return $size;
|
|
|
|
|
}
|
|
|
|
|
return self::DEFAULT_SIZE;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-23 12:58:19 +01:00
|
|
|
private function findVariantPath(string $dir, int $size): ?string
|
2026-02-04 23:31:53 +01:00
|
|
|
{
|
|
|
|
|
$matches = glob($dir . '/avatar-' . $size . '.*');
|
|
|
|
|
if (!$matches) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
usort($matches, static function ($a, $b) {
|
|
|
|
|
return filemtime($b) <=> filemtime($a);
|
|
|
|
|
});
|
|
|
|
|
return $matches[0] ?? null;
|
|
|
|
|
}
|
|
|
|
|
}
|