Restores a trashItem.

@param $trashItemId

@throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException

@return \eZ\Publish\Core\REST\Server\Values\ResourceCreated
330115
public function restoreTrashItem($trashItemId, Request $request)
    {
        $requestDestination = null;
        try {
            $requestDestination = $request->headers->get('Destination');
        } catch (InvalidArgumentException $e) {
            // No Destination header
        }

        $parentLocation = null;
        if ($request->headers->has('Destination')) {
            $locationPathParts = explode(
                '/',
                $this->requestParser->parseHref($request->headers->get('Destination'), 'locationPath')
            );

            try {
                $parentLocation = $this->locationService->loadLocation(array_pop($locationPathParts));
            } catch (NotFoundException $e) {
                throw new ForbiddenException($e->getMessage());
            }
        }

        $trashItem = $this->trashService->loadTrashItem($trashItemId);

        if ($requestDestination === null) {
            // If we're recovering under the original location
            // check if it exists, to return "403 Forbidden" in case it does not
            try {
                $this->locationService->loadLocation($trashItem->parentLocationId);
            } catch (NotFoundException $e) {
                throw new ForbiddenException($e->getMessage());
            }
        }

        $location = $this->trashService->recover($trashItem, $parentLocation);

        return new Values\ResourceCreated(
            $this->router->generate(
                'ezpublish_rest_loadLocation',
                array(
                    'locationPath' => trim($location->pathString, '/'),
                )
            )
        );
    }
1346782
public function index($trashed = false)
    {
        $this->authorize(PostsPolicy::PERMISSION_LIST);

        $posts = $this->post->with(['author', 'category'])->when($trashed, function ($query) {
            return $query->onlyTrashed();
        })->paginate(30);

        $title = trans('blog::posts.titles.posts-list');
        $this->setTitle($title . ($trashed ? ' - '.trans('core::generals.trashed') : ''));
        $this->addBreadcrumb($title);

        return $this->view('admin.posts.index', compact('trashed', 'posts'));
    }
442953
public function postRestore()
    {
        $oHttpCodes = Factory::service('HttpCodes');

        if (!userHasPermission('admin:cdn:manager:object:restore')) {
            throw new ApiException(
                'You do not have permission to access this resource',
                $oHttpCodes::STATUS_UNAUTHORIZED
            );
        }

        $oInput    = Factory::service('Input');
        $oCdn      = Factory::service('Cdn', 'nails/module-cdn');
        $iObjectId = $oInput->post('object_id');

        if (!$oCdn->objectRestore($iObjectId)) {
            throw new ApiException(
                $oCdn->lastError(),
                $oHttpCodes::STATUS_INTERNAL_SERVER_ERROR
            );
        }

        return Factory::factory('ApiResponse', 'nails/module-api');
    }
549592
public function getTrashService()
    {
        if ($this->trashService !== null) {
            return $this->trashService;
        }

        $this->trashService = new TrashService(
            $this,
            $this->persistenceHandler,
            $this->getNameSchemaService(),
            $this->getPermissionCriterionResolver(),
            $this->serviceSettings['trash']
        );

        return $this->trashService;
    }
682066
public function setLastMod($lastmod)
    {
        try {
            parent::setLastMod($lastmod);
        } catch (UrlItemException $e) {
            throw new IndexItemException($e->getMessage());
        }

        return $this;
    }
418436
public function findOnlyTrashed($modelitemId)
    {
        $this->model = $this->model->onlyTrashed()->findOrFail($modelitemId);

        return $this->model;
    }
