Ejemplo n.º 1
0
 /**
  * validate a request object on basis of function-name(action)
  *
  * @param string $function
  * @param \Cms\Request\Abstract $actionRequest
  * @param boolean $setHttpErrorCode
  * @return true
  * @throws Exception
  */
 public function validate($function, Request $actionRequest, $abortExceptions = true)
 {
     $methodName = 'validateMethod' . $function;
     if (method_exists($this, $methodName)) {
         try {
             $this->{$methodName}($actionRequest);
         } catch (PropertyAccessException $e) {
             $message = str_replace('%name%', $e->getName(), $this->_('error.validation.missing_parameter'));
             $this->addError(new Error($e->getName(), null, array($message)));
         }
         if (count($this->getErrors()) > 0) {
             foreach ($this->getErrors() as $error) {
                 \Cms\ExceptionStack::addException($error);
             }
             if (count(\Cms\ExceptionStack::getExceptions()) > 0) {
                 // soll nur der Status-Code veraendert werden (Bsp: Rueckgabe Images)
                 if ($abortExceptions == true) {
                     // bisherige Fehler loggen und reset
                     foreach (\Cms\ExceptionStack::getExceptions() as $exception) {
                         \Seitenbau\Registry::getLogger()->logException(__METHOD__, __LINE__, $exception, \Seitenbau\Log::NOTICE);
                     }
                     //\Cms\ExceptionStack::reset();
                     return false;
                 } else {
                     \Cms\ExceptionStack::throwErrors();
                 }
             }
         }
         return true;
     } else {
         $data = array('method' => $methodName);
         throw new \Cms\Exception(-12, __METHOD__, __LINE__, $data);
     }
 }
Ejemplo n.º 2
0
 /**
  * Erstellt die komplette Ausgabe der Actions als JSON
  * Wirft evtl. aufgetretene Fehler
  */
 public function postDispatch(\Zend_Controller_Request_Abstract $request)
 {
     // Exceptions ausgeben, wenn welche im Stack liegen
     $exceptions = \Cms\ExceptionStack::getExceptions();
     if (count($exceptions) > 0) {
         \Cms\ExceptionStack::throwErrors();
     }
     parent::postDispatch($request);
 }
Ejemplo n.º 3
0
 public function errorAction()
 {
     $errors = $this->_getParam('error_handler');
     if ($errors === null) {
         \Cms\ExceptionStack::throwErrors();
     }
     $this->setResponseStatusCode($errors);
     if ($errors->exception instanceof \Cms\ExceptionStackException) {
         $this->handleStackExceptions($errors->exception);
         $responseData = $errors->exception->getResponseData();
     } else {
         $this->handleError($errors->exception);
         $responseData = null;
     }
     $response = $this->generateResponse($this->responseErrors, $responseData);
     $this->responseData = $response;
     \Cms\ExceptionStack::reset();
 }
Ejemplo n.º 4
0
 /**
  * @SWG\Api(
  *   path="/websitesettings/editmultiple",
  *   @SWG\Operation(
  *        method="GET, POST",
  *        summary="Updates website settings",
  *        notes="Update website settings section and return the new website settings.",
  *        type="WebsiteSettingsEdit",
  *        nickname="edit")
  * ))
  */
 public function editmultipleAction()
 {
     /** @var $validatedRequest \Cms\Request\WebsiteSettings\EditMultiple */
     $validatedRequest = $this->getValidatedRequest('WebsiteSettings', 'EditMultiple');
     $this->getBusiness()->checkUserRights('edit', array('websiteId' => $validatedRequest->getWebsiteId()));
     $allNewWebsiteSettings = $validatedRequest->getAllWebsiteSettings();
     foreach ($allNewWebsiteSettings as $id => $websiteSettings) {
         try {
             $attributes = get_object_vars($websiteSettings);
             $this->getBusiness()->update($validatedRequest->getWebsiteId(), $id, $attributes);
         } catch (\Exception $e) {
             CmsExceptionStack::addException($e);
         }
     }
     $allWebsiteSettings = $this->getBusiness()->getAll($validatedRequest->getWebsiteId());
     $responseData = new Response\GetAll($allWebsiteSettings);
     if (CmsExceptionStack::hasErrors()) {
         CmsExceptionStack::throwErrors($responseData);
     }
     $this->responseData->setData($responseData);
 }
Ejemplo n.º 5
0
 /**
  * deletes the modules given by $ids
  *
  * @param ModuleSource $moduleSource
  * @param string[]     $ids
  */
 public function deleteByIds(ModuleSource $moduleSource, array $ids)
 {
     $allModuleInfo = $this->getAllBaseInfo($moduleSource);
     foreach ($ids as $id) {
         if (!isset($allModuleInfo[$id]) || empty($allModuleInfo[$id])) {
             continue;
         }
         try {
             $this->checkIfModuleIsWritable($allModuleInfo[$id]);
             FS::rmdir($allModuleInfo[$id]->getDirectory());
         } catch (\Exception $e) {
             CmsExceptionStack::addException($e);
         }
     }
     $this->resetCache();
     if (CmsExceptionStack::hasErrors()) {
         CmsExceptionStack::throwErrors();
     }
 }
Ejemplo n.º 6
0
 /**
  * Erstellt die komplette Ausgabe der Actions als JSON
  * Wirft evtl. aufgetretene Fehler
  */
 public function postDispatch()
 {
     // Exceptions ausgeben, wenn welche im Stack liegen
     $exceptions = \Cms\ExceptionStack::getExceptions();
     if (count($exceptions) > 0) {
         // response->data weitergeben?
         $data = $this->pushDataToErrorController === true ? $this->responseData->getData() : null;
         \Cms\ExceptionStack::throwErrors($data);
     }
     parent::postDispatch();
 }
Ejemplo n.º 7
0
 /**
  * Empty all theme files
  */
 public function resetTheme()
 {
     $this->createTargetDirectory();
     // empty theme files
     CmsExceptionStack::reset();
     foreach ($this->themeFileNames as $file => $target) {
         try {
             FS::rmFile(FS::joinPath($this->targetPath, $target));
         } catch (\Exception $e) {
             CmsExceptionStack::addException($e);
         }
     }
     if (CmsExceptionStack::hasErrors()) {
         CmsExceptionStack::throwErrors();
     }
 }
Ejemplo n.º 8
0
 /**
  * @param string      $websiteId
  * @param string      $importDirectory
  * @param string|null $allowedImportMode
  * @param string|null $websiteName
  *
  * @return array|null
  * @throws CmsException
  * @throws ConflictException
  * @throws \Cms\ExceptionStackException
  * @throws \Exception
  */
 public function importFromDirectory($websiteId, $importDirectory, $allowedImportMode, $websiteName)
 {
     if (!file_exists($importDirectory)) {
         throw new CmsException(24, __METHOD__, __LINE__, array('file' => $importDirectory));
     }
     $this->currentImportFile = null;
     $this->currentImportUnzipDirectory = $importDirectory;
     $this->prepareImport($websiteId, $allowedImportMode);
     $this->handleConflicts($websiteId, $importDirectory);
     $importData = $this->_import($websiteId, $websiteName);
     if (CmsExceptionStack::hasErrors()) {
         CmsExceptionStack::throwErrors();
     }
     return $importData;
 }
Ejemplo n.º 9
0
 /**
  * Reparse von Pages
  *
  * @param       $websiteId
  * @param array $pageIds
  *
  * @return array
  */
 private function reparsePages($websiteId, array $pageIds)
 {
     if (count($pageIds) == 0) {
         return array();
     }
     $idsOfReparsedPages = array();
     $pageBusiness = $this->getPageBusiness();
     foreach ($pageIds as $pageId) {
         try {
             $page = $pageBusiness->getById($pageId, $websiteId);
             if ($this->reparsePage($page)) {
                 $idsOfReparsedPages[] = $page->getId();
             }
         } catch (\Exception $e) {
             \Cms\ExceptionStack::addException($e);
         }
     }
     if (\Cms\ExceptionStack::hasErrors()) {
         \Cms\ExceptionStack::throwErrors();
     }
     return $idsOfReparsedPages;
 }
Ejemplo n.º 10
0
 /**
  * @param  string $id
  * @param  string $websiteId
  * @param  array  $groupIds
  *
  * @return boolean
  */
 public function removeGroups($id, $websiteId, array $groupIds)
 {
     /** @var $groupService \Cms\Service\Group */
     $groupService = $this->getService('Group');
     foreach ($groupIds as $groupId) {
         try {
             $groupService->removeUsers($groupId, $websiteId, array($id));
         } catch (\Exception $e) {
             CmsExceptionStack::addException($e);
         }
     }
     if (CmsExceptionStack::hasErrors()) {
         CmsExceptionStack::throwErrors();
     }
     return true;
 }