Skip to content
Draft
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
29 changes: 19 additions & 10 deletions src/Controller/Admin/Asset/AssetHelperController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

namespace OpenDxp\Bundle\AdminBundle\Controller\Admin\Asset;

use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\ParameterType;
use Exception;
use League\Flysystem\FilesystemException;
use League\Flysystem\UnableToReadFile;
Expand Down Expand Up @@ -96,13 +98,14 @@ public function getSharedGridColumnConfigs(User $user, string $classId, ?string
$userIds = [$user->getId()];
// collect all roles
$userIds = [...$userIds, ...$user->getRoles()];
$userIds = implode(',', $userIds);

$query = 'select distinct c1.id from gridconfigs c1, gridconfig_shares s
where (c1.searchType = ' . $db->quote($searchType) . ' and ((c1.id = s.gridConfigId and s.sharedWithUserId IN (' . $userIds . '))) and c1.classId = ' . $db->quote($classId) . ')
UNION distinct select c2.id from gridconfigs c2 where shareGlobally = 1 and c2.classId = '. $db->quote($classId) . ' and c2.ownerId != ' . $db->quote($user->getId());

$ids = $db->fetchFirstColumn($query);
$ids = $db->fetchFirstColumn(
'SELECT DISTINCT c1.id FROM gridconfigs c1, gridconfig_shares s
WHERE (c1.searchType = ? AND c1.id = s.gridConfigId AND s.sharedWithUserId IN (?) AND c1.classId = ?)
UNION DISTINCT SELECT c2.id FROM gridconfigs c2 WHERE shareGlobally = 1 AND c2.classId = ? AND c2.ownerId != ?',
[$searchType, $userIds, $classId, $classId, $user->getId()],
[ParameterType::STRING, ArrayParameterType::INTEGER, ParameterType::STRING, ParameterType::STRING, ParameterType::INTEGER]
);

if ($ids) {
$ids = implode(',', $ids);
Expand Down Expand Up @@ -207,8 +210,11 @@ private function doGetGridColumnConfig(array $params, bool $isDelete = false): a
try {
$userIds = [$this->getAdminUser()->getId()];
$userIds = [...$userIds, ...$this->getAdminUser()->getRoles()];
$userIds = implode(',', $userIds);
$shared = ($savedGridConfig->getOwnerId() !== $userId && $savedGridConfig->isShareGlobally()) || $db->fetchOne('select * from gridconfig_shares where sharedWithUserId IN (' . $userIds . ') and gridConfigId = ' . $savedGridConfig->getId());
$shared = ($savedGridConfig->getOwnerId() !== $userId && $savedGridConfig->isShareGlobally()) || $db->fetchOne(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variable assignment with this condition and implicit type casting is hard to read. I would propose something like this:

$isOwner = $savedGridConfig->getOwnerId() === $userId;
$isGlobalShare = $savedGridConfig->isShareGlobally();
$isSharedViaDb = false;

if (!$isOwner && !$isGlobalShare) {
    $isSharedViaDb = (bool) $db->fetchOne(
        'SELECT 1 FROM gridconfig_shares 
         WHERE sharedWithUserId IN (?) 
         AND gridConfigId = ?',
        [$userIds, $savedGridConfig->getId()],
        [ArrayParameterType::INTEGER, ParameterType::INTEGER]
    );
}

$shared = (!$isOwner && $isGlobalShare) || $isSharedViaDb;

'SELECT * FROM gridconfig_shares WHERE sharedWithUserId IN (?) AND gridConfigId = ?',
[$userIds, $savedGridConfig->getId()],
[ArrayParameterType::INTEGER, ParameterType::INTEGER]
);
} catch (Exception) {
// fail silently?
}
Expand Down Expand Up @@ -432,8 +438,11 @@ protected function getShareSettings(int $gridConfigId): array
];

$db = Db::get();
$allShares = $db->fetchAllAssociative('select s.sharedWithUserId, u.type from gridconfig_shares s, users u
where s.sharedWithUserId = u.id and s.gridConfigId = ' . $gridConfigId);
$allShares = $db->fetchAllAssociative(
'SELECT s.sharedWithUserId, u.type FROM gridconfig_shares s, users u
WHERE s.sharedWithUserId = u.id AND s.gridConfigId = ?',
[$gridConfigId]
);

foreach ($allShares as $share) {
$type = $share['type'];
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Admin/DataObject/ClassController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1838,9 +1838,9 @@ public function getIconsAction(Request $request, EventDispatcherInterface $event
public function suggestClassIdentifierAction(): Response
{
$db = Db::get();
$maxId = $db->fetchOne('SELECT MAX(CAST(id AS SIGNED)) FROM classes;');
$maxId = $db->fetchOne('SELECT MAX(CAST(id AS SIGNED)) FROM classes');

$existingIds = $db->fetchFirstColumn('select LOWER(id) from classes');
$existingIds = $db->fetchFirstColumn('SELECT LOWER(id) FROM classes');

$result = [
'suggestedIdentifier' => $maxId ? $maxId + 1 : 1,
Expand Down
19 changes: 13 additions & 6 deletions src/Controller/Admin/DataObject/ClassificationstoreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace OpenDxp\Bundle\AdminBundle\Controller\Admin\DataObject;

use Doctrine\DBAL\ArrayParameterType;
use Exception;
use OpenDxp\Bundle\AdminBundle\Controller\AdminAbstractController;
use OpenDxp\Controller\KernelControllerEventInterface;
Expand Down Expand Up @@ -218,8 +219,11 @@ public function collectionsActionGet(Request $request): JsonResponse

if ($allowedGroupIds) {
$db = \OpenDxp\Db::get();
$query = 'select * from classificationstore_collectionrelations where groupId in (' . implode(',', $allowedGroupIds) .')';
$relationList = $db->fetchAllAssociative($query);
$relationList = $db->fetchAllAssociative(
'SELECT * FROM classificationstore_collectionrelations WHERE groupId IN (?)',
[$allowedGroupIds],
[ArrayParameterType::INTEGER]
);

foreach ($relationList as $item) {
$allowedCollectionIds[] = $item['colId'];
Expand Down Expand Up @@ -902,9 +906,12 @@ public function addCollectionsAction(Request $request): JsonResponse
if ($ids) {
$db = \OpenDxp\Db::get();
$mappedData = [];
$groupsData = $db->fetchAllAssociative('select * from classificationstore_groups g, classificationstore_collectionrelations c where colId IN (:ids) and g.id = c.groupId', [
'ids' => implode(',', array_filter($ids, is_numeric(...))),
]);
$groupsData = $db->fetchAllAssociative(
'SELECT * FROM classificationstore_groups g, classificationstore_collectionrelations c
WHERE colId IN (?) AND g.id = c.groupId',
[array_values(array_filter($ids, is_numeric(...)))],
[ArrayParameterType::INTEGER]
);

foreach ($groupsData as $groupData) {
$mappedData[$groupData['id']] = $groupData;
Expand Down Expand Up @@ -1434,7 +1441,7 @@ public function getPageAction(Request $request): JsonResponse
) all_rows) item where id = ' . $id . ';';
}

$db->executeQuery('select @rownum := 0;');
$db->executeStatement('SET @rownum = 0');
$result = $db->fetchAllAssociative($query);

$page = (int) $result[0]['page'] ;
Expand Down
7 changes: 3 additions & 4 deletions src/Controller/Admin/DataObject/DataObjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1204,8 +1204,7 @@ protected function reindexBasedOnSortOrder(DataObject\AbstractObject $parentObje

$db = Db::get();
$children = $db->fetchAllAssociative(
'SELECT id, modificationDate, versionCount FROM objects'
.' WHERE parentId = ? ORDER BY `index` ASC',
'SELECT id, modificationDate, versionCount FROM objects WHERE parentId = ? ORDER BY `index` ASC',
[$parentObject->getId()]
);
$index = 0;
Expand Down Expand Up @@ -1279,8 +1278,8 @@ protected function updateIndexesOfObjectSiblings(DataObject\AbstractObject $upda
);

$siblings = $db->fetchAllAssociative(
'SELECT id, modificationDate, versionCount, `key`, `index` FROM objects'
." WHERE parentId = ? AND id != ? AND `type` IN ('object', 'variant','folder') ORDER BY `index` ASC",
'SELECT id, modificationDate, versionCount, `key`, `index` FROM objects
WHERE parentId = ? AND id != ? AND `type` IN ("object", "variant", "folder") ORDER BY `index` ASC',
[$updatedObject->getParentId(), $updatedObject->getId()]
);
$index = 0;
Expand Down
48 changes: 27 additions & 21 deletions src/Controller/Admin/DataObject/DataObjectHelperController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

namespace OpenDxp\Bundle\AdminBundle\Controller\Admin\DataObject;

use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\ParameterType;
use Exception;
use InvalidArgumentException;
use League\Flysystem\FilesystemException;
Expand Down Expand Up @@ -109,14 +111,15 @@ public function getSharedGridColumnConfigs(User $user, string $classId, ?string
$userIds = [$user->getId()];
// collect all roles
$userIds = [...$userIds, ...$user->getRoles()];
$userIds = implode(',', $userIds);
$db = Db::get();

$query = 'select distinct c1.id from gridconfigs c1, gridconfig_shares s
where (c1.searchType = ' . $db->quote($searchType) . ' and ((c1.id = s.gridConfigId and s.sharedWithUserId IN (' . $userIds . '))) and c1.classId = ' . $db->quote($classId) . ')
UNION distinct select c2.id from gridconfigs c2 where shareGlobally = 1 and c2.classId = '. $db->quote($classId) . ' and c2.ownerId != ' . $db->quote($user->getId());

$ids = $db->fetchFirstColumn($query);
$ids = $db->fetchFirstColumn(
'SELECT DISTINCT c1.id FROM gridconfigs c1, gridconfig_shares s
WHERE (c1.searchType = ? AND c1.id = s.gridConfigId AND s.sharedWithUserId IN (?) AND c1.classId = ?)
UNION DISTINCT SELECT c2.id FROM gridconfigs c2 WHERE shareGlobally = 1 AND c2.classId = ? AND c2.ownerId != ?',
[$searchType, $userIds, $classId, $classId, $user->getId()],
[ParameterType::STRING, ArrayParameterType::INTEGER, ParameterType::STRING, ParameterType::STRING, ParameterType::INTEGER]
);

if ($ids) {
$ids = implode(',', $ids);
Expand Down Expand Up @@ -307,8 +310,11 @@ private function doGetGridColumnConfig(Request $request, array $params, Config $
if (!$this->getAdminUser()->isAdmin()) {
$userIds = [$this->getAdminUser()->getId()];
$userIds = [...$userIds, ...$this->getAdminUser()->getRoles()];
$userIds = implode(',', $userIds);
$shared = ($savedGridConfig->getOwnerId() !== $userId && $savedGridConfig->isShareGlobally()) || $db->fetchOne('select 1 from gridconfig_shares where sharedWithUserId IN ('.$userIds.') and gridConfigId = '.$savedGridConfig->getId());
$shared = ($savedGridConfig->getOwnerId() !== $userId && $savedGridConfig->isShareGlobally()) || $db->fetchOne(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code readability? same like in AssetHelperController

'SELECT 1 FROM gridconfig_shares WHERE sharedWithUserId IN (?) AND gridConfigId = ?',
[$userIds, $savedGridConfig->getId()],
[ArrayParameterType::INTEGER, ParameterType::INTEGER]
);
// $shared = $savedGridConfig->isShareGlobally() || GridConfigShare::getByGridConfigAndSharedWithId($savedGridConfig->getId(), $this->getUser()->getId());

if (!$shared && $savedGridConfig->getOwnerId() !== $this->getAdminUser()->getId()) {
Expand Down Expand Up @@ -716,11 +722,10 @@ public function gridConfigApplyToAllAction(Request $request): JsonResponse
$searchType = $request->request->get('searchType');
$user = $this->getAdminUser();
$db = Db::get();
$db->executeQuery('delete from gridconfig_favourites where '
. 'ownerId = ' . $user->getId()
. ' and classId = ' . $db->quote($classId) .
' and searchType = ' . $db->quote($searchType)
. ' and objectId != ' . $objectId . ' and objectId != 0');
$db->executeStatement(
'DELETE FROM gridconfig_favourites WHERE ownerId = ? AND classId = ? AND searchType = ? AND objectId != ? AND objectId != 0',
[$user->getId(), $classId, $searchType, $objectId]
);

return $this->adminJson(['success' => true]);
}
Expand Down Expand Up @@ -766,12 +771,10 @@ public function gridMarkFavouriteColumnConfigAction(Request $request): JsonRespo
$favourite->save();
}
$db = Db::get();
$count = $db->fetchOne('select * from gridconfig_favourites where '
. 'ownerId = ' . $user->getId()
. ' and classId = ' . $db->quote($classId).
' and searchType = ' . $db->quote($searchType)
. ' and objectId != ' . $objectId . ' and objectId != 0'
. ' and `type` != ' . $db->quote($type));
$count = $db->fetchOne(
'SELECT * FROM gridconfig_favourites WHERE ownerId = ? AND classId = ? AND searchType = ? AND objectId != ? AND objectId != 0 AND `type` != ?',
[$user->getId(), $classId, $searchType, $objectId, $type]
);
$specializedConfigs = $count > 0;
} catch (Exception) {
$favourite->delete();
Expand All @@ -791,8 +794,11 @@ protected function getShareSettings(int $gridConfigId): array
];

$db = Db::get();
$allShares = $db->fetchAllAssociative('select s.sharedWithUserId, u.type from gridconfig_shares s, users u
where s.sharedWithUserId = u.id and s.gridConfigId = ' . $gridConfigId);
$allShares = $db->fetchAllAssociative(
'SELECT s.sharedWithUserId, u.type FROM gridconfig_shares s, users u
WHERE s.sharedWithUserId = u.id AND s.gridConfigId = ?',
[$gridConfigId]
);

foreach ($allShares as $share) {
$type = $share['type'];
Expand Down
15 changes: 12 additions & 3 deletions src/Controller/Admin/PortalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,18 @@ public function portletModificationStatisticsAction(Request $request): JsonRespo
$end = $startDate - ($i * 86400);
$start = $end - 86399;

$o = $db->fetchOne('SELECT COUNT(*) AS count FROM objects WHERE modificationDate > '.$start . ' AND modificationDate < '.$end);
$a = $db->fetchOne('SELECT COUNT(*) AS count FROM assets WHERE modificationDate > '.$start . ' AND modificationDate < '.$end);
$d = $db->fetchOne('SELECT COUNT(*) AS count FROM documents WHERE modificationDate > '.$start . ' AND modificationDate < '.$end);
$o = $db->fetchOne(
'SELECT COUNT(*) AS count FROM objects WHERE modificationDate > ? AND modificationDate < ?',
[$start, $end]
);
$a = $db->fetchOne(
'SELECT COUNT(*) AS count FROM assets WHERE modificationDate > ? AND modificationDate < ?',
[$start, $end]
);
$d = $db->fetchOne(
'SELECT COUNT(*) AS count FROM documents WHERE modificationDate > ? AND modificationDate < ?',
[$start, $end]
);

$date = new DateTime();
$date->setTimestamp($start);
Expand Down
7 changes: 3 additions & 4 deletions src/Controller/Admin/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ public function clearTemporaryFilesAction(EventDispatcherInterface $eventDispatc

// public files
Tool\Storage::get('thumbnail')->deleteDirectory('/');
Db::get()->executeQuery('TRUNCATE TABLE assets_image_thumbnail_cache');
Db::get()->executeStatement('TRUNCATE TABLE assets_image_thumbnail_cache');

Tool\Storage::get('asset_cache')->deleteDirectory('/');

Expand Down Expand Up @@ -1199,12 +1199,11 @@ public function getAvailableAlgorithmsAction(Request $request): JsonResponse
protected function deleteViews(string $language, string $dbName): void
{
$db = \OpenDxp\Db::get();
$views = $db->fetchAllAssociative('SHOW FULL TABLES IN ' . $db->quoteIdentifier($dbName) . " WHERE TABLE_TYPE LIKE 'VIEW'");
$views = $db->fetchAllAssociative(sprintf('SHOW FULL TABLES IN %s WHERE TABLE_TYPE LIKE "VIEW"', $db->quoteIdentifier($dbName)));

foreach ($views as $view) {
if (preg_match('/^object_localized_[0-9]+_' . $language . '$/', $view['Tables_in_' . $dbName])) {
$sql = 'DROP VIEW ' . $db->quoteIdentifier($view['Tables_in_' . $dbName]);
$db->executeQuery($sql);
$db->executeStatement(sprintf('DROP VIEW %s', $db->quoteIdentifier($view['Tables_in_' . $dbName])));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/DataObject/GridColumnConfig/Operator/RequiredBy.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ public function getLabeledValue(array|ElementInterface $element): stdClass
}

if ($this->getOnlyCount()) {
$query = 'select count(*) from dependencies where targettype = ? AND targetid = ?'. $typeCondition;
$query = 'SELECT COUNT(*) FROM dependencies WHERE targettype = ? AND targetid = ?' . $typeCondition;
$count = $db->fetchOne($query, [Service::getElementType($element), $element->getId()]);
$result->value = $count;
} else {
$resultList = [];
$query = 'select * from dependencies where targettype = ? AND targetid = ?'. $typeCondition;
$query = 'SELECT * FROM dependencies WHERE targettype = ? AND targetid = ?' . $typeCondition;
$dependencies = $db->fetchAllAssociative($query, [Service::getElementType($element), $element->getId()]);
foreach ($dependencies as $dependency) {
$sourceType = $dependency['sourcetype'];
Expand Down
21 changes: 15 additions & 6 deletions src/EventListener/GridConfigListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

namespace OpenDxp\Bundle\AdminBundle\EventListener;

use Doctrine\DBAL\ArrayParameterType;
use OpenDxp\Db;
use OpenDxp\Event\DataObjectClassDefinitionEvents;
use OpenDxp\Event\DataObjectEvents;
Expand Down Expand Up @@ -54,9 +55,13 @@ public function onClassDelete(ClassDefinitionEvent $event): void

// collect gridConfigs for that class id
$db = Db::get();
$gridConfigIds = $db->fetchFirstColumn('select id from gridconfigs where classId = ?', [$classId]);
$gridConfigIds = $db->fetchFirstColumn('SELECT id FROM gridconfigs WHERE classId = ?', [$classId]);
if ($gridConfigIds) {
$db->executeQuery('delete from gridconfig_shares where gridConfigId in (' . implode('', $gridConfigIds) . ')');
$db->executeStatement(
'DELETE FROM gridconfig_shares WHERE gridConfigId IN (?)',
[$gridConfigIds],
[ArrayParameterType::INTEGER]
);
}

$this->cleanupGridConfigs('classId = ' . $db->quote($classId));
Expand All @@ -70,9 +75,13 @@ public function onUserDelete(UserRoleEvent $event): void

$db = Db::get();

$gridConfigIds = $db->fetchFirstColumn('select id from gridconfigs where ownerId = ' . $userId);
$gridConfigIds = $db->fetchFirstColumn('SELECT id FROM gridconfigs WHERE ownerId = ?', [$userId]);
if ($gridConfigIds) {
$db->executeQuery('delete from gridconfig_shares where gridConfigId in (' . implode('', $gridConfigIds) . ')');
$db->executeStatement(
'DELETE FROM gridconfig_shares WHERE gridConfigId IN (?)',
[$gridConfigIds],
[ArrayParameterType::INTEGER]
);
}

$this->cleanupGridConfigs('ownerId = ' . $userId);
Expand All @@ -82,12 +91,12 @@ public function onUserDelete(UserRoleEvent $event): void
protected function cleanupGridConfigs(string $condition): void
{
$db = Db::get();
$db->executeQuery('DELETE FROM gridconfigs where ' . $condition);
$db->executeStatement('DELETE FROM gridconfigs WHERE ' . $condition);
}

protected function cleanupGridConfigFavourites(string $condition): void
{
$db = Db::get();
$db->executeQuery('DELETE FROM gridconfig_favourites where ' . $condition);
$db->executeStatement('DELETE FROM gridconfig_favourites WHERE ' . $condition);
}
}
Loading