483662
public function reorderItems()
    {
        if (!$this->request->isAll(['ajax', 'post'])) {
            throw new MethodNotAllowedException();
        }

        if (empty($this->request->data)) {
            throw new BadRequestException();
        }

        $this->request->data = Hash::map($this->request->data, '{n}', function($item) {
            if ($item['parent_id'] === 'null') {
                $item['parent_id'] = null;
            }
            return $item;
        });

        // save the new language positions
        $menuItems = $this->MenuItems->patchEntities(
            $this->MenuItems->find('threaded'),
            $this->request->data
        );
        $this->MenuItems->connection()->begin();
        foreach ($menuItems as $menuItem) {
            $this->MenuItems->behaviors()->unload('Tree');
            if (!$this->MenuItems->save($menuItem)) {
                $this->MenuItems->connection()->rollback();
                break;
            }
        }
        if ($this->MenuItems->connection()->inTransaction()) {
            $this->MenuItems->connection()->commit();
            $status = 'success';
            $flashMessage = __d('wasabi_core', 'The menu item positions have been updated.');
        } else {
            $status = 'error';
            $flashMessage = $this->dbErrorMessage;
        }

        $this->set([
            'status' => $status,
            'flashMessage' => $flashMessage,
            '_serialize' => ['status', 'flashMessage']
        ]);
    }
444553
public function postRestore($modelitemId)
    {
        if (!$this->modelAdmin->hasSoftDeleting()) {
            return $this->missingMethod();
        }

        $this->modelAdmin->restore($modelitemId);

        return redirect($this->modelAdmin->currentUrl())->with('notifications_below_header', [['type' => 'success', 'icon' => 'check-circle', 'title' => 'Success!', 'message' => 'The '.$this->modelAdmin->getTitle().' was successfully restored.', 'dismissable' => false]]);
    }
210648
public function trashAction()
    {
        if (false === $this->admin->isGranted('LIST')) {
            throw new AccessDeniedException();
        }

        $em = $this->getDoctrine()->getManager();
        $em->getFilters()->disable('softdeleteable');
        $em->getFilters()->enable('softdeleteabletrash');
        $em->getFilters()->getFilter("softdeleteabletrash")->enableForEntity($this->admin->getClass());

        $datagrid = $this->admin->getDatagrid();
        $formView = $datagrid->getForm()->createView();

        // set the theme for the current Admin Form
        $this->get('twig')->getExtension('form')->renderer->setTheme($formView, $this->admin->getFilterTheme());

        return $this->render($this->admin->getTemplate('trash'), array(
            'action'     => 'trash',
            'form'       => $formView,
            'datagrid'   => $datagrid,
            'csrf_token' => $this->getCsrfToken('sonata.batch'),
        ));
    }
1067184
protected function buildAttributesResolver(ItemInterface $templateItem)
    {
        $resolver = new AttributesResolver();
        $resolver->setDefault('taxonomy_attribute', 'categories', 'string')
            ->setDefault('permalink', '/:name')
            ->setDefault('pagination_permalink', '/page:num', 'string');

        $attributes = $templateItem->getAttributes();

        return $resolver->resolve($attributes);
    }
890164
public function delete_item( $request ) {

		$force = isset( $request['force'] ) ? (bool) $request['force'] : false;

		// We don't support trashing for this resource type.
		if ( ! $force ) {
			return new WP_Error( 'rest_trash_not_supported', __( 'Resource does not support trashing.' ), array( 'status' => 501 ) );
		}

		$term = get_term( (int) $request['id'], $this->taxonomy );
		$request->set_param( 'context', 'view' );
		$response = $this->prepare_item_for_response( $term, $request );

		$retval = wp_delete_term( $term->term_id, $term->taxonomy );
		if ( ! $retval ) {
			return new WP_Error( 'rest_cannot_delete', __( 'The resource cannot be deleted.' ), array( 'status' => 500 ) );
		}

		/**
		 * Fires after a single term is deleted via the REST API.
		 *
		 * @param WP_Term          $term     The deleted term.
		 * @param WP_REST_Response $response The response data.
		 * @param WP_REST_Request  $request  The request sent to the API.
		 */
		do_action( "rest_delete_{$this->taxonomy}", $term, $response, $request );

		return $response;
	}
