From b05269826a64f9a45dd84c29b6d76884c9dff2f3 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Thu, 24 Mar 2016 20:44:54 +0300 Subject: [PATCH 1/6] Add releasenotes class --- lib/private/releasenotes.php | 105 ++++++++++++++++++++++++++++++++ tests/lib/releasenotes.php | 114 +++++++++++++++++++++++++++++++++++ 2 files changed, 219 insertions(+) create mode 100644 lib/private/releasenotes.php create mode 100644 tests/lib/releasenotes.php diff --git a/lib/private/releasenotes.php b/lib/private/releasenotes.php new file mode 100644 index 00000000000..581c20d47e2 --- /dev/null +++ b/lib/private/releasenotes.php @@ -0,0 +1,105 @@ + + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OC; + +use Doctrine\DBAL\Platforms\MySqlPlatform; +use OCP\IDBConnection; + +/** + * Class to store release notes + */ +class ReleaseNotes { + /** @var \OCP\IDBConnection $dbConnection */ + protected $dbConnection; + + /** + * @param OCP\IDBConnection $connection + */ + public function __construct(IDBConnection $dbConnection){ + $this->dbConnection = $dbConnection; + } + + /** + * @param string $fromVersion + * @param string $toVersion + * @return array + */ + public function getReleaseNotes($fromVersion, $toVersion){ + $releaseNotes = []; + + try { + $fromVersionMajorMinor = $this->getMajorMinor($fromVersion); + } catch (\InvalidArgumentException $e) { + $fromVersionMajorMinor = ''; + } + + try { + $toVersionMajorMinor = $this->getMajorMinor($toVersion); + } catch (\InvalidArgumentException $e) { + $toVersionMajorMinor = ''; + } + + if ( $fromVersionMajorMinor === '8.2' && $toVersionMajorMinor === '9.0' ) { + // MySQL only + if ($this->isMysql()) { + if ($this->countFilecacheEntries() > 200000) { + $message = \OC::$server->getL10N('core')->t( + "You have an ownCloud installation with over 200.000 files so the upgrade might take a while. Hint: You can speed up the upgrade by executing this SQL command manually: ALTER TABLE %s ADD COLUMN checksum varchar(255) DEFAULT NULL AFTER permissions;", + [$this->dbConnection->getPrefix().'filecache'] + ); + $releaseNotes[] = $message; + } + } + } + return $releaseNotes; + } + + /** + * @return bool + */ + protected function isMysql(){ + return $this->dbConnection->getDatabasePlatform() instanceof MySqlPlatform; + } + + /** + * Count entries in filecache table + * @return int + */ + protected function countFilecacheEntries(){ + $result = $this->dbConnection->executeQuery("SELECT COUNT(*) FROM *PREFIX*filecache"); + $count = $result->fetchColumn(); + return $count ? $count : 0; + } + + /** + * Strip everything except first digits + * @param string $version + * @return string + */ + private function getMajorMinor($version){ + $versionArray = explode('.', $version); + if ( count($versionArray)<2 ) { + throw new \InvalidArgumentException('Version should have at least 2 parts separated by dot.'); + } + return implode('.', [ $versionArray[0], $versionArray[1] ]); + } +} diff --git a/tests/lib/releasenotes.php b/tests/lib/releasenotes.php new file mode 100644 index 00000000000..8219c6194d3 --- /dev/null +++ b/tests/lib/releasenotes.php @@ -0,0 +1,114 @@ + + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +class Test_ReleaseNotes extends \Test\TestCase { + protected $prefix = 'ocx_'; + + protected function setUp() { + parent::setUp(); + } + + protected function tearDown() { + $this->expected = []; + parent::tearDown(); + } + + public function resultProvider82to90(){ + return [ + [ [], false, 20 ], + [ [], false, 1000000 ], + [ [], true, 20 ], + [ [ + \OC::$server->getL10N('core')->t( + "You have an ownCloud installation with over 200.000 files so the upgrade might take a while. Hint: You can speed up the upgrade by executing this SQL command manually: ALTER TABLE %s ADD COLUMN checksum varchar(255) DEFAULT NULL AFTER permissions;", + ['ocx_filecache'] + ) + ], true, 1000000 ], + ]; + } + + /** + * @dataProvider resultProvider82to90 + */ + public function test82to90($expected, $isMysql, $fileCount){ + $releaseNotesMock = $this->getReleaseNotesMock($isMysql, $fileCount); + $actual = $releaseNotesMock->getReleaseNotes('8.2.22', '9.0.1'); + $this->assertEquals($expected, $actual); + } + + + + public function resultProvider90to91(){ + return [ + [ [], false, 20 ], + [ [], false, 1000000 ], + [ [], true, 20 ], + [ [], true, 1000000 ], + ]; + } + + /** + * @dataProvider resultProvider90to91 + */ + public function test90to91($expected, $isMysql, $fileCount){ + $releaseNotesMock = $this->getReleaseNotesMock($isMysql, $fileCount); + $actual = $releaseNotesMock->getReleaseNotes('9.0.1', '9.1.0'); + $this->assertEquals($expected, $actual); + } + + + private function getReleaseNotesMock($isMysql, $fileCount){ + $dbConnectionMock = $this->getMockBuilder('OCP\IDBConnection') + ->setMethods(array_merge($this->getMethods('OCP\IDBConnection'), ['getPrefix'])) + ->getMock() + ; + $dbConnectionMock->expects($this->any()) + ->method('getPrefix') + ->willReturn($this->prefix) + ; + $releaseNotesMock = $this->getMockBuilder('OC\ReleaseNotes') + ->setConstructorArgs([$dbConnectionMock]) + ->setMethods(['isMysql', 'countFilecacheEntries']) + ->getMock() + ; + + $releaseNotesMock->expects($this->any()) + ->method('isMysql') + ->willReturn($isMysql) + ; + $releaseNotesMock->expects($this->any()) + ->method('countFilecacheEntries') + ->willReturn($fileCount) + ; + return $releaseNotesMock; + } + + private function getMethods($class){ + $methods = []; + if (class_exists($class) || interface_exists($class)) { + $reflector = new ReflectionClass($class); + foreach ($reflector->getMethods( ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_ABSTRACT ) as $method) { + $methods[] = $method->getName(); + } + } + return $methods; + } +} From 118c39d4722b52b5024cc4efa588fe2bfe7577a7 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Fri, 25 Mar 2016 13:22:22 +0300 Subject: [PATCH 2/6] Show cli notice for big installations --- lib/private/releasenotes.php | 29 +++++++++++++------- tests/lib/releasenotes.php | 53 +++++++++++++++++++++++------------- 2 files changed, 53 insertions(+), 29 deletions(-) diff --git a/lib/private/releasenotes.php b/lib/private/releasenotes.php index 581c20d47e2..32ab036f9c1 100644 --- a/lib/private/releasenotes.php +++ b/lib/private/releasenotes.php @@ -45,6 +45,7 @@ class ReleaseNotes { */ public function getReleaseNotes($fromVersion, $toVersion){ $releaseNotes = []; + $l10n = \OC::$server->getL10N('core'); try { $fromVersionMajorMinor = $this->getMajorMinor($fromVersion); @@ -59,20 +60,28 @@ class ReleaseNotes { } if ( $fromVersionMajorMinor === '8.2' && $toVersionMajorMinor === '9.0' ) { - // MySQL only - if ($this->isMysql()) { - if ($this->countFilecacheEntries() > 200000) { - $message = \OC::$server->getL10N('core')->t( - "You have an ownCloud installation with over 200.000 files so the upgrade might take a while. Hint: You can speed up the upgrade by executing this SQL command manually: ALTER TABLE %s ADD COLUMN checksum varchar(255) DEFAULT NULL AFTER permissions;", - [$this->dbConnection->getPrefix().'filecache'] - ); - $releaseNotes[] = $message; - } + if (!$this->isCliMode() && $this->countFilecacheEntries() > 200000) { + $releaseNotes[] = $l10n->t( + "You have an ownCloud installation with over 200.000 files so the upgrade might take a while. The recommendation is to use the command-line instead of the web interface for big ownCloud servers." + ); + } + if ($this->isMysql() && $this->countFilecacheEntries() > 200000) { + $releaseNotes[] = $l10n->t( + "Hint: You can speed up the upgrade by executing this SQL command manually: ALTER TABLE %s ADD COLUMN checksum varchar(255) DEFAULT NULL AFTER permissions;", + [$this->dbConnection->getPrefix().'filecache'] + ); } } return $releaseNotes; } - + + /** + * @return bool + */ + protected function isCliMode(){ + return \OC::$CLI; + } + /** * @return bool */ diff --git a/tests/lib/releasenotes.php b/tests/lib/releasenotes.php index 8219c6194d3..ca2c3db66fb 100644 --- a/tests/lib/releasenotes.php +++ b/tests/lib/releasenotes.php @@ -32,24 +32,31 @@ class Test_ReleaseNotes extends \Test\TestCase { } public function resultProvider82to90(){ + $l10n = \OC::$server->getL10N('core'); + $alterTableMessage = $l10n->t( + "Hint: You can speed up the upgrade by executing this SQL command manually: ALTER TABLE %s ADD COLUMN checksum varchar(255) DEFAULT NULL AFTER permissions;", + ['ocx_filecache'] + ); + $useCliMessage = $l10n->t( + "You have an ownCloud installation with over 200.000 files so the upgrade might take a while. The recommendation is to use the command-line instead of the web interface for big ownCloud servers." + ); return [ - [ [], false, 20 ], - [ [], false, 1000000 ], - [ [], true, 20 ], - [ [ - \OC::$server->getL10N('core')->t( - "You have an ownCloud installation with over 200.000 files so the upgrade might take a while. Hint: You can speed up the upgrade by executing this SQL command manually: ALTER TABLE %s ADD COLUMN checksum varchar(255) DEFAULT NULL AFTER permissions;", - ['ocx_filecache'] - ) - ], true, 1000000 ], + [ [], false, false, 20 ], + [ [], false, true, 20 ], + [ [], true, false, 20 ], + [ [], true, true, 20 ], + [ [ $useCliMessage ], false, false, 1000000 ], + [ [], false, true, 1000000 ], + [ [ $useCliMessage, $alterTableMessage ], true, false, 1000000 ], + [ [ $alterTableMessage ], true, true, 1000000 ], ]; } /** * @dataProvider resultProvider82to90 */ - public function test82to90($expected, $isMysql, $fileCount){ - $releaseNotesMock = $this->getReleaseNotesMock($isMysql, $fileCount); + public function test82to90($expected, $isMysql, $isCliMode, $fileCount){ + $releaseNotesMock = $this->getReleaseNotesMock($isMysql, $isCliMode, $fileCount); $actual = $releaseNotesMock->getReleaseNotes('8.2.22', '9.0.1'); $this->assertEquals($expected, $actual); } @@ -58,24 +65,28 @@ class Test_ReleaseNotes extends \Test\TestCase { public function resultProvider90to91(){ return [ - [ [], false, 20 ], - [ [], false, 1000000 ], - [ [], true, 20 ], - [ [], true, 1000000 ], + [ [], false, false, 20 ], + [ [], false, true, 20 ], + [ [], true, false, 20 ], + [ [], true, true, 20 ], + [ [], false, false, 1000000 ], + [ [], false, true, 1000000 ], + [ [], true, false, 1000000 ], + [ [], true, true, 1000000 ], ]; } /** * @dataProvider resultProvider90to91 */ - public function test90to91($expected, $isMysql, $fileCount){ - $releaseNotesMock = $this->getReleaseNotesMock($isMysql, $fileCount); + public function test90to91($expected, $isMysql, $isCliMode, $fileCount){ + $releaseNotesMock = $this->getReleaseNotesMock($isMysql, $isCliMode, $fileCount); $actual = $releaseNotesMock->getReleaseNotes('9.0.1', '9.1.0'); $this->assertEquals($expected, $actual); } - private function getReleaseNotesMock($isMysql, $fileCount){ + private function getReleaseNotesMock($isMysql, $isCliMode, $fileCount){ $dbConnectionMock = $this->getMockBuilder('OCP\IDBConnection') ->setMethods(array_merge($this->getMethods('OCP\IDBConnection'), ['getPrefix'])) ->getMock() @@ -86,7 +97,7 @@ class Test_ReleaseNotes extends \Test\TestCase { ; $releaseNotesMock = $this->getMockBuilder('OC\ReleaseNotes') ->setConstructorArgs([$dbConnectionMock]) - ->setMethods(['isMysql', 'countFilecacheEntries']) + ->setMethods(['isMysql', 'isCliMode', 'countFilecacheEntries']) ->getMock() ; @@ -94,6 +105,10 @@ class Test_ReleaseNotes extends \Test\TestCase { ->method('isMysql') ->willReturn($isMysql) ; + $releaseNotesMock->expects($this->any()) + ->method('isCliMode') + ->willReturn($isCliMode) + ; $releaseNotesMock->expects($this->any()) ->method('countFilecacheEntries') ->willReturn($fileCount) From cfd8cc3fd8382038a556ea729bb7c9beb09e4765 Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Fri, 25 Mar 2016 16:16:49 +0300 Subject: [PATCH 3/6] Show release notes --- core/templates/update.admin.php | 5 +++++ lib/base.php | 3 +++ lib/private/server.php | 13 +++++++++++++ 3 files changed, 21 insertions(+) diff --git a/core/templates/update.admin.php b/core/templates/update.admin.php index 75815de84bc..543820e054f 100644 --- a/core/templates/update.admin.php +++ b/core/templates/update.admin.php @@ -34,6 +34,11 @@
t('Please make sure that the database, the config folder and the data folder have been backed up before proceeding.')) ?>
+ +
+ +
+
t('To avoid timeouts with larger installations, you can instead run the following command from your installation directory:')) ?> diff --git a/lib/base.php b/lib/base.php index 35c8592fe10..a5b0dd429ae 100644 --- a/lib/base.php +++ b/lib/base.php @@ -392,12 +392,15 @@ class OC { $tmpl->assign('isAppsOnlyUpgrade', false); } + $releaseNotes = \OC::$server->getReleaseNotes(); + // get third party apps $ocVersion = \OCP\Util::getVersion(); $tmpl->assign('appsToUpgrade', $appManager->getAppsNeedingUpgrade($ocVersion)); $tmpl->assign('incompatibleAppsList', $appManager->getIncompatibleApps($ocVersion)); $tmpl->assign('productName', 'ownCloud'); // for now $tmpl->assign('oldTheme', $oldTheme); + $tmpl->assign('releaseNotes', $releaseNotes->getReleaseNotes($installedVersion, $currentVersion)); $tmpl->printPage(); } diff --git a/lib/private/server.php b/lib/private/server.php index 581a2b44cea..00ee4e5c565 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -623,6 +623,12 @@ class Server extends ServerContainer implements IServerContainer { return $manager; }); + + $this->registerService('ReleaseNotes', function (Server $c) { + return new \OC\ReleaseNotes( + $c->getDatabaseConnection() + ); + }); } /** @@ -1276,4 +1282,11 @@ class Server extends ServerContainer implements IServerContainer { return $this->query('ShareManager'); } + /** + * @return \OC\ReleaseNotes + */ + public function getReleaseNotes() { + return $this->query('ReleaseNotes'); + } + } From b87b27cbd94275895fd9da3f29edced27cd5aaad Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Tue, 29 Mar 2016 16:57:41 +0300 Subject: [PATCH 4/6] Show hint in CLI --- core/command/upgrade.php | 38 +++++++++- core/register_command.php | 6 +- lib/base.php | 2 +- lib/private/releasenotes.php | 30 +++++--- lib/private/server.php | 13 ---- tests/lib/releasenotes.php | 129 --------------------------------- tests/lib/releasenotestest.php | 119 ++++++++++++++++++++++++++++++ 7 files changed, 179 insertions(+), 158 deletions(-) delete mode 100644 tests/lib/releasenotes.php create mode 100644 tests/lib/releasenotestest.php diff --git a/core/command/upgrade.php b/core/command/upgrade.php index c45984d7a30..c76c9be4ed8 100644 --- a/core/command/upgrade.php +++ b/core/command/upgrade.php @@ -30,6 +30,7 @@ namespace OC\Core\Command; use OC\Console\TimestampFormatter; +use OC\ReleaseNotes; use OC\Updater; use OCP\IConfig; use OCP\ILogger; @@ -37,8 +38,9 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputOption; +use Symfony\Component\Console\Question\ConfirmationQuestion; -class Upgrade extends Command { +class Upgrade extends Base { const ERROR_SUCCESS = 0; const ERROR_NOT_INSTALLED = 1; @@ -53,17 +55,23 @@ class Upgrade extends Command { /** @var ILogger */ private $logger; + /** @var ReleaseNotes */ + private $releaseNotes; + /** * @param IConfig $config * @param ILogger $logger + * @param ReleaseNotes $releaseNotes */ - public function __construct(IConfig $config, ILogger $logger) { + public function __construct(IConfig $config, ILogger $logger, ReleaseNotes $releaseNotes) { parent::__construct(); $this->config = $config; $this->logger = $logger; + $this->releaseNotes = $releaseNotes; } protected function configure() { + parent::configure(); $this ->setName('upgrade') ->setDescription('run upgrade routines after installation of a new release. The release has to be installed before.') @@ -95,6 +103,19 @@ class Upgrade extends Command { */ protected function execute(InputInterface $input, OutputInterface $output) { + if ($input->isInteractive()) { + $installedVersion = $this->config->getSystemValue('version', '0.0.0'); + $currentVersion = \OCP\Util::getVersion(); + + $releaseNotesArray = $this->releaseNotes->getReleaseNotes($installedVersion, $currentVersion); + if (!empty($releaseNotesArray)) { + $this->writeArrayInOutputFormat($input, $output, $releaseNotesArray); + if (!$this->ask($input, $output)){ + return self::ERROR_SUCCESS; + } + } + } + $simulateStepEnabled = true; $updateStepEnabled = true; $skip3rdPartyAppsDisable = false; @@ -262,4 +283,17 @@ class Upgrade extends Command { ); } } + + /** + * Ask for confirmation + * @param InputInterface $input + * @param OutputInterface $output + * @return bool + */ + public function ask(InputInterface $input, OutputInterface $output){ + $helper = $this->getHelper('question'); + $question = new ConfirmationQuestion('Continue with update (y/n)' . PHP_EOL, true); + return $helper->ask($input, $output, $question); + } + } diff --git a/core/register_command.php b/core/register_command.php index 17bd573133a..e06ff436f50 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -114,7 +114,11 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) { $application->add(new OC\Core\Command\Maintenance\Repair(new \OC\Repair(\OC\Repair::getRepairSteps()), \OC::$server->getConfig())); $application->add(new OC\Core\Command\Maintenance\SingleUser(\OC::$server->getConfig())); - $application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->getLogger())); + $application->add(new OC\Core\Command\Upgrade( + \OC::$server->getConfig(), + \OC::$server->getLogger(), + new \OC\ReleaseNotes(\OC::$server->getDatabaseConnection()) + )); $application->add(new OC\Core\Command\User\Add(\OC::$server->getUserManager(), \OC::$server->getGroupManager())); $application->add(new OC\Core\Command\User\Delete(\OC::$server->getUserManager())); diff --git a/lib/base.php b/lib/base.php index a5b0dd429ae..e77a07239c4 100644 --- a/lib/base.php +++ b/lib/base.php @@ -392,7 +392,7 @@ class OC { $tmpl->assign('isAppsOnlyUpgrade', false); } - $releaseNotes = \OC::$server->getReleaseNotes(); + $releaseNotes = new \OC\ReleaseNotes(\OC::$server->getDatabaseConnection()); // get third party apps $ocVersion = \OCP\Util::getVersion(); diff --git a/lib/private/releasenotes.php b/lib/private/releasenotes.php index 32ab036f9c1..a7caf8601ae 100644 --- a/lib/private/releasenotes.php +++ b/lib/private/releasenotes.php @@ -32,18 +32,18 @@ class ReleaseNotes { protected $dbConnection; /** - * @param OCP\IDBConnection $connection + * @param \OCP\IDBConnection $dbConnection */ - public function __construct(IDBConnection $dbConnection){ + public function __construct(IDBConnection $dbConnection) { $this->dbConnection = $dbConnection; } /** * @param string $fromVersion * @param string $toVersion - * @return array + * @return string[] */ - public function getReleaseNotes($fromVersion, $toVersion){ + public function getReleaseNotes($fromVersion, $toVersion) { $releaseNotes = []; $l10n = \OC::$server->getL10N('core'); @@ -59,16 +59,16 @@ class ReleaseNotes { $toVersionMajorMinor = ''; } - if ( $fromVersionMajorMinor === '8.2' && $toVersionMajorMinor === '9.0' ) { + if ($fromVersionMajorMinor === '8.2' && $toVersionMajorMinor === '9.0') { if (!$this->isCliMode() && $this->countFilecacheEntries() > 200000) { $releaseNotes[] = $l10n->t( - "You have an ownCloud installation with over 200.000 files so the upgrade might take a while. The recommendation is to use the command-line instead of the web interface for big ownCloud servers." + 'You have an ownCloud installation with over 200.000 files so the upgrade might take a while. The recommendation is to use the command-line instead of the web interface for big ownCloud servers.' ); } if ($this->isMysql() && $this->countFilecacheEntries() > 200000) { $releaseNotes[] = $l10n->t( - "Hint: You can speed up the upgrade by executing this SQL command manually: ALTER TABLE %s ADD COLUMN checksum varchar(255) DEFAULT NULL AFTER permissions;", - [$this->dbConnection->getPrefix().'filecache'] + 'Hint: You can speed up the upgrade by executing this SQL command manually: ALTER TABLE %s ADD COLUMN checksum varchar(255) DEFAULT NULL AFTER permissions;', + [$this->dbConnection->getQueryBuilder()->getTableName('filecache')] ); } } @@ -78,7 +78,7 @@ class ReleaseNotes { /** * @return bool */ - protected function isCliMode(){ + protected function isCliMode() { return \OC::$CLI; } @@ -94,9 +94,15 @@ class ReleaseNotes { * @return int */ protected function countFilecacheEntries(){ - $result = $this->dbConnection->executeQuery("SELECT COUNT(*) FROM *PREFIX*filecache"); - $count = $result->fetchColumn(); - return $count ? $count : 0; + $query = $this->dbConnection->getQueryBuilder(); + $query->selectAlias($query->createFunction('COUNT(*)'), 'num_entries') + ->from('filecache'); + + $result = $query->execute(); + $row = $result->fetch(); + $result->closeCursor(); + + return (int) $row['num_entries']; } /** diff --git a/lib/private/server.php b/lib/private/server.php index 00ee4e5c565..581a2b44cea 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -623,12 +623,6 @@ class Server extends ServerContainer implements IServerContainer { return $manager; }); - - $this->registerService('ReleaseNotes', function (Server $c) { - return new \OC\ReleaseNotes( - $c->getDatabaseConnection() - ); - }); } /** @@ -1282,11 +1276,4 @@ class Server extends ServerContainer implements IServerContainer { return $this->query('ShareManager'); } - /** - * @return \OC\ReleaseNotes - */ - public function getReleaseNotes() { - return $this->query('ReleaseNotes'); - } - } diff --git a/tests/lib/releasenotes.php b/tests/lib/releasenotes.php deleted file mode 100644 index ca2c3db66fb..00000000000 --- a/tests/lib/releasenotes.php +++ /dev/null @@ -1,129 +0,0 @@ - - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -class Test_ReleaseNotes extends \Test\TestCase { - protected $prefix = 'ocx_'; - - protected function setUp() { - parent::setUp(); - } - - protected function tearDown() { - $this->expected = []; - parent::tearDown(); - } - - public function resultProvider82to90(){ - $l10n = \OC::$server->getL10N('core'); - $alterTableMessage = $l10n->t( - "Hint: You can speed up the upgrade by executing this SQL command manually: ALTER TABLE %s ADD COLUMN checksum varchar(255) DEFAULT NULL AFTER permissions;", - ['ocx_filecache'] - ); - $useCliMessage = $l10n->t( - "You have an ownCloud installation with over 200.000 files so the upgrade might take a while. The recommendation is to use the command-line instead of the web interface for big ownCloud servers." - ); - return [ - [ [], false, false, 20 ], - [ [], false, true, 20 ], - [ [], true, false, 20 ], - [ [], true, true, 20 ], - [ [ $useCliMessage ], false, false, 1000000 ], - [ [], false, true, 1000000 ], - [ [ $useCliMessage, $alterTableMessage ], true, false, 1000000 ], - [ [ $alterTableMessage ], true, true, 1000000 ], - ]; - } - - /** - * @dataProvider resultProvider82to90 - */ - public function test82to90($expected, $isMysql, $isCliMode, $fileCount){ - $releaseNotesMock = $this->getReleaseNotesMock($isMysql, $isCliMode, $fileCount); - $actual = $releaseNotesMock->getReleaseNotes('8.2.22', '9.0.1'); - $this->assertEquals($expected, $actual); - } - - - - public function resultProvider90to91(){ - return [ - [ [], false, false, 20 ], - [ [], false, true, 20 ], - [ [], true, false, 20 ], - [ [], true, true, 20 ], - [ [], false, false, 1000000 ], - [ [], false, true, 1000000 ], - [ [], true, false, 1000000 ], - [ [], true, true, 1000000 ], - ]; - } - - /** - * @dataProvider resultProvider90to91 - */ - public function test90to91($expected, $isMysql, $isCliMode, $fileCount){ - $releaseNotesMock = $this->getReleaseNotesMock($isMysql, $isCliMode, $fileCount); - $actual = $releaseNotesMock->getReleaseNotes('9.0.1', '9.1.0'); - $this->assertEquals($expected, $actual); - } - - - private function getReleaseNotesMock($isMysql, $isCliMode, $fileCount){ - $dbConnectionMock = $this->getMockBuilder('OCP\IDBConnection') - ->setMethods(array_merge($this->getMethods('OCP\IDBConnection'), ['getPrefix'])) - ->getMock() - ; - $dbConnectionMock->expects($this->any()) - ->method('getPrefix') - ->willReturn($this->prefix) - ; - $releaseNotesMock = $this->getMockBuilder('OC\ReleaseNotes') - ->setConstructorArgs([$dbConnectionMock]) - ->setMethods(['isMysql', 'isCliMode', 'countFilecacheEntries']) - ->getMock() - ; - - $releaseNotesMock->expects($this->any()) - ->method('isMysql') - ->willReturn($isMysql) - ; - $releaseNotesMock->expects($this->any()) - ->method('isCliMode') - ->willReturn($isCliMode) - ; - $releaseNotesMock->expects($this->any()) - ->method('countFilecacheEntries') - ->willReturn($fileCount) - ; - return $releaseNotesMock; - } - - private function getMethods($class){ - $methods = []; - if (class_exists($class) || interface_exists($class)) { - $reflector = new ReflectionClass($class); - foreach ($reflector->getMethods( ReflectionMethod::IS_PUBLIC | ReflectionMethod::IS_ABSTRACT ) as $method) { - $methods[] = $method->getName(); - } - } - return $methods; - } -} diff --git a/tests/lib/releasenotestest.php b/tests/lib/releasenotestest.php new file mode 100644 index 00000000000..aaa47bb2481 --- /dev/null +++ b/tests/lib/releasenotestest.php @@ -0,0 +1,119 @@ + + * + * @copyright Copyright (c) 2016, ownCloud, Inc. + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace Test; + +class ReleaseNotesTest extends \Test\TestCase { + + /** + * @param bool $isMysql + * @param bool $isCliMode + * @param int $fileCount + * @return \PHPUnit_Framework_MockObject_MockObject|\OC\ReleaseNotes + */ + protected function getReleaseNotesMock($isMysql, $isCliMode, $fileCount) { + $query = $this->getMockBuilder('OCP\DB\QueryBuilder\IQueryBuilder') + ->disableOriginalConstructor() + ->getMock(); + $query->expects($this->any()) + ->method('getTableName') + ->willReturnCallback(function($tableName) { + return 'ocx_' . $tableName; + }); + + $dbConnectionMock = $this->getMockBuilder('OCP\IDBConnection') + ->disableOriginalConstructor() + ->getMock(); + $dbConnectionMock->expects($this->any()) + ->method('getQueryBuilder') + ->willReturn($query); + $releaseNotesMock = $this->getMockBuilder('OC\ReleaseNotes') + ->setConstructorArgs([$dbConnectionMock]) + ->setMethods(['isMysql', 'isCliMode', 'countFilecacheEntries']) + ->getMock(); + + $releaseNotesMock->expects($this->any()) + ->method('isMysql') + ->willReturn($isMysql); + $releaseNotesMock->expects($this->any()) + ->method('isCliMode') + ->willReturn($isCliMode); + $releaseNotesMock->expects($this->any()) + ->method('countFilecacheEntries') + ->willReturn($fileCount); + return $releaseNotesMock; + } + + public function data82to90() { + $alterTableMessage = 'Hint: You can speed up the upgrade by executing this SQL command manually: ALTER TABLE ocx_filecache ADD COLUMN checksum varchar(255) DEFAULT NULL AFTER permissions;'; + $useCliMessage = 'You have an ownCloud installation with over 200.000 files so the upgrade might take a while. The recommendation is to use the command-line instead of the web interface for big ownCloud servers.'; + return [ + [[], false, false, 20], + [[], false, true, 20], + [[], true, false, 20], + [[], true, true, 20], + [[$useCliMessage], false, false, 1000000], + [[], false, true, 1000000], + [[$useCliMessage, $alterTableMessage], true, false, 1000000], + [[$alterTableMessage], true, true, 1000000], + ]; + } + + /** + * @dataProvider data82to90 + * + * @param string[] $expected + * @param bool $isMysql + * @param bool $isCliMode + * @param int $fileCount + */ + public function test82to90($expected, $isMysql, $isCliMode, $fileCount) { + $releaseNotesMock = $this->getReleaseNotesMock($isMysql, $isCliMode, $fileCount); + $actual = $releaseNotesMock->getReleaseNotes('8.2.22', '9.0.1'); + $this->assertEquals($expected, $actual); + } + + public function data90to91() { + return [ + [false, false, 20], + [false, true, 20], + [true, false, 20], + [true, true, 20], + [false, false, 1000000], + [false, true, 1000000], + [true, false, 1000000], + [true, true, 1000000], + ]; + } + + /** + * @dataProvider data90to91 + * + * @param bool $isMysql + * @param bool $isCliMode + * @param int $fileCount + */ + public function test90to91($isMysql, $isCliMode, $fileCount) { + $releaseNotesMock = $this->getReleaseNotesMock($isMysql, $isCliMode, $fileCount); + $actual = $releaseNotesMock->getReleaseNotes('9.0.1', '9.1.0'); + $this->assertCount(0, $actual); + } +} From e5bec54e4e746364b621a4d26e400f7178c9c62f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 6 Apr 2016 15:41:25 +0200 Subject: [PATCH 5/6] Make the version a string --- core/command/upgrade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/command/upgrade.php b/core/command/upgrade.php index c76c9be4ed8..a60eee9e327 100644 --- a/core/command/upgrade.php +++ b/core/command/upgrade.php @@ -105,7 +105,7 @@ class Upgrade extends Base { if ($input->isInteractive()) { $installedVersion = $this->config->getSystemValue('version', '0.0.0'); - $currentVersion = \OCP\Util::getVersion(); + $currentVersion = implode('.', \OCP\Util::getVersion()); $releaseNotesArray = $this->releaseNotes->getReleaseNotes($installedVersion, $currentVersion); if (!empty($releaseNotesArray)) { From c43713515b7615cd34b695327e8b246d9de6d800 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 6 Apr 2016 15:51:25 +0200 Subject: [PATCH 6/6] Remove duplicated message --- lib/private/releasenotes.php | 21 ++++------------ tests/lib/releasenotestest.php | 44 +++++++++++----------------------- 2 files changed, 19 insertions(+), 46 deletions(-) diff --git a/lib/private/releasenotes.php b/lib/private/releasenotes.php index a7caf8601ae..5da416c19f0 100644 --- a/lib/private/releasenotes.php +++ b/lib/private/releasenotes.php @@ -28,11 +28,11 @@ use OCP\IDBConnection; * Class to store release notes */ class ReleaseNotes { - /** @var \OCP\IDBConnection $dbConnection */ + /** @var IDBConnection $dbConnection */ protected $dbConnection; /** - * @param \OCP\IDBConnection $dbConnection + * @param IDBConnection $dbConnection */ public function __construct(IDBConnection $dbConnection) { $this->dbConnection = $dbConnection; @@ -60,11 +60,6 @@ class ReleaseNotes { } if ($fromVersionMajorMinor === '8.2' && $toVersionMajorMinor === '9.0') { - if (!$this->isCliMode() && $this->countFilecacheEntries() > 200000) { - $releaseNotes[] = $l10n->t( - 'You have an ownCloud installation with over 200.000 files so the upgrade might take a while. The recommendation is to use the command-line instead of the web interface for big ownCloud servers.' - ); - } if ($this->isMysql() && $this->countFilecacheEntries() > 200000) { $releaseNotes[] = $l10n->t( 'Hint: You can speed up the upgrade by executing this SQL command manually: ALTER TABLE %s ADD COLUMN checksum varchar(255) DEFAULT NULL AFTER permissions;', @@ -74,14 +69,7 @@ class ReleaseNotes { } return $releaseNotes; } - - /** - * @return bool - */ - protected function isCliMode() { - return \OC::$CLI; - } - + /** * @return bool */ @@ -109,10 +97,11 @@ class ReleaseNotes { * Strip everything except first digits * @param string $version * @return string + * @throws \InvalidArgumentException */ private function getMajorMinor($version){ $versionArray = explode('.', $version); - if ( count($versionArray)<2 ) { + if (count($versionArray) < 2) { throw new \InvalidArgumentException('Version should have at least 2 parts separated by dot.'); } return implode('.', [ $versionArray[0], $versionArray[1] ]); diff --git a/tests/lib/releasenotestest.php b/tests/lib/releasenotestest.php index aaa47bb2481..584f396038b 100644 --- a/tests/lib/releasenotestest.php +++ b/tests/lib/releasenotestest.php @@ -25,11 +25,10 @@ class ReleaseNotesTest extends \Test\TestCase { /** * @param bool $isMysql - * @param bool $isCliMode * @param int $fileCount * @return \PHPUnit_Framework_MockObject_MockObject|\OC\ReleaseNotes */ - protected function getReleaseNotesMock($isMysql, $isCliMode, $fileCount) { + protected function getReleaseNotesMock($isMysql, $fileCount) { $query = $this->getMockBuilder('OCP\DB\QueryBuilder\IQueryBuilder') ->disableOriginalConstructor() ->getMock(); @@ -47,15 +46,12 @@ class ReleaseNotesTest extends \Test\TestCase { ->willReturn($query); $releaseNotesMock = $this->getMockBuilder('OC\ReleaseNotes') ->setConstructorArgs([$dbConnectionMock]) - ->setMethods(['isMysql', 'isCliMode', 'countFilecacheEntries']) + ->setMethods(['isMysql', 'countFilecacheEntries']) ->getMock(); $releaseNotesMock->expects($this->any()) ->method('isMysql') ->willReturn($isMysql); - $releaseNotesMock->expects($this->any()) - ->method('isCliMode') - ->willReturn($isCliMode); $releaseNotesMock->expects($this->any()) ->method('countFilecacheEntries') ->willReturn($fileCount); @@ -63,17 +59,11 @@ class ReleaseNotesTest extends \Test\TestCase { } public function data82to90() { - $alterTableMessage = 'Hint: You can speed up the upgrade by executing this SQL command manually: ALTER TABLE ocx_filecache ADD COLUMN checksum varchar(255) DEFAULT NULL AFTER permissions;'; - $useCliMessage = 'You have an ownCloud installation with over 200.000 files so the upgrade might take a while. The recommendation is to use the command-line instead of the web interface for big ownCloud servers.'; return [ - [[], false, false, 20], - [[], false, true, 20], - [[], true, false, 20], - [[], true, true, 20], - [[$useCliMessage], false, false, 1000000], - [[], false, true, 1000000], - [[$useCliMessage, $alterTableMessage], true, false, 1000000], - [[$alterTableMessage], true, true, 1000000], + [[], false, 20], + [[], true, 20], + [[], false, 1000000], + [['Hint: You can speed up the upgrade by executing this SQL command manually: ALTER TABLE ocx_filecache ADD COLUMN checksum varchar(255) DEFAULT NULL AFTER permissions;'], true, 1000000], ]; } @@ -82,25 +72,20 @@ class ReleaseNotesTest extends \Test\TestCase { * * @param string[] $expected * @param bool $isMysql - * @param bool $isCliMode * @param int $fileCount */ - public function test82to90($expected, $isMysql, $isCliMode, $fileCount) { - $releaseNotesMock = $this->getReleaseNotesMock($isMysql, $isCliMode, $fileCount); + public function test82to90($expected, $isMysql, $fileCount) { + $releaseNotesMock = $this->getReleaseNotesMock($isMysql, $fileCount); $actual = $releaseNotesMock->getReleaseNotes('8.2.22', '9.0.1'); $this->assertEquals($expected, $actual); } public function data90to91() { return [ - [false, false, 20], - [false, true, 20], - [true, false, 20], - [true, true, 20], - [false, false, 1000000], - [false, true, 1000000], - [true, false, 1000000], - [true, true, 1000000], + [false, 20], + [true, 20], + [false, 1000000], + [true, 1000000], ]; } @@ -108,11 +93,10 @@ class ReleaseNotesTest extends \Test\TestCase { * @dataProvider data90to91 * * @param bool $isMysql - * @param bool $isCliMode * @param int $fileCount */ - public function test90to91($isMysql, $isCliMode, $fileCount) { - $releaseNotesMock = $this->getReleaseNotesMock($isMysql, $isCliMode, $fileCount); + public function test90to91($isMysql, $fileCount) { + $releaseNotesMock = $this->getReleaseNotesMock($isMysql, $fileCount); $actual = $releaseNotesMock->getReleaseNotes('9.0.1', '9.1.0'); $this->assertCount(0, $actual); }