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 = (int) get_input('destination_container_guid');
8 
9 if (empty($guid) || empty($destination_container_guid)) {
10  return elgg_error_response(elgg_echo('error:missing_data'));
11 }
12 
14  return get_entity($guid);
15 });
16 if (!$entity instanceof \ElggEntity || !$entity->isDeleted()) {
17  return elgg_error_response(elgg_echo('entity:restore:item_not_found'));
18 }
19 
21 if (!$new_container instanceof \ElggEntity) {
22  return elgg_error_response(elgg_echo('error:missing_data'));
23 }
24 
25 if (!$new_container->canWriteToContainer(0, $entity->type, $entity->subtype)) {
26  return elgg_error_response(elgg_echo('entity:restore:container_permission', [$new_container->getDisplayName()]));
27 }
28 
29 // determine what name to show on success
30 $display_name = $entity->getDisplayName() ?: elgg_echo('entity:restore:item');
31 
32 if (!$entity->restore()) {
33  return elgg_error_response(elgg_echo('entity:restore:fail', [$display_name]));
34 }
35 
36 $entity->container_guid = $new_container->guid;
37 if (!$entity->save()) {
38  return elgg_error_response(elgg_echo('entity:restore:fail', [$display_name]));
39 }
40 
42  "entity:restore:{$entity->type}:{$entity->subtype}:success",
43  "entity:restore:{$entity->type}:success",
44  'entity:restore:success',
45 ];
46 
47 $message = '';
48 if (get_input('show_success', true)) {
49  foreach ($success_keys as $success_key) {
50  if (elgg_language_key_exists($success_key)) {
51  $message = elgg_echo($success_key, [$display_name]);
52  break;
53  }
54  }
55 }
56 
57 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:296
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:68
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.