/** * Save the metadata and store the catalog data for this published * monograph. */ function execute($request) { parent::execute(); $monograph = $this->getMonograph(); $monographDao = DAORegistry::getDAO('MonographDAO'); $publishedMonographDao = DAORegistry::getDAO('PublishedMonographDAO'); $publishedMonograph = $publishedMonographDao->getById($monograph->getId(), null, false); /* @var $publishedMonograph PublishedMonograph */ $isExistingEntry = $publishedMonograph ? true : false; if (!$publishedMonograph) { $publishedMonograph = $publishedMonographDao->newDataObject(); $publishedMonograph->setId($monograph->getId()); } // Populate the published monograph with the cataloging metadata $publishedMonograph->setAudience($this->getData('audience')); $publishedMonograph->setAudienceRangeQualifier($this->getData('audienceRangeQualifier')); $publishedMonograph->setAudienceRangeFrom($this->getData('audienceRangeFrom')); $publishedMonograph->setAudienceRangeTo($this->getData('audienceRangeTo')); $publishedMonograph->setAudienceRangeExact($this->getData('audienceRangeExact')); // If a cover image was uploaded, deal with it. if ($temporaryFileId = $this->getData('temporaryFileId')) { // Fetch the temporary file storing the uploaded library file $temporaryFileDao = DAORegistry::getDAO('TemporaryFileDAO'); $temporaryFile = $temporaryFileDao->getTemporaryFile($temporaryFileId, $this->_userId); $temporaryFilePath = $temporaryFile->getFilePath(); import('classes.file.SimpleMonographFileManager'); $simpleMonographFileManager = new SimpleMonographFileManager($monograph->getPressId(), $publishedMonograph->getId()); $basePath = $simpleMonographFileManager->getBasePath(); // Delete the old file if it exists $oldSetting = $publishedMonograph->getCoverImage(); if ($oldSetting) { $simpleMonographFileManager->deleteFile($basePath . $oldSetting['thumbnailName']); $simpleMonographFileManager->deleteFile($basePath . $oldSetting['catalogName']); $simpleMonographFileManager->deleteFile($basePath . $oldSetting['name']); } // The following variables were fetched in validation assert($this->_sizeArray && $this->_imageExtension); // Load the cover image for surrogate production $cover = null; // Scrutinizer switch ($this->_imageExtension) { case '.jpg': $cover = imagecreatefromjpeg($temporaryFilePath); break; case '.png': $cover = imagecreatefrompng($temporaryFilePath); break; case '.gif': $cover = imagecreatefromgif($temporaryFilePath); break; } assert(isset($cover)); // Copy the new file over (involves creating the appropriate subdirectory too) $filename = 'cover' . $this->_imageExtension; $simpleMonographFileManager->copyFile($temporaryFile->getFilePath(), $basePath . $filename); // Generate surrogate images (thumbnail and catalog image) $press = $request->getPress(); $coverThumbnailsMaxWidth = $press->getSetting('coverThumbnailsMaxWidth'); $coverThumbnailsMaxHeight = $press->getSetting('coverThumbnailsMaxHeight'); $thumbnailImageInfo = $this->_buildSurrogateImage($cover, $basePath, SUBMISSION_IMAGE_TYPE_THUMBNAIL, $coverThumbnailsMaxWidth, $coverThumbnailsMaxHeight); $catalogImageInfo = $this->_buildSurrogateImage($cover, $basePath, SUBMISSION_IMAGE_TYPE_CATALOG); // Clean up imagedestroy($cover); $publishedMonograph->setCoverImage(array('name' => $filename, 'width' => $this->_sizeArray[0], 'height' => $this->_sizeArray[1], 'thumbnailName' => $thumbnailImageInfo['filename'], 'thumbnailWidth' => $thumbnailImageInfo['width'], 'thumbnailHeight' => $thumbnailImageInfo['height'], 'catalogName' => $catalogImageInfo['filename'], 'catalogWidth' => $catalogImageInfo['width'], 'catalogHeight' => $catalogImageInfo['height'], 'uploadName' => $temporaryFile->getOriginalFileName(), 'dateUploaded' => Core::getCurrentDate())); // Clean up the temporary file import('lib.pkp.classes.file.TemporaryFileManager'); $temporaryFileManager = new TemporaryFileManager(); $temporaryFileManager->deleteFile($temporaryFileId, $this->_userId); } if ($this->getData('attachPermissions')) { $monograph->setCopyrightYear($this->getData('copyrightYear')); $monograph->setCopyrightHolder($this->getData('copyrightHolder'), null); // Localized $monograph->setLicenseURL($this->getData('licenseURL')); } else { $monograph->setCopyrightYear(null); $monograph->setCopyrightHolder(null, null); $monograph->setLicenseURL(null); } $monographDao->updateObject($monograph); // Update the modified fields or insert new. if ($isExistingEntry) { $publishedMonographDao->updateObject($publishedMonograph); } else { $publishedMonographDao->insertObject($publishedMonograph); } import('classes.publicationFormat.PublicationFormatTombstoneManager'); $publicationFormatTombstoneMgr = new PublicationFormatTombstoneManager(); $publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO'); $publicationFormatFactory = $publicationFormatDao->getBySubmissionId($monograph->getId()); $publicationFormats = $publicationFormatFactory->toAssociativeArray(); $notificationMgr = new NotificationManager(); if ($this->getData('confirm')) { // Update the monograph status. $monograph->setStatus(STATUS_PUBLISHED); $monographDao->updateObject($monograph); $publishedMonograph->setDatePublished(Core::getCurrentDate()); $publishedMonographDao->updateObject($publishedMonograph); $notificationMgr->updateNotification($request, array(NOTIFICATION_TYPE_APPROVE_SUBMISSION), null, ASSOC_TYPE_MONOGRAPH, $publishedMonograph->getId()); // Remove publication format tombstones. $publicationFormatTombstoneMgr->deleteTombstonesByPublicationFormats($publicationFormats); // Update the search index for this published monograph. import('classes.search.MonographSearchIndex'); MonographSearchIndex::indexMonographMetadata($monograph); // Log the publication event. import('lib.pkp.classes.log.SubmissionLog'); SubmissionLog::logEvent($request, $monograph, SUBMISSION_LOG_METADATA_PUBLISH, 'submission.event.metadataPublished'); } else { if ($isExistingEntry) { // Update the monograph status. $monograph->setStatus(STATUS_QUEUED); $monographDao->updateObject($monograph); // Unpublish monograph. $publishedMonograph->setDatePublished(null); $publishedMonographDao->updateObject($publishedMonograph); $notificationMgr->updateNotification($request, array(NOTIFICATION_TYPE_APPROVE_SUBMISSION), null, ASSOC_TYPE_MONOGRAPH, $publishedMonograph->getId()); // Create tombstones for each publication format. $publicationFormatTombstoneMgr->insertTombstonesByPublicationFormats($publicationFormats, $request->getContext()); // Log the unpublication event. import('lib.pkp.classes.log.SubmissionLog'); SubmissionLog::logEvent($request, $monograph, SUBMISSION_LOG_METADATA_UNPUBLISH, 'submission.event.metadataUnpublished'); } } }
/** * Set a format's "available" state * @param $args array * @param $request PKPRequest * @return JSONMessage JSON object */ function setAvailable($args, $request) { $context = $request->getContext(); $publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO'); $publicationFormat = $publicationFormatDao->getById($request->getUserVar('representationId'), null, $context->getId()); if (!$publicationFormat) { return new JSONMessage(false, __('manager.setup.errorDeletingItem')); } $newAvailableState = (int) $request->getUserVar('newAvailableState'); $publicationFormat->setIsAvailable($newAvailableState); $publicationFormatDao->updateObject($publicationFormat); // log the state changing of the format. import('lib.pkp.classes.log.SubmissionLog'); import('classes.log.SubmissionEventLogEntry'); SubmissionLog::logEvent($request, $this->getSubmission(), $newAvailableState ? SUBMISSION_LOG_PUBLICATION_FORMAT_AVAILABLE : SUBMISSION_LOG_PUBLICATION_FORMAT_UNAVAILABLE, $newAvailableState ? 'submission.event.publicationFormatMadeAvailable' : 'submission.event.publicationFormatMadeUnavailable', array('publicationFormatName' => $publicationFormat->getLocalizedName())); // Update the formats tombstones. import('classes.publicationFormat.PublicationFormatTombstoneManager'); $publicationFormatTombstoneMgr = new PublicationFormatTombstoneManager(); if ($publicationFormat->getIsAvailable() && $publicationFormat->getIsApproved()) { // Delete any existing tombstone. $publicationFormatTombstoneMgr->deleteTombstonesByPublicationFormats(array($publicationFormat)); } else { // (Re)create a tombstone for this publication format. $publicationFormatTombstoneMgr->deleteTombstonesByPublicationFormats(array($publicationFormat)); $publicationFormatTombstoneMgr->insertTombstoneByPublicationFormat($publicationFormat, $context); } return DAO::getDataChangedEvent($publicationFormat->getId()); }
/** * 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 the metadata and store the catalog data for this specific publication format. */ function execute($request) { parent::execute(); $monograph = $this->getMonograph(); $publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO'); $publicationFormat = $publicationFormatDao->getById($this->getPublicationFormatId(), $monograph->getId()); assert($publicationFormat); // Manage tombstones for the publication format. if ($publicationFormat->getIsApproved() && !$this->getData('isApproved')) { // Publication format was approved and its being disabled. Create // a tombstone for it. $press = $request->getPress(); import('classes.publicationFormat.PublicationFormatTombstoneManager'); $publicationFormatTombstoneMgr = new PublicationFormatTombstoneManager(); $publicationFormatTombstoneMgr->insertTombstoneByPublicationFormat($publicationFormat, $press); // Log unpublish event. import('lib.pkp.classes.log.SubmissionLog'); SubmissionLog::logEvent($request, $monograph, SUBMISSION_LOG_PUBLICATION_FORMAT_UNPUBLISH, 'submission.event.publicationFormatUnpublished', array('publicationFormatName' => $publicationFormat->getLocalizedName())); } elseif (!$publicationFormat->getIsApproved() && $this->getData('isApproved')) { // Wasn't approved and now it is. Delete tombstone. $tombstoneDao = DAORegistry::getDAO('DataObjectTombstoneDAO'); $tombstoneDao->deleteByDataObjectId($publicationFormat->getId()); // Log publish event. import('lib.pkp.classes.log.SubmissionLog'); SubmissionLog::logEvent($request, $monograph, SUBMISSION_LOG_PUBLICATION_FORMAT_PUBLISH, 'submission.event.publicationFormatPublished', array('publicationFormatName' => $publicationFormat->getLocalizedName())); } // populate the published monograph with the cataloging metadata $publicationFormat->setFileSize($this->getData('override') ? $this->getData('fileSize') : null); $publicationFormat->setFrontMatter($this->getData('frontMatter')); $publicationFormat->setBackMatter($this->getData('backMatter')); $publicationFormat->setHeight($this->getData('height')); $publicationFormat->setHeightUnitCode($this->getData('heightUnitCode')); $publicationFormat->setWidth($this->getData('width')); $publicationFormat->setWidthUnitCode($this->getData('widthUnitCode')); $publicationFormat->setThickness($this->getData('thickness')); $publicationFormat->setThicknessUnitCode($this->getData('thicknessUnitCode')); $publicationFormat->setWeight($this->getData('weight')); $publicationFormat->setWeightUnitCode($this->getData('weightUnitCode')); $publicationFormat->setProductCompositionCode($this->getData('productCompositionCode')); $publicationFormat->setProductFormDetailCode($this->getData('productFormDetailCode')); $publicationFormat->setCountryManufactureCode($this->getData('countryManufactureCode')); $publicationFormat->setImprint($this->getData('imprint')); $publicationFormat->setProductAvailabilityCode($this->getData('productAvailabilityCode')); $publicationFormat->setTechnicalProtectionCode($this->getData('technicalProtectionCode')); $publicationFormat->setReturnableIndicatorCode($this->getData('returnableIndicatorCode')); $publicationFormat->setIsApproved($this->getData('isApproved') ? true : false); // consider the additional field names from the public identifer plugins $pubIdPluginHelper = $this->_getPubIdPluginHelper(); $pubIdPluginHelper->execute($this, $publicationFormat); $publicationFormatDao->updateObject($publicationFormat); }
/** * 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(); } }