Skip to content

Commit

Permalink
Merge remote-tracking branch 'remote/master' into sax_master
Browse files Browse the repository at this point in the history
# Conflicts:
#	engine/classes/Elgg/Database/Clauses/AccessWhereClause.php
#	engine/classes/Elgg/Database/Clauses/AnnotationWhereClause.php
#	engine/tests/classes/Elgg/Mocks/Database/AnnotationsTable.php
#	engine/tests/phpunit/unit/Elgg/Database/Clauses/AnnotationWhereClauseUnitTest.php
  • Loading branch information
jeabakker committed Mar 18, 2024
2 parents 62c837b + bbe4be2 commit 89a07e1
Show file tree
Hide file tree
Showing 20 changed files with 124 additions and 576 deletions.
14 changes: 13 additions & 1 deletion docs/appendix/upgrade-notes/5.x-to-6.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ alias for the ``annotations`` table has been changed from ``n_table`` to ``a_tab
If your code uses very specific clauses (select, where, order_by, etc.) you need to update your code. If you use the
``\Elgg\Database\QueryBuilder`` for your query parts you should be ok.

Enabled column
~~~~~~~~~~~~~~

The ``enabled`` column for annotations has been removed. An annotation is no longer enabled or disabled.
You can no longer perform the ``enable`` and ``disable`` API calls on annotations. Other related API functions have been removed.

Entity Icons
------------

Expand Down Expand Up @@ -95,12 +101,18 @@ Changes in functions
Removed lib functions
~~~~~~~~~~~~~~~~~~~~~

* ``elgg_unrequire_css()`` has been removed. Use ``elgg_unregister_external_file('css', $view)`` as replacement.
* ``elgg_disable_annotations()`` has been removed
* ``elgg_enable_annotations()`` has been removed
* ``elgg_set_view_location()`` has been removed
* ``elgg_unrequire_css()`` has been removed. Use ``elgg_unregister_external_file('css', $view)`` as replacement.

Removed class functions
~~~~~~~~~~~~~~~~~~~~~~~

* ``\ElggAnnotation->enable()``
* ``\ElggAnnotation->disable()``
* ``\ElggEntity->disableAnnotations()``
* ``\ElggEntity->enableAnnotations()``
* ``\ElggEntity->getTags()`` use ``elgg_get_metadata()`` as an alternative.

Lib functions function parameters
Expand Down
22 changes: 13 additions & 9 deletions docs/design/database.rst
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,10 @@ Annotations are stored as instances of the ``ElggAnnotation`` class.
Each annotation has:

- An internal annotation type (like *comment*)
- A value (which can be a string or integer)
- A value (which can be a string, a boolean or an integer)
- An access permission distinct from the entity it's attached to
- An owner

Like metadata, values are stored as strings unless the value given is a PHP integer (``is_int($value)`` is true),
or unless the ``$vartype`` is manually specified as ``integer``.

Adding an annotation
--------------------

Expand Down Expand Up @@ -356,6 +353,7 @@ reference). What you need to know is:
- You can potentially have multiple items of each type of metadata
attached to a single entity
- Like annotations, values are stored as strings, booleans or integers
- The metadata name is case sensitive

The simple case
---------------
Expand Down Expand Up @@ -408,7 +406,7 @@ described in the *finer control* section below.

If you stored multiple values in this piece of metadata (as in the
"tags" example above), you will get an array of all those values back.
If you stored only one value, you will get a string or integer back.
If you stored only one value, you will get a string, boolean or integer back.
Storing an array with only one value will return a string back to you.
E.g.

Expand Down Expand Up @@ -448,6 +446,11 @@ Or to get all metadata objects:
'limit' => false,
]);
.. note::

When retrieving metadata by name the names are matched case-insensitive.
Keep your code clean and do not mix uppercase and lowercase metadata names.

Common mistakes
---------------

