feat : depth for search and download source for updates
This commit is contained in:
parent
1e3942f609
commit
5c7858c4e0
2 changed files with 57 additions and 22 deletions
|
@ -283,6 +283,12 @@ function removePhpFpmConfig($user)
|
||||||
exec('service ' . $_SERVER['phpservice'] . ' reload', $output);
|
exec('service ' . $_SERVER['phpservice'] . ' reload', $output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function upgradeWiki($srcDir, $destDir)
|
||||||
|
{
|
||||||
|
$output = 'Update ' . $destDir;
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
function copyYesWikiFiles($domain, $user, $dbUser, $herseUser = null, $hersePass = null, $nossl = null)
|
function copyYesWikiFiles($domain, $user, $dbUser, $herseUser = null, $hersePass = null, $nossl = null)
|
||||||
{
|
{
|
||||||
$tmpFile = '/tmp/yeswiki.zip';
|
$tmpFile = '/tmp/yeswiki.zip';
|
||||||
|
@ -343,13 +349,15 @@ function addStatistics()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function searchWikis($path, $pattern)
|
function searchWikis($path, $pattern, $depth = 1)
|
||||||
{
|
{
|
||||||
$it = new RecursiveDirectoryIterator($path);
|
$it = new RecursiveDirectoryIterator($path);
|
||||||
$list = array();
|
$list = array();
|
||||||
$httpClient = HttpClientBuilder::buildDefault();
|
$httpClient = HttpClientBuilder::buildDefault();
|
||||||
$nb = 0;
|
$nb = 0;
|
||||||
foreach (new RecursiveIteratorIterator($it) as $file) {
|
$files = new RecursiveIteratorIterator($it);
|
||||||
|
$files->setMaxDepth($depth);
|
||||||
|
foreach ($files as $file) {
|
||||||
if (preg_match('/' . preg_quote($pattern) . '$/i', $file)) {
|
if (preg_match('/' . preg_quote($pattern) . '$/i', $file)) {
|
||||||
$nb++;
|
$nb++;
|
||||||
$wakkaConfig = [];
|
$wakkaConfig = [];
|
||||||
|
|
|
@ -7,8 +7,9 @@ use DevCoder\DotEnv;
|
||||||
|
|
||||||
$climate = new League\CLImate\CLImate();
|
$climate = new League\CLImate\CLImate();
|
||||||
$climate->description('yeswiki-updater, find and update YesWiki like a professionnal 🌈🦄');
|
$climate->description('yeswiki-updater, find and update YesWiki like a professionnal 🌈🦄');
|
||||||
|
$isRoot = (0 == posix_getuid());
|
||||||
|
|
||||||
if (0 == posix_getuid()) {
|
if ($isRoot) {
|
||||||
$absolutePathToEnvFile = __DIR__ . '/.env';
|
$absolutePathToEnvFile = __DIR__ . '/.env';
|
||||||
if (file_exists($absolutePathToEnvFile)) {
|
if (file_exists($absolutePathToEnvFile)) {
|
||||||
(new DotEnv($absolutePathToEnvFile))->load();
|
(new DotEnv($absolutePathToEnvFile))->load();
|
||||||
|
@ -36,6 +37,12 @@ if (0 == posix_getuid()) {
|
||||||
'description' => 'Update to latest version of stable yeswiki',
|
'description' => 'Update to latest version of stable yeswiki',
|
||||||
'noValue' => true
|
'noValue' => true
|
||||||
],
|
],
|
||||||
|
'depth' => [
|
||||||
|
'prefix' => 'd',
|
||||||
|
'longPrefix' => 'depth',
|
||||||
|
'description' => 'Depth to scan folders for wikis',
|
||||||
|
'defaultValue' => 1
|
||||||
|
],
|
||||||
]);
|
]);
|
||||||
try {
|
try {
|
||||||
$climate->arguments->parse();
|
$climate->arguments->parse();
|
||||||
|
@ -51,10 +58,29 @@ if (0 == posix_getuid()) {
|
||||||
try {
|
try {
|
||||||
$update = $climate->arguments->get('update');
|
$update = $climate->arguments->get('update');
|
||||||
$output = $climate->arguments->get('output');
|
$output = $climate->arguments->get('output');
|
||||||
$matches = searchWikis($path, 'wakka.config.php');
|
$depth = $climate->arguments->get('depth');
|
||||||
if (count($matches) > 0 && $update) {
|
$matches = searchWikis($path, 'wakka.config.php', $depth);
|
||||||
$climate->info('update');
|
if (count($matches) == 0) {
|
||||||
|
$climate->info('No yeswiki found on path ' . $path . ' with depth ' . $depth);
|
||||||
|
exit;
|
||||||
}
|
}
|
||||||
|
if (count($matches) > 0 && $update) { // update yeswiki list
|
||||||
|
$climate->info('Update yeswiki');
|
||||||
|
$tmpFile = '/tmp/yeswiki.zip';
|
||||||
|
$destDir = '/tmp/yeswiki_for_update';
|
||||||
|
exec('rm -rf ' . $destDir . ' && mkdir -p ' . $destDir, $output);
|
||||||
|
if (file_exists($tmpFile)) {
|
||||||
|
unlink($tmpFile);
|
||||||
|
}
|
||||||
|
exec('curl --insecure -s -o ' . $tmpFile . ' ' . $_SERVER['source_archive_url']);
|
||||||
|
exec('unzip ' . $tmpFile . ' "doryphore/*" -d ' . $destDir);
|
||||||
|
exec('mv ' . $destDir . '/doryphore/* ' . $destDir . '/');
|
||||||
|
exec('rm -rf ' . $destDir . '/doryphore');
|
||||||
|
unlink($tmpFile);
|
||||||
|
foreach ($matches as $k => $wiki) {
|
||||||
|
$climate->info(upgradeWiki($destDir, $wiki['PATH']));
|
||||||
|
}
|
||||||
|
} else { // show yeswiki list info
|
||||||
$climate->info(count($matches) . ' yeswikis found on ' . $path);
|
$climate->info(count($matches) . ' yeswikis found on ' . $path);
|
||||||
switch ($output) {
|
switch ($output) {
|
||||||
|
|
||||||
|
@ -75,6 +101,7 @@ if (0 == posix_getuid()) {
|
||||||
$climate->info($fileName . ' was created.');
|
$climate->info($fileName . ' was created.');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$climate->error('ERROR : ' . $e->getMessage());
|
$climate->error('ERROR : ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue