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 May 15, 2024
1 parent ceee7af commit e64f57e
Show file tree
Hide file tree
Showing 18 changed files with 82 additions and 97 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 @@
Entity 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/entity_tools/actions/workflows/lint.yml/badge.svg?event=push)
[![Latest Stable Version](https://poser.pugx.org/coldtrick/entity_tools/v/stable.svg)](https://packagist.org/packages/coldtrick/entity_tools)
[![License](https://poser.pugx.org/coldtrick/entity_tools/license.svg)](https://packagist.org/packages/coldtrick/entity_tools)
Expand Down
3 changes: 1 addition & 2 deletions classes/ColdTrick/EntityTools/Gatekeeper.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ class Gatekeeper extends ElggGatekeeper {
* @return void
* @throws HttpException
*/
public function __invoke(Request $request) {

public function __invoke(Request $request): void {
parent::__invoke($request);

if (elgg_is_admin_logged_in()) {
Expand Down
33 changes: 11 additions & 22 deletions classes/ColdTrick/EntityTools/Migrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,17 @@
*/
abstract class Migrate {

/**
* @var \ElggObject the entity being migrated
*/
protected $object;

/**
* @var array some of the original attributes of the entity before being changed
*/
protected $original_attributes = [];
protected array $original_attributes = [];

/**
* Create a migration helper object
*
* @param \ElggObject $object the object to migrate
*/
public function __construct(\ElggObject $object) {

$this->object = $object;

public function __construct(protected \ElggObject $object) {
$this->original_attributes = [
'time_created' => $object->time_created,
'owner_guid' => $object->owner_guid,
Expand All @@ -34,11 +26,11 @@ public function __construct(\ElggObject $object) {
}

/**
* Return the object used in the migrate
* Return the object used in this migrate class
*
* @return \ElggObject
*/
public function getObject() {
public function getObject(): \ElggObject {
return $this->object;
}

Expand All @@ -47,7 +39,7 @@ public function getObject() {
*
* @return bool
*/
abstract public function canBackDate();
abstract public function canBackDate(): bool;

/**
* Backdate the entity
Expand All @@ -56,7 +48,7 @@ abstract public function canBackDate();
*
* @return void
*/
public function backDate($new_time) {
public function backDate(int $new_time): void {
$this->object->time_created = $new_time;
}

Expand All @@ -65,7 +57,7 @@ public function backDate($new_time) {
*
* @return bool
*/
abstract public function canChangeOwner();
abstract public function canChangeOwner(): bool;

/**
* Changed the owner_guid of the entity
Expand All @@ -74,8 +66,7 @@ abstract public function canChangeOwner();
*
* @return void
*/
public function changeOwner($new_owner_guid) {

public function changeOwner(int $new_owner_guid): void {
if (!get_user($new_owner_guid)) {
return;
}
Expand All @@ -91,7 +82,7 @@ public function changeOwner($new_owner_guid) {
*
* @return bool
*/
abstract public function canChangeContainer();
abstract public function canChangeContainer(): bool;

/**
* Change the container_guid of the entity
Expand All @@ -100,8 +91,7 @@ abstract public function canChangeContainer();
*
* @return void
*/
public function changeContainer($new_container_guid) {

public function changeContainer(int $new_container_guid): void {
$this->object->container_guid = $new_container_guid;

// check access_id for the new container
Expand All @@ -113,10 +103,9 @@ public function changeContainer($new_container_guid) {
*
* @return void
*/
public function updateAccessID() {
public function updateAccessID(): void {
// ignore access restrictions
elgg_call(ELGG_IGNORE_ACCESS, function() {

$old_access_id = (int) $this->object->access_id;
$new_access_id = $old_access_id;
if (!in_array($new_access_id, [ACCESS_PUBLIC, ACCESS_LOGGED_IN, ACCESS_PRIVATE])) {
Expand Down
12 changes: 6 additions & 6 deletions classes/ColdTrick/EntityTools/Migrate/Blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ public function __construct(\ElggBlog $object) {
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function canBackDate() {
public function canBackDate(): bool {
return true;
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function canChangeOwner() {
public function canChangeOwner(): bool {
return true;
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function canChangeContainer() {
public function canChangeContainer(): bool {
return true;
}
}
12 changes: 6 additions & 6 deletions classes/ColdTrick/EntityTools/Migrate/Discussion.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ public function __construct(\ElggDiscussion $object) {
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function canBackDate() {
public function canBackDate(): bool {
return true;
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function canChangeOwner() {
public function canChangeOwner(): bool {
return true;
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function canChangeContainer() {
public function canChangeContainer(): bool {
return true;
}
}
38 changes: 16 additions & 22 deletions classes/ColdTrick/EntityTools/Migrate/Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,30 @@ public function __construct(\ElggPage $object) {
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function canBackDate() {
public function canBackDate(): bool {
return true;
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function canChangeOwner() {
public function canChangeOwner(): bool {
return true;
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function canChangeContainer() {
public function canChangeContainer(): bool {
return true;
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function changeOwner($new_owner_guid) {

public function changeOwner(int $new_owner_guid): void {
// do all the default stuff
parent::changeOwner($new_owner_guid);

Expand All @@ -53,10 +52,9 @@ public function changeOwner($new_owner_guid) {
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function changeContainer($new_container_guid) {

public function changeContainer(int $new_container_guid): void {
// do all the default stuff
parent::changeContainer($new_container_guid);

Expand All @@ -69,10 +67,9 @@ public function changeContainer($new_container_guid) {
*
* @return void
*/
protected function moveLastRevision() {

protected function moveLastRevision(): void {
/* @var $entity \ElggPage */
$entity = $this->object;
$entity = $this->getObject();
$old_owner_guid = (int) $this->original_attributes['owner_guid'];

// get the last revision
Expand Down Expand Up @@ -106,13 +103,11 @@ protected function moveLastRevision() {
*
* @return void
*/
protected function updateSubpagesOwnerGUID($new_owner_guid) {

protected function updateSubpagesOwnerGUID(int $new_owner_guid): void {
/* @var $entity \ElggPage */
$entity = $this->object;
$entity = $this->getObject();

$old_owner_guid = (int) $this->original_attributes['owner_guid'];
$new_owner_guid = (int) $new_owner_guid;
if ($old_owner_guid === $new_owner_guid) {
return;
}
Expand All @@ -133,8 +128,7 @@ protected function updateSubpagesOwnerGUID($new_owner_guid) {
*
* @return \ElggPage[]
*/
protected function getOwnedSubPages(\ElggPage $entity) {

protected function getOwnedSubPages(\ElggPage $entity): array {
$old_owner_guid = (int) $this->original_attributes['owner_guid'];

return elgg_call(ELGG_IGNORE_ACCESS, function() use ($entity, $old_owner_guid) {
Expand Down Expand Up @@ -175,7 +169,7 @@ protected function getOwnedSubPages(\ElggPage $entity) {
*
* @return void
*/
protected function moveSubpages($new_container_guid) {
protected function moveSubpages(int $new_container_guid): void {
// ignore access for this part
elgg_call(ELGG_IGNORE_ACCESS, function() use ($new_container_guid) {
$batch = elgg_get_entities([
Expand Down
12 changes: 6 additions & 6 deletions classes/ColdTrick/EntityTools/Migrate/TheWire.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ public function __construct(\ElggWire $object) {
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function canBackDate() {
public function canBackDate(): bool {
return true;
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function canChangeOwner() {
public function canChangeOwner(): bool {
return true;
}

/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function canChangeContainer() {
public function canChangeContainer(): bool {
return false;
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"npm-asset/jquery-datetimepicker": "~2.5.21"
},
"conflict": {
"elgg/elgg": "<5.1"
"elgg/elgg": "<6.0"
},
"config": {
"fxp-asset": {
Expand Down
6 changes: 3 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions elgg-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@
'resource' => 'entity_tools/site',
'middleware' => [
Gatekeeper::class,
\Elgg\Router\Middleware\AdminGatekeeper::class,
],
],
'entity_tools:owner' => [
'path' => 'entities/owner/{username}/{subtype?}',
'resource' => 'entity_tools/owner',
'middleware' => [
Gatekeeper::class,
\Elgg\Router\Middleware\UserPageOwnerGatekeeper::class,
\Elgg\Router\Middleware\UserPageOwnerCanEditGatekeeper::class,
],
'detect_page_owner' => true,
],
Expand All @@ -41,7 +42,7 @@
'resource' => 'entity_tools/group',
'middleware' => [
Gatekeeper::class,
\Elgg\Router\Middleware\GroupPageOwnerGatekeeper::class,
\Elgg\Router\Middleware\GroupPageOwnerCanEditGatekeeper::class,
],
'detect_page_owner' => true,
],
Expand Down
4 changes: 2 additions & 2 deletions views/default/forms/entity_tools/update_entities.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
}

.elgg-input-datetime,
.elgg-input-dropdown,
.elgg-input-select,
.elgg-user-picker {
width: 200px;
white-space: nowrap;
}

.elgg-user-picker-list {
.elgg-entity-picker-list {
.elgg-image {
display: none;
}
Expand Down
Loading

0 comments on commit e64f57e

Please sign in to comment.