154592
protected static function get_backup_ids_cached($restoreid, $itemname, $itemid) {
        global $DB;

        $key = "$itemid $itemname $restoreid";

        // If record exists in cache then return.
        if (isset(self::$backupidsexist[$key]) && isset(self::$backupidscache[$key])) {
            // Return a copy of cached data, to avoid any alterations in cached data.
            return clone self::$backupidscache[$key];
        }

        // Clean cache, if it's full.
        if (self::$backupidscachesize <= 0) {
            // Remove some records, to keep memory in limit.
            self::$backupidscache = array_slice(self::$backupidscache, self::$backupidsslice, null, true);
            self::$backupidscachesize = self::$backupidscachesize + self::$backupidsslice;
        }
        if (self::$backupidsexistsize <= 0) {
            self::$backupidsexist = array_slice(self::$backupidsexist, self::$backupidsslice, null, true);
            self::$backupidsexistsize = self::$backupidsexistsize + self::$backupidsslice;
        }

        // Retrive record from database.
        $record = array(
            'backupid' => $restoreid,
            'itemname' => $itemname,
            'itemid'   => $itemid
        );
        if ($dbrec = $DB->get_record('backup_ids_temp', $record)) {
            self::$backupidsexist[$key] = $dbrec->id;
            self::$backupidscache[$key] = $dbrec;
            self::$backupidscachesize--;
            self::$backupidsexistsize--;
            return $dbrec;
        } else {
            return false;
        }
    }
672549
public function create(Resource\ResourceData $resourceData)
    {
        return $this->crudRepositoryAdapter->createResource($this->resourceType, $resourceData);
    }
98914
public function urlServe($objectId, $forceDownload = false)
    {
        $isTrashed = false;

        if (empty($objectId)) {
            $oObj = $this->emptyObject();
        } elseif (is_numeric($objectId)) {

            $oObj = $this->getObject($objectId);

            if (!$oObj) {

                /**
                 * If the user is a logged in admin with can_browse_trash permission then have a look in the trash
                 */

                if (userHasPermission('admin:cdn:trash:browse')) {
                    $oObj = $this->getObjectFromTrash($objectId);
                    if (!$oObj) {
                        //  Cool, guess it really doesn't exist. Let the renderer show a bad_src graphic
                        $oObj = $this->emptyObject();
                    } else {
                        $isTrashed = true;
                    }
                } else {
                    //  Let the renderer show a bad_src graphic
                    $oObj = $this->emptyObject();
                }
            }
        } elseif (is_object($objectId)) {
            $oObj = $objectId;
        } else {
            throw new UrlException('Supplied $objectId must be numeric or an object', 1);
        }

        $url = $this->callDriver(
            'urlServe',
            [$oObj->file->name->disk, $oObj->bucket->slug, $forceDownload],
            $oObj->driver
        );
        $url .= $isTrashed ? '?trashed=1' : '';

        return $url;
    }
32143
public function deleteDriveItem($driveItemId)
    {
        $message = sprintf(
            '%s() is deprecated and will be removed in version 3;'
                . ' use Krizalys\Onedrive\Proxy\DriveItemProxy::delete()'
                . ' instead',
            __METHOD__
        );

        @trigger_error($message, E_USER_DEPRECATED);
        $drive = $this->getMyDrive();
        $item  = $this->getDriveItemById($drive->id, $driveItemId);
        $item->delete();
    }
840741
public function importAction(ResourceNode $directory)
    {
        $form = $this->formFactory->create(new ImportResourcesType());
        $form->handleRequest($this->request);

        /*try {*/
            if ($form->isValid()) {
                $template = $form->get('file')->getData();
                $config = Configuration::fromTemplate($template);
                $user = $this->tokenStorage->getToken()->getUser();
                $this->transferManager->importResources($config, $user, $directory);
                $this->transferManager->importRichText();

                return new JsonResponse(array());
            } else {

                return array('form' => $form->createView(), 'directory' => $directory);
            }/*
        } catch (\Exception $e) {
            $errorMsg = $this->translator->trans(
                'invalid_file',
                array(),
                'platform'
            );
            $form->addError(new FormError($e->getMessage()));*/

            return array('form' => $form->createView(), 'directory' => $directory);
        //}
    }
1269590
public function getRestore($modelitemId)
    {
        if (!$this->modelAdmin->hasSoftDeleting()) {
            return $this->missingMethod();
        }

        return view('flare::admin.modeladmin.restore', ['modelItem' => $this->modelAdmin->model]);
    }