Skip to content

Commit

Permalink
Merge pull request #314 from effective-webwork/issue-1946
Browse files Browse the repository at this point in the history
Issue 1946
  • Loading branch information
Erikmitk authored Dec 22, 2024
2 parents 1921647 + 935b171 commit c93e353
Show file tree
Hide file tree
Showing 15 changed files with 170 additions and 52 deletions.
11 changes: 11 additions & 0 deletions Classes/Configuration/ClientConfigurationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,17 @@ public function getFisCollections()
return array_filter($fisCollections, 'strlen');
}

public function getNoReplyAddress()
{
$settings = $this->getTypoScriptSettings();

if (isset($settings['noReplyAddress']) && $settings['noReplyAddress']) {
return $settings['noReplyAddress'];
}

return trim($this->extensionConfiguration['noReplyAddress']);
}

/**
* @param string $xpath
* @return string
Expand Down
7 changes: 6 additions & 1 deletion Classes/Controller/DocumentFormBackofficeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ public function updateDocumentAction(\EWW\Dpf\Domain\Model\DocumentForm $documen
if ( $updateDocument->isTemporaryCopy() && $saveMode == 'saveWorkingCopy') {
$saveWorkingCopy = true;
$updateDocument->setTemporary(false);

if ($updateDocument->isActiveEmbargo()) {
$updateDocument->setEmbargoWorkingCopy(true);
}

$workflowTransition = DocumentWorkflow::TRANSITION_IN_PROGRESS;
} elseif ($updateDocument->isTemporaryCopy() && $saveMode == 'saveAndUpdate') {
$workflowTransition = DocumentWorkflow::TRANSITION_REMOTE_UPDATE;
Expand Down Expand Up @@ -406,7 +411,7 @@ public function updateDocumentAction(\EWW\Dpf\Domain\Model\DocumentForm $documen
$this->addFlashMessage($message, '', AbstractMessage::OK);

if ($this->security->getUserRole() === Security::ROLE_LIBRARIAN) {
if ($saveWorkingCopy) {
if ($saveWorkingCopy || $document->isActiveEmbargo()) {
if (
$this->bookmarkRepository->addBookmark(
$updateDocument,
Expand Down
35 changes: 35 additions & 0 deletions Classes/Domain/Model/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ class Document extends AbstractEntity
*/
protected $embargoDate = null;

/**
* date
*
* @var bool
*/
protected $embargoWorkingCopy = false;

/**
* newlyAssignedFobIdentifiers
*
Expand Down Expand Up @@ -931,6 +938,34 @@ public function setEmbargoDate(?\DateTime $embargoDate)
$this->embargoDate = $embargoDate;
}

/**
* @return bool
*/
public function isEmbargoWorkingCopy(): bool
{
return $this->embargoWorkingCopy;
}

/**
* @param bool $embargoWorkingCopy
* @return void
*/
public function setEmbargoWorkingCopy(bool $embargoWorkingCopy): void
{
$this->embargoWorkingCopy = $embargoWorkingCopy;
}

public function isActiveEmbargo(): bool
{
$currentDate = new \DateTime('now');
if($currentDate > $this->getEmbargoDate()){
// embargo is expired
return false;
} else {
return true;
}
}

