Skip to content

Commit

Permalink
Merge 855651f into f02d33e
Browse files Browse the repository at this point in the history
  • Loading branch information
haogatyp committed Jun 16, 2021
2 parents f02d33e + 855651f commit 29c434a
Show file tree
Hide file tree
Showing 54 changed files with 1,276 additions and 1,499 deletions.
43 changes: 43 additions & 0 deletions Classes/Configuration/ClientConfigurationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,47 @@ public function getTypoScriptSettings()
return $settings;
}

public function getFileIdXpath()
{
return $this->trimFileXpath($this->getSetting("fileIdXpath", "fileIdXpath"));
}

public function getFileMimetypeXpath()
{
return $this->trimFileXpath($this->getSetting("fileMimetypeXpath", "fileMimetypeXpath"));
}

public function getFileHrefXpath()
{
return $this->trimFileXpath($this->getSetting("fileHrefXpath", "fileHrefXpath"));
}

public function getFileDownloadXpath()
{
return $this->trimFileXpath($this->getSetting("fileDownloadXpath", "fileDownloadXpath"));
}

public function getFileArchiveXpath()
{
return $this->trimFileXpath($this->getSetting("fileArchiveXpath", "fileArchiveXpath"));
}

public function getFileDeletedXpath()
{
return$this->trimFileXpath($this->getSetting("fileDeletedXpath", "fileDeletedXpath"));
}

public function getFileTitleXpath()
{
return $this->trimFileXpath($this->getSetting("fileTitleXpath", "fileTitleXpath"));
}

/**
* @param string $xpath
* @return string
*/
protected function trimFileXpath(string $xpath): ?string
{
return trim($xpath, "@/ ");
}
}
46 changes: 14 additions & 32 deletions Classes/Controller/AbstractDocumentFormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function initializeCreateAction()
if (!$formDataReader->uploadError() || $virtualType === true) {
$this->request->setArguments($requestArguments);
} else {
$t = $docForm->getNewFileNames();
$t = $docForm->getFileNames();
$this->redirect('list', 'DocumentForm', null, array('message' => 'UPLOAD_MAX_FILESIZE_ERROR', 'errorFiles' => $t));
}
} else {
Expand Down Expand Up @@ -245,8 +245,7 @@ public function createAction(DocumentForm $newDocumentForm)
$depositLicenseLog->setUrn($newDocument->getPrimaryUrn());
$depositLicenseLog->setLicenceUri($newDocument->getDepositLicense());

if ($newDocument->getFileData()) {

if ($newDocument->hasFiles()) {
$fileList = [];
foreach ($newDocument->getFile() as $file) {
if (!$file->isFileGroupDeleted()) {
Expand All @@ -264,17 +263,17 @@ public function createAction(DocumentForm $newDocumentForm)
}

// Add or update files
$newFiles = $newDocumentForm->getNewFiles();

if (is_array($newFiles)) {
foreach ($newFiles as $newFile) {

if ($newFile->getUID()) {
$this->fileRepository->update($newFile);
$files = $newDocumentForm->getFiles();
// TODO: Is this still necessary?
if (is_array($files)) {
foreach ($files as $file) {
// TODO: Is this still necessary?
if ($file->getUID()) {
$this->fileRepository->update($file);
} else {
$newFile->setDocument($newDocument);
$this->fileRepository->add($newFile);
$newDocument->addFile($newFile);
$file->setDocument($newDocument);
$this->fileRepository->add($file);
$newDocument->addFile($file);
$this->documentRepository->update($newDocument);
}
}
Expand Down Expand Up @@ -351,10 +350,11 @@ public function initializeUpdateAction()
$documentType = $this->documentTypeRepository->findByUid($docTypeUid);
$virtualType = $documentType->getVirtualType();


if (!$formDataReader->uploadError() || $virtualType === true) {
$this->request->setArguments($requestArguments);
} else {
$t = $docForm->getNewFileNames();
$t = $docForm->getFileNames();
$this->redirect('list', 'Document', null, array('message' => 'UPLOAD_MAX_FILESIZE_ERROR', 'errorFiles' => $t));
}
} else {
Expand Down Expand Up @@ -391,24 +391,6 @@ public function updateAction(DocumentForm $documentForm)
$updateDocument->setChanged(true);
$this->documentRepository->update($updateDocument);


// Delete files
foreach ($documentForm->getDeletedFiles() as $deleteFile) {
$deleteFile->setStatus(File::STATUS_DELETED);
$this->fileRepository->update($deleteFile);
}

// Add or update files
foreach ($documentForm->getNewFiles() as $newFile) {

if ($newFile->getUID()) {
$this->fileRepository->update($newFile);
} else {
$updateDocument->addFile($newFile);
}

}

// index the document
$this->signalSlotDispatcher->dispatch(AbstractController::class, 'indexDocument', [$updateDocument]);
}
Expand Down
47 changes: 40 additions & 7 deletions Classes/Controller/AjaxDocumentFormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* The TYPO3 project - inspiring people to share!
*/

use EWW\Dpf\Domain\Model\MetadataGroup;
use EWW\Dpf\Services\Identifier\Urn;
use EWW\Dpf\Services\Transfer\DocumentTransferManager;
use EWW\Dpf\Services\Transfer\FedoraRepository;
Expand Down Expand Up @@ -57,7 +58,7 @@ class AjaxDocumentFormController extends \EWW\Dpf\Controller\AbstractController
*/
public function groupAction($pageUid, $groupUid, $groupIndex)
{

/** @var MetadataGroup $group */
$group = $this->metadataGroupRepository->findByUid($groupUid);

//$groupItem = array();
Expand Down Expand Up @@ -87,6 +88,9 @@ public function groupAction($pageUid, $groupUid, $groupIndex)
}

$groupItem->setGroupType($group->getGroupType());
$groupItem->setMandatory($group->getMandatory());
$groupItem->setMaxIteration($group->getMaxIteration());
$groupItem->setEmptyGroup(true);

if ($this->security->getFisPersId()) {
$this->view->assign('fisPersId', $this->security->getFisPersId());
Expand Down Expand Up @@ -147,7 +151,7 @@ public function fieldAction($pageUid, $groupUid, $groupIndex, $fieldUid, $fieldI
*
* @return void
*/
public function primaryUploadAction($groupIndex)
public function uploadAction($groupIndex)
{
}

Expand All @@ -163,13 +167,42 @@ public function secondaryUploadAction($groupIndex)
}

/**
*
* @param integer $fileUid
* @param integer $isPrimary
* @return void
* @param int $fileUid
* @param int $pageUid
* @param int $groupUid
* @param int $groupIndex
* @param int $fieldUid
* @param int $fieldIndex
* @param int $isPrimary
*/
public function deleteFileAction($fileUid, $isPrimary = 0)
public function deleteFileAction($fileUid, $pageUid, $groupUid, $groupIndex, $fieldUid, $fieldIndex, $isPrimary = 0)
{
$field = $this->metadataObjectRepository->findByUid($fieldUid);

$fieldItem = new \EWW\Dpf\Domain\Model\DocumentFormField();

$fieldItem->setUid($field->getUid());
$fieldItem->setDisplayName($field->getDisplayName());
$fieldItem->setMandatory($field->getMandatory());
$fieldItem->setAccessRestrictionRoles($field->getAccessRestrictionRoles());
$fieldItem->setInputField($field->getInputField());
$fieldItem->setInputOptions($field->getInputOptionList());
$fieldItem->setMaxIteration($field->getMaxIteration());
$fieldItem->setFillOutService($field->getFillOutService());
$fieldItem->setValidation($field->getValidation());
$fieldItem->setDataType($field->getDataType());
$fieldItem->setGndFieldUid($field->getGndFieldUid());
$fieldItem->setMaxInputLength($field->getMaxInputLength());
$fieldItem->setValue("", $field->getDefaultValue());
$fieldItem->setObjectType($field->getObjectType());

$this->view->assign('formPageUid', $pageUid);
$this->view->assign('formGroupUid', $groupUid);
$this->view->assign('groupIndex', $groupIndex);

$this->view->assign('fieldIndex', $fieldIndex);
$this->view->assign('fieldItem', $fieldItem);

$this->view->assign('fileUid', $fileUid);
$this->view->assign('isPrimary', $isPrimary);
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public function addFisIdAction($document, $id, $token) {
$doc->setProcessNumber($processNumber);
}

if ($this->documentManager->update($doc, null, [], [], true)) {
if ($this->documentManager->update($doc, null,true)) {
return '{"success": "Document '.$document.' added '.$id.'"}';
} else {
return '{"failed": Could not update the Document"}';
Expand Down
36 changes: 13 additions & 23 deletions Classes/Controller/DocumentFormBackofficeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,12 @@ public function createSuggestionDocumentAction(\EWW\Dpf\Domain\Model\DocumentFor
{
$documentMapper = $this->objectManager->get(DocumentMapper::class);

$hasFilesFlag = true;

$workingCopy = $this->documentRepository->findByUid($documentForm->getDocumentUid());

if ($workingCopy->isTemporary()) {
$workingCopy->setTemporary(false);
}

if (empty($workingCopy->getFileData())) {
// no files are linked to the document
$hasFilesFlag = false;
}

$newDocument = $this->objectManager->get(Document::class);

$this->documentRepository->add($newDocument);
Expand All @@ -220,17 +213,19 @@ public function createSuggestionDocumentAction(\EWW\Dpf\Domain\Model\DocumentFor
$newDocument->setTransferStatus("RESTORE");
}

if (!$hasFilesFlag) {
if ($workingCopy->hasFiles()) {
// Add or update files
foreach ($documentForm->getNewFiles() as $newFile) {
if ($newFile->getUID()) {
$this->fileRepository->update($newFile);
// TODO: Is this still necessary?
foreach ($documentForm->getFiles() as $file) {
// TODO: Is this still necessary?
if ($file->getUID()) {
$this->fileRepository->update($file);
} else {
$newFile->setDocument($newDocument);
$this->fileRepository->add($newFile);
$file->setDocument($newDocument);
$this->fileRepository->add($file);
}

$newDocument->addFile($newFile);
$newDocument->addFile($file);
}
} else {
// remove files for suggest object
Expand Down Expand Up @@ -268,7 +263,7 @@ public function createSuggestionDocumentAction(\EWW\Dpf\Domain\Model\DocumentFor
$depositLicenseLog->setUrn($newDocument->getPrimaryUrn());
$depositLicenseLog->setLicenceUri($newDocument->getDepositLicense());

if ($newDocument->getFileData()) {
if ($newDocument->hasFiles()) {
$fileList = [];
foreach ($newDocument->getFile() as $file) {
$fileList[] = $file->getTitle();
Expand Down Expand Up @@ -301,7 +296,7 @@ public function updateAction(\EWW\Dpf\Domain\Model\DocumentForm $documentForm)
}

$backToList = $this->request->getArgument('documentData')['backToList'];

if ($this->request->hasArgument('saveAndUpdate')) {
$saveMode = 'saveAndUpdate';
} elseif ($this->request->hasArgument('saveWorkingCopy')) {
Expand Down Expand Up @@ -389,12 +384,7 @@ public function updateDocumentAction(\EWW\Dpf\Domain\Model\DocumentForm $documen
$workflowTransition = DocumentWorkflow::TRANSITION_IN_PROGRESS;
}

if (
$this->documentManager->update(
$updateDocument, $workflowTransition,
$documentForm->getDeletedFiles(), $documentForm->getNewFiles()
)
) {
if ($this->documentManager->update($updateDocument, $workflowTransition)) {

$depositLicenseLog = $this->depositLicenseLogRepository->findOneByProcessNumber($document->getProcessNumber());
if (empty($depositLicenseLog) && $updateDocument->getDepositLicense()) {
Expand All @@ -409,7 +399,7 @@ public function updateDocumentAction(\EWW\Dpf\Domain\Model\DocumentForm $documen
$depositLicenseLog->setUrn($document->getPrimaryUrn());
$depositLicenseLog->setLicenceUri($document->getDepositLicense());

if ($document->getFileData()) {
if ($document->hasFiles()) {
$fileList = [];
foreach ($document->getFile() as $file) {
$fileList[] = $file->getTitle();
Expand Down
10 changes: 5 additions & 5 deletions Classes/Controller/DocumentFormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ public function newAction(\EWW\Dpf\Domain\Model\DocumentForm $newDocumentForm =
*/
public function createAction(\EWW\Dpf\Domain\Model\DocumentForm $newDocumentForm)
{
foreach ($newDocumentForm->getNewFiles() as $newFile) {
$uid = $newFile->getUID();
foreach ($newDocumentForm->getFiles() as $file) {
$uid = $file->getUID();
if (empty($uid)) {
$newFile->setDownload(true);
$file->setDownload(true);
}
$files[] = $newFile;
$files[] = $file;
}

$newDocumentForm->setNewFiles($files);
$newDocumentForm->setFiles($files);

try {
parent::createAction($newDocumentForm);
Expand Down
Loading

0 comments on commit 29c434a

Please sign in to comment.