Skip to content

Commit

Permalink
feat(core): added temporary bin
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Finn Thomas <[email protected]>
Co-authored-by: SirDisappointing <[email protected]>
Co-authored-by: Yana Lazareva <[email protected]>
Co-authored-by: Jumanah <[email protected]>
Co-authored-by: bako <[email protected]>
Co-authored-by: 493611 <[email protected]>
Co-authored-by: finndthomas <[email protected]>
Co-authored-by: SirDisappointing <[email protected]>
  • Loading branch information
9 people authored Mar 11, 2024
1 parent 8807978 commit 2074ab7
Show file tree
Hide file tree
Showing 64 changed files with 2,419 additions and 239 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/vendor

# don't ignore bundled plugins
!/mod/bin
!/mod/activity
!/mod/blog/
!/mod/bookmarks/
Expand Down
6 changes: 6 additions & 0 deletions actions/admin/site/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,13 @@
$friendly_time_number_of_days = 30;
}

$bin_cleanup_grace_period = get_input('bin_cleanup_grace_period', 30);
if ($bin_cleanup_grace_period === '') {
$bin_cleanup_grace_period = 30;
}

elgg_save_config('friendly_time_number_of_days', (int) $friendly_time_number_of_days);
elgg_save_config('bin_cleanup_grace_period', (int) $bin_cleanup_grace_period);
elgg_save_config('message_delay', (int) get_input('message_delay', 6));

elgg_invalidate_caches();
Expand Down
109 changes: 109 additions & 0 deletions actions/entity/chooserestoredestination.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php
/**
* Action for choosing destination to restore a post to.
*
*/

$guid = (int) get_input('entity_guid');
$deleter_guid = (int) get_input('deleter_guid');
$destination_container_guid = (int) get_input('destination_container_guid');

$entity = elgg_call(ELGG_SHOW_SOFT_DELETED_ENTITIES, function () use ($guid){
return get_entity($guid);
});
if (!$entity instanceof \ElggEntity) {
return elgg_error_response(elgg_echo('entity:restore:item_not_found'));
}

set_time_limit(0);

// determine what name to show on success
$display_name = $entity->getDisplayName() ?: elgg_echo('entity:restore:item');


$soft_deletable_entities = elgg_entity_types_with_capability('soft_deletable');


if ($entity->getSoftDeleted() === 'yes') {
// restore-and-move: move the entity to new container. Currently NOT fail-safe against fail restore.
if (!$entity->restore(false)) {
return elgg_error_response(elgg_echo('entity:restore:fail', [$display_name]));
}

if (!($entity->overrideEntityContainerID($entity->guid, $entity->type, $entity->subtype, $destination_container_guid))) {
return elgg_error_response(elgg_echo('entity:restore:fail', [$display_name]));
}
}

$type = $entity->getType();
$subtype = $entity->getSubtype();
$container = $entity->getContainerEntity();

// determine forward URL
$forward_url = get_input('forward_url');
if (!empty($forward_url)) {
$forward_url = elgg_normalize_site_url((string) $forward_url);
}

if (empty($forward_url)) {
$forward_url = REFERRER;
$referrer_url = elgg_extract('HTTP_REFERER', $_SERVER, '');
$site_url = elgg_get_site_url();

$find_forward_url = function (\ElggEntity $container = null) use ($type, $subtype) {
$routes = _elgg_services()->routes;

// check if there is a collection route (eg. blog/owner/username)
$route_name = false;
if ($container instanceof \ElggUser) {
$route_name = "collection:{$type}:{$subtype}:owner";
} elseif ($container instanceof \ElggGroup) {
$route_name = "collection:{$type}:{$subtype}:group";
}

if ($route_name && $routes->get($route_name)) {
$params = $routes->resolveRouteParameters($route_name, $container);

return elgg_generate_url($route_name, $params);
}

// no route found, fallback to container url
if ($container instanceof \ElggEntity) {
return $container->getURL();
}

// no container
return '';
};

if (!empty($referrer_url) && elgg_strpos($referrer_url, $site_url) === 0) {
// referer is on current site
$referrer_path = elgg_substr($referrer_url, elgg_strlen($site_url));
$segments = explode('/', $referrer_path);

if (in_array($guid, $segments)) {
// referrer URL contains a reference to the entity that will be deleted
$forward_url = $find_forward_url($container);
}
} elseif ($container instanceof \ElggEntity) {
$forward_url = $find_forward_url($container);
}
}

$success_keys = [
"entity:restore:{$type}:{$subtype}:success",
"entity:restore:{$type}:success",
'entity:restore:success',
];

$message = '';
if (get_input('show_success', true)) {
foreach ($success_keys as $success_key) {
if (elgg_language_key_exists($success_key)) {
$message = elgg_echo($success_key, [$display_name]);
break;
}
}
}

return elgg_ok_response('', $message, $forward_url);
20 changes: 16 additions & 4 deletions actions/entity/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
*/

$guid = (int) get_input('guid');

$entity = get_entity($guid);
$deleter_guid = (int) get_input('deleter_guid');
$entity = elgg_call(ELGG_SHOW_SOFT_DELETED_ENTITIES, function () use ($guid){
return get_entity($guid);
});
if (!$entity instanceof \ElggEntity) {
return elgg_error_response(elgg_echo('entity:delete:item_not_found'));
}
Expand All @@ -23,8 +25,18 @@
$subtype = $entity->getSubtype();
$container = $entity->getContainerEntity();

