Deletes a content

@param Pluf_HTTP_Request $request
@param array $match
@throws Pluf_Exception_PermissionDenied
@return Pluf_HTTP_Response
179048
public function delete($request, $match)
    {
        // تعیین داده‌ها
        $content = Pluf_Shortcuts_GetObjectOr404('CMS_Content', $match['modelId']);
        // بررسی دسترسی‌ها
        if (! CMS_Precondition::isAuthor($request)) {
            throw new Pluf_Exception_PermissionDenied('You are not an author');
        }
        if (! CMS_Precondition::isEditor($request) && $request->user->id !== $content->author_id) {
            throw new Pluf_Exception_PermissionDenied('You can not delete content created by another author');
        }
        return parent::deleteObject($request, $match, array(
            'model' => 'CMS_Content'
        ));
    }
483092
public static function add($request, $match)
    {
        $perm = Pluf_Shortcuts_GetObjectOr404('User_Role', $match['role_id']);
        $group = Pluf_Shortcuts_GetObjectOr404('User_Group', isset($match['group_id']) ? $match['group_id'] : $request->REQUEST['group_id']);
        $perm->setAssoc($group);
        return $group;
    }
1155088
public static function getDiscount($request, $match)
    {
        $discount = Pluf_Shortcuts_GetObjectOr404('Discount_Discount', $match['modelId']);
        $discountEngine = $discount->get_engine();
        $validationCode = $discountEngine->validate($discount, $request);
        $discount->__set('validation_code', $validationCode);
        // حق دسترسی
        // CMS_Precondition::userCanAccessContent($request, $content);
        // اجرای درخواست
        return $discount;
    }
651410
public function delete($match = '*')
	{
		if ($this->isAuthenticated())
		{
			$url = $this->getLink();

			if ($match === true)
			{
				$match = $this->xml->xpath('./@gd:etag');
				$match = $match[0];
			}

			try
			{
				$jdata = $this->query($url, null, array('GData-Version' => 2, 'If-Match' => $match), 'delete');
			}
			catch (\Exception $e)
			{
				if (strpos($e->getMessage(), 'Error code 412 received requesting data: Mismatch: etags') === 0)
				{
					throw new \RuntimeException("Etag match failed: `$match`.");
				}

				throw $e;
			}

			if ($jdata->body != '')
			{
				throw new \UnexpectedValueException("Unexpected data received from Google: `{$jdata->body}`.");
			}

			$this->xml = null;

			return true;
		}
		else
		{
			return false;
		}
	}
1361232
public function password($request, $match)
    {
        $msg = array(
            'message' => 'succcess'
        );
        // TODO: maso, 2017: recover by mail
        if (array_key_exists('email', $request->REQUEST)) {
            $sql = new Pluf_SQL('email=%s', array(
                $request->REQUEST['email']
            ));
            $user = $request->user->getOne($sql->gen());
            if ($user) {
                $this->sendPasswordToken($request, $user);
            }
            return $msg;
        }
        // TODO: maso, 2017: recover by login
        if (array_key_exists('login', $request->REQUEST)) {
            $sql = new Pluf_SQL('login=%s', array(
                $request->REQUEST['login']
            ));
            $user = $request->user->getOne($sql->gen());
            if ($user) {
                $this->sendPasswordToken($request, $user);
            }
            return $msg;
        }
        // Reset password by token
        if (array_key_exists('token', $request->REQUEST)) {
            $token = new User_PasswordToken();
            $sql = new Pluf_SQL('token=%s', array(
                $request->REQUEST['token']
            ));
            $token = $token->getOne($sql->gen());
            if (! $token || $token->isExpired()) {
                throw new Pluf_Exception_DoesNotExist('Token not exist');
            }
            $user = $token->get_user();
            $user->setPassword($request->REQUEST['new']);
            $user->update();
            $token->delete();
            return $msg;
        }
        // Reset password by old password
        if (array_key_exists('old', $request->REQUEST) || array_key_exists('old_password', $request->REQUEST)) {
            $oldPass = array_key_exists('old', $request->REQUEST) ? 
            $request->REQUEST['old'] : $request->REQUEST['old_password'];
            if ($request->user->isAnonymous()) {
                throw new Pluf_Exception_Unauthorized();
            }
            // Retreive credential
            $cred = User_Credential::getCredential($request->user->id);
            if (! $cred->checkPassword($oldPass)) {
                throw new Pluf_Exception_MismatchParameter('Old pass is not currect');
            }
            $newPass = array_key_exists('new', $request->REQUEST) ? 
                $request->REQUEST['new'] : $request->REQUEST['password'];
            $cred->setPassword($newPass);
            $cred->update();
            return $msg;
        }

        throw new Pluf_Exception_MismatchParameter('Invalid request params');
    }
942369
public function find($request, $match)
    {
        $builder = new Pluf_Paginator_Builder(new CMS_Content());
        return $builder->setRequest($request)->build();
    }
1301205
public function hasPermissionLike($match)
    {
        if ($this->isAdmin()) {
            return true;
        }

        if (is_null($this->permissions)) {
            $this->permissions = $this->getPermissions();
        }

        foreach ($this->permissions as $permission) {
            if (substr($permission, -strlen($match)) === $match) {
                return true;
            }
        }

        return false;
    }
1103251
public function update($request, $match)
    {
        // تعیین داده‌ها
        $content = Pluf_Shortcuts_GetObjectOr404('CMS_Content', $match['modelId']);
        // بررسی دسترسی‌ها
        if (! CMS_Precondition::isAuthor($request)) {
            throw new Pluf_Exception_PermissionDenied('You are not an author');
        }
        if (! CMS_Precondition::isEditor($request) && $request->user->id !== $content->author_id) {
            throw new Pluf_Exception_PermissionDenied('You can not change content created by another author');
        }
        return parent::updateObject($request, $match, array(
            'model' => 'CMS_Content'
        ));
    }
1143422
public function login($request, $match)
    {
        if (! $request->user->isAnonymous()) {
            return $request->user;
        }
        
        $backends = Pluf::f('auth_backends', array(
            'User_Auth_ModelBackend'
        ));
        foreach ($backends as $backend) {
            $user = call_user_func(array(
                $backend,
                'authenticate'
            ), $request->POST);
            if ($user !== false) {
                break;
            }
        }
        
        if (false === $user) {
            throw new Pluf_Exception('user authentication incorrect');
        }
        
        $request->user = $user;
        $request->session->clear();
        $request->session->setData('login_time', gmdate('Y-m-d H:i:s'));
        $user->last_login = gmdate('Y-m-d H:i:s');
        $user->update();
        
        return $user;
    }
769426
public function loadGsonFile ($request, $match)
    {
        foreach ($request->FILES as $file) {
            if (is_readable($file['tmp_name'])) {
                Geo_Shortcuts_LoadJson($request->tenant, $request->user, $file['tmp_name']);
            }
        }
        return new Pluf_HTTP_Response_Json(
                new ArrayObject(array(
                        'success' => true
                )));
    }
1261848
public function deleteTagBykeyvalue ($request, $match)
    {
        $location = Geo_Shortcuts_GetLocationOr404($match[1]);
        Geo_Precondition::canEditLocation($request, $location);
        $tag = SaaSKM_Tag::getFromString($request->tenant, $request->REQUEST['tag']);
        if(! $tag){
            throw new Pluf_Exception("Tag not found");
        }
        // XXX: maso, 1394: بررسی وجود برچسب
        SaaSKM_TagRow::remove($request->tenant, $location, $tag);
        return new Pluf_HTTP_Response_Json($location);
    }
666511
public function delete($request, $params = null) {
        if (is_string ($request)) {
            $request = array(
                "uri" => $request,
                "params" => $params
            );
        }

        $request["params"] = isset ($request["params"]) && is_array ($request["params"]) ? $request["params"] : array();

        if (!isset ($request["authenticate"]) || $request["authenticate"] !== false) {
            $request["params"]["access_token"] = $this->get_access_token();
        }

        $result = MPRestClient::delete($request);
        return $result;
    }
1048340
public function deleteAction(Request $request)
    {
        if (!$request->isXmlHttpRequest()) {
            throw new NotFoundHttpException();
        }

        $folder = $this->findFolderById($request->attributes->get('id'));

        $result = array();
        try {
            $this->removeFolder($folder);
        } catch (DBALException $e) {
            $result = array(
                'error'   => true,
                'message' => 'Ce dossier n\'est pas vide.',
            );
        }

        $response = new Response(json_encode($result, JSON_FORCE_OBJECT));
        $response->headers->add(array('Content-Type' => 'application/json'));
        return $response;
    }
1295957
function create ($request, $match)
    {
        $extra = array(
                'user' => $request->user,
                'tenant' => $request->tenant
        );
        $form = new Geo_Form_Location(
                array_merge($request->REQUEST, $request->FILES), $extra);
        $cuser = $form->save();
        $request->user->setMessage(
                sprintf(__('the location %s has been created.'), 
                        (string) $cuser->name));
        
        User_Shortcuts_UpdateLeveFor($request->user, "jahanjoo_location_add");
        // Return response
        return new Pluf_HTTP_Response_Json($cuser);
    }
377213
public function getResources($match = null) {

		if(null !== $match && false === is_string($match)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($match)), E_USER_ERROR);
		}

		$permissions = [];
		$match 		 = null === $match ? '.*?' : $match;

		foreach($this -> permissions as $permission) {

			foreach($permission as $type => $value) {

				if(preg_match(sprintf('#%s#', str_replace('#', '\#', $match)), $type)) {
					$permissions[] = $type;			
				}
			}
		}

		return array_unique($permissions);
	}
396418
public function removeAction(Request $request): Response
    {
        $form = $this->formFactory->removeContentDraft();
        $form->handleRequest($request);

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (ContentRemoveData $data) {
                foreach (array_keys($data->getVersions()) as $version) {
                    $versionId = VersionId::fromString($version);

                    $this->contentService->deleteVersion(
                        $this->contentService->loadVersionInfoById(
                            $versionId->getContentId(),
                            $versionId->getVersionNo()
                        )
                    );
                }

                return $this->redirectToRoute('ezplatform.content_draft.list');
            });

            if ($result instanceof Response) {
                return $result;
            }
        }

        return $this->redirectToRoute('ezplatform.content_draft.list');
    }
35764
private function internalGet($request, $match){
        $model = new Tenant_Configuration();
        $model = $model->getOne("`key`='" . $match['key'] . "'");
        return $model;
    }