| 1 | <?php |
||
| 2 | /* |
||
| 3 | * This file is part of the TYPO3 CMS project. |
||
| 4 | * |
||
| 5 | * It is free software; you can redistribute it and/or modify it under |
||
| 6 | * the terms of the GNU General Public License, either version 2 |
||
| 7 | * of the License, or any later version. |
||
| 8 | * |
||
| 9 | * For the full copyright and license information, please read the |
||
| 10 | * LICENSE.txt file that was distributed with this source code. |
||
| 11 | * |
||
| 12 | * The TYPO3 project - inspiring people to share! |
||
| 13 | */ |
||
| 14 | |||
| 15 | if (!defined('TYPO3_MODE')) { |
||
| 16 | die('Access denied.'); |
||
| 17 | } |
||
| 18 | |||
| 19 | use EWW\Dpf\Domain\Repository\DocumentRepository; |
||
| 20 | use TYPO3\CMS\Core\Utility\GeneralUtility; |
||
| 21 | use TYPO3\CMS\Core\Registry; |
||
| 22 | use TYPO3\CMS\Extbase\Object\ObjectManager; |
||
| 23 | use EWW\Dpf\Security\Security; |
||
| 24 | |||
| 25 | |||
| 26 | class ext_update { |
||
| 27 | |||
| 28 | // Ideally the version corresponds with the extension version |
||
| 29 | const VERSION = "v4.0.0"; |
||
| 30 | |||
| 31 | public function access() { |
||
| 32 | $registry = GeneralUtility::makeInstance(Registry::class); |
||
| 33 | $version = $registry->get('tx_dpf','updatescript-'.self::VERSION); |
||
| 34 | |||
| 35 | // If the version has already been registered in the table sys_register the updatscript will be blocked. |
||
| 36 | if ($version) { |
||
| 37 | return FALSE; |
||
| 38 | } |
||
| 39 | |||
| 40 | return TRUE; |
||
| 41 | } |
||
| 42 | |||
| 43 | public function main() { |
||
| 44 | // This script registers itself into the sys_registry table to prevent a re-run with the same version number. |
||
| 45 | $registry = GeneralUtility::makeInstance(Registry::class); |
||
| 46 | $version = $registry->get('tx_dpf','updatescript-'.self::VERSION); |
||
| 47 | if ($version) { |
||
| 48 | return FALSE; |
||
| 49 | } else { |
||
| 50 | |||
| 51 | try { |
||
| 52 | // The necessary updates. |
||
| 53 | (new UpdateState)->execute(); |
||
| 54 | (new UpdateAccessRestrictions)->execute(); |
||
| 55 | (new UpdateVirtualType)->execute(); |
||
| 56 | //$GLOBALS['TYPO3_DB']->sql_query("update tx_dpf_domain_model_document set creator = owner"); |
||
| 57 | } catch (\Throwable $throwable) { |
||
| 58 | return "Error while updating the extension: ".($throwable->getMessage()); |
||
| 59 | } |
||
| 60 | |||
| 61 | $registry->set('tx_dpf','updatescript-'.self::VERSION,TRUE); |
||
| 62 | } |
||
| 63 | |||
| 64 | return "The extension has been successfully updated."; |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | |||
| 69 | class UpdateState |
||
| 70 | { |
||
| 71 | const OBJECT_STATE_NEW = "NEW"; |
||
| 72 | const OBJECT_STATE_ACTIVE = "ACTIVE"; |
||
| 73 | const OBJECT_STATE_INACTIVE = "INACTIVE"; |
||
| 74 | const OBJECT_STATE_DELETED = "DELETED"; |
||
| 75 | const OBJECT_STATE_LOCALLY_DELETED = "LOCALLY_DELETED"; |
||
| 76 | |||
| 77 | public function execute() |
||
| 78 | { |
||
| 79 | $objectManager = GeneralUtility::makeInstance(ObjectManager::class); |
||
| 80 | $documentRepository = $objectManager->get(DocumentRepository::class); |
||
| 81 | |||
| 82 | $documents = $documentRepository->crossClientFindAll(); |
||
| 83 | |||
| 84 | foreach ($documents as $oldDocument) { |
||
| 85 | $oldState = $oldDocument['state']; |
||
| 86 | $objectIdentifier = $oldDocument['objectIdentifier']; |
||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 87 | |||
| 88 | $newDocument = $documentRepository->findByUid($oldDocument['uid']); |
||
| 89 | |||
| 90 | switch ($oldState) { |
||
| 91 | case self::OBJECT_STATE_NEW: |
||
| 92 | $newDocument->setState(\EWW\Dpf\Domain\Workflow\DocumentWorkflow::STATE_NEW_NONE); |
||
| 93 | break; |
||
| 94 | case self::OBJECT_STATE_ACTIVE: |
||
| 95 | $newDocument->setState(\EWW\Dpf\Domain\Workflow\DocumentWorkflow::STATE_IN_PROGRESS_ACTIVE); |
||
| 96 | break; |
||
| 97 | case self::OBJECT_STATE_INACTIVE: |
||
| 98 | $newDocument->setState(\EWW\Dpf\Domain\Workflow\DocumentWorkflow::STATE_IN_PROGRESS_INACTIVE); |
||
| 99 | break; |
||
| 100 | case self::OBJECT_STATE_DELETED: |
||
| 101 | $newDocument->setState(\EWW\Dpf\Domain\Workflow\DocumentWorkflow::STATE_IN_PROGRESS_DELETED); |
||
| 102 | break; |
||
| 103 | case self::OBJECT_STATE_LOCALLY_DELETED: |
||
| 104 | $newDocument->setState(\EWW\Dpf\Domain\Workflow\DocumentWorkflow::STATE_NONE_NONE); |
||
| 105 | break; |
||
| 106 | } |
||
| 107 | |||
| 108 | $documentRepository->update($newDocument); |
||
| 109 | } |
||
| 110 | } |
||
| 111 | } |
||
| 112 | |||
| 113 | class UpdateAccessRestrictions |
||
| 114 | { |
||
| 115 | public function execute() { |
||
| 116 | |||
| 117 | $objectManager = GeneralUtility::makeInstance(ObjectManager::class); |
||
| 118 | $repositories[] = $objectManager->get(\EWW\Dpf\Domain\Repository\MetadataObjectRepository::class); |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
| 119 | $repositories[] = $objectManager->get(\EWW\Dpf\Domain\Repository\MetadataGroupRepository::class); |
||
| 120 | $repositories[] = $objectManager->get(\EWW\Dpf\Domain\Repository\MetadataPageRepository::class); |
||
| 121 | |||
| 122 | foreach ($repositories as $repository) { |
||
| 123 | foreach ($repository->crossClientFindAll() as $record) { |
||
| 124 | if ($record['backend_only']) { |
||
| 125 | $recordObject = $repository->findByUid($record['uid']); |
||
| 126 | $recordObject->setAccessRestrictionRoles(array(Security::ROLE_LIBRARIAN, Security::ROLE_RESEARCHER)); |
||
| 127 | $repository->update($recordObject); |
||
| 128 | } |
||
| 129 | } |
||
| 130 | } |
||
| 131 | } |
||
| 132 | } |
||
| 133 | |||
| 134 | class UpdateVirtualType |
||
| 135 | { |
||
| 136 | public function execute() { |
||
| 137 | |||
| 138 | $objectManager = GeneralUtility::makeInstance(ObjectManager::class); |
||
| 139 | $repository = $objectManager->get(\EWW\Dpf\Domain\Repository\DocumentTypeRepository::class); |
||
| 140 | |||
| 141 | foreach ($repository->crossClientFindAll() as $record) { |
||
| 142 | if ($record['virtual']) { |
||
| 143 | $recordObject = $repository->findByUid($record['uid']); |
||
| 144 | $recordObject->setVirtualType($record['virtual'] === 1); |
||
| 145 | $repository->update($recordObject); |
||
| 146 | } |
||
| 147 | } |
||
| 148 | |||
| 149 | // $GLOBALS['TYPO3_DB']->sql_query("ALTER TABLE tx_dpf_domain_model_documenttype CHANGE virtual zzz_deleted_virtual SMALLINT UNSIGNED DEFAULT 0 NOT NULL"); |
||
| 150 | |||
| 151 | } |
||
| 152 | } |