Skip to content

Commit

Permalink
feature(Setup/Cli): pass additional struct tables to --setup
Browse files Browse the repository at this point in the history
setup.php --backup -- structTables=timemachine_modlog,notes
  • Loading branch information
pschuele committed Jan 22, 2024
1 parent de8ed03 commit 2a41245
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
26 changes: 19 additions & 7 deletions tine20/Setup/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2797,12 +2797,14 @@ public function isFilesystemAvailable()
* 'db' => bool // backup database
* 'files' => bool // backup files
* 'novalidate' => bool // do not validate sql backup
* 'structTables' => array // additional struct only tables (data backup is omitted)
* )
*/
public function backup($options)
{
if (! $this->isInstalled('Tinebase')) {
Setup_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' Tine 2.0 is not installed');
Setup_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' '
. Tinebase_Config::getInstance()->get(Tinebase_Config::BRANDING_TITLE) . ' is not installed');
return;
}

Expand Down Expand Up @@ -2842,12 +2844,15 @@ public function backup($options)
throw new Exception('db not configured, cannot backup');
}

$structTables = $this->getBackupStructureOnlyTables($options['structTables'] ?? null);
$backupOptions = array(
'backupDir' => $backupDir,
'structTables' => $this->getBackupStructureOnlyTables(),
'structTables' => $structTables,
'novalidate' => isset($options['novalidate']) && $options['novalidate'],
);

Setup_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Using options: ' . print_r($backupOptions, true));

$this->_backend->backup($backupOptions);

Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Backup of DB successful');
Expand Down Expand Up @@ -2885,14 +2890,21 @@ public function backup($options)
/**
* returns an array of all tables of all applications that should only backup the structure
*
* @param ?string $structTablesString
* @return array
* @throws Setup_Exception_NotFound
*
* TODO support <backupStructureOnly>true</backupStructureOnly> for MC models without a table definition in setup.xml
*/
public function getBackupStructureOnlyTables()
public function getBackupStructureOnlyTables(?string $structTablesString = null): array
{
$tables = array();
$tables = [];

if ($structTablesString) {
foreach (explode(',', $structTablesString) as $table) {
$tables[] = SQL_TABLE_PREFIX . $table;
}
}

// find tables that only backup structure
$applications = Tinebase_Application::getInstance()->getApplications();
Expand All @@ -2905,10 +2917,10 @@ public function getBackupStructureOnlyTables()
if (! $tableDef) {
continue;
}
$structOnlys = $tableDef->xpath('//table/backupStructureOnly[text()="true"]');
$structOnly = $tableDef->xpath('//table/backupStructureOnly[text()="true"]');

foreach ($structOnlys as $structOnly) {
$tableName = $structOnly->xpath('./../name/text()');
foreach ($structOnly as $structOnlyTable) {
$tableName = $structOnlyTable->xpath('./../name/text()');
$tables[] = SQL_TABLE_PREFIX . $tableName[0];
}
}
Expand Down
2 changes: 1 addition & 1 deletion tine20/Setup/Server/Cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function handle(\Laminas\Http\Request $request = null, $body = null)
setup.php --updateAllAccountsWithAccountEmail -- fromInstance=master.mytine20.com',
'backup' => 'backup config and data
Examples:
setup.php --backup -- config=1 db=1 files=1 emailusers=1 backupDir=/backup/tine20 noTimestamp=1 novalidate=1',
setup.php --backup -- config=1 db=1 files=1 emailusers=1 backupDir=/backup/tine20 noTimestamp=1 novalidate=1 structTables=timemachine_modlog,notes',
'restore' => 'restore config and data
Examples:
setup.php --restore -- config=1 db=1 files=1 backupDir=/backup/tine20',
Expand Down

0 comments on commit 2a41245

Please sign in to comment.