feat(updater): better num version + backup parameter
Some checks are pending
/ test (push) Waiting to run
Some checks are pending
/ test (push) Waiting to run
This commit is contained in:
parent
abd61a963c
commit
3020238f96
1 changed files with 35 additions and 26 deletions
|
@ -317,7 +317,7 @@ function saveSql($wikiDir, $backupDir)
|
|||
return '==== Mysql database saved in '.$backupDir.'/database.sql ==========='. "\n";
|
||||
}
|
||||
|
||||
function upgradeWiki($srcDir, $destDir)
|
||||
function upgradeWiki($srcDir, $destDir, $backup)
|
||||
{
|
||||
$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'];
|
||||
$defaultExtensions = array_map('basename', array_filter(glob($srcDir.'/tools/*'), 'is_dir'));
|
||||
|
@ -329,30 +329,39 @@ function upgradeWiki($srcDir, $destDir)
|
|||
$sudo = 'sudo -u ' . $user . ' ';
|
||||
$wakkaConfig = [];
|
||||
require $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";
|
||||
exit($output);
|
||||
return;
|
||||
if ($backup === true) {
|
||||
$tmpbackupDir = '/root/yeswiki_backups/'.str_replace(['https://', 'http://', '/?', '/'], ['','','','-'], $wakkaConfig['base_url']);
|
||||
if (is_dir($tmpbackupDir)) {
|
||||
$output .= 'ERROR: found existing backup in "' . $tmpbackupDir . '" aborting' . "\n";
|
||||
exit($output);
|
||||
return;
|
||||
} else {
|
||||
exec('mkdir -p ' . $tmpbackupDir);
|
||||
}
|
||||
$output .= '==== Move files to temporary backup dir ' . $tmpbackupDir . ' ' . $bars;
|
||||
foreach ($filesToMove as $f) {
|
||||
if (file_exists($destDir . '/' . $f)) {
|
||||
exec('mv ' . $destDir . '/' . $f . ' ' . $tmpbackupDir . '/' . $f);
|
||||
} else {
|
||||
$output .= 'File not found "' . $f . '"' . "\n";
|
||||
}
|
||||
}
|
||||
foreach ($filesToCopy as $f) {
|
||||
if (file_exists($destDir . '/' . $f)) {
|
||||
exec('cp -rf ' . $destDir . '/' . $f . ' ' . $tmpbackupDir . '/' . $f);
|
||||
} else {
|
||||
$output .= 'File not found "' . $f . '"' . "\n";
|
||||
}
|
||||
}
|
||||
$output .= saveSql($destDir, $tmpbackupDir);
|
||||
} else {
|
||||
exec('mkdir -p ' . $tmpbackupDir);
|
||||
}
|
||||
$output .= '==== Move files to temporary backup dir ' . $tmpbackupDir . ' ' . $bars;
|
||||
foreach ($filesToMove as $f) {
|
||||
if (file_exists($destDir . '/' . $f)) {
|
||||
exec('mv ' . $destDir . '/' . $f . ' ' . $tmpbackupDir . '/' . $f);
|
||||
} else {
|
||||
$output .= 'File not found "' . $f . '"' . "\n";
|
||||
$output .= '==== Remove old files before upgrade ' . $bars;
|
||||
foreach ($filesToMove as $f) {
|
||||
if (file_exists($destDir . '/' . $f)) {
|
||||
exec('rm -rf ' . $destDir . '/' . $f);
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($filesToCopy as $f) {
|
||||
if (file_exists($destDir . '/' . $f)) {
|
||||
exec('cp -rf ' . $destDir . '/' . $f . ' ' . $tmpbackupDir . '/' . $f);
|
||||
} else {
|
||||
$output .= 'File not found "' . $f . '"' . "\n";
|
||||
}
|
||||
}
|
||||
$output .= saveSql($destDir, $tmpbackupDir);
|
||||
$output .= '==== Update to latest sources ' . $bars;
|
||||
foreach ($filesToMove as $f) {
|
||||
if (file_exists($srcDir . '/' . $f)) {
|
||||
|
@ -364,7 +373,7 @@ function upgradeWiki($srcDir, $destDir)
|
|||
$output .= runUpgrades($sudo, $destDir, array_diff($installedExtensions, $defaultExtensions));
|
||||
$version = trim(cli("cat $destDir/includes/constants.php | grep YESWIKI_RELEASE | sed -r -e \"s/.*([0-9]+\\.[0-9]+\\.[0-9]+).*/\\1/\""));
|
||||
$output .= '==== Change YesWiki version to '.$version.' '. $bars;
|
||||
$output .= cli("sed -r -i -e \"s/(['\\\"]yeswiki_release['\\\"].*)[0-9]+\\.[0-9]+\\.[0-9]+/\\1$version/\" $destDir/wakka.config.php");
|
||||
$output .= cli("sed -r -i -e \"s/(['\\\"]yeswiki_release['\\\"].*)/'yeswiki_release' => '$version',/\" $destDir/wakka.config.php");
|
||||
$output .= '== End update wiki in path: ' . $destDir . ' ' . $bars;
|
||||
return $output;
|
||||
}
|
||||
|
@ -387,7 +396,7 @@ function runUpgrades($sudo, $destDir, $extensions = [])
|
|||
$output .= runMigrations($sudo, $destDir);
|
||||
foreach ($extensions as $ext) {
|
||||
$output .= '==== Install latest version of extension ' . $ext."\n";
|
||||
//$output .= cli('cd '.$destDir.' && '.$sudo.' ./yeswicli upgrade '.$ext);
|
||||
cli('cd '.$destDir.' && '.$sudo.' ./yeswicli upgrade '.$ext);
|
||||
}
|
||||
$output .= cli('cd '.$startDir);
|
||||
return $output;
|
||||
|
@ -397,8 +406,8 @@ function runMigrations($sudo, $destDir)
|
|||
{
|
||||
$output = '==== Run migrations on core'."\n";
|
||||
$startDir = getcwd();
|
||||
//$output .= cli('cd '.$destDir.' && '.$sudo.' ./yeswicli migrate');
|
||||
//$output .= cli('cd '.$startDir);
|
||||
cli('cd '.$destDir.' && '.$sudo.' ./yeswicli migrate');
|
||||
$output .= cli('cd '.$startDir);
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue