DataHandlerHook.php 3.25 KB
Newer Older
1
2
<?php

3
4
namespace T3o\T3oLdap\Hooks;

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/***************************************************************
 * Copyright notice
 *
 * (c) 2016 Andreas Beutel, mehrwert intermediale kommunikation GmbH <typo3@mehrwert.de>
 * All rights reserved
 *
 * This script is part of the TYPO3 project. The TYPO3 project is
 * free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * The GNU General Public License can be found at
 * http://www.gnu.org/copyleft/gpl.html.
 * A copy is found in the textfile GPL.txt and important notices to the license
 * from the author is found in LICENSE.txt distributed with these scripts.
 *
 *
 * This script is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/

31
32
use TYPO3\CMS\Core\Utility\GeneralUtility;

33
34
35
/**
 * Hook Functions for \TYPO3\CMS\Core\DataHandling\DataHandler
 */
36
37
class DataHandlerHook
{
38
39

    /**
40
41
     * Use DataHandler "afterAllOperations" hook to update or create FE Users
     * in LDAP.
42
43
44
     *
     * @return void
     */
45
46
    public function processDatamap_afterAllOperations(\TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler)
    {
47

48
        $extensionConfiguration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['t3o_ldap']);
49
        $enableLdapPasswordUpdates = (int)$extensionConfiguration['enableLdapPasswordUpdates'];
50

51
        if ($enableLdapPasswordUpdates === 1) {
52
53
54
55
            try {
                foreach ($dataHandler->datamap as $tableName => $configuration) {
                    if ($tableName === 'fe_users') {
                        foreach ($configuration as $feUserUid => $changedFields) {
56
                            $objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
57
                            $userRepository = $objectManager->get(\T3o\T3omy\Domain\Repository\MyProfileRepository::class);
58
                            $user = $userRepository->findByUid($feUserUid);
59
60
                            /** @var \T3o\T3oLdap\Utility\UserCreateUpdateDelete $userUtility */
                            $userUtility = GeneralUtility::makeInstance(\T3o\T3oLdap\Utility\UserCreateUpdateDelete::class);
61
                            $userUtility->updateUser($user);
62
                        }
63
64
                    }
                }
65
66
            } catch (\Exception $e) {
                /** @var $flashMessage \TYPO3\CMS\Core\Messaging\FlashMessage */
67
68
69
70
71
72
                $flashMessage = GeneralUtility::makeInstance(
                    \TYPO3\CMS\Core\Messaging\FlashMessage::class,
                    'Failed to update users in LDAP: ' . $e->getMessage(),
                    'Error in processDatamap_afterAllOperations',
                    \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
                );
73
                \TYPO3\CMS\Core\Messaging\FlashMessageQueue::addMessage($flashMessage);
74
75
            }
        }
76

77
78
    }

79
}