Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some more small fixes to cherry-pick. #1294

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
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
16 changes: 9 additions & 7 deletions application/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,16 @@ public function filterMedia(ZendEvent $event)
$qb->innerJoin('omeka_root.item', $itemAlias);

// Users can view media they do not own that belong to public items.
$expression = $qb->expr()->eq("$itemAlias.isPublic", true);
$expr = $qb->expr();
$expression = $expr->eq("$itemAlias.isPublic", true);

$identity = $this->getServiceLocator()
->get('Omeka\AuthenticationService')->getIdentity();
if ($identity) {
// Users can view all media they own.
$expression = $qb->expr()->orX(
$expression = $expr->orX(
$expression,
$qb->expr()->eq(
$expr->eq(
"$itemAlias.owner",
$adapter->createNamedParameter($qb, $identity)
)
Expand All @@ -399,23 +400,24 @@ public function filterSites(ZendEvent $event)
$qb = $event->getParam('queryBuilder');

// Users can view sites they do not own that are public.
$expression = $qb->expr()->eq("omeka_root.isPublic", true);
$expr = $qb->expr();
$expression = $expr->eq("omeka_root.isPublic", true);

$identity = $this->getServiceLocator()
->get('Omeka\AuthenticationService')->getIdentity();
if ($identity) {
$sitePermissionAlias = $adapter->createAlias();
$qb->leftJoin('omeka_root.sitePermissions', $sitePermissionAlias);

$expression = $qb->expr()->orX(
$expression = $expr->orX(
$expression,
// Users can view all sites they own.
$qb->expr()->eq(
$expr->eq(
'omeka_root.owner',
$adapter->createNamedParameter($qb, $identity)
),
// Users can view sites where they have a role (any role).
$qb->expr()->eq(
$expr->eq(
"$sitePermissionAlias.user",
$adapter->createNamedParameter($qb, $identity)
)
Expand Down
2 changes: 1 addition & 1 deletion application/asset/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@

$('.batch-edit td input[type="checkbox"]').change(function() {
if ($('.select-all:checked').length > 0) {
$('.select-all').prop('checked', false);
$('.select-all').prop('checked', false);
}
Omeka.manageSelectedActions();
});
Expand Down
34 changes: 18 additions & 16 deletions application/asset/js/ckeditor_config.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
/**
* @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or http://ckeditor.com/license
* For licensing, see LICENSE.md or https://ckeditor.com/license
*/
CKEDITOR.editorConfig = function( config ) {
// Define changes to default configuration here.
// For complete reference see:
// http://docs.ckeditor.com/#!/api/CKEDITOR.config
// https://docs.ckeditor.com/#!/api/CKEDITOR.config

config.toolbar = [
{ "name" : "advanced", "items" :
['Sourcedialog', '-',
'Link', 'Unlink', 'Anchor', '-',
'Format', 'Styles', 'PasteFromWord'
]
},
"/",
{ "items" :
['Bold', 'Italic', 'Underline', 'Strike', '-',
'NumberedList', 'BulletedList', 'Indent', 'Outdent', 'Blockquote'
]
}
];
{
'name': 'advanced',
'items': [
'Sourcedialog', '-',
'Link', 'Unlink', 'Anchor', '-',
'Format', 'Styles', 'PasteFromWord',
],
},
'/',
{
'items': [
'Bold', 'Italic', 'Underline', 'Strike', '-',
'NumberedList', 'BulletedList', 'Indent', 'Outdent', 'Blockquote',
],
},
];

// Disable content filtering
config.allowedContent = true;
config.extraPlugins = 'sourcedialog';
};

42 changes: 16 additions & 26 deletions application/src/Api/Adapter/AbstractEntityAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use Omeka\Api\Exception;
use Omeka\Api\Request;
use Omeka\Api\Response;
use Omeka\Entity\User;
use Omeka\Entity\EntityInterface;
use Omeka\Entity\User;
use Omeka\Stdlib\ErrorStore;
use Laminas\EventManager\Event;

Expand Down Expand Up @@ -212,28 +212,16 @@ public function search(Request $request)
$query = $request->getContent();

// Set default query parameters
if (!isset($query['page'])) {
$query['page'] = null;
}
if (!isset($query['per_page'])) {
$query['per_page'] = null;
}
if (!isset($query['limit'])) {
$query['limit'] = null;
}
if (!isset($query['offset'])) {
$query['offset'] = null;
}
if (!isset($query['sort_by'])) {
$query['sort_by'] = null;
}
if (isset($query['sort_order'])
&& in_array(strtoupper($query['sort_order']), ['ASC', 'DESC'])
) {
$query['sort_order'] = strtoupper($query['sort_order']);
} else {
$query['sort_order'] = 'ASC';
}
$defaultQuery = [
'page' => null,
'per_page' => null,
'limit' => null,
'offset' => null,
'sort_by' => null,
'sort_order' => null,
];
$query += $defaultQuery;
$query['sort_order'] = strtoupper($query['sort_order']) === 'DESC' ? 'DESC' : 'ASC';

// Begin building the search query.
$entityClass = $this->getEntityClass();
Expand Down Expand Up @@ -667,8 +655,9 @@ public function findEntity($criteria, $request = null)
$this->index = 0;
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('omeka_root')->from($entityClass, 'omeka_root');
$expr = $qb->expr();
foreach ($criteria as $field => $value) {
$qb->andWhere($qb->expr()->eq(
$qb->andWhere($expr->eq(
"omeka_root.$field",
$this->createNamedParameter($qb, $value)
));
Expand Down Expand Up @@ -747,18 +736,19 @@ public function isUnique(EntityInterface $entity, array $criteria)
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('e.id')
->from($this->getEntityClass(), 'e');
$expr = $qb->expr();

// Exclude the passed entity from the query if it has an persistent
// indentifier.
if ($entity->getId()) {
$qb->andWhere($qb->expr()->neq(
$qb->andWhere($expr->neq(
'e.id',
$this->createNamedParameter($qb, $entity->getId())
));
}

foreach ($criteria as $field => $value) {
$qb->andWhere($qb->expr()->eq(
$qb->andWhere($expr->eq(
"e.$field",
$this->createNamedParameter($qb, $value)
));
Expand Down
63 changes: 35 additions & 28 deletions application/src/Api/Adapter/AbstractResourceEntityAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ abstract class AbstractResourceEntityAdapter extends AbstractEntityAdapter imple
public function buildQuery(QueryBuilder $qb, array $query)
{
$this->buildPropertyQuery($qb, $query);
$expr = $qb->expr();

if (isset($query['search'])) {
$this->buildPropertyQuery($qb, ['property' => [[
Expand All @@ -30,7 +31,7 @@ public function buildQuery(QueryBuilder $qb, array $query)
'omeka_root.owner',
$userAlias
);
$qb->andWhere($qb->expr()->eq(
$qb->andWhere($expr->eq(
"$userAlias.id",
$this->createNamedParameter($qb, $query['owner_id']))
);
Expand All @@ -42,7 +43,7 @@ public function buildQuery(QueryBuilder $qb, array $query)
'omeka_root.resourceClass',
$resourceClassAlias
);
$qb->andWhere($qb->expr()->eq(
$qb->andWhere($expr->eq(
"$resourceClassAlias.label",
$this->createNamedParameter($qb, $query['resource_class_label']))
);
Expand All @@ -55,7 +56,7 @@ public function buildQuery(QueryBuilder $qb, array $query)
}
$classes = array_filter($classes, 'is_numeric');
if ($classes) {
$qb->andWhere($qb->expr()->in(
$qb->andWhere($expr->in(
'omeka_root.resourceClass',
$this->createNamedParameter($qb, $classes)
));
Expand All @@ -68,7 +69,7 @@ public function buildQuery(QueryBuilder $qb, array $query)
'omeka_root.resourceTemplate',
$resourceTemplateAlias
);
$qb->andWhere($qb->expr()->eq(
$qb->andWhere($expr->eq(
"$resourceTemplateAlias.label",
$this->createNamedParameter($qb, $query['resource_template_label']))
);
Expand All @@ -81,15 +82,15 @@ public function buildQuery(QueryBuilder $qb, array $query)
}
$templates = array_filter($templates, 'is_numeric');
if ($templates) {
$qb->andWhere($qb->expr()->in(
$qb->andWhere($expr->in(
'omeka_root.resourceTemplate',
$this->createNamedParameter($qb, $templates)
));
}
}

if (isset($query['is_public']) && (is_numeric($query['is_public']) || is_bool($query['is_public']))) {
$qb->andWhere($qb->expr()->eq(
$qb->andWhere($expr->eq(
'omeka_root.isPublic',
$this->createNamedParameter($qb, (bool) $query['is_public'])
));
Expand Down Expand Up @@ -131,7 +132,7 @@ public function sortQuery(QueryBuilder $qb, array $query)
public function hydrate(Request $request, EntityInterface $entity,
ErrorStore $errorStore
) {
$data = $request->getContent();
// $data = $request->getContent();

if ($this->shouldHydrate($request, 'o:is_public')) {
$entity->setIsPublic($request->getValue('o:is_public', true));
Expand Down Expand Up @@ -209,8 +210,12 @@ protected function buildPropertyQuery(QueryBuilder $qb, array $query)
if (!isset($query['property']) || !is_array($query['property'])) {
return;
}

$expr = $qb->expr();
$valuesJoin = 'omeka_root.values';
$where = '';
// @see \Doctrine\ORM\QueryBuilder::expr().
$expr = $qb->expr();

foreach ($query['property'] as $queryRow) {
if (!(is_array($queryRow)
Expand Down Expand Up @@ -241,11 +246,11 @@ protected function buildPropertyQuery(QueryBuilder $qb, array $query)
->createQueryBuilder()
->select("$subqueryAlias.id")
->from('Omeka\Entity\Resource', $subqueryAlias)
->where($qb->expr()->eq("$subqueryAlias.title", $param));
$predicateExpr = $qb->expr()->orX(
$qb->expr()->in("$valuesAlias.valueResource", $subquery->getDQL()),
$qb->expr()->eq("$valuesAlias.value", $param),
$qb->expr()->eq("$valuesAlias.uri", $param)
->where($expr->eq("$subqueryAlias.title", $param));
$predicateExpr = $expr->orX(
$expr->in("$valuesAlias.valueResource", $subquery->getDQL()),
$expr->eq("$valuesAlias.value", $param),
$expr->eq("$valuesAlias.uri", $param)
);
break;
case 'nin':
Expand All @@ -257,25 +262,26 @@ protected function buildPropertyQuery(QueryBuilder $qb, array $query)
->createQueryBuilder()
->select("$subqueryAlias.id")
->from('Omeka\Entity\Resource', $subqueryAlias)
->where($qb->expr()->like("$subqueryAlias.title", $param));
$predicateExpr = $qb->expr()->orX(
$qb->expr()->in("$valuesAlias.valueResource", $subquery->getDQL()),
$qb->expr()->like("$valuesAlias.value", $param),
$qb->expr()->like("$valuesAlias.uri", $param)
->where($expr->like("$subqueryAlias.title", $param));
$predicateExpr = $expr->orX(
$expr->in("$valuesAlias.valueResource", $subquery->getDQL()),
$expr->like("$valuesAlias.value", $param),
$expr->like("$valuesAlias.uri", $param)
);
break;

case 'nres':
$positive = false;
case 'res':
$predicateExpr = $qb->expr()->eq(
$predicateExpr = $expr->eq(
"$valuesAlias.valueResource",
$this->createNamedParameter($qb, $value)
);
break;
case 'nex':
$positive = false;
case 'ex':
$predicateExpr = $qb->expr()->isNotNull("$valuesAlias.id");
$predicateExpr = $expr->isNotNull("$valuesAlias.id");
break;
default:
continue 2;
Expand All @@ -294,18 +300,18 @@ protected function buildPropertyQuery(QueryBuilder $qb, array $query)
$propertyId = 0;
}
}
$joinConditions[] = $qb->expr()->eq("$valuesAlias.property", (int) $propertyId);
$joinConditions[] = $expr->eq("$valuesAlias.property", (int) $propertyId);
}

if ($positive) {
$whereClause = '(' . $predicateExpr . ')';
} else {
$joinConditions[] = $predicateExpr;
$whereClause = $qb->expr()->isNull("$valuesAlias.id");
$whereClause = $expr->isNull("$valuesAlias.id");
}

if ($joinConditions) {
$qb->leftJoin($valuesJoin, $valuesAlias, 'WITH', $qb->expr()->andX(...$joinConditions));
$qb->leftJoin($valuesJoin, $valuesAlias, 'WITH', $expr->andX(...$joinConditions));
} else {
$qb->leftJoin($valuesJoin, $valuesAlias);
}
Expand Down Expand Up @@ -369,26 +375,27 @@ public function getSubjectValues(Resource $resource, $page = null, $perPage = nu

$em = $this->getEntityManager();
$qb = $em->createQueryBuilder();
$expr = $qb->expr();
$qb->select('v')
->from('Omeka\Entity\Value', 'v')
->join('v.resource', 'r')
->where($qb->expr()->eq('v.valueResource', $this->createNamedParameter($qb, $resource)))
->where($expr->eq('v.valueResource', $this->createNamedParameter($qb, $resource)))
// Limit subject values to those belonging to primary resources.
->andWhere($qb->expr()->orX(
->andWhere($expr->orX(
'r INSTANCE OF Omeka\Entity\Item',
'r INSTANCE OF Omeka\Entity\ItemSet',
'r INSTANCE OF Omeka\Entity\Media'
));

if (!$acl->userIsAllowed('Omeka\Entity\Resource', 'view-all')) {
$qb->andWhere($qb->expr()->orX(
$qb->expr()->eq('r.isPublic', '1'),
$qb->expr()->eq('r.owner', $this->createNamedParameter($qb, $identity))
$qb->andWhere($expr->orX(
$expr->eq('r.isPublic', '1'),
$expr->eq('r.owner', $this->createNamedParameter($qb, $identity))
));
}

if ($property) {
$qb->andWhere($qb->expr()->eq('v.property', $this->createNamedParameter($qb, $property)));
$qb->andWhere($expr->eq('v.property', $this->createNamedParameter($qb, $property)));
}

$qb->setMaxResults($perPage);
Expand Down
2 changes: 1 addition & 1 deletion application/src/Api/Adapter/AssetAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function buildQuery(QueryBuilder $qb, array $query)

public function hydrate(Request $request, EntityInterface $entity, ErrorStore $errorStore)
{
$data = $request->getContent();
// $data = $request->getContent();

if (Request::CREATE === $request->getOperation()) {
$fileData = $request->getFileData();
Expand Down
Loading