Skip to content

Commit

Permalink
changed: updated for Elgg 6
Browse files Browse the repository at this point in the history
  • Loading branch information
jeabakker committed Jun 11, 2024
1 parent 3e4193b commit a6dcf90
Show file tree
Hide file tree
Showing 93 changed files with 948 additions and 948 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: PHPUnit Plugin Tests
on: [push, pull_request]

jobs:
lint:
phpunit:
name: Run PHPUnit test suites
uses: ColdTrick/.github/.github/workflows/phpunit.yml@master
with:
elgg_major_version: 6
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Group Tools
===========

![Elgg 5.1](https://img.shields.io/badge/Elgg-5.1-green.svg)
![Elgg 6.0](https://img.shields.io/badge/Elgg-6.0-green.svg)
![Lint Checks](https://github.com/ColdTrick/group_tools/actions/workflows/lint.yml/badge.svg?event=push)
[![Latest Stable Version](https://poser.pugx.org/coldtrick/group_tools/v/stable.svg)](https://packagist.org/packages/coldtrick/group_tools)
[![License](https://poser.pugx.org/coldtrick/group_tools/license.svg)](https://packagist.org/packages/coldtrick/group_tools)
Expand Down
2 changes: 1 addition & 1 deletion actions/group_tools/admin/approve.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
if ($access_id === ACCESS_PRIVATE) {
$group_acl = $group->getOwnedAccessCollection('group_acl');

$access_id = ($group_acl instanceof ElggAccessCollection) ? (int) $group_acl->id : ACCESS_LOGGED_IN;
$access_id = ($group_acl instanceof \ElggAccessCollection) ? (int) $group_acl->id : ACCESS_LOGGED_IN;
}
}

Expand Down
2 changes: 1 addition & 1 deletion actions/group_tools/remove_concept_status.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
if ($access_id === ACCESS_PRIVATE) {
$group_acl = $group->getOwnedAccessCollection('group_acl');

$access_id = ($group_acl instanceof ElggAccessCollection) ? (int) $group_acl->id : ACCESS_LOGGED_IN;
$access_id = ($group_acl instanceof \ElggAccessCollection) ? (int) $group_acl->id : ACCESS_LOGGED_IN;
}
}

Expand Down
2 changes: 1 addition & 1 deletion actions/groups/decline_email_invitation.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
return elgg_error_response(elgg_echo('error:missing_data'));
}

// ignore access in order to cleanup the invitation
// ignore access in order to clean up the invitation
$deleted = elgg_call(ELGG_IGNORE_ACCESS, function() use ($invitecode) {
return elgg_delete_annotations([
'annotation_name' => 'email_invitation',
Expand Down
3 changes: 0 additions & 3 deletions actions/groups/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,6 @@

// group creator needs to be member of new group and river entry created
if ($is_new_group) {
// @todo this should not be necessary...
elgg_set_page_owner_guid($group->guid);

$group->join($user);
elgg_create_river_item([
'view' => 'river/group/create',
Expand Down
4 changes: 1 addition & 3 deletions actions/groups/email_invitation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
use Elgg\Database\QueryBuilder;

$invitecode = get_input('invitecode');

$user = elgg_get_logged_in_user_entity();

if (empty($invitecode)) {
return elgg_error_response(elgg_echo('error:missing_data'));
}
Expand All @@ -18,6 +15,7 @@
return elgg_error_response(elgg_echo('group_tools:action:groups:email_invitation:error:code'));
}

$user = elgg_get_logged_in_user_entity();
if (!$group->join($user)) {
return elgg_error_response(elgg_echo('group_tools:action:groups:email_invitation:error:join', [$group->getDisplayName()]));
}
Expand Down
91 changes: 45 additions & 46 deletions actions/groups/invite.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,57 +129,56 @@
// this could take a while
set_time_limit(0);

$fh = fopen($csv->getPathname(), 'r');

if (!empty($fh)) {
while (($data = fgetcsv($fh, 0, ';')) !== false) {
/*
* data structure
* data[0] => e-mail address
*/
$email = '';
if (isset($data[0])) {
$email = trim($data[0]);
}

if (empty($email) || !elgg_is_valid_email($email)) {
$fh = $csv->openFile('r');
while (!$fh->eof()) {
/*
* data structure
* data[0] => e-mail address
*/
$data = $fh->fgetcsv(';');

$email = '';
if (isset($data[0])) {
$email = trim($data[0]);
}

if (empty($email) || !elgg_is_valid_email($email)) {
continue;
}

$user = elgg_get_user_by_email($email);
if ($user instanceof \ElggUser) {
// found a user with this email on the site, so invite (or add)
if ($group->isMember($user)) {
$member++;
continue;
}

$user = elgg_get_user_by_email($email);
if ($user instanceof \ElggUser) {
// found a user with this email on the site, so invite (or add)
if ($group->isMember($user)) {
$member++;
continue;
if ($adding) {
if (group_tools_add_user($group, $user, $text)) {
$join++;
}

if ($adding) {
if (group_tools_add_user($group, $user, $text)) {
$join++;
}

continue;
}

if ($group->hasRelationship($user->guid, 'invited') && !$resend) {
// user was already invited
$already_invited++;
continue;
}

// invite user
if (group_tools_invite_user($group, $user, $text, $resend)) {
$invited++;
}
} else {
// user not found so invite based on email address
$invite_result = group_tools_invite_email($group, $email, $text, $resend);
if ($invite_result === true) {
$invited++;
} elseif ($invite_result === null) {
$already_invited++;
}
continue;
}

if ($group->hasRelationship($user->guid, 'invited') && !$resend) {
// user was already invited
$already_invited++;
continue;
}

// invite user
if (group_tools_invite_user($group, $user, $text, $resend)) {
$invited++;
}
} else {
// user not found so invite based on email address
$invite_result = group_tools_invite_email($group, $email, $text, $resend);
if ($invite_result === true) {
$invited++;
} elseif ($invite_result === null) {
$already_invited++;
}
}
}
Expand Down
26 changes: 14 additions & 12 deletions classes/ColdTrick/GroupTools/Cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace ColdTrick\GroupTools;

use Doctrine\DBAL\Query\QueryBuilder as DBalQueryBuilder;
use Elgg\Database\EntityTable;
use Elgg\Database\MetadataTable;
use Elgg\Database\QueryBuilder;
use Elgg\Values;

Expand Down Expand Up @@ -55,7 +57,7 @@ public static function notifyStaleGroupOwners(\Elgg\Event $event): void {
*
* @return \ElggGroup[]
*/
protected static function findStaleGroups($ts) {
protected static function findStaleGroups(int $ts): array {
if (empty($ts)) {
return [];
}
Expand Down Expand Up @@ -94,11 +96,11 @@ protected static function findStaleGroups($ts) {
'callback' => $row_to_guid,
'wheres' => [
function (QueryBuilder $qb, $main_alias) use ($compare_ts_lower, $compare_ts_upper) {
$select = $qb->subquery('metadata', 'tmd');
$select->select('tmd.entity_guid')
->andWhere($qb->compare('tmd.name', '=', 'group_tools_stale_touch_ts', ELGG_VALUE_STRING))
->andWhere($qb->compare('tmd.value', '>', $compare_ts_lower, ELGG_VALUE_INTEGER))
->andWhere($qb->compare('tmd.value', '<', $compare_ts_upper, ELGG_VALUE_INTEGER));
$select = $qb->subquery(MetadataTable::TABLE_NAME, 'tmd');
$select->select("{$select->getTableAlias()}.entity_guid")
->andWhere($qb->compare("{$select->getTableAlias()}.name", '=', 'group_tools_stale_touch_ts', ELGG_VALUE_STRING))
->andWhere($qb->compare("{$select->getTableAlias()}.value", '>', $compare_ts_lower, ELGG_VALUE_INTEGER))
->andWhere($qb->compare("{$select->getTableAlias()}.value", '<', $compare_ts_upper, ELGG_VALUE_INTEGER));

return $qb->compare("{$main_alias}.guid", 'IN', $select->getSQL());
},
Expand Down Expand Up @@ -133,7 +135,7 @@ function (QueryBuilder $qb, $main_alias) use ($compare_ts_lower, $compare_ts_upp
'callback' => $row_to_guid,
'wheres' => [
function (QueryBuilder $qb, $main_alias) use ($object_subtypes, $compare_ts_lower, $compare_ts_upper) {
$content_sub = $qb->subquery('entities');
$content_sub = $qb->subquery(EntityTable::TABLE_NAME);
$content_sub->select('container_guid', 'max(time_updated) as time_updated')
->where($qb->compare('type', '=', 'object', ELGG_VALUE_STRING))
->andWhere($qb->compare('subtype', 'in', $object_subtypes, ELGG_VALUE_STRING))
Expand Down Expand Up @@ -162,11 +164,11 @@ function (QueryBuilder $qb, $main_alias) use ($object_subtypes, $compare_ts_lowe
'callback' => $row_to_guid,
'wheres' => [
function (QueryBuilder $qb, $main_alias) use ($compare_ts_lower, $compare_ts_upper) {
$comments_sub = $qb->subquery('entities', 're');
$comments_sub->joinEntitiesTable('re', 'container_guid', 'inner', 'ce');
$comments_sub->select('ce.container_guid', 'max(re.time_updated) as time_updated')
->where($qb->compare('re.type', '=', 'object', ELGG_VALUE_STRING))
->andWhere($qb->compare('re.subtype', '=', 'comment', ELGG_VALUE_STRING))
$comments_sub = $qb->subquery(EntityTable::TABLE_NAME, 're');
$comments_sub->joinEntitiesTable($comments_sub->getTableAlias(), 'container_guid', 'inner', 'ce');
$comments_sub->select('ce.container_guid', "max({$comments_sub->getTableAlias()}.time_updated) as time_updated")
->where($qb->compare("{$comments_sub->getTableAlias()}.type", '=', 'object', ELGG_VALUE_STRING))
->andWhere($qb->compare("{$comments_sub->getTableAlias()}.subtype", '=', 'comment', ELGG_VALUE_STRING))
->groupBy('ce.container_guid');

$container_sub = new DBalQueryBuilder($qb->getConnection());
Expand Down
18 changes: 1 addition & 17 deletions classes/ColdTrick/GroupTools/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Membership {
protected static $NOTIFICATIONS_TOGGLE;

/**
* Listen to the delete of a membership request
* Listen to the delete event of a membership request
*
* @param \Elgg\Event $event 'delete', 'relationship'
*
Expand Down Expand Up @@ -258,22 +258,6 @@ protected static function sendWelcomeMessage(\ElggUser $recipient, \ElggGroup $g
notify_user($recipient->guid, $group->guid, $subject, $welcome_message, $mail_params);
}

/**
* Validate that the relationship is a site membership relationship
*
* @param \ElggRelationship $relationship the relationship to check
*
* @return bool
*/
protected static function validateSiteJoinRelationship($relationship): bool {

if (!$relationship instanceof \ElggRelationship || $relationship->relationship !== 'member_of_site') {
return false;
}

return get_user($relationship->guid_one) instanceof \ElggUser;
}

/**
* Listen to the validate user event
*
Expand Down
2 changes: 2 additions & 0 deletions classes/ColdTrick/GroupTools/Menus/Annotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public static function registerEmailInvitation(\Elgg\Event $event): ?MenuItems {
/* @var $result MenuItems */
$result = $event->getValue();

$result->remove('delete');

$result[] = \ElggMenuItem::factory([
'name' => 'revoke',
'text' => elgg_echo('revoke'),
Expand Down
11 changes: 6 additions & 5 deletions classes/ColdTrick/GroupTools/Menus/Title.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ public static function groupInvite(\Elgg\Event $event): ?MenuItems {
return null;
}

$entity = $event->getEntityParam();
$user = elgg_get_logged_in_user_entity();
if (!$entity instanceof \ElggGroup || !$user instanceof \ElggUser) {
if (!$user instanceof \ElggUser) {
return null;
}

Expand Down Expand Up @@ -123,7 +122,8 @@ public static function groupInvite(\Elgg\Event $event): ?MenuItems {
}

// this is only allowed for group members
if (!$entity->isMember($user)) {
$entity = $event->getEntityParam();
if ($entity instanceof \ElggGroup || !$entity->isMember($user)) {
return null;
}

Expand Down Expand Up @@ -309,7 +309,7 @@ public static function conceptGroup(\Elgg\Event $event): ?MenuItems {
'edit',
'delete',
'entity_explorer', // developer tools
'opensearch_inspect', // opensearch
'opensearch_inspect', // OpenSearch
];

/* @var $return MenuItems */
Expand Down Expand Up @@ -388,11 +388,12 @@ public static function addGroupToolPresets(\Elgg\Event $event): ?MenuItems {
}

$url = elgg_generate_url('add:group:group', [
'container_guid' => $user->guid,
'guid' => $user->guid,
]);

if ($add_button->getHref() !== $url) {
// not the group add button
var_dump($url, $add_button->getHref());
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,13 @@ public function getSubscriptions(): array {
]);
/* @var $user \ElggUser */
foreach ($batch as $user) {
if (!(bool) elgg_get_plugin_user_setting('notify_approval', $user->guid, 'group_tools')) {
// only if the admin wants the notifications
$settings = $user->getNotificationSettings('group_tools_group_approval');
$settings = array_keys(array_filter($settings));
if (empty($settings)) {
continue;
}

$notification_settings = $user->getNotificationSettings();
if (empty($notification_settings)) {
continue;
}

$return[$user->guid] = array_keys(array_filter($notification_settings));
$return[$user->guid] = $settings;
}

return $return;
Expand Down
19 changes: 11 additions & 8 deletions classes/ColdTrick/GroupTools/Plugins/CSVExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,17 @@ function (QueryBuilder $qb, $main_alias) use ($entity) {
return $qb->compare("{$main_alias}.guid", '!=', $entity->owner_guid, ELGG_VALUE_GUID);
},
],
'batch' => true,
];

$exportable_value = $event->getParam('exportable_value');
switch ($exportable_value) {
case 'group_tools_user_group_admin_name':
$result = [];
$batch = new \ElggBatch('elgg_get_entities', $group_admin_options);

/* @var $batch \ElggBatch */
$batch = elgg_get_entities($group_admin_options);

/* @var $group_admin \ElggUser */
foreach ($batch as $group_admin) {
$result[] = "\"{$group_admin->getDisplayName()}\"";
Expand All @@ -213,7 +217,10 @@ function (QueryBuilder $qb, $main_alias) use ($entity) {

case 'group_tools_user_group_admin_url':
$result = [];
$batch = new \ElggBatch('elgg_get_entities', $group_admin_options);

/* @var $batch \ElggBatch */
$batch = elgg_get_entities($group_admin_options);

/* @var $group_admin \ElggUser */
foreach ($batch as $group_admin) {
$result[] = $group_admin->getURL();
Expand Down Expand Up @@ -362,7 +369,7 @@ public static function addApprovalReasons(\Elgg\Event $event): ?array {
*/
public static function exportApprovalReasons(\Elgg\Event $event) {
$return = $event->getValue();
if (!is_null($return)) {
if (!is_null($return) || $event->getParam('exportable_value') !== 'group_tools_admin_approval_reason_question') {
// someone already provided output
return null;
}
Expand All @@ -387,10 +394,6 @@ public static function exportApprovalReasons(\Elgg\Event $event) {
return unserialize($value);
};

$exportable_value = $event->getParam('exportable_value');
switch ($exportable_value) {
case 'group_tools_admin_approval_reason_question':
return $get_annotation_value('question');
}
return $get_annotation_value('question');
}
}
Loading

0 comments on commit a6dcf90

Please sign in to comment.