Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/be user #103

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions Classes/Domain/Model/Backend/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php
namespace T3Monitor\T3monitoring\Domain\Model\Backend;

/*
* This file is part of the t3monitoring extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/

use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;

class User extends AbstractEntity
{
/**
* @var string
*/
protected $userName;

/**
* @var string
*/
protected $realName;

/**
* @var string
*/
protected $description;

/**
* @var string
*/
protected $lastLogin;

/**
* @var string
*/
protected $emailAddress;

/**
* @return string
*/
public function getUserName()
{
return $this->userName;
}

/**
* @param string $userName
*/
public function setUserName($userName)
{
$this->userName = $userName;
}

/**
* @return string
*/
public function getRealName()
{
return $this->realName;
}

/**
* @param string $realName
*/
public function setRealName($realName)
{
$this->realName = $realName;
}

/**
* @return string
*/
public function getDescription()
{
return $this->description;
}

/**
* @param string $description
*/
public function setDescription($description)
{
$this->description = $description;
}

/**
* @return string
*/
public function getLastLogin()
{
return $this->lastLogin;
}

/**
* @param string $lastLogin
*/
public function setLastLogin($lastLogin)
{
$this->lastLogin = $lastLogin;
}

/**
* @return string
*/
public function getEmailAddress()
{
return $this->emailAddress;
}

/**
* @param string $emailAddress
*/
public function setEmailAddress($emailAddress)
{
$this->emailAddress = $emailAddress;
}
}
52 changes: 52 additions & 0 deletions Classes/Domain/Model/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* LICENSE.txt file that was distributed with this source code.
*/

use T3Monitor\T3monitoring\Domain\Model\Backend\User;
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;

Expand All @@ -18,6 +19,7 @@ class Client extends AbstractEntity
{

/**
*
* @var string
* @validate NotEmpty
*/
Expand Down Expand Up @@ -115,6 +117,12 @@ class Client extends AbstractEntity
*/
protected $lastSuccessfulImport = null;

/**
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\T3Monitor\T3monitoring\Domain\Model\Backend\User>
* @lazy
*/
protected $backendUsers = null;

/**
* @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\T3Monitor\T3monitoring\Domain\Model\Extension>
* @lazy
Expand Down Expand Up @@ -159,6 +167,7 @@ public function __construct()
protected function initStorageObjects()
{
$this->extensions = new ObjectStorage();
$this->backendUsers = new ObjectStorage();
}

/**
Expand Down Expand Up @@ -613,6 +622,49 @@ public function setExtensions(ObjectStorage $extensions)
$this->extensions = $extensions;
}

/**
* Adds a backend user
*
* @param User $backendUser
* @return void
*/
public function addBackendUser(User $backendUser)
{
$this->backendUsers->attach($backendUser);
}

/**
* Removes a backend user
*
* @param User $backendUserToRemove The backend user to be removed
* @return void
*/
public function removeBackendUser(User $backendUserToRemove)
{
$this->backendUsers->detach($backendUserToRemove);
}

/**
* Returns the backend users
*
* @return \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\T3Monitor\T3monitoring\Domain\Model\Backend\User> $backendUsers
*/
public function getBackendUsers()
{
return $this->backendUsers;
}

/**
* Sets the backend users
*
* @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\T3Monitor\T3monitoring\Domain\Model\Backend\User> $backendUsers
* @return void
*/
public function setBackendUsers(ObjectStorage $backendUsers)
{
$this->backendUsers = $backendUsers;
}

/**
* Returns the core
*
Expand Down
16 changes: 16 additions & 0 deletions Classes/Domain/Repository/Backend/UserRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
namespace T3Monitor\T3monitoring\Domain\Repository\Backend;

/*
* This file is part of the t3monitoring extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/

use T3Monitor\T3monitoring\Domain\Repository\BaseRepository;

class UserRepository extends BaseRepository
{

}
59 changes: 59 additions & 0 deletions Classes/Service/Import/ClientImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ protected function importSingleClient(array $row)
'disk_free_space' => $json['core']['diskFreeSpace'],
'core' => $this->getUsedCore($json['core']['typo3Version']),
'extensions' => $this->handleExtensionRelations($row['uid'], (array)$json['extensions']),
'backend_users' => $this->handleBackendUserRelations($row['uid'], (array)$json['users']['backend']),
);

$this->addExtraData($json, $update, 'info');
Expand Down Expand Up @@ -264,6 +265,64 @@ protected function handleExtensionRelations($client, array $extensions = array()
return count($extensions);
}

/**
* @param int $client client uid
* @param array $users list of extensions
* @return int count of used extensions
*/
protected function handleBackendUserRelations($client, array $users = array())
{
$table = 'tx_t3monitoring_domain_model_backend_user';
$mmTable = 'tx_t3monitoring_client_backend_user_mm';

$existingUsers = $this->getDatabaseConnection()->exec_SELECTgetRows('A.*', $table.' A LEFT OUTER JOIN '.$mmTable.' B ON A.uid=B.uid_foreign', 'B.uid_local='.(int)$client);

foreach ($users as $user) {
$found = null;

foreach ($existingUsers as $existingUser) {
if($existingUser['user_name'] == $user['userName']) {
$found = $existingUser;
break;
}
}

if ($found) {
$relationId = $found['uid'];
$update = array(
'real_name' => (string)$user['realName'],
'email_address' => (string)$user['emailAddress'],
'description' => (string)$user['description'],
'last_login' => (string)$user['lastLogin'],
'tstamp' => $GLOBALS['EXEC_TIME'],
);
$this->getDatabaseConnection()->exec_UPDATEquery($table, 'uid='.(int)$relationId, $update);
} else {
$insert = array(
'pid' => $this->emConfiguration->getPid(),
'user_name' => (string)$user['userName'],
'real_name' => (string)$user['realName'],
'email_address' => (string)$user['emailAddress'],
'description' => (string)$user['description'],
'last_login' => (string)$user['lastLogin'],
'tstamp' => $GLOBALS['EXEC_TIME'],
);
$this->getDatabaseConnection()->exec_INSERTquery($table, $insert);
$relationId = $this->getDatabaseConnection()->sql_insert_id();
}
$fields = array('uid_local', 'uid_foreign');
$relationsToBeAdded[] = array(
$client,
$relationId
);

$this->getDatabaseConnection()->exec_DELETEquery($mmTable, 'uid_local=' . (int)$client);
$this->getDatabaseConnection()->exec_INSERTmultipleRows($mmTable, $fields, $relationsToBeAdded);
}

return count($users);
}

/**
* @param string $version
* @return int
Expand Down
100 changes: 100 additions & 0 deletions Configuration/TCA/tx_t3monitoring_domain_model_backend_user.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?php
return [
'ctrl' => [
'title' => 'LLL:EXT:t3monitoring/Resources/Private/Language/locallang.xlf:tx_t3monitoring_domain_model_backend_user',
'label' => 'real_name',
'label_alt' => 'user_name',
'label_alt_force' => true,
'hideTable' => true,
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'cruser_id' => 'cruser_id',
'delete' => 'deleted',
'enablecolumns' => [
'disabled' => 'hidden',
],
'searchFields' => 'user_name,real_name,email_address,last_login,description,',
'iconfile' => 'EXT:t3monitoring/Resources/Public/Icons/tx_t3monitoring_domain_model_backend_user.gif'
],
'interface' => [
'showRecordFieldList' => 'hidden, user_name, real_name, email_address, description, last_login',
],
'types' => [
'1' => [
'showitem' => '
--div--;Readonly information,user_name, real_name, email_address, description, last_login'
],
],
'palettes' => [
],
'columns' => [

'hidden' => [
'exclude' => 1,
'label' => 'LLL:EXT:lang/locallang_general.xlf:LGL.hidden',
'config' => [
'type' => 'check',
],
],

'user_name' => [
'exclude' => 1,
'label' => 'LLL:EXT:t3monitoring/Resources/Private/Language/locallang.xlf:tx_t3monitoring_domain_model_backend_user.user_name',
'config' => [
'readOnly' => true,
'type' => 'input',
'size' => 30,
'eval' => 'trim,required',
'max' => 255
],

],
'email_address' => [
'exclude' => 1,
'label' => 'LLL:EXT:t3monitoring/Resources/Private/Language/locallang.xlf:tx_t3monitoring_domain_model_backend_user.email_address',
'config' => [
'readOnly' => true,
'type' => 'input',
'size' => 30,
'eval' => 'trim',
'max' => 255
],

],
'real_name' => [
'exclude' => 1,
'label' => 'LLL:EXT:t3monitoring/Resources/Private/Language/locallang.xlf:tx_t3monitoring_domain_model_backend_user.real_name',
'config' => [
'readOnly' => true,
'type' => 'input',
'size' => 30,
'eval' => 'trim,required',
'max' => 255
],

],
'description' => [
'exclude' => 1,
'label' => 'LLL:EXT:t3monitoring/Resources/Private/Language/locallang.xlf:tx_t3monitoring_domain_model_backend_user.description',
'config' => [
'readOnly' => true,
'type' => 'text',
'default' => '',
'cols' => 40,
'rows' => 5,
],

],
'last_login' => [
'exclude' => 1,
'label' => 'LLL:EXT:t3monitoring/Resources/Private/Language/locallang.xlf:tx_t3monitoring_domain_model_backend_user.last_login',
'config' => [
'readOnly' => true,
'type' => 'input',
'size' => 30,
'eval' => 'datetime'
],

],
],
];
Loading