From 11d53344db674b92a7aaacdfbc4e11781856ae6a Mon Sep 17 00:00:00 2001 From: Mohsin Khan Date: Fri, 9 Jun 2017 02:03:16 +0200 Subject: [PATCH 1/3] Import and Export of be_groups now based on Group Title (Because UID's may have conflict in diffrent TYPO3 systems) --- Classes/Command/ExportCommandController.php | 14 +++++++++- Classes/Command/ImportCommandController.php | 29 +++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/Classes/Command/ExportCommandController.php b/Classes/Command/ExportCommandController.php index 57c0899..25eef7a 100644 --- a/Classes/Command/ExportCommandController.php +++ b/Classes/Command/ExportCommandController.php @@ -193,7 +193,19 @@ public function exportTable( if (in_array($column, $skipColumns)) { continue; } - $explodedValue = explode(',', $value); + + // do not update usergroups by UID when exporting to other systems + // UID maybe diffrent for the same usergroup name + if($table == 'be_users' && $column == 'usergroup' && $value) { + $usergroups = $this->databaseConnection->exec_SELECTgetRows('title', 'be_groups', 'uid IN ('.$value.')'); + foreach ($usergroups as $singleUserGroup) { + $usergroupsTitles[] = $singleUserGroup['title']; + } + $explodedValue = $usergroupsTitles; + } else { + $explodedValue = explode(',', $value); + } + if (count($explodedValue) > 1) { $explodedRow[$column] = $explodedValue; } elseif ($value) { diff --git a/Classes/Command/ImportCommandController.php b/Classes/Command/ImportCommandController.php index 443c48b..3872305 100644 --- a/Classes/Command/ImportCommandController.php +++ b/Classes/Command/ImportCommandController.php @@ -153,6 +153,9 @@ protected function importData($table, $matchFields, $file = null) if ($row) { $this->successMessage('Found existing ' . $table . ' record by matchfields: ' . $matchClause); $this->message('Updating . . .'); + if(isset($record['usergroup'])) { + $record['usergroup'] = $this->convertUsergroupNamesToUid($record); + } $record = $this->updateTimeFields($record, $columnNames, array('tstamp')); $this->databaseConnection->exec_UPDATEquery( $table, @@ -171,4 +174,30 @@ protected function importData($table, $matchFields, $file = null) } } } + + /** + * Usergroup names to uid conversion + * + * @since 1.0.0 + * + * @param $record database record for the user that is going to import + * @return string + */ + protected function convertUsergroupNamesToUid($record) + { + if(!isset($record['usergroup'])) + return ''; + + foreach(explode(",",$record['usergroup']) as $usergroupTitle) { + $whereInCondition .= $whereInCondition ? ",": ""; + $whereInCondition .= '"'.$usergroupTitle.'"'; + } + $groupsUids = $this->databaseConnection->exec_SELECTgetRows('uid','be_groups','title IN('.$whereInCondition.')'); + foreach ($groupsUids as $group) { + $commaSepratedGroupUids .= $commaSepratedGroupUids ? ",": ""; + $commaSepratedGroupUids .= $group['uid']; + } + + return $commaSepratedGroupUids; + } } From c78ddb9b2cc6157b81436905aab0c05471853cff Mon Sep 17 00:00:00 2001 From: Mohsin Khan Date: Fri, 9 Jun 2017 02:47:14 +0200 Subject: [PATCH 2/3] optional parameter for all export commands added to make yaml file human readable --- Classes/Command/ExportCommandController.php | 36 ++++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/Classes/Command/ExportCommandController.php b/Classes/Command/ExportCommandController.php index 25eef7a..28e37a3 100644 --- a/Classes/Command/ExportCommandController.php +++ b/Classes/Command/ExportCommandController.php @@ -45,14 +45,16 @@ class ExportCommandController extends AbstractCommandController * @param string $skipColumns A comma separated list of column names to skip. Default: **uc,crdate,lastlogin,tstamp** * @param bool $includeDeleted Export deleted records. Default: **false** * @param bool $includeHidden Export hidden/disable records. Default: **false** + * @param integer $indentLevel indent level to make yaml file human readable. Default: **2** */ public function backendUsersCommand( $file = null, $skipColumns = 'crdate,lastlogin,tstamp,uc', $includeDeleted = false, - $includeHidden = false + $includeHidden = false, + $indentLevel = 2 ) { - $this->exportTable('be_users', $file, $skipColumns, $includeDeleted, $includeHidden); + $this->exportTable('be_users', $file, $skipColumns, $includeDeleted, $includeHidden, $indentLevel); } /** * Export be_groups table to yml file @@ -63,14 +65,16 @@ public function backendUsersCommand( * @param string $skipColumns A comma separated list of column names to skip. Default: **uc,crdate,lastlogin,tstamp** * @param bool $includeDeleted Export deleted records. Default: **false** * @param bool $includeHidden Export hidden/disable records. Default: **false** + * @param integer $indentLevel indent level to make yaml file human readable. Default: **2** */ public function backendGroupsCommand( $file = null, $skipColumns = 'crdate,lastlogin,tstamp,uc', $includeDeleted = false, - $includeHidden = false + $includeHidden = false, + $indentLevel = 2 ) { - $this->exportTable('be_groups', $file, $skipColumns, $includeDeleted, $includeHidden); + $this->exportTable('be_groups', $file, $skipColumns, $includeDeleted, $includeHidden, $indentLevel); } /** @@ -82,14 +86,16 @@ public function backendGroupsCommand( * @param string $skipColumns A comma separated list of column names to skip. Default: **uc,crdate,lastlogin,tstamp** * @param bool $includeDeleted Export deleted records. Default: **false** * @param bool $includeHidden Export hidden/disable records. Default: **false** + * @param integer $indentLevel indent level to make yaml file human readable. Default: **2** */ public function frontendUsersCommand( $file = null, $skipColumns = 'crdate,lastlogin,tstamp,uc', $includeDeleted = false, - $includeHidden = false + $includeHidden = false, + $indentLevel = 2 ) { - $this->exportTable('fe_users', $file, $skipColumns, $includeDeleted, $includeHidden); + $this->exportTable('fe_users', $file, $skipColumns, $includeDeleted, $includeHidden, $indentLevel); } /** @@ -101,14 +107,16 @@ public function frontendUsersCommand( * @param string $skipColumns A comma separated list of column names to skip. Default: **uc,crdate,lastlogin,tstamp** * @param bool $includeDeleted Export deleted records. Default: **false** * @param bool $includeHidden Export hidden/disable records. Default: **false** + * @param integer $indentLevel indent level to make yaml file human readable. Default: **2** */ public function frontendGroupsCommand( $file = null, $skipColumns = 'crdate,lastlogin,tstamp,uc', $includeDeleted = false, - $includeHidden = false + $includeHidden = false, + $indentLevel = 2 ) { - $this->exportTable('fe_groups', $file, $skipColumns, $includeDeleted, $includeHidden); + $this->exportTable('fe_groups', $file, $skipColumns, $includeDeleted, $includeHidden, $indentLevel); } /** @@ -121,15 +129,17 @@ public function frontendGroupsCommand( * @param string $skipColumns A comma separated list of column names to skip. Default: **uc,crdate,lastlogin,tstamp** * @param bool $includeDeleted Dump deleted records. Default: **false** * @param bool $includeHidden Dump hidden/disable records. Default: **false** + * @param integer $indentLevel indent level to make yaml file human readable. Default: **2** */ public function tableCommand( $table, $file = null, $skipColumns = 'crdate,lastlogin,tstamp,uc', $includeDeleted = false, - $includeHidden = false + $includeHidden = false, + $indentLevel = 2 ) { - $this->exportTable($table, $file, $skipColumns, $includeDeleted, $includeHidden); + $this->exportTable($table, $file, $skipColumns, $includeDeleted, $includeHidden, $indentLevel); } /** @@ -142,6 +152,7 @@ public function tableCommand( * @param string $skipColumns * @param bool $includeDeleted Export deleted records. Default: **false** * @param bool $includeHidden Export hidden/disable records. Default: **false** + * @param integer $indentLevel indent level to make yaml file human readable. Default: **2** * * @return void */ @@ -150,7 +161,8 @@ public function exportTable( $file = null, $skipColumns = 'crdate,lastlogin,tstamp,uc', $includeDeleted = false, - $includeHidden = false + $includeHidden = false, + $indentLevel = 2 ) { $table = preg_replace('/[^a-z0-9_]/', '', $table); $skipColumns = explode(',', $skipColumns); @@ -221,7 +233,7 @@ public function exportTable( ) ) ); - $yaml = Yaml::dump($dump); + $yaml = Yaml::dump($dump, $indentLevel); } if ($yaml !== '') { From 2f51c5c786742a21cd2a9eaf3ca70f93cbf54e29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=84=B3ichiel=20=E2=84=9Boos?= Date: Tue, 13 Jun 2017 11:55:16 +0200 Subject: [PATCH 3/3] Update ImportCommandController.php --- Classes/Command/ImportCommandController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/Command/ImportCommandController.php b/Classes/Command/ImportCommandController.php index 3872305..ea92b6e 100644 --- a/Classes/Command/ImportCommandController.php +++ b/Classes/Command/ImportCommandController.php @@ -178,7 +178,7 @@ protected function importData($table, $matchFields, $file = null) /** * Usergroup names to uid conversion * - * @since 1.0.0 + * @since 1.1.0 * * @param $record database record for the user that is going to import * @return string