Expand Down Expand Up @@ -693,6 +696,7 @@ It contains the following fields:
- **access\_id** Access controls on this entity
- **time\_created** Unix timestamp of when the entity is created
- **time\_updated** Unix timestamp of when the entity was updated
- **last\_action** Unix timestamp of when the user last performed an action or when within the entity as container something happened
- **enabled** If this is 'yes' an entity is accessible, if 'no' the entity
has been disabled (Elgg treats it as if it were deleted without actually
removing it from the database)
Expand All @@ -710,9 +714,8 @@ This table contains `Metadata`_, extra information attached to an entity.
- **entity\_guid** The entity this is attached to
- **name** The name string
- **value** The value string
- **value\_type** The value class, either text or an integer
- **value\_type** The value class, either text, bool or an integer
- **time\_created** Unix timestamp of when the metadata is created
- **enabled** If this is 'yes' an item is accessible, if 'no' the item has been disabled

Table: annotations
~~~~~~~~~~~~~~~~~~
Expand All @@ -723,7 +726,7 @@ This table contains `Annotations`_, this is distinct from `Metadata`_.
- **entity\_guid** The entity this is attached to
- **name** The name string
- **value** The value string
- **value\_type** The value class, either text or an integer
- **value\_type** The value class, either text, bool or an integer
- **owner\_guid** The owner GUID of the owner who set this annotation
- **access\_id** An Access controls on this annotation
- **time\_created** Unix timestamp of when the annotation is created.
Expand All @@ -740,6 +743,7 @@ This table defines `Relationships`_, these link one entity with another.
- **guid\_one** The GUID of the subject entity.
- **relationship** The type of the relationship.
- **guid\_two** The GUID of the target entity.
- **time\_created** Unix timestamp of when the relationship is created.

Secundairy tables
-----------------
Expand All @@ -750,6 +754,6 @@ Table: access_collections
This table defines Access Collections, which grant users access to `Entities`_ or `Annotations`_.

- **id** A unique IDentifier
- ***name** The name of the access collection
- **name** The name of the access collection
- **owner_guid** The GUID of the owning entity (eg. a user or a group)
- **subtype** the subtype of the access collection (eg. `friends` or `group_acl`)
13 changes: 2 additions & 11 deletions docs/guides/events-list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,8 @@ User events
**invalidate:after, user**
Triggered when user's account validation has been revoked.

**login:after, user**
Triggered after the user logs in.

**login:before, user**
Triggered during login. Returning false prevents the user from logging
**login, user** |sequence|
Triggered when a user is being logged in.

**login:forward, user** |results|
Filters the URL to which the user will be forwarded after login.
Expand Down Expand Up @@ -434,12 +431,6 @@ Annotation events

**delete, annotation**
Called before annotation is deleted. Return false to prevent deletion.

**disable, annotations**
Called when disabling annotations. Return false to prevent disabling.

**enable, annotation**
Called when enabling annotations. Return false to prevent enabling.

**update, annotation**
Called after the annotation has been updated. Return false to *delete the annotation.*
Expand Down
143 changes: 0 additions & 143 deletions engine/classes/Elgg/Database/AnnotationsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,78 +182,6 @@ public function update(\ElggAnnotation $annotation): bool {
return $result;
}

/**
* Disable the annotation.
*
* @param \ElggAnnotation $annotation Annotation
*
* @return bool
* @since 1.8
*/
public function disable(\ElggAnnotation $annotation): bool {
if ($annotation->enabled === 'no') {
return true;
}

if (!$annotation->canEdit()) {
return false;
}

if (!_elgg_services()->events->trigger('disable', $annotation->getType(), $annotation)) {
return false;
}

if ($annotation->id) {
$qb = Update::table(self::TABLE_NAME);
$qb->set('enabled', $qb->param('no', ELGG_VALUE_STRING))
->where($qb->compare('id', '=', $annotation->id, ELGG_VALUE_INTEGER));

if (!$this->db->updateData($qb)) {
return false;
}
}

$annotation->enabled = 'no';

return true;
}

