Skip to content

Commit 4c59ee0

Browse files
committed
Merge pull request #23922 from owncloud/upgrade-only-with-cli-for-big-installations
Suggest cli based updater in case the instance is bigger
2 parents 92dfb4e + 739dfb5 commit 4c59ee0

4 files changed

Lines changed: 62 additions & 13 deletions

File tree

config/config.sample.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,11 @@
11961196
*/
11971197
'memcache.locking' => '\\OC\\Memcache\\Redis',
11981198

1199+
/**
1200+
* Disable the web based updater
1201+
*/
1202+
'upgrade.disable-web' => false,
1203+
11991204
/**
12001205
* Set this ownCloud instance to debugging mode
12011206
*

core/ajax/update.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,17 @@
3737
// need to send an initial message to force-init the event source,
3838
// which will then trigger its own CSRF check and produces its own CSRF error
3939
// message
40-
$eventSource->send('success', (string)$l->t('Preparing update'));
40+
//$eventSource->send('success', (string)$l->t('Preparing update'));
4141

4242
if (OC::checkUpgrade(false)) {
43+
44+
$config = \OC::$server->getSystemConfig();
45+
if ($config->getValue('upgrade.disable-web', true)) {
46+
$eventSource->send('failure', (string)$l->t('Updates need to be installed. Please use the command line updater.'));
47+
$eventSource->close();
48+
exit();
49+
}
50+
4351
// if a user is currently logged in, their session must be ignored to
4452
// avoid side effects
4553
\OC_User::setIncognitoMode(true);

core/templates/update.use-cli.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<div class="update" data-productname="<?php p($_['productName']) ?>" data-version="<?php p($_['version']) ?>">
2+
<div class="updateOverview">
3+
<h2 class="title"><?php p($l->t('Update needed')) ?></h2>
4+
<div class="infogroup">
5+
<?php if ($_['tooBig']) {
6+
p($l->t('Please use the command line updater because you have a big instance.'));
7+
} else {
8+
p($l->t('Please use the command line updater because automatic updating is disabled in the config.php.'));
9+
} ?><br><br>
10+
<?php
11+
print_unescaped($l->t('For help, see the <a target="_blank" rel="noreferrer" href="%s">documentation</a>.', [link_to_docs('admin-cli-upgrade')])); ?><br><br>
12+
</div>
13+
</div>
14+
</div>

lib/base.php

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -337,27 +337,49 @@ public static function checkUpgrade($showTemplate = true) {
337337
*/
338338
private static function printUpgradePage() {
339339
$systemConfig = \OC::$server->getSystemConfig();
340+
341+
$disableWebUpdater = $systemConfig->getValue('upgrade.disable-web', false);
342+
$tooBig = false;
343+
if (!$disableWebUpdater) {
344+
// count users
345+
$stats = \OC::$server->getUserManager()->countUsers();
346+
$totalUsers = array_sum($stats);
347+
$tooBig = ($totalUsers > 50);
348+
}
349+
if ($disableWebUpdater || $tooBig) {
350+
// send http status 503
351+
header('HTTP/1.1 503 Service Temporarily Unavailable');
352+
header('Status: 503 Service Temporarily Unavailable');
353+
header('Retry-After: 120');
354+
355+
// render error page
356+
$template = new OC_Template('', 'update.use-cli', 'guest');
357+
$template->assign('productName', 'ownCloud'); // for now
358+
$template->assign('version', OC_Util::getVersionString());
359+
$template->assign('tooBig', $tooBig);
360+
361+
$template->printPage();
362+
die();
363+
}
364+
365+
// check whether this is a core update or apps update
366+
$installedVersion = $systemConfig->getValue('version', '0.0.0');
367+
$currentVersion = implode('.', \OCP\Util::getVersion());
368+
369+
// if not a core upgrade, then it's apps upgrade
370+
$isAppsOnlyUpgrade = (version_compare($currentVersion, $installedVersion, '='));
371+
340372
$oldTheme = $systemConfig->getValue('theme');
341373
$systemConfig->setValue('theme', '');
342374
\OCP\Util::addScript('config'); // needed for web root
343375
\OCP\Util::addScript('update');
344376
\OCP\Util::addStyle('update');
345377

346-
// check whether this is a core update or apps update
347-
$installedVersion = $systemConfig->getValue('version', '0.0.0');
348-
$currentVersion = implode('.', \OCP\Util::getVersion());
349-
350378
$appManager = \OC::$server->getAppManager();
351379

352380
$tmpl = new OC_Template('', 'update.admin', 'guest');
353381
$tmpl->assign('version', OC_Util::getVersionString());
354-
355-
// if not a core upgrade, then it's apps upgrade
356-
if (version_compare($currentVersion, $installedVersion, '=')) {
357-
$tmpl->assign('isAppsOnlyUpgrade', true);
358-
} else {
359-
$tmpl->assign('isAppsOnlyUpgrade', false);
360-
}
382+
$tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade);
361383

362384
// get third party apps
363385
$ocVersion = \OCP\Util::getVersion();
@@ -423,7 +445,7 @@ private static function getSessionLifeTime() {
423445
}
424446

425447
public static function loadAppClassPaths() {
426-
foreach (OC_APP::getEnabledApps() as $app) {
448+
foreach (OC_App::getEnabledApps() as $app) {
427449
$appPath = OC_App::getAppPath($app);
428450
if ($appPath === false) {
429451
continue;

0 commit comments

Comments
 (0)