From 450dda699728db25f935a8a8dedbbcdcd8e1f678 Mon Sep 17 00:00:00 2001 From: Florian Schmitt Date: Tue, 25 Mar 2025 19:10:10 +0300 Subject: [PATCH] feat(updater): save sql --- utils.inc.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/utils.inc.php b/utils.inc.php index 7cf374c..ecd06ef 100644 --- a/utils.inc.php +++ b/utils.inc.php @@ -307,19 +307,32 @@ function removePhpFpmConfig($user) unlink($phpConfFile); exec('service ' . $_SERVER['phpservice'] . ' reload', $output); } +function saveSql($srcDir, $destDir) +{ + $output = '== Save mysql database ==========='. "\n"; + $user = posix_getpwuid(fileowner($destDir . '/wakka.config.php'))['name']; + $sudo = 'sudo -u ' . $user . ' '; + $wakkaConfig = []; + include_once($destDir.'/wakka.config.php'); + exec($sudo . 'mysqldump -u'.$wakkaConfig['mysql_user'].' -p'.$wakkaConfig['mysql_password'].' '.$wakkaConfig['mysql_database'].' '.$wakkaConfig['table_prefix'].'acls, '.$wakkaConfig['table_prefix'].'links '.$wakkaConfig['table_prefix'].'nature '.$wakkaConfig['table_prefix'].'pages '.$wakkaConfig['table_prefix'].'referrers '.$wakkaConfig['table_prefix'].'triples '.$wakkaConfig['table_prefix'].'usersname > ' . $destDir.'/database.sql'); + +} function upgradeWiki($srcDir, $destDir) { - $filesToMove = ['actions', 'cache', 'custom', 'docker', 'docs', 'files', 'formatters', 'handlers', 'includes', 'javascripts', 'lang', 'private', 'setup', 'styles', 'templates', 'tests', 'themes', 'tools', 'vendor', 'docker-compose.yml', 'composer.json', 'composer.lock', 'index.php', 'INSTALL.md', 'interwiki.conf', 'LICENSE', 'Makefile', 'package.json', 'README.md', 'SECURITY.md', 'wakka.basic.css', 'wakka.css', 'wakka.php', 'yarn.lock', 'yeswicli']; - $filesToCopy = ['wakka.config.php']; + $filesToMove = ['actions', 'cache', 'docker', 'docs', 'formatters', 'handlers', 'includes', 'javascripts', 'lang', 'private', 'setup', 'styles', 'templates', 'tests', 'themes', 'tools', 'vendor', 'composer.json', 'composer.lock', 'index.php', 'INSTALL.md', 'interwiki.conf', 'LICENSE', 'Makefile', 'package.json', 'README.md', 'SECURITY.md', 'wakka.basic.css', 'wakka.css', 'wakka.php', 'yarn.lock', 'yeswicli']; + $filesToCopy = ['files', 'custom', 'wakka.config.php']; $bars = '============' . "\n"; $output = '== Update wiki in path: ' . $destDir . ' ' . $bars; $user = posix_getpwuid(fileowner($destDir . '/wakka.config.php'))['name']; $sudo = 'sudo -u ' . $user . ' '; - $tmpbackupDir = $destDir . '/tmpbackup'; + $wakkaConfig = []; + include_once($destDir.'/wakka.config.php'); + $tmpbackupDir = '/root/yeswiki_backups/'.str_replace(['https://', 'http://', '/?', '/'], ['','','','-'], $wakkaConfig['base_url']); if (is_dir($tmpbackupDir)) { $output .= 'ERROR: found existing backup in "' . $tmpbackupDir . '" aborting' . "\n"; - return $output; + exit($output); + return; } else { exec($sudo . 'mkdir -p ' . $tmpbackupDir); }