if (!$entity->delete()) {
return elgg_error_response(elgg_echo('entity:delete:fail', [$display_name]));
$soft_deletable_entities = elgg_entity_types_with_capability('soft_deletable');


$non_recursive_delete = (bool) get_input('recursive', true);
if ($entity->soft_deleted === 'no' && $entity->hasCapability('soft_deletable')) {
if (!$entity->softDelete($deleter_guid)) {
return elgg_error_response(elgg_echo('entity:delete:fail', [$display_name]));
}
} else {
if (!$entity->delete($non_recursive_delete)) {
return elgg_error_response(elgg_echo('entity:delete:fail', [$display_name]));
}
}

// determine forward URL
Expand Down
103 changes: 103 additions & 0 deletions actions/entity/restore.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php
/**
* Default entity restore action
*/

$guid = (int) get_input('guid');
$deleter_guid = (int) get_input('deleter_guid');
$recursive = (bool) get_input('recursive', true);

$entity = elgg_call(ELGG_SHOW_SOFT_DELETED_ENTITIES, function () use ($guid){
return get_entity($guid);
});
if (!$entity instanceof \ElggEntity) {
return elgg_error_response(elgg_echo('entity:restore:item_not_found'));
}

set_time_limit(0);

// determine what name to show on success
$display_name = $entity->getDisplayName() ?: elgg_echo('entity:restore:item');

$type = $entity->getType();
$subtype = $entity->getSubtype();
$container = $entity->getContainerEntity();

$soft_deletable_entities = elgg_entity_types_with_capability('soft_deletable');



if ($entity->getSoftDeleted() === 'yes') {
if (!$entity->restore($recursive)) {
return elgg_error_response(elgg_echo('entity:restore:fail', [$display_name]));
}
}

// determine forward URL
$forward_url = get_input('forward_url');
if (!empty($forward_url)) {
$forward_url = elgg_normalize_site_url((string) $forward_url);
}

if (empty($forward_url)) {
$forward_url = REFERRER;
$referrer_url = elgg_extract('HTTP_REFERER', $_SERVER, '');
$site_url = elgg_get_site_url();

$find_forward_url = function (\ElggEntity $container = null) use ($type, $subtype) {
$routes = _elgg_services()->routes;

// check if there is a collection route (eg. blog/owner/username)
$route_name = false;
if ($container instanceof \ElggUser) {
$route_name = "collection:{$type}:{$subtype}:owner";
} elseif ($container instanceof \ElggGroup) {
$route_name = "collection:{$type}:{$subtype}:group";
}

if ($route_name && $routes->get($route_name)) {
$params = $routes->resolveRouteParameters($route_name, $container);

return elgg_generate_url($route_name, $params);
}

// no route found, fallback to container url
if ($container instanceof \ElggEntity) {
return $container->getURL();
}

// no container
return '';
};

if (!empty($referrer_url) && elgg_strpos($referrer_url, $site_url) === 0) {
// referer is on current site
$referrer_path = elgg_substr($referrer_url, elgg_strlen($site_url));
$segments = explode('/', $referrer_path);

if (in_array($guid, $segments)) {
// referrer URL contains a reference to the entity that will be deleted
$forward_url = $find_forward_url($container);
}
} elseif ($container instanceof \ElggEntity) {
$forward_url = $find_forward_url($container);
}
}

$success_keys = [
"entity:restore:{$type}:{$subtype}:success",
"entity:restore:{$type}:success",
'entity:restore:success',
];

$message = '';
if (get_input('show_success', true)) {
foreach ($success_keys as $success_key) {
if (elgg_language_key_exists($success_key)) {
$message = elgg_echo($success_key, [$display_name]);
break;
}
}
}

return elgg_ok_response('', $message, $forward_url);
7 changes: 7 additions & 0 deletions docs/design/database.rst
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,10 @@ It contains the following fields:
- **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)
- **soft\_deleted** If this is 'yes' an entity is marked for soft deletion,
if 'no' (default) the entity is visibile within the regular site.
If the bin plugin is enabled, soft deleted content is stored in the Temporary Bin.
- **time\_soft\_deleted** Unix timestamp of when the entity was soft deleted.

Table: metadata
~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -724,6 +728,9 @@ This table contains `Annotations`_, this is distinct from `Metadata`_.
- **access\_id** An Access controls on this annotation
- **time\_created** Unix timestamp of when the annotation is created.
- **enabled** If this is 'yes' an item is accessible, if 'no' the item has been disabled
- **soft\_deleted** If this is 'yes' an entity is marked for soft deletion,
if 'no' (default) the entity is visibile within the regular site.
- **time\_soft\_deleted** Unix timestamp of when the entity was soft deleted.

Table: relationships
~~~~~~~~~~~~~~~~~~~~
Expand Down
3 changes: 2 additions & 1 deletion docs/tutorials/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ The instructions are detailed enough that you don't need much previous experienc
indexpage
blog
wysiwyg
widget
widget
temporary_bin
Loading

0 comments on commit 2074ab7

Please sign in to comment.