Skip to content

Commit

Permalink
Add occ command to reset for all users
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Needham committed Nov 9, 2018
1 parent bf78e45 commit 2b657d7
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 0 deletions.
3 changes: 3 additions & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@ The First run wizard can be customized to meet specific design goals, or to chan
</dependencies>
<version>1.1</version>
<default_enable/>
<commands>
<command>OCA\FirstRunWizard\Command\ResetAll</command>
</commands>
</info>
62 changes: 62 additions & 0 deletions lib/Command/ResetAll.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

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("<info>Done</info>");
}
}
12 changes: 12 additions & 0 deletions lib/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,16 @@ public function isEnabled() {
return false;
}
}

/**
* Enables the firstrunwizard for all users again that had it disbaled
* @throws \OCP\PreConditionNotMetException
*/
public function resetAllUsers(\Closure $callback) {
$users = $this->config->getUsersForUserValue('firstrunwizard', 'show', 0);
foreach ($users as $user) {
\call_user_func($callback, $user);
$this->config->setUserValue($user, 'firstrunwizard', 'show' , 1);
}
}
}

0 comments on commit 2b657d7

Please sign in to comment.