/**
* Enable the annotation
*
* @param \ElggAnnotation $annotation Annotation
*
* @return bool
* @since 1.8
*/
public function enable(\ElggAnnotation $annotation): bool {
if ($annotation->enabled == 'yes') {
return true;
}

if (!$annotation->canEdit()) {
return false;
}

if (!$this->events->trigger('enable', $annotation->getType(), $annotation)) {
return false;
}

if ($annotation->id) {
$qb = Update::table(self::TABLE_NAME);
$qb->set('enabled', $qb->param('yes', ELGG_VALUE_STRING))
->where($qb->compare('id', '=', $annotation->id, ELGG_VALUE_INTEGER));

if (!$this->db->updateData($qb)) {
return false;
}
}

$annotation->enabled = 'yes';

return true;
}

/**
* Returns annotations. Accepts all {@link elgg_get_entities()} options
*
Expand Down Expand Up @@ -309,77 +237,6 @@ public function deleteAll(array $options): bool {

return $success === $count;
}

/**
* Disables annotations based on $options.
*
* @warning Unlike elgg_get_annotations() this will not accept an empty options array!
*
* @param array $options An options array. {@link elgg_get_annotations()}
* @return bool true on success, false on failure
*/
public function disableAll(array $options): bool {
if (!$this->isValidOptionsForBatchOperation($options)) {
return false;
}

// if we can see hidden (disabled) we need to use the offset
// otherwise we risk an infinite loop if there are more than 50
$inc_offset = _elgg_services()->session_manager->getDisabledEntityVisibility();

$options['batch'] = true;
$options['batch_size'] = 50;
$options['batch_inc_offset'] = $inc_offset;

$annotations = Annotations::find($options);
$count = $annotations->count();

if (!$count) {
return true;
}

$success = 0;
foreach ($annotations as $annotation) {
if ($annotation->disable()) {
$success++;
}
}

return $success === $count;
}

/**
* Enables annotations based on $options.
*
* @warning Unlike elgg_get_annotations() this will not accept an empty options array!
*
* @param array $options An options array. {@link elgg_get_annotations()}
* @return bool true on success, false on failure
*/
public function enableAll(array $options): bool {
if (!$this->isValidOptionsForBatchOperation($options)) {
return false;
}

$options['batch'] = true;
$options['batch_size'] = 50;

$annotations = Annotations::find($options);
$count = $annotations->count();

if (!$count) {
return true;
}

$success = 0;
foreach ($annotations as $annotation) {
if ($annotation->enable()) {
$success++;
}
}

return $success === $count;
}

/**
* Checks if there are some constraints on the options array for potentially dangerous operations
Expand Down
47 changes: 10 additions & 37 deletions engine/classes/Elgg/Database/Clauses/AccessWhereClause.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,23 @@
*/
class AccessWhereClause extends WhereClause {

/**
* @var string
*/
public $access_column = 'access_id';
public string $access_column = 'access_id';

/**
* @var string
*/
public $owner_guid_column = 'owner_guid';
public string $owner_guid_column = 'owner_guid';

/**
* @var string
*/
public $guid_column = 'guid';
public string $guid_column = 'guid';

/**
* @var string
*/
public $enabled_column = 'enabled';
public string $enabled_column = 'enabled';

/**
* @var string
*/
public $soft_deleted_column = 'soft_deleted';
public string $soft_deleted_column = 'soft_deleted';

/**
* @var bool
*/
public $ignore_access;
public ?bool $ignore_access = null;

/**
* @var bool
*/
public $use_enabled_clause;
public ?bool $use_enabled_clause = null;

public ?bool $show_soft_deleted = null;

/**
* @var bool
*/
public $show_soft_deleted;

/**
* @var int
*/
public $viewer_guid;
public ?int $viewer_guid = null;

/**
* {@inheritdoc}
Expand Down
Loading

0 comments on commit 89a07e1

Please sign in to comment.