Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use TYPO3\CMS\Core\Utility\GeneralUtility;
- class ext_update
- {
- /**
- * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface
- */
- protected $objectManager;
- /**
- * frontendUserGroupRepository
- *
- * @var \TYPO3\CMS\Extbase\Domain\Repository\FrontendUserGroupRepository
- * @ inject
- */
- protected $frontendUserGroupRepository;
- /**
- * Checks whether the "UPDATE!" menu item should be
- * shown.
- *
- * @return boolean
- */
- function access() {
- # @var \TYPO3\CMS\Extbase\Validation\ValidatorResolver $validatorResolver
- $this->objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('Tx_Extbase_Object_ObjectManager');
- $this->frontendUserGroupRepository = $this->objectManager->get('\TYPO3\CMS\Extbase\Domain\Repository\FrontendUserGroupRepository');
- $querySettings = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('\TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings');
- $querySettings->setRespectStoragePage(false);
- # $querySettings->setStoragePageIds(array(2,28));
- $this->frontendUserGroupRepository->setDefaultQuerySettings($querySettings);
- if (
- (0 == $this->frontendUserGroupRepository->countByTitle('GROUP1')) or
- (0 == $this->frontendUserGroupRepository->countByTitle('GROUP2'))
- )
- return true; // Update necessary
- else
- return false; // Update not necessary
- }
- /**
- * Main method that is called whenever UPDATE! was clicked.
- *
- * @return string HTML to display
- */
- function main() {
- $operation = GeneralUtility::_GP('operation');
- if ($operation) {
- // TODO: Use the value from the input field as PID
- $this->getFrontendUserGroupByName('GROUP1', 2);
- $this->getFrontendUserGroupByName('GROUP2', 2);
- $out[] = 'Update performed!';
- } else {
- $out[] = '<form action="' . GeneralUtility::linkThisScript() . '" method="post" class="container-fluid">';
- $out[] = '<label>Page UID for new Groups to be created on</label>';
- $out[] = '<input name="pid" type="number" min="1" value=""/><br/>';
- $out[] = '<button name="operation" value="UPDATE">UPDATE</button>';
- $out[] = '</form>';
- }
- return implode(LF, $out);
- }
- // Helper function
- function getFrontendUserGroupByName($frontendUserGroupTitle, $pid) {
- /** @noinspection PhpUndefinedMethodInspection */
- if (0 == $this->frontendUserGroupRepository->countByTitle('GENSER')) {
- $fe_group = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
- '\\TYPO3\\CMS\\Extbase\\Domain\\Model\\FrontendUserGroup', $frontendUserGroupTitle
- );
- $fe_group->setPid($pid); // pageID where the group should be created
- $this->frontendUserGroupRepository->add($fe_group);
- }
- return;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment