/**
  * Delete a press.
  * @param $args array
  * @param $request PKPRequest
  * @return string Serialized JSON object
  */
 function deleteContext($args, $request)
 {
     // Identify the current context.
     $context = $request->getContext();
     // Identify the press Id.
     $pressId = $request->getUserVar('rowId');
     $pressDao = DAORegistry::getDAO('PressDAO');
     $press = $pressDao->getById($pressId);
     if ($pressId) {
         $pressDao->deleteById($pressId);
         // Add publication formats tombstones for all press published monographs.
         import('classes.publicationFormat.PublicationFormatTombstoneManager');
         $publicationFormatTombstoneMgr = new PublicationFormatTombstoneManager();
         $publicationFormatTombstoneMgr->insertTombstonesByPress($press);
         // Delete press file tree
         // FIXME move this somewhere better.
         import('lib.pkp.classes.file.ContextFileManager');
         $pressFileManager = new ContextFileManager($pressId);
         $pressFileManager->rmtree($pressFileManager->getBasePath());
         import('classes.file.PublicFileManager');
         $publicFileManager = new PublicFileManager();
         $publicFileManager->rmtree($publicFileManager->getPressFilesPath($pressId));
         // If user is deleting the same press where he is...
         if ($context && $context->getId() == $pressId) {
             // return a redirect js event to index handler.
             $dispatcher = $request->getDispatcher();
             $url = $dispatcher->url($request, ROUTE_PAGE, null, 'index');
             return $request->redirectUrlJson($url);
         }
         return DAO::getDataChangedEvent($pressId);
     }
     return new JSONMessage();
 }
 /**
  * Save press settings.
  * @param $request PKPRequest
  */
 function execute($request)
 {
     $pressDao = DAORegistry::getDAO('PressDAO');
     if (isset($this->contextId)) {
         $press = $pressDao->getById($this->contextId);
         /* @var $press Press */
         import('classes.publicationFormat.PublicationFormatTombstoneManager');
         $publicationFormatTombstoneMgr = new PublicationFormatTombstoneManager();
         if ($press->getEnabled() && !$this->getData('enabled')) {
             // Will disable the press. Create tombstones for all
             // published monographs publication formats.
             $publicationFormatTombstoneMgr->insertTombstonesByPress($press);
         } elseif (!$press->getEnabled() && $this->getData('enabled')) {
             // Will enable the press. Delete all tombstones.
             $publicationFormatTombstoneMgr->deleteTombstonesByPressId($press->getId());
         }
     }
     if (!isset($press)) {
         $press = $pressDao->newDataObject();
     }
     // Check if the press path has changed.
     $pathChanged = false;
     $pressPath = $press->getPath();
     if ($pressPath != $this->getData('path')) {
         $pathChanged = true;
     }
     $press->setPath($this->getData('path'));
     $press->setEnabled($this->getData('enabled'));
     $isNewPress = false;
     $site = $request->getSite();
     if ($press->getId() != null) {
         $pressDao->updateObject($press);
     } else {
         $isNewPress = true;
         // Give it a default primary locale
         $press->setPrimaryLocale($site->getPrimaryLocale());
         $contextId = $pressDao->insertObject($press);
         $pressDao->resequence();
         // Make the file directories for the press
         import('lib.pkp.classes.file.ContextFileManager');
         $pressFileManager = new ContextFileManager($contextId);
         $pressFileManager->mkdir($pressFileManager->getBasePath());
         $pressFileManager->mkdir($pressFileManager->getBasePath() . '/monographs');
         $installedLocales = $site->getInstalledLocales();
         // Install default genres
         $genreDao = DAORegistry::getDAO('GenreDAO');
         $genreDao->installDefaults($contextId, $installedLocales);
         /* @var $genreDao GenreDAO */
         // load the default user groups and stage assignments.
         $this->_loadDefaultUserGroups($press->getId());
         $this->_assignManagerGroup($press->getId());
         // Install default press settings
         $pressSettingsDao = DAORegistry::getDAO('PressSettingsDAO');
         $titles = $this->getData('title');
         AppLocale::requireComponents(LOCALE_COMPONENT_APP_DEFAULT, LOCALE_COMPONENT_PKP_DEFAULT);
         $pressSettingsDao->installSettings($contextId, 'registry/pressSettings.xml', array('indexUrl' => $request->getIndexUrl(), 'pressPath' => $this->getData('path'), 'primaryLocale' => $site->getPrimaryLocale(), 'contextName' => $titles[$site->getPrimaryLocale()], 'ldelim' => '{', 'rdelim' => '}'));
     }
     $press->updateSetting('supportedLocales', $site->getSupportedLocales());
     $press->updateSetting('name', $this->getData('name'), 'string', true);
     $press->updateSetting('description', $this->getData('description'), 'string', true);
     // Make sure all plugins are loaded for settings preload
     PluginRegistry::loadAllPlugins();
     HookRegistry::call('PressSiteSettingsForm::execute', array(&$this, &$press, &$isNewPress));
     if ($isNewPress || $pathChanged) {
         return $press->getPath();
     }
 }