Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Controller/Admin/DataObject/ClassController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1820,6 +1820,9 @@ public function getIconsAction(Request $request, EventDispatcherInterface $event
for ($i = $startIndex; $i < $limit; $i++) {
$icon = $icons[$i];
$content = file_get_contents(OPENDXP_WEB_ROOT . $icon);
if ($content === false) {
continue;
}
$result[] = [
'text' => sprintf(
'<img style="%s" src="data:%s;base64,%s"/>',
Expand Down
23 changes: 14 additions & 9 deletions src/Controller/Admin/DataObject/QuantityValueController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\Routing\Attribute\Route;

/**
Expand All @@ -46,6 +47,9 @@ public function unitImportAction(Request $request): JsonResponse
$uploadFile = $request->files->get('Filedata');

$json = file_get_contents($uploadFile->getPathname());
if ($json === false) {
throw new BadRequestHttpException('Failed to read file');
}
$success = $this->service->importDefinitionFromJson($json);
$response = $this->adminJson(['success' => $success]);
$response->headers->set('Content-Type', 'text/html');
Expand Down Expand Up @@ -126,10 +130,14 @@ public function unitProxyAction(Request $request): JsonResponse
$this->checkPermission('quantityValueUnits');

if ($request->request->has('data')) {
$data = json_decode($request->request->get('data'), true);
if (!is_array($data)) {
throw new BadRequestHttpException('Invalid data format');
}
$id = $data['id'];
$unit = Unit::getById($id);

if ($request->query->get('xaction') === 'destroy') {
$data = json_decode($request->request->get('data'), true);
$id = $data['id'];
$unit = \OpenDxp\Model\DataObject\QuantityValue\Unit::getById($id);
if (!empty($unit)) {
$unit->delete();

Expand All @@ -139,8 +147,6 @@ public function unitProxyAction(Request $request): JsonResponse
throw new Exception('Unit with id ' . $id . ' not found.');
}
if ($request->query->get('xaction') === 'update') {
$data = json_decode($request->request->get('data'), true);
$unit = Unit::getById($data['id']);
if (!empty($unit)) {
if (($data['baseunit'] ?? null) == -1) {
$data['baseunit'] = null;
Expand All @@ -151,15 +157,14 @@ public function unitProxyAction(Request $request): JsonResponse
return $this->adminJson(['data' => $unit->getObjectVars(), 'success' => true]);
}

throw new Exception('Unit with id ' . $data['id'] . ' not found.');
throw new Exception('Unit with id ' . $id . ' not found.');
}
if ($request->query->get('xaction') === 'create') {
$data = json_decode($request->request->get('data'), true);
if (isset($data['baseunit']) && $data['baseunit'] === -1) {
$data['baseunit'] = null;
}
$id = $data['id'];
if (Unit::getById($id)) {

if ($unit instanceof Unit) {
throw new Exception('unit with ID [' . $id . '] already exists');
}
if (mb_strlen($id) > 50) {
Expand Down
3 changes: 3 additions & 0 deletions src/GDPR/DataProvider/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public function doExportData(Asset $asset): Response

foreach (array_keys($this->exportIds) as $id) {
$theAsset = Asset::getById((int) $id);
if (!$theAsset instanceof Asset) {
continue;
}

$resultItem = Exporter::exportAsset($theAsset);
$resultItem = json_encode($resultItem);
Expand Down
8 changes: 6 additions & 2 deletions src/GDPR/DataProvider/DataObjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,17 @@ public function doExportData(AbstractObject $object): array
if (!empty($this->exportIds['object'])) {
foreach (array_keys($this->exportIds['object']) as $id) {
$object = AbstractObject::getById((int)$id);
$exportResult[] = Exporter::exportObject($object);
if ($object instanceof AbstractObject) {
$exportResult[] = Exporter::exportObject($object);
}
}
}
if (!empty($this->exportIds['image'])) {
foreach (array_keys($this->exportIds['image']) as $id) {
$theAsset = Asset::getById((int) $id);
$exportResult[] = Exporter::exportAsset($theAsset);
if ($theAsset instanceof Asset) {
$exportResult[] = Exporter::exportAsset($theAsset);
}
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/Twig/Extension/AdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,14 @@ public function getLoginBackgroundImage(string $overwrite = ''): string
#[\Twig\Attribute\AsTwigFilter('opendxp_inline_icon')]
public function inlineIcon(string $icon): string
{
if (!is_file($icon)) {
return '<!-- Icon file not found: ' . htmlspecialchars($icon) . ' -->';
}

$content = file_get_contents($icon);
if ($content === false) {
return '<!-- Failed to read icon file: ' . htmlspecialchars($icon) . ' -->';
}

return sprintf(
'<img src="data:%s;base64,%s" title="%s" data-imgpath="%s" />',
Expand Down
Loading