Skip to content

Commit 37d7acf

Browse files
committed
Suggest cli based updater in case the instance is bigger - #23913
1 parent 85d809c commit 37d7acf

4 files changed

Lines changed: 58 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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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('Updates need to be installed.')) ?></h2>
4+
<div class="infogroup">
5+
<ul>
6+
<li>
7+
<?php print_unescaped($l->t('Please use the command line updater. For help, see the <a target="_blank" rel="noreferrer" href="%s">documentation</a>.', [link_to_docs('admin-cli-upgrade')])) ?><br><br>
8+
</li>
9+
</ul>
10+
</div>
11+
</div>
12+
</div>

lib/base.php

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -337,27 +337,47 @@ 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+
if (!$disableWebUpdater) {
343+
// count users
344+
$stats = \OC::$server->getUserManager()->countUsers();
345+
$totalUsers = array_sum($stats);
346+
$disableWebUpdater = ($totalUsers > 50);
347+
}
348+
if ($disableWebUpdater) {
349+
// send http status 503
350+
header('HTTP/1.1 503 Service Temporarily Unavailable');
351+
header('Status: 503 Service Temporarily Unavailable');
352+
header('Retry-After: 120');
353+
354+
// render error page
355+
$template = new OC_Template('', 'update.use-cli', 'guest');
356+
$template->assign('productName', 'ownCloud'); // for now
357+
$template->assign('version', OC_Util::getVersionString());
358+
359+
$template->printPage();
360+
die();
361+
}
362+
363+
// check whether this is a core update or apps update
364+
$installedVersion = $systemConfig->getValue('version', '0.0.0');
365+
$currentVersion = implode('.', \OCP\Util::getVersion());
366+
367+
// if not a core upgrade, then it's apps upgrade
368+
$isAppsOnlyUpgrade = (version_compare($currentVersion, $installedVersion, '='));
369+
340370
$oldTheme = $systemConfig->getValue('theme');
341371
$systemConfig->setValue('theme', '');
342372
\OCP\Util::addScript('config'); // needed for web root
343373
\OCP\Util::addScript('update');
344374
\OCP\Util::addStyle('update');
345375

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-
350376
$appManager = \OC::$server->getAppManager();
351377

352378
$tmpl = new OC_Template('', 'update.admin', 'guest');
353379
$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-
}
380+
$tmpl->assign('isAppsOnlyUpgrade', $isAppsOnlyUpgrade);
361381

362382
// get third party apps
363383
$ocVersion = \OCP\Util::getVersion();
@@ -423,7 +443,7 @@ private static function getSessionLifeTime() {
423443
}
424444

425445
public static function loadAppClassPaths() {
426-
foreach (OC_APP::getEnabledApps() as $app) {
446+
foreach (OC_App::getEnabledApps() as $app) {
427447
$appPath = OC_App::getAppPath($app);
428448
if ($appPath === false) {
429449
continue;

0 commit comments

Comments
 (0)