Elgg  Version master
chooserestoredestination.php
Go to the documentation of this file.
1 <?php
6 $guid = (int) get_input('entity_guid');
7 $destination_container_guid = (array) get_input('destination_container_guid');
9  return is_numeric($value);
10 });
11 $destination_container_guid = array_map(function($value) {
12  return (int) $value;
14 
15 if (empty($guid) || empty($destination_container_guid)) {
16  return elgg_error_response(elgg_echo('error:missing_data'));
17 }
18 
20  return get_entity($guid);
21 });
22 if (!$entity instanceof \ElggEntity || !$entity->isDeleted()) {
23  return elgg_error_response(elgg_echo('entity:restore:item_not_found'));
24 }
25 
27 if (!$new_container instanceof \ElggEntity) {
28  return elgg_error_response(elgg_echo('error:missing_data'));
29 }
30 
31 if (!$new_container->canWriteToContainer(0, $entity->type, $entity->subtype)) {
32  return elgg_error_response(elgg_echo('entity:restore:container_permission', [$new_container->getDisplayName()]));
33 }
34 
35 // determine what name to show on success
36 $display_name = $entity->getDisplayName() ?: elgg_echo('entity:restore:item');
37 
38 if (!$entity->restore()) {
39  return elgg_error_response(elgg_echo('entity:restore:fail', [$display_name]));
40 }
41 
42 $entity->container_guid = $new_container->guid;
43 if (!$entity->save()) {
44  return elgg_error_response(elgg_echo('entity:restore:fail', [$display_name]));
45 }
46 
48  "entity:restore:{$entity->type}:{$entity->subtype}:success",
49  "entity:restore:{$entity->type}:success",
50  'entity:restore:success',
51 ];
52 
53 $message = '';
54 if (get_input('show_success', true)) {
55  foreach ($success_keys as $success_key) {
56  if (elgg_language_key_exists($success_key)) {
57  $message = elgg_echo($success_key, [$display_name]);
58  break;
59  }
60  }
61 }
62 
63 return elgg_ok_response('', $message);
if(empty($guid)||empty($destination_container_guid)) $entity
if(! $entity instanceof \ElggEntity||! $entity->isDeleted()) $new_container
if(! $new_container instanceof \ElggEntity) if(! $new_container->canWriteToContainer(0, $entity->type, $entity->subtype)) $display_name
if(! $entity->save()) $success_keys
$destination_container_guid
$guid
Action for choosing destination to restore a post to.
canWriteToContainer(int $user_guid=0, string $type='', string $subtype='')
Can a user add an entity to this container.
Definition: ElggEntity.php:425
getDisplayName()
Get the entity's display name.
Definition: ElggEntity.php:306
const ELGG_SHOW_DISABLED_ENTITIES
Definition: constants.php:123
const ELGG_SHOW_DELETED_ENTITIES
Definition: constants.php:127
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags.
Definition: elgglib.php:306
get_input(string $variable, $default=null, bool $filter_result=true)
Parameter input functions.
Definition: input.php:20
get_entity(int $guid)
Loads and returns an entity object from a guid.
Definition: entities.php:70
$value
Definition: generic.php:51
elgg_language_key_exists(string $key, string $language='en')
Check if a given language key exists.
Definition: languages.php:44
elgg_echo(string $message_key, array $args=[], string $language='')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
elgg_ok_response($content='', string|array $message='', ?string $forward_url=null, int $status_code=ELGG_HTTP_OK)
Prepares a successful response to be returned by a page or an action handler.
elgg_error_response(string|array $message='', string $forward_url=REFERRER, int $status_code=ELGG_HTTP_BAD_REQUEST)
Prepare an error response to be returned by a page or an action handler.