diff --git a/appinfo/info.xml b/appinfo/info.xml
index d97f6c7d49d..01795683b3b 100755
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -11,7 +11,11 @@ The First run wizard can be customized to meet specific design goals, or to chan
1.1.1
+ FirstRunWizard
true
166055
+
+ OCA\FirstRunWizard\Command\ResetAll
+
diff --git a/lib/Command/ResetAll.php b/lib/Command/ResetAll.php
new file mode 100644
index 00000000000..3af548f6cdf
--- /dev/null
+++ b/lib/Command/ResetAll.php
@@ -0,0 +1,80 @@
+
+*
+* @copyright Copyright (c) 2019, ownCloud GmbH
+* @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 OCA\FirstRunWizard\Command;
+
+use OCA\FirstRunWizard\Config;
+use Symfony\Component\Console\Command\Command;
+use Symfony\Component\Console\Helper\ProgressBar;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+/**
+ * Class ResetAll
+ *
+ * @package OCA\FirstRunWizard\Command
+ */
+class ResetAll extends Command {
+ /**
+ * @var Config
+ */
+ protected $config;
+
+ /**
+ * ResetAll constructor.
+ *
+ * @param Config $config
+ */
+ public function __construct(Config $config) {
+ parent::__construct();
+ $this->config = $config;
+ }
+
+ /**
+ * Setup the command
+ *
+ * @return int|null|void
+ */
+ public function configure() {
+ $this
+ ->setName('firstrunwizard:reset-all')
+ ->setDescription('Reset the first run wizard for all users');
+ }
+
+ /**
+ * Execute the command
+ *
+ * @param InputInterface $input
+ * @param OutputInterface $output
+ *
+ * @return int|null|void
+ */
+ public function execute(InputInterface $input, OutputInterface $output) {
+ $output->writeln('Resetting firstrunwizard for all users');
+ $progress = new ProgressBar($output);
+ $this->config->resetAllUsers(function ($user) use ($progress) {
+ $progress->advance();
+ });
+ $progress->finish();
+ $output->writeln("");
+ $output->writeln("Done");
+ }
+}
diff --git a/lib/config.php b/lib/config.php
index 88c565b4b59..42e622e3bee 100755
--- a/lib/config.php
+++ b/lib/config.php
@@ -1,5 +1,4 @@
.
*
*/
+
namespace OCA\FirstRunWizard;
use OCP\IConfig;
use OCP\IUserSession;
+/**
+ * Class Config
+ *
+ * @package OCA\FirstRunWizard
+ */
class Config {
+
+ /**
+ * @var IConfig
+ */
protected $config;
+ /**
+ * @var IUserSession
+ */
protected $userSession;
/**
@@ -72,4 +84,25 @@ public function isEnabled() {
return false;
}
}
+
+ /**
+ * Enables the firstrunwizard for all users again that had it disabled
+ *
+ * @param callable $callback called with the current user being set
+ *
+ * @return void
+ *
+ * @throws \OCP\PreConditionNotMetException
+ */
+ public function resetAllUsers(callable $callback) {
+ $users = $this->config->getUsersForUserValue(
+ 'firstrunwizard',
+ 'show',
+ 0
+ );
+ foreach ($users as $user) {
+ \call_user_func($callback, $user);
+ $this->config->setUserValue($user, 'firstrunwizard', 'show', 1);
+ }
+ }
}
diff --git a/tests/lib/configtest.php b/tests/lib/configtest.php
index 64722d1319b..8131d6f1a61 100644
--- a/tests/lib/configtest.php
+++ b/tests/lib/configtest.php
@@ -4,14 +4,29 @@
use OCA\FirstRunWizard\Config;
+/**
+ * Class ConfigTest
+ *
+ * @package OCA\FirstRunWizard\Tests
+ */
class ConfigTest extends \PHPUnit_Framework_TestCase {
/**
+ * @param bool $isUserAvailable
+ *
* @dataProvider enableDisableData
+ *
+ * @return void
*/
public function testEnable($isUserAvailable) {
+ /**
+ * @var IConfig | \PHPUnit_Framework_MockObject_MockObject $config
+ */
$config = $this->getMockBuilder('\OCP\IConfig')
->disableOriginalConstructor()->getMock();
+ /**
+ * @var IUserSession | \PHPUnit_Framework_MockObject_MockObject $userSession
+ */
$userSession = $this->getMockBuilder('\OCP\IUserSession')
->disableOriginalConstructor()->getMock();
$user = $this->getMockBuilder('\OCP\IUser')
@@ -47,11 +62,21 @@ public function testEnable($isUserAvailable) {
}
/**
+ * @param bool $isUserAvailable
+ *
+ * @return void
+ *
* @dataProvider enableDisableData
*/
public function testDisable($isUserAvailable) {
+ /**
+ * @var IConfig | \PHPUnit_Framework_MockObject_MockObject $config
+ */
$config = $this->getMockBuilder('\OCP\IConfig')
->disableOriginalConstructor()->getMock();
+ /**
+ * @var IUserSession | \PHPUnit_Framework_MockObject_MockObject $userSession
+ */
$userSession = $this->getMockBuilder('\OCP\IUserSession')
->disableOriginalConstructor()->getMock();
$user = $this->getMockBuilder('\OCP\IUser')
@@ -86,6 +111,9 @@ public function testDisable($isUserAvailable) {
}
}
+ /**
+ * @return array
+ */
public function enableDisableData() {
return [
[true],
@@ -94,11 +122,21 @@ public function enableDisableData() {
}
/**
+ * @param bool $isEnabled
+ *
+ * @return void
+ *
* @dataProvider isEnabledData
*/
public function testIsEnabled($isEnabled) {
+ /**
+ * @var IConfig | \PHPUnit_Framework_MockObject_MockObject $config
+ */
$config = $this->getMockBuilder('\OCP\IConfig')
->disableOriginalConstructor()->getMock();
+ /**
+ * @var IUserSession | \PHPUnit_Framework_MockObject_MockObject $userSession
+ */
$userSession = $this->getMockBuilder('\OCP\IUserSession')
->disableOriginalConstructor()->getMock();
$user = $this->getMockBuilder('\OCP\IUser')
@@ -150,6 +188,9 @@ public function testIsEnabled($isEnabled) {
}
}
+ /**
+ * @return array
+ */
public function isEnabledData() {
return [
[true],
@@ -157,4 +198,43 @@ public function isEnabledData() {
[null],
];
}
+
+ /**
+ * Test that the config is reset for all users
+ *
+ * @return void
+ *
+ * @throws \OCP\PreConditionNotMetException
+ */
+ public function testResetAllUsers() {
+ $users = [];
+ $users[] = $this->getMockBuilder('\OCP\IUser')
+ ->disableOriginalConstructor()->getMock();
+ $users[] = $this->getMockBuilder('\OCP\IUser')
+ ->disableOriginalConstructor()->getMock();
+ /**
+ * @var IConfig | \PHPUnit_Framework_MockObject_MockObject $config
+ */
+ $config = $this->getMockBuilder('\OCP\IConfig')
+ ->disableOriginalConstructor()->getMock();
+ $config->method('getUsersForUserValue')
+ ->with('firstrunwizard', 'show', 0)
+ ->willReturn($users);
+ $config->expects($this->exactly(\count($users)))
+ ->method('setUserValue');
+ /**
+ * @var IUserSession | \PHPUnit_Framework_MockObject_MockObject $userSession
+ */
+ $userSession = $this->getMockBuilder('\OCP\IUserSession')
+ ->disableOriginalConstructor()->getMock();
+ $c = new Config($config, $userSession);
+ // Create a fake callback to check it gets called
+ $mock = $this->getMockBuilder('stdClass');
+ $mock->setMethods(['callback']);
+ $mock = $mock->getMock();
+ $mock->expects($this->exactly(\count($users)))
+ ->method('callback')
+ ->will($this->returnValue(true));
+ $c->resetAllUsers([$mock, 'callback']);
+ }
}