/**
* @return array
*/
Expand Down
7 changes: 7 additions & 0 deletions Classes/Services/Document/DocumentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ public function update(
$updateResult = $this->updateRemotely($document, $workflowTransition);

} elseif ($document->isWorkingCopy()) {
if ($this->hasActiveEmbargo($document)) {
$document->setEmbargoWorkingCopy(true);
}

// if local working copy with no state change
$this->documentRepository->update($document);
Expand All @@ -269,6 +272,8 @@ public function update(
$this->removeDocument($document);
} else {
$document->setState(DocumentWorkflow::constructState(DocumentWorkflow::LOCAL_STATE_IN_PROGRESS, $document->getRemoteState()));
$document->setEmbargoWorkingCopy(true);
$this->documentRepository->update($document);
}
$updateResult = $document->getDocumentIdentifier();
} else {
Expand Down Expand Up @@ -359,6 +364,8 @@ protected function updateRemotely(Document $document, $workflowTransition = null
$this->removeDocument($document);
} else {
$document->setState(DocumentWorkflow::LOCAL_STATE_IN_PROGRESS . ':' . $document->getRemoteState());
$document->setTemporary(false);
$document->setEmbargoWorkingCopy(true);
$this->documentRepository->update($document);
}

Expand Down
4 changes: 2 additions & 2 deletions Classes/Services/Email/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -671,11 +671,11 @@ protected function replaceMarkers($message, $args)

protected function sendMail($reveiver, $subject, $body, $args, $mailType)
{
$settings = $this->clientConfigurationManager->getTypoScriptSettings();
$noReplyAddress = $this->clientConfigurationManager->getNoReplyAddress();
$emailReceiver = array();
$emailReceiver[$reveiver] = $reveiver;
$message = (new \TYPO3\CMS\Core\Mail\MailMessage())
->setFrom(array($settings['noReplyAddress'] => $settings['noReplyAddress']))
->setFrom([$noReplyAddress => $noReplyAddress])
->setTo($emailReceiver)
->setSubject($this->replaceMarkers($subject,$args))
->setBody($this->replaceMarkers($body,$args),$mailType);
Expand Down
64 changes: 39 additions & 25 deletions Classes/Services/Storage/DocumentStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,17 @@ public function ingest(Document $document) : ?Document

$this->fedoraTransaction->commit($transactionUri);

$containerTuple = $this->fedoraTransaction->getResourceTuple(null, $containerId);
$repositoryLastModified = $containerTuple->getValue('fedora:lastModified');

$document->setRemoteLastModDate($repositoryLastModified);

// Reset file states to indicate that the files correspond to the ones in fedora
foreach ($document->getFile() as $file) {
$file->setStatus('');
$this->fileRepository->update($file);
}

// TODO: Is this really needed inside ingest?
$this->documentRepository->update($document);

Expand Down Expand Up @@ -290,26 +301,31 @@ public function update(Document $document, string $state = null)
$file->setDatastreamIdentifier($dataStreamIdentifier);
$file->setLink($dataStreamIdentifier);

if ($file->getStatus() === File::STATUS_ADDED) {
$this->fedoraTransaction->createBinary(
$transactionUri,
$containerId,
$dataStreamIdentifier,
$file->getContentType(),
$file->getTitle(),
$fileSrc
);

} elseif ($file->getStatus() === File::STATUS_CHANGED) {
$this->fedoraTransaction->updateContent(
$transactionUri,
$containerId,
$dataStreamIdentifier,
$file->getContentType(),
$file->getTitle(),
$fileSrc
);
if ($file->getStatus() === File::STATUS_ADDED || $file->getStatus() === File::STATUS_CHANGED) {
if ($this->fedoraTransaction->isResourceExist($containerId, $dataStreamIdentifier)) {
$this->fedoraTransaction->updateContent(
$transactionUri,
$containerId,
$dataStreamIdentifier,
$file->getContentType(),
$file->getTitle(),
$fileSrc,
DocumentWorkflow::REMOTE_STATE_ACTIVE
);
} else {
$this->fedoraTransaction->createBinary(
$transactionUri,
$containerId,
$dataStreamIdentifier,
$file->getContentType(),
$file->getTitle(),
$fileSrc
);
}
}

// Reset file state to indicate that the file corresponds to the one in fedora
$file->setStatus('');
}
}
}
Expand All @@ -334,13 +350,11 @@ public function update(Document $document, string $state = null)

unlink($tmpFilePath);

$this->documentRepository->update($document);
$containerTuple = $this->fedoraTransaction->getResourceTuple($transactionUri, $containerId);
$lastModDate = $containerTuple->getValue('fedora:lastModified');
$document->setRemoteLastModDate($lastModDate);

// TODO:
// Why is the document removed?
// Could this lead to an error or inconsistency in case of an embargo.
// See method updateRemotely() in the DocumentManager.
$this->documentRepository->remove($document);
$this->documentRepository->update($document);

$this->fedoraTransaction->commit($transactionUri);

Expand Down
46 changes: 24 additions & 22 deletions Classes/Services/Storage/Fedora/FedoraTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,29 +581,31 @@ function updateResourceTuple(
$insert[] = '<> <' . $value['uri'] . '> "' . $value['value'] . '"';
}

$insertResponse = $client->request('PATCH', $path,
[
'auth' => [
$this->clientConfigurationManager->getFedoraUser(),
$this->clientConfigurationManager->getFedoraPassword()
],
'headers' => [
'Atomic-ID' => $transactionUri,
'Content-Typ' => 'application/sparql-update'
],
'body' => 'INSERT {' . implode(' . ', $insert) .'} WHERE {}'
]
);

if ($insertResponse->getStatusCode() !== 204) {
$this->logger->warning(
$errorMessage . 'Unexpected http response: ' . $insertResponse->getStatusCode()
. '. Update aborted.'
if (!empty($insert)) {
$insertResponse = $client->request('PATCH', $path,
[
'auth' => [
$this->clientConfigurationManager->getFedoraUser(),
$this->clientConfigurationManager->getFedoraPassword()
],
'headers' => [
'Atomic-ID' => $transactionUri,
'Content-Typ' => 'application/sparql-update'
],
'body' => 'INSERT {' . implode(' . ', $insert) .'} WHERE {}'
]
);

throw FedoraException::create('Update resource tuple failed. Unexpected http response.',
FedoraException::UNEXPECTED_RESPONSE, $requestUri, $insertResponse->getStatusCode()
);
if ($insertResponse->getStatusCode() !== 204) {
$this->logger->warning(
$errorMessage . 'Unexpected http response: ' . $insertResponse->getStatusCode()
. '. Update aborted.'
);

throw FedoraException::create('Update resource tuple failed. Unexpected http response.',
FedoraException::UNEXPECTED_RESPONSE, $requestUri, $insertResponse->getStatusCode()
);
}
}

} catch (GuzzleConnectException $guzzleConnectException) {
Expand Down Expand Up @@ -639,7 +641,7 @@ function updateResourceTuple(
* @return bool
* @throws GuzzleException
*/
protected function isResourceExist(string $containerIdentifier, string $binaryIdentifier = null) : bool
public function isResourceExist(string $containerIdentifier, string $binaryIdentifier = null) : bool
{
$path = $containerIdentifier . ($binaryIdentifier? '/' . $binaryIdentifier : '');

Expand Down
11 changes: 11 additions & 0 deletions Configuration/TCA/tx_dpf_domain_model_document.php
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,17 @@
'default' => time(),
),
),

'embargo_working_copy' => array(
'exclude' => 1,
'l10n_mode' => 'exclude',
'label' => 'LLL:EXT:dpf/Resources/Private/Language/locallang_db.xlf:tx_dpf_domain_model_document.embargo_working_copy',
'config' => array(
'type' => 'check',
'default' => 0,
),
),

'pid' => array(
'config' => array(
'type' => 'passthrough',
Expand Down
14 changes: 14 additions & 0 deletions Resources/Private/Language/de.locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,20 @@
<source>Do you really want to delete the working copy?</source>
<target>Möchten Sie die Arbeitskopie wirklich löschen?</target>
</trans-unit>
<trans-unit id="manager.confirmDeleteEmbargoWorkingCopy.message" approved="yes" xml:space="preserve">
<source><![CDATA[You are about to delete the working copy of an embargoed document. If you continue, embargo notifications for this document will no longer work and the associated full-text file in the repository may be lost.
<strong>This cannot be undone.</strong><br /><br />
To disable embargo notifications for this document, delete the embargo end date from the metadata. To discard the document, use the “Discard” button.]]>
</source>
<target><![CDATA[Sie sind dabei, die Arbeitskopie eines Dokuments zu löschen, das unter Embargo steht. Wenn Sie fortfahren, funktionieren Embargo-Benachrichtigungen für dieses Dokument nicht mehr und die zugehörige Volltext-Datei im Repository kann verloren gehen.
<strong>Das kann nicht rückgängig gemacht werden.</strong><br /><br />
Um Embargo-Benachrichtigungen für dieses Dokument zu deaktivieren, löschen Sie das Embargo-Enddatum aus den Metadaten. Um das Dokument zu verwerfen, nutzen Sie den Button "Verwerfen".]]>
</target>
</trans-unit>
<trans-unit id="manager.confirmDeleteEmbargoWorkingCopy.messageHeader" approved="yes">
<source>This action is not recommended!</source>
<target>Diese Aktion ist nicht empfohlen!</target>
</trans-unit>
<trans-unit id="manager.confirmRegister.message" approved="yes" xml:space="preserve">
<source>The document is handed over to the library for further processing.</source>
<target>Das Dokument wird zur weiteren Bearbeitung an die Bibliothek übergeben.</target>
Expand Down
9 changes: 9 additions & 0 deletions Resources/Private/Language/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,15 @@
<trans-unit id="manager.confirmDeleteWorkingCopy.messageHeader" approved="yes">
<source>Do you really want to delete the working copy?</source>
</trans-unit>
<trans-unit id="manager.confirmDeleteEmbargoWorkingCopy.message" xml:space="preserve">
<source><![CDATA[You are about to delete the working copy of an embargoed document. If you continue, embargo notifications for this document will no longer work and the associated full-text file in the repository may be lost.
<strong>This cannot be undone.</strong><br /><br />
To disable embargo notifications for this document, delete the embargo end date from the metadata. To discard the document, use the “Discard” button.]]>
</source>
</trans-unit>
<trans-unit id="manager.confirmDeleteEmbargoWorkingCopy.messageHeader" approved="yes">
<source>This action is not recommended!</source>
</trans-unit>
<trans-unit id="manager.confirmRegister.message" approved="yes" xml:space="preserve">
<source>The document is handed over to the library for further processing.</source>
</trans-unit>
Expand Down
6 changes: 5 additions & 1 deletion Resources/Private/Partials/Document/ConfirmAction.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ <h5 class="modal-title">{f:translate(key: 'manager.confirm{actionName}{actionSuf
aria-hidden="true">&times;</span></button>
</div>
<div class="modal-body">
<p>{f:translate(key: 'manager.confirm{actionName}{actionSuffix}.message', arguments: {0: '%s'})}</p>
<p>
<f:format.raw>
{f:translate(key: 'manager.confirm{actionName}{actionSuffix}.message', arguments: {0: '%s'})}
</f:format.raw>
</p>
<f:form id="confirm{actionName}Document" action="postpone" method="post" name="document" object="{document}" enctype="multipart/form-data">
<f:if condition="{reasonRequired}">
<label data-error="wrong" data-success="right">
Expand Down
3 changes: 2 additions & 1 deletion Resources/Private/Templates/Document/ShowDetails.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ <h1 class="h2">Details</h1>
controller="Document"
arguments="{document:document, tstamp:document.tstamp}"
class="isDocumentEditable btn btn-sm btn-danger"
additionalAttributes="{data-documenttitle: document.title,data-toggle: 'modal',data-confirmTarget: '#confirmDeleteWorkingCopy'}">
additionalAttributes="{data-documenttitle: document.title,data-toggle: 'modal',data-confirmTarget: '{f:if(condition:\'{document.embargoWorkingCopy}\', then:\'#confirmDeleteEmbargoWorkingCopy\', else:\'#confirmDeleteWorkingCopy\')}'}">
<i class="fas fa-trash-alt"></i>
{f:translate(key: 'form_button.deleteWorkingCopy')}
</f:link.action>
Expand Down Expand Up @@ -204,6 +204,7 @@ <h1 class="h2">Details</h1>
<f:render partial="Document/ConfirmAction" arguments="{action: 'postpone', reasonRequired: '1', reasonOptions:postponeOptions, destructiveAction: '1'}" />
<f:render partial="Document/ConfirmAction" arguments="{action: 'deleteLocally', destructiveAction: '1'}" />
<f:render partial="Document/ConfirmAction" arguments="{action: 'deleteWorkingCopy', destructiveAction: '1'}" />
<f:render partial="Document/ConfirmAction" arguments="{action: 'deleteEmbargoWorkingCopy', destructiveAction: '1'}" />
<f:render partial="Document/ConfirmAction" arguments="{action: 'register'}" />
<f:render partial="Document/ConfirmAction" arguments="{action: 'releasePublish'}" />
<f:render partial="Document/ConfirmAction" arguments="{action: 'releaseActivate'}" />
Expand Down
1 change: 1 addition & 0 deletions Resources/Public/JavaScript/kitodopublication.js
Original file line number Diff line number Diff line change
Expand Up @@ -2252,6 +2252,7 @@ $(document).ready(function() {
documentListConfirmDialog("#confirmDeleteLocally");
documentListConfirmDialog("#confirmDeleteLocallySuggestion");
documentListConfirmDialog("#confirmDeleteWorkingCopy");
documentListConfirmDialog("#confirmDeleteEmbargoWorkingCopy");
documentListConfirmDialog("#confirmRegister");
documentListConfirmDialog("#confirmPostpone");

Expand Down
3 changes: 3 additions & 0 deletions ext_conf_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ uploadDirectory = uploads/tx_dpf

# cat=Upload; type=string; label=LLL:EXT:dpf/Resources/Private/Language/locallang.xlf:config.uploadDomain
uploadDomain =

# cat=E-Mail; type=string; label=no reply email address
noReplyAddress = [email protected]
1 change: 1 addition & 0 deletions ext_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ CREATE TABLE tx_dpf_domain_model_document (
valid tinyint(1) unsigned DEFAULT '0' NOT NULL,
embargo_date int(11) unsigned DEFAULT '0' NOT NULL,
automatic_embargo tinyint(1) unsigned DEFAULT '0' NOT NULL,
embargo_working_copy tinyint(1) unsigned DEFAULT '0' NOT NULL,

file int(11) unsigned DEFAULT '0' NOT NULL,
owner int(11) unsigned default '0' NOT NULL,
Expand Down

0 comments on commit c93e353

Please sign in to comment.