Skip to content

Commit

Permalink
Merge pull request #25 from oliverschroeder/dev-24
Browse files Browse the repository at this point in the history
Dev 24
  • Loading branch information
Tuurlijk authored Mar 26, 2018
2 parents 132ec2e + 5a00ab2 commit 56677f4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 18 deletions.
27 changes: 17 additions & 10 deletions Classes/Command/ExportCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
*/
class ExportCommandController extends AbstractCommandController
{

/**
* Export be_users table to yml file
*
Expand All @@ -45,16 +46,19 @@ 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**
* @param integer $indentLevel Indent level to make yaml file human readable. Default: **2**
* @param bool $beUserMatchGroupByTitle Match be_group settings in be_users.usergroup by title or uid;
* if true be_groups.title is used. Default: **false**
*/
public function backendUsersCommand(
$file = null,
$skipColumns = 'crdate,lastlogin,tstamp,uc',
$includeDeleted = false,
$includeHidden = false,
$indentLevel = 2
$indentLevel = 2,
$beUserMatchGroupByTitle = false
) {
$this->exportTable('be_users', $file, $skipColumns, $includeDeleted, $includeHidden, $indentLevel);
$this->exportTable('be_users', $file, $skipColumns, $includeDeleted, $includeHidden, $indentLevel, $beUserMatchGroupByTitle);
}
/**
* Export be_groups table to yml file
Expand All @@ -65,7 +69,7 @@ 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**
* @param integer $indentLevel Indent level to make yaml file human readable. Default: **2**
*/
public function backendGroupsCommand(
$file = null,
Expand All @@ -86,7 +90,7 @@ 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**
* @param integer $indentLevel Indent level to make yaml file human readable. Default: **2**
*/
public function frontendUsersCommand(
$file = null,
Expand All @@ -107,7 +111,7 @@ 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**
* @param integer $indentLevel Indent level to make yaml file human readable. Default: **2**
*/
public function frontendGroupsCommand(
$file = null,
Expand All @@ -129,7 +133,7 @@ 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**
* @param integer $indentLevel Indent level to make yaml file human readable. Default: **2**
*/
public function tableCommand(
$table,
Expand All @@ -152,7 +156,9 @@ 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**
* @param integer $indentLevel Indent level to make yaml file human readable. Default: **2**
* @param bool $beUserMatchGroupByTitle Match be_group settings in be_users.usergroup by title or uid;
* if true be_groups.title is used. Default: **false**
*
* @return void
*/
Expand All @@ -162,7 +168,8 @@ public function exportTable(
$skipColumns = 'crdate,lastlogin,tstamp,uc',
$includeDeleted = false,
$includeHidden = false,
$indentLevel = 2
$indentLevel = 2,
$beUserMatchGroupByTitle = false
) {
$table = preg_replace('/[^a-z0-9_]/', '', $table);
$skipColumns = explode(',', $skipColumns);
Expand Down Expand Up @@ -208,7 +215,7 @@ public function exportTable(

// Do not update usergroups by UID when exporting to other systems
// UID maybe different for the same usergroup name
if ($table == 'be_users' && $column == 'usergroup' && $value) {
if ($beUserMatchGroupByTitle && $table == 'be_users' && $column == 'usergroup' && $value) {
$usergroups = $this->databaseConnection->exec_SELECTgetRows('title', 'be_groups', 'uid IN (' . $value . ')');
// @todo Currently the sorting of usergroups in the original records is ignored when exporting usergroups
$usergroupsTitles = [];
Expand Down
25 changes: 17 additions & 8 deletions Classes/Command/ImportCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,18 @@ class ImportCommandController extends AbstractCommandController
* @since 1.0.0
*
* @param string $matchFields Comma separated list of fields used to match configurations to database records. Default: **username**
* @param bool $beUserMatchGroupByTitle Match be_group settings in be_users.usergroup by title or uid;
* if true be_groups.title is used. Default: **false**
* @param string $file Path to the yml file you wish to import. If none is given, all yml files in directories named 'Configuration' will be parsed
*/
public function backendUsersCommand($matchFields = 'username', $file = null)
public function backendUsersCommand($matchFields = 'username', $beUserMatchGroupByTitle = false, $file = null)
{
$this->importData('be_users', $matchFields, $file);
$this->importData('be_users', $matchFields, $beUserMatchGroupByTitle, $file);
}

/**
* Import backend groups from yml file
* Import backend groups from yml file into be_users table. Existing records will be updated.
* Import backend groups from yml file into be_groups table. Existing records will be updated.
*
* @since 1.0.0
*
Expand Down Expand Up @@ -112,11 +114,13 @@ public function tableCommand($table, $matchFields, $file = null)
*
* @since 1.0.0
*
* @param $table
* @param string $table
* @param string $matchFields Comma separated list of fields used to match configurations to database records.
* @param bool $beUserMatchGroupByTitle Match be_group settings in be_users.usergroup by title or uid;
* if true be_groups.title is used. Default: **false**
* @param string $file Path to the yml file you wish to import. If none is given, all yml files in directories named 'Configuration' will be parsed
*/
protected function importData($table, $matchFields, $file = null)
protected function importData($table, $matchFields, $beUserMatchGroupByTitle = false, $file = null)
{
$table = preg_replace('/[^a-z0-9_]/', '', $table);
$matchFields = explode(',', preg_replace('/[^a-z0-9_,]/', '', $matchFields));
Expand Down Expand Up @@ -153,7 +157,7 @@ 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'])) {
if (isset($record['usergroup']) && $beUserMatchGroupByTitle) {
$record['usergroup'] = $this->convertUsergroupNamesToUid($record);
}
$record = $this->updateTimeFields($record, $columnNames, array('tstamp'));
Expand All @@ -180,24 +184,29 @@ protected function importData($table, $matchFields, $file = null)
*
* @since 1.1.0
*
* @param $record database record for the user that is going to import
* @param array $record Database record for the user that is going to import
* @return string
*/
protected function convertUsergroupNamesToUid($record)
{
if(!isset($record['usergroup']))
if(!isset($record['usergroup'])) {
return '';
}

$whereInCondition = '';
foreach(explode(",",$record['usergroup']) as $usergroupTitle) {
$whereInCondition .= $whereInCondition ? ",": "";
$whereInCondition .= '"'.$usergroupTitle.'"';
}

$groupsUids = $this->databaseConnection->exec_SELECTgetRows('uid','be_groups','title IN('.$whereInCondition.')');
$commaSepratedGroupUids = '';
foreach ($groupsUids as $group) {
$commaSepratedGroupUids .= $commaSepratedGroupUids ? ",": "";
$commaSepratedGroupUids .= $group['uid'];
}

return $commaSepratedGroupUids;
}

}
4 changes: 4 additions & 0 deletions Documentation/CommandReference/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ Options
Export deleted records. Default: **false**
``--include-hidden``
Export hidden/disable records. Default: **false**
``--be-user-match-group-by-title``
If set to true, references to table be_groups in field ``usergroup`` are stored as group titles not as uid's. Make sure to exclude field ``uid`` in ``--skip-columns`` in order to prevend duplicate entries for primary key ``uid`` when importing the records. Default: **false**



Expand Down Expand Up @@ -199,6 +201,8 @@ Options
Comma separated list of fields used to match configurations to database records. Default: **username**
``--file``
Path to the yml file you wish to import. If none is given, all yml files in directories named 'Configuration' will be parsed
``--be-user-match-group-by-title``
If set to true, references to table ``be_groups`` in field ``usergroup`` are matched using group titles not uid's. Make sure to use option ``--be-user-match-group-by-title`` set to true when exporting the records. Default: **false**



Expand Down

0 comments on commit 56677f4

Please sign in to comment.