Skip to content

Commit

Permalink
Merge pull request #21 from cassini-mohsin/master
Browse files Browse the repository at this point in the history
Added some beautify options in export and some fixes for beusers group export
  • Loading branch information
Tuurlijk authored Jun 13, 2017
2 parents ee7a4e9 + 2f51c5c commit 96a1f2d
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 13 deletions.
50 changes: 37 additions & 13 deletions Classes/Command/ExportCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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
*/
Expand All @@ -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);
Expand Down Expand Up @@ -193,7 +205,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 (strlen($value)) {
Expand All @@ -209,7 +233,7 @@ public function exportTable(
)
)
);
$yaml = Yaml::dump($dump);
$yaml = Yaml::dump($dump, $indentLevel);
}

if ($yaml !== '') {
Expand Down
29 changes: 29 additions & 0 deletions Classes/Command/ImportCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -171,4 +174,30 @@ protected function importData($table, $matchFields, $file = null)
}
}
}

/**
* Usergroup names to uid conversion
*
* @since 1.1.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;
}
}

0 comments on commit 96a1f2d

Please sign in to comment.