@@ -51,7 +51,7 @@ |
||
51 | 51 | */ |
52 | 52 | public function completeArgumentValues($argumentName, CompletionContext $context) { |
53 | 53 | if ($argumentName === 'uid') { |
54 | - return array_map(function (IUser $user) { |
|
54 | + return array_map(function(IUser $user) { |
|
55 | 55 | return $user->getUID(); |
56 | 56 | }, $this->userManager->search($context->getCurrentWord(), 100)); |
57 | 57 | } |
@@ -31,33 +31,33 @@ |
||
31 | 31 | |
32 | 32 | class Base extends \OC\Core\Command\Base { |
33 | 33 | |
34 | - /** @var IUserManager */ |
|
35 | - protected $userManager; |
|
34 | + /** @var IUserManager */ |
|
35 | + protected $userManager; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Return possible values for the named option |
|
39 | - * |
|
40 | - * @param string $optionName |
|
41 | - * @param CompletionContext $context |
|
42 | - * @return string[] |
|
43 | - */ |
|
44 | - public function completeOptionValues($optionName, CompletionContext $context) { |
|
45 | - return []; |
|
46 | - } |
|
37 | + /** |
|
38 | + * Return possible values for the named option |
|
39 | + * |
|
40 | + * @param string $optionName |
|
41 | + * @param CompletionContext $context |
|
42 | + * @return string[] |
|
43 | + */ |
|
44 | + public function completeOptionValues($optionName, CompletionContext $context) { |
|
45 | + return []; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * Return possible values for the named argument |
|
50 | - * |
|
51 | - * @param string $argumentName |
|
52 | - * @param CompletionContext $context |
|
53 | - * @return string[] |
|
54 | - */ |
|
55 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
56 | - if ($argumentName === 'uid') { |
|
57 | - return array_map(function (IUser $user) { |
|
58 | - return $user->getUID(); |
|
59 | - }, $this->userManager->search($context->getCurrentWord(), 100)); |
|
60 | - } |
|
61 | - return []; |
|
62 | - } |
|
48 | + /** |
|
49 | + * Return possible values for the named argument |
|
50 | + * |
|
51 | + * @param string $argumentName |
|
52 | + * @param CompletionContext $context |
|
53 | + * @return string[] |
|
54 | + */ |
|
55 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
56 | + if ($argumentName === 'uid') { |
|
57 | + return array_map(function (IUser $user) { |
|
58 | + return $user->getUID(); |
|
59 | + }, $this->userManager->search($context->getCurrentWord(), 100)); |
|
60 | + } |
|
61 | + return []; |
|
62 | + } |
|
63 | 63 | } |
@@ -28,35 +28,35 @@ |
||
28 | 28 | use Symfony\Component\Console\Output\OutputInterface; |
29 | 29 | |
30 | 30 | class Check extends Base { |
31 | - /** |
|
32 | - * @var SystemConfig |
|
33 | - */ |
|
34 | - private $config; |
|
31 | + /** |
|
32 | + * @var SystemConfig |
|
33 | + */ |
|
34 | + private $config; |
|
35 | 35 | |
36 | - public function __construct(SystemConfig $config) { |
|
37 | - parent::__construct(); |
|
38 | - $this->config = $config; |
|
39 | - } |
|
36 | + public function __construct(SystemConfig $config) { |
|
37 | + parent::__construct(); |
|
38 | + $this->config = $config; |
|
39 | + } |
|
40 | 40 | |
41 | - protected function configure() { |
|
42 | - parent::configure(); |
|
41 | + protected function configure() { |
|
42 | + parent::configure(); |
|
43 | 43 | |
44 | - $this |
|
45 | - ->setName('check') |
|
46 | - ->setDescription('check dependencies of the server environment') |
|
47 | - ; |
|
48 | - } |
|
44 | + $this |
|
45 | + ->setName('check') |
|
46 | + ->setDescription('check dependencies of the server environment') |
|
47 | + ; |
|
48 | + } |
|
49 | 49 | |
50 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
51 | - $errors = \OC_Util::checkServer($this->config); |
|
52 | - if (!empty($errors)) { |
|
53 | - $errors = array_map(function ($item) { |
|
54 | - return (string) $item['error']; |
|
55 | - }, $errors); |
|
50 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
51 | + $errors = \OC_Util::checkServer($this->config); |
|
52 | + if (!empty($errors)) { |
|
53 | + $errors = array_map(function ($item) { |
|
54 | + return (string) $item['error']; |
|
55 | + }, $errors); |
|
56 | 56 | |
57 | - $this->writeArrayInOutputFormat($input, $output, $errors); |
|
58 | - return 1; |
|
59 | - } |
|
60 | - return 0; |
|
61 | - } |
|
57 | + $this->writeArrayInOutputFormat($input, $output, $errors); |
|
58 | + return 1; |
|
59 | + } |
|
60 | + return 0; |
|
61 | + } |
|
62 | 62 | } |
@@ -50,7 +50,7 @@ |
||
50 | 50 | protected function execute(InputInterface $input, OutputInterface $output) { |
51 | 51 | $errors = \OC_Util::checkServer($this->config); |
52 | 52 | if (!empty($errors)) { |
53 | - $errors = array_map(function ($item) { |
|
53 | + $errors = array_map(function($item) { |
|
54 | 54 | return (string) $item['error']; |
55 | 55 | }, $errors); |
56 | 56 |
@@ -67,11 +67,11 @@ |
||
67 | 67 | */ |
68 | 68 | protected function writeModuleList(InputInterface $input, OutputInterface $output, $items) { |
69 | 69 | if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) { |
70 | - array_walk($items, function (&$item) { |
|
70 | + array_walk($items, function(&$item) { |
|
71 | 71 | if (!$item['default']) { |
72 | 72 | $item = $item['displayName']; |
73 | 73 | } else { |
74 | - $item = $item['displayName'] . ' [default*]'; |
|
74 | + $item = $item['displayName'].' [default*]'; |
|
75 | 75 | } |
76 | 76 | }); |
77 | 77 | } |
@@ -31,69 +31,69 @@ |
||
31 | 31 | use Symfony\Component\Console\Output\OutputInterface; |
32 | 32 | |
33 | 33 | class ListModules extends Base { |
34 | - /** @var IManager */ |
|
35 | - protected $encryptionManager; |
|
34 | + /** @var IManager */ |
|
35 | + protected $encryptionManager; |
|
36 | 36 | |
37 | - /** @var IConfig */ |
|
38 | - protected $config; |
|
37 | + /** @var IConfig */ |
|
38 | + protected $config; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param IManager $encryptionManager |
|
42 | - * @param IConfig $config |
|
43 | - */ |
|
44 | - public function __construct( |
|
45 | - IManager $encryptionManager, |
|
46 | - IConfig $config |
|
47 | - ) { |
|
48 | - parent::__construct(); |
|
49 | - $this->encryptionManager = $encryptionManager; |
|
50 | - $this->config = $config; |
|
51 | - } |
|
40 | + /** |
|
41 | + * @param IManager $encryptionManager |
|
42 | + * @param IConfig $config |
|
43 | + */ |
|
44 | + public function __construct( |
|
45 | + IManager $encryptionManager, |
|
46 | + IConfig $config |
|
47 | + ) { |
|
48 | + parent::__construct(); |
|
49 | + $this->encryptionManager = $encryptionManager; |
|
50 | + $this->config = $config; |
|
51 | + } |
|
52 | 52 | |
53 | - protected function configure() { |
|
54 | - parent::configure(); |
|
53 | + protected function configure() { |
|
54 | + parent::configure(); |
|
55 | 55 | |
56 | - $this |
|
57 | - ->setName('encryption:list-modules') |
|
58 | - ->setDescription('List all available encryption modules') |
|
59 | - ; |
|
60 | - } |
|
56 | + $this |
|
57 | + ->setName('encryption:list-modules') |
|
58 | + ->setDescription('List all available encryption modules') |
|
59 | + ; |
|
60 | + } |
|
61 | 61 | |
62 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
63 | - $isMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
64 | - if ($isMaintenanceModeEnabled) { |
|
65 | - $output->writeln("Maintenance mode must be disabled when listing modules"); |
|
66 | - $output->writeln("in order to list the relevant encryption modules correctly."); |
|
67 | - return; |
|
68 | - } |
|
62 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
63 | + $isMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); |
|
64 | + if ($isMaintenanceModeEnabled) { |
|
65 | + $output->writeln("Maintenance mode must be disabled when listing modules"); |
|
66 | + $output->writeln("in order to list the relevant encryption modules correctly."); |
|
67 | + return; |
|
68 | + } |
|
69 | 69 | |
70 | - $encryptionModules = $this->encryptionManager->getEncryptionModules(); |
|
71 | - $defaultEncryptionModuleId = $this->encryptionManager->getDefaultEncryptionModuleId(); |
|
70 | + $encryptionModules = $this->encryptionManager->getEncryptionModules(); |
|
71 | + $defaultEncryptionModuleId = $this->encryptionManager->getDefaultEncryptionModuleId(); |
|
72 | 72 | |
73 | - $encModules = []; |
|
74 | - foreach ($encryptionModules as $module) { |
|
75 | - $encModules[$module['id']]['displayName'] = $module['displayName']; |
|
76 | - $encModules[$module['id']]['default'] = $module['id'] === $defaultEncryptionModuleId; |
|
77 | - } |
|
78 | - $this->writeModuleList($input, $output, $encModules); |
|
79 | - } |
|
73 | + $encModules = []; |
|
74 | + foreach ($encryptionModules as $module) { |
|
75 | + $encModules[$module['id']]['displayName'] = $module['displayName']; |
|
76 | + $encModules[$module['id']]['default'] = $module['id'] === $defaultEncryptionModuleId; |
|
77 | + } |
|
78 | + $this->writeModuleList($input, $output, $encModules); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @param InputInterface $input |
|
83 | - * @param OutputInterface $output |
|
84 | - * @param array $items |
|
85 | - */ |
|
86 | - protected function writeModuleList(InputInterface $input, OutputInterface $output, $items) { |
|
87 | - if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) { |
|
88 | - array_walk($items, function (&$item) { |
|
89 | - if (!$item['default']) { |
|
90 | - $item = $item['displayName']; |
|
91 | - } else { |
|
92 | - $item = $item['displayName'] . ' [default*]'; |
|
93 | - } |
|
94 | - }); |
|
95 | - } |
|
81 | + /** |
|
82 | + * @param InputInterface $input |
|
83 | + * @param OutputInterface $output |
|
84 | + * @param array $items |
|
85 | + */ |
|
86 | + protected function writeModuleList(InputInterface $input, OutputInterface $output, $items) { |
|
87 | + if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) { |
|
88 | + array_walk($items, function (&$item) { |
|
89 | + if (!$item['default']) { |
|
90 | + $item = $item['displayName']; |
|
91 | + } else { |
|
92 | + $item = $item['displayName'] . ' [default*]'; |
|
93 | + } |
|
94 | + }); |
|
95 | + } |
|
96 | 96 | |
97 | - $this->writeArrayInOutputFormat($input, $output, $items); |
|
98 | - } |
|
97 | + $this->writeArrayInOutputFormat($input, $output, $items); |
|
98 | + } |
|
99 | 99 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | use Symfony\Component\EventDispatcher\GenericEvent; |
36 | 36 | |
37 | 37 | if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { |
38 | - @set_time_limit(0); |
|
38 | + @set_time_limit(0); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | require_once '../../lib/base.php'; |
@@ -49,190 +49,190 @@ discard block |
||
49 | 49 | $eventSource->send('success', (string)$l->t('Preparing update')); |
50 | 50 | |
51 | 51 | class FeedBackHandler { |
52 | - /** @var integer */ |
|
53 | - private $progressStateMax = 100; |
|
54 | - /** @var integer */ |
|
55 | - private $progressStateStep = 0; |
|
56 | - /** @var string */ |
|
57 | - private $currentStep; |
|
58 | - /** @var \OCP\IEventSource */ |
|
59 | - private $eventSource; |
|
60 | - /** @var \OCP\IL10N */ |
|
61 | - private $l10n; |
|
62 | - |
|
63 | - public function __construct(\OCP\IEventSource $eventSource, \OCP\IL10N $l10n) { |
|
64 | - $this->eventSource = $eventSource; |
|
65 | - $this->l10n = $l10n; |
|
66 | - } |
|
67 | - |
|
68 | - public function handleRepairFeedback($event) { |
|
69 | - if (!$event instanceof GenericEvent) { |
|
70 | - return; |
|
71 | - } |
|
72 | - |
|
73 | - switch ($event->getSubject()) { |
|
74 | - case '\OC\Repair::startProgress': |
|
75 | - $this->progressStateMax = $event->getArgument(0); |
|
76 | - $this->progressStateStep = 0; |
|
77 | - $this->currentStep = $event->getArgument(1); |
|
78 | - break; |
|
79 | - case '\OC\Repair::advance': |
|
80 | - $this->progressStateStep += $event->getArgument(0); |
|
81 | - $desc = $event->getArgument(1); |
|
82 | - if (empty($desc)) { |
|
83 | - $desc = $this->currentStep; |
|
84 | - } |
|
85 | - $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $desc])); |
|
86 | - break; |
|
87 | - case '\OC\Repair::finishProgress': |
|
88 | - $this->progressStateMax = $this->progressStateStep; |
|
89 | - $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep])); |
|
90 | - break; |
|
91 | - case '\OC\Repair::step': |
|
92 | - $this->eventSource->send('success', (string)$this->l10n->t('Repair step:') . ' ' . $event->getArgument(0)); |
|
93 | - break; |
|
94 | - case '\OC\Repair::info': |
|
95 | - $this->eventSource->send('success', (string)$this->l10n->t('Repair info:') . ' ' . $event->getArgument(0)); |
|
96 | - break; |
|
97 | - case '\OC\Repair::warning': |
|
98 | - $this->eventSource->send('notice', (string)$this->l10n->t('Repair warning:') . ' ' . $event->getArgument(0)); |
|
99 | - break; |
|
100 | - case '\OC\Repair::error': |
|
101 | - $this->eventSource->send('notice', (string)$this->l10n->t('Repair error:') . ' ' . $event->getArgument(0)); |
|
102 | - break; |
|
103 | - } |
|
104 | - } |
|
52 | + /** @var integer */ |
|
53 | + private $progressStateMax = 100; |
|
54 | + /** @var integer */ |
|
55 | + private $progressStateStep = 0; |
|
56 | + /** @var string */ |
|
57 | + private $currentStep; |
|
58 | + /** @var \OCP\IEventSource */ |
|
59 | + private $eventSource; |
|
60 | + /** @var \OCP\IL10N */ |
|
61 | + private $l10n; |
|
62 | + |
|
63 | + public function __construct(\OCP\IEventSource $eventSource, \OCP\IL10N $l10n) { |
|
64 | + $this->eventSource = $eventSource; |
|
65 | + $this->l10n = $l10n; |
|
66 | + } |
|
67 | + |
|
68 | + public function handleRepairFeedback($event) { |
|
69 | + if (!$event instanceof GenericEvent) { |
|
70 | + return; |
|
71 | + } |
|
72 | + |
|
73 | + switch ($event->getSubject()) { |
|
74 | + case '\OC\Repair::startProgress': |
|
75 | + $this->progressStateMax = $event->getArgument(0); |
|
76 | + $this->progressStateStep = 0; |
|
77 | + $this->currentStep = $event->getArgument(1); |
|
78 | + break; |
|
79 | + case '\OC\Repair::advance': |
|
80 | + $this->progressStateStep += $event->getArgument(0); |
|
81 | + $desc = $event->getArgument(1); |
|
82 | + if (empty($desc)) { |
|
83 | + $desc = $this->currentStep; |
|
84 | + } |
|
85 | + $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $desc])); |
|
86 | + break; |
|
87 | + case '\OC\Repair::finishProgress': |
|
88 | + $this->progressStateMax = $this->progressStateStep; |
|
89 | + $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep])); |
|
90 | + break; |
|
91 | + case '\OC\Repair::step': |
|
92 | + $this->eventSource->send('success', (string)$this->l10n->t('Repair step:') . ' ' . $event->getArgument(0)); |
|
93 | + break; |
|
94 | + case '\OC\Repair::info': |
|
95 | + $this->eventSource->send('success', (string)$this->l10n->t('Repair info:') . ' ' . $event->getArgument(0)); |
|
96 | + break; |
|
97 | + case '\OC\Repair::warning': |
|
98 | + $this->eventSource->send('notice', (string)$this->l10n->t('Repair warning:') . ' ' . $event->getArgument(0)); |
|
99 | + break; |
|
100 | + case '\OC\Repair::error': |
|
101 | + $this->eventSource->send('notice', (string)$this->l10n->t('Repair error:') . ' ' . $event->getArgument(0)); |
|
102 | + break; |
|
103 | + } |
|
104 | + } |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | if (\OCP\Util::needUpgrade()) { |
108 | 108 | |
109 | - $config = \OC::$server->getSystemConfig(); |
|
110 | - if ($config->getValue('upgrade.disable-web', false)) { |
|
111 | - $eventSource->send('failure', (string)$l->t('Please use the command line updater because automatic updating is disabled in the config.php.')); |
|
112 | - $eventSource->close(); |
|
113 | - exit(); |
|
114 | - } |
|
115 | - |
|
116 | - // if a user is currently logged in, their session must be ignored to |
|
117 | - // avoid side effects |
|
118 | - \OC_User::setIncognitoMode(true); |
|
119 | - |
|
120 | - $logger = \OC::$server->getLogger(); |
|
121 | - $config = \OC::$server->getConfig(); |
|
122 | - $updater = new \OC\Updater( |
|
123 | - $config, |
|
124 | - \OC::$server->getIntegrityCodeChecker(), |
|
125 | - $logger, |
|
126 | - \OC::$server->query(\OC\Installer::class) |
|
127 | - ); |
|
128 | - $incompatibleApps = []; |
|
129 | - |
|
130 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
131 | - $dispatcher->addListener('\OC\DB\Migrator::executeSql', function ($event) use ($eventSource, $l) { |
|
132 | - if ($event instanceof GenericEvent) { |
|
133 | - $eventSource->send('success', (string)$l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()])); |
|
134 | - } |
|
135 | - }); |
|
136 | - $dispatcher->addListener('\OC\DB\Migrator::checkTable', function ($event) use ($eventSource, $l) { |
|
137 | - if ($event instanceof GenericEvent) { |
|
138 | - $eventSource->send('success', (string)$l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()])); |
|
139 | - } |
|
140 | - }); |
|
141 | - $feedBack = new FeedBackHandler($eventSource, $l); |
|
142 | - $dispatcher->addListener('\OC\Repair::startProgress', [$feedBack, 'handleRepairFeedback']); |
|
143 | - $dispatcher->addListener('\OC\Repair::advance', [$feedBack, 'handleRepairFeedback']); |
|
144 | - $dispatcher->addListener('\OC\Repair::finishProgress', [$feedBack, 'handleRepairFeedback']); |
|
145 | - $dispatcher->addListener('\OC\Repair::step', [$feedBack, 'handleRepairFeedback']); |
|
146 | - $dispatcher->addListener('\OC\Repair::info', [$feedBack, 'handleRepairFeedback']); |
|
147 | - $dispatcher->addListener('\OC\Repair::warning', [$feedBack, 'handleRepairFeedback']); |
|
148 | - $dispatcher->addListener('\OC\Repair::error', [$feedBack, 'handleRepairFeedback']); |
|
149 | - |
|
150 | - $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) { |
|
151 | - $eventSource->send('success', (string)$l->t('Turned on maintenance mode')); |
|
152 | - }); |
|
153 | - $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($eventSource, $l) { |
|
154 | - $eventSource->send('success', (string)$l->t('Turned off maintenance mode')); |
|
155 | - }); |
|
156 | - $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($eventSource, $l) { |
|
157 | - $eventSource->send('success', (string)$l->t('Maintenance mode is kept active')); |
|
158 | - }); |
|
159 | - $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($eventSource, $l) { |
|
160 | - $eventSource->send('success', (string)$l->t('Updating database schema')); |
|
161 | - }); |
|
162 | - $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) { |
|
163 | - $eventSource->send('success', (string)$l->t('Updated database')); |
|
164 | - }); |
|
165 | - $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use ($eventSource, $l) { |
|
166 | - $eventSource->send('success', (string)$l->t('Checking whether the database schema can be updated (this can take a long time depending on the database size)')); |
|
167 | - }); |
|
168 | - $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use ($eventSource, $l) { |
|
169 | - $eventSource->send('success', (string)$l->t('Checked database schema update')); |
|
170 | - }); |
|
171 | - $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($eventSource, $l) { |
|
172 | - $eventSource->send('success', (string)$l->t('Checking updates of apps')); |
|
173 | - }); |
|
174 | - $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($eventSource, $l) { |
|
175 | - $eventSource->send('success', (string)$l->t('Checking for update of app "%s" in appstore', [$app])); |
|
176 | - }); |
|
177 | - $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($eventSource, $l) { |
|
178 | - $eventSource->send('success', (string)$l->t('Update app "%s" from appstore', [$app])); |
|
179 | - }); |
|
180 | - $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($eventSource, $l) { |
|
181 | - $eventSource->send('success', (string)$l->t('Checked for update of app "%s" in appstore', [$app])); |
|
182 | - }); |
|
183 | - $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($eventSource, $l) { |
|
184 | - $eventSource->send('success', (string)$l->t('Checking whether the database schema for %s can be updated (this can take a long time depending on the database size)', [$app])); |
|
185 | - }); |
|
186 | - $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($eventSource, $l) { |
|
187 | - $eventSource->send('success', (string)$l->t('Checked database schema update for apps')); |
|
188 | - }); |
|
189 | - $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l) { |
|
190 | - $eventSource->send('success', (string)$l->t('Updated "%1$s" to %2$s', [$app, $version])); |
|
191 | - }); |
|
192 | - $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps) { |
|
193 | - $incompatibleApps[]= $app; |
|
194 | - }); |
|
195 | - $updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource, $config) { |
|
196 | - $eventSource->send('failure', $message); |
|
197 | - $eventSource->close(); |
|
198 | - $config->setSystemValue('maintenance', false); |
|
199 | - }); |
|
200 | - $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l) { |
|
201 | - $eventSource->send('success', (string)$l->t('Set log level to debug')); |
|
202 | - }); |
|
203 | - $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l) { |
|
204 | - $eventSource->send('success', (string)$l->t('Reset log level')); |
|
205 | - }); |
|
206 | - $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($eventSource, $l) { |
|
207 | - $eventSource->send('success', (string)$l->t('Starting code integrity check')); |
|
208 | - }); |
|
209 | - $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($eventSource, $l) { |
|
210 | - $eventSource->send('success', (string)$l->t('Finished code integrity check')); |
|
211 | - }); |
|
212 | - |
|
213 | - try { |
|
214 | - $updater->upgrade(); |
|
215 | - } catch (\Exception $e) { |
|
216 | - \OC::$server->getLogger()->logException($e, [ |
|
217 | - 'level' => ILogger::ERROR, |
|
218 | - 'app' => 'update', |
|
219 | - ]); |
|
220 | - $eventSource->send('failure', get_class($e) . ': ' . $e->getMessage()); |
|
221 | - $eventSource->close(); |
|
222 | - exit(); |
|
223 | - } |
|
224 | - |
|
225 | - $disabledApps = []; |
|
226 | - foreach ($incompatibleApps as $app) { |
|
227 | - $disabledApps[$app] = (string) $l->t('%s (incompatible)', [$app]); |
|
228 | - } |
|
229 | - |
|
230 | - if (!empty($disabledApps)) { |
|
231 | - $eventSource->send('notice', |
|
232 | - (string)$l->t('Following apps have been disabled: %s', [implode(', ', $disabledApps)])); |
|
233 | - } |
|
109 | + $config = \OC::$server->getSystemConfig(); |
|
110 | + if ($config->getValue('upgrade.disable-web', false)) { |
|
111 | + $eventSource->send('failure', (string)$l->t('Please use the command line updater because automatic updating is disabled in the config.php.')); |
|
112 | + $eventSource->close(); |
|
113 | + exit(); |
|
114 | + } |
|
115 | + |
|
116 | + // if a user is currently logged in, their session must be ignored to |
|
117 | + // avoid side effects |
|
118 | + \OC_User::setIncognitoMode(true); |
|
119 | + |
|
120 | + $logger = \OC::$server->getLogger(); |
|
121 | + $config = \OC::$server->getConfig(); |
|
122 | + $updater = new \OC\Updater( |
|
123 | + $config, |
|
124 | + \OC::$server->getIntegrityCodeChecker(), |
|
125 | + $logger, |
|
126 | + \OC::$server->query(\OC\Installer::class) |
|
127 | + ); |
|
128 | + $incompatibleApps = []; |
|
129 | + |
|
130 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
131 | + $dispatcher->addListener('\OC\DB\Migrator::executeSql', function ($event) use ($eventSource, $l) { |
|
132 | + if ($event instanceof GenericEvent) { |
|
133 | + $eventSource->send('success', (string)$l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()])); |
|
134 | + } |
|
135 | + }); |
|
136 | + $dispatcher->addListener('\OC\DB\Migrator::checkTable', function ($event) use ($eventSource, $l) { |
|
137 | + if ($event instanceof GenericEvent) { |
|
138 | + $eventSource->send('success', (string)$l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()])); |
|
139 | + } |
|
140 | + }); |
|
141 | + $feedBack = new FeedBackHandler($eventSource, $l); |
|
142 | + $dispatcher->addListener('\OC\Repair::startProgress', [$feedBack, 'handleRepairFeedback']); |
|
143 | + $dispatcher->addListener('\OC\Repair::advance', [$feedBack, 'handleRepairFeedback']); |
|
144 | + $dispatcher->addListener('\OC\Repair::finishProgress', [$feedBack, 'handleRepairFeedback']); |
|
145 | + $dispatcher->addListener('\OC\Repair::step', [$feedBack, 'handleRepairFeedback']); |
|
146 | + $dispatcher->addListener('\OC\Repair::info', [$feedBack, 'handleRepairFeedback']); |
|
147 | + $dispatcher->addListener('\OC\Repair::warning', [$feedBack, 'handleRepairFeedback']); |
|
148 | + $dispatcher->addListener('\OC\Repair::error', [$feedBack, 'handleRepairFeedback']); |
|
149 | + |
|
150 | + $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) { |
|
151 | + $eventSource->send('success', (string)$l->t('Turned on maintenance mode')); |
|
152 | + }); |
|
153 | + $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($eventSource, $l) { |
|
154 | + $eventSource->send('success', (string)$l->t('Turned off maintenance mode')); |
|
155 | + }); |
|
156 | + $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($eventSource, $l) { |
|
157 | + $eventSource->send('success', (string)$l->t('Maintenance mode is kept active')); |
|
158 | + }); |
|
159 | + $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($eventSource, $l) { |
|
160 | + $eventSource->send('success', (string)$l->t('Updating database schema')); |
|
161 | + }); |
|
162 | + $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) { |
|
163 | + $eventSource->send('success', (string)$l->t('Updated database')); |
|
164 | + }); |
|
165 | + $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use ($eventSource, $l) { |
|
166 | + $eventSource->send('success', (string)$l->t('Checking whether the database schema can be updated (this can take a long time depending on the database size)')); |
|
167 | + }); |
|
168 | + $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use ($eventSource, $l) { |
|
169 | + $eventSource->send('success', (string)$l->t('Checked database schema update')); |
|
170 | + }); |
|
171 | + $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($eventSource, $l) { |
|
172 | + $eventSource->send('success', (string)$l->t('Checking updates of apps')); |
|
173 | + }); |
|
174 | + $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($eventSource, $l) { |
|
175 | + $eventSource->send('success', (string)$l->t('Checking for update of app "%s" in appstore', [$app])); |
|
176 | + }); |
|
177 | + $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($eventSource, $l) { |
|
178 | + $eventSource->send('success', (string)$l->t('Update app "%s" from appstore', [$app])); |
|
179 | + }); |
|
180 | + $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($eventSource, $l) { |
|
181 | + $eventSource->send('success', (string)$l->t('Checked for update of app "%s" in appstore', [$app])); |
|
182 | + }); |
|
183 | + $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($eventSource, $l) { |
|
184 | + $eventSource->send('success', (string)$l->t('Checking whether the database schema for %s can be updated (this can take a long time depending on the database size)', [$app])); |
|
185 | + }); |
|
186 | + $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($eventSource, $l) { |
|
187 | + $eventSource->send('success', (string)$l->t('Checked database schema update for apps')); |
|
188 | + }); |
|
189 | + $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l) { |
|
190 | + $eventSource->send('success', (string)$l->t('Updated "%1$s" to %2$s', [$app, $version])); |
|
191 | + }); |
|
192 | + $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps) { |
|
193 | + $incompatibleApps[]= $app; |
|
194 | + }); |
|
195 | + $updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource, $config) { |
|
196 | + $eventSource->send('failure', $message); |
|
197 | + $eventSource->close(); |
|
198 | + $config->setSystemValue('maintenance', false); |
|
199 | + }); |
|
200 | + $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l) { |
|
201 | + $eventSource->send('success', (string)$l->t('Set log level to debug')); |
|
202 | + }); |
|
203 | + $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l) { |
|
204 | + $eventSource->send('success', (string)$l->t('Reset log level')); |
|
205 | + }); |
|
206 | + $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($eventSource, $l) { |
|
207 | + $eventSource->send('success', (string)$l->t('Starting code integrity check')); |
|
208 | + }); |
|
209 | + $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($eventSource, $l) { |
|
210 | + $eventSource->send('success', (string)$l->t('Finished code integrity check')); |
|
211 | + }); |
|
212 | + |
|
213 | + try { |
|
214 | + $updater->upgrade(); |
|
215 | + } catch (\Exception $e) { |
|
216 | + \OC::$server->getLogger()->logException($e, [ |
|
217 | + 'level' => ILogger::ERROR, |
|
218 | + 'app' => 'update', |
|
219 | + ]); |
|
220 | + $eventSource->send('failure', get_class($e) . ': ' . $e->getMessage()); |
|
221 | + $eventSource->close(); |
|
222 | + exit(); |
|
223 | + } |
|
224 | + |
|
225 | + $disabledApps = []; |
|
226 | + foreach ($incompatibleApps as $app) { |
|
227 | + $disabledApps[$app] = (string) $l->t('%s (incompatible)', [$app]); |
|
228 | + } |
|
229 | + |
|
230 | + if (!empty($disabledApps)) { |
|
231 | + $eventSource->send('notice', |
|
232 | + (string)$l->t('Following apps have been disabled: %s', [implode(', ', $disabledApps)])); |
|
233 | + } |
|
234 | 234 | } else { |
235 | - $eventSource->send('notice', (string)$l->t('Already up to date')); |
|
235 | + $eventSource->send('notice', (string)$l->t('Already up to date')); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | $eventSource->send('done', ''); |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | // need to send an initial message to force-init the event source, |
47 | 47 | // which will then trigger its own CSRF check and produces its own CSRF error |
48 | 48 | // message |
49 | -$eventSource->send('success', (string)$l->t('Preparing update')); |
|
49 | +$eventSource->send('success', (string) $l->t('Preparing update')); |
|
50 | 50 | |
51 | 51 | class FeedBackHandler { |
52 | 52 | /** @var integer */ |
@@ -82,23 +82,23 @@ discard block |
||
82 | 82 | if (empty($desc)) { |
83 | 83 | $desc = $this->currentStep; |
84 | 84 | } |
85 | - $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $desc])); |
|
85 | + $this->eventSource->send('success', (string) $this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $desc])); |
|
86 | 86 | break; |
87 | 87 | case '\OC\Repair::finishProgress': |
88 | 88 | $this->progressStateMax = $this->progressStateStep; |
89 | - $this->eventSource->send('success', (string)$this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep])); |
|
89 | + $this->eventSource->send('success', (string) $this->l10n->t('[%d / %d]: %s', [$this->progressStateStep, $this->progressStateMax, $this->currentStep])); |
|
90 | 90 | break; |
91 | 91 | case '\OC\Repair::step': |
92 | - $this->eventSource->send('success', (string)$this->l10n->t('Repair step:') . ' ' . $event->getArgument(0)); |
|
92 | + $this->eventSource->send('success', (string) $this->l10n->t('Repair step:').' '.$event->getArgument(0)); |
|
93 | 93 | break; |
94 | 94 | case '\OC\Repair::info': |
95 | - $this->eventSource->send('success', (string)$this->l10n->t('Repair info:') . ' ' . $event->getArgument(0)); |
|
95 | + $this->eventSource->send('success', (string) $this->l10n->t('Repair info:').' '.$event->getArgument(0)); |
|
96 | 96 | break; |
97 | 97 | case '\OC\Repair::warning': |
98 | - $this->eventSource->send('notice', (string)$this->l10n->t('Repair warning:') . ' ' . $event->getArgument(0)); |
|
98 | + $this->eventSource->send('notice', (string) $this->l10n->t('Repair warning:').' '.$event->getArgument(0)); |
|
99 | 99 | break; |
100 | 100 | case '\OC\Repair::error': |
101 | - $this->eventSource->send('notice', (string)$this->l10n->t('Repair error:') . ' ' . $event->getArgument(0)); |
|
101 | + $this->eventSource->send('notice', (string) $this->l10n->t('Repair error:').' '.$event->getArgument(0)); |
|
102 | 102 | break; |
103 | 103 | } |
104 | 104 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | |
109 | 109 | $config = \OC::$server->getSystemConfig(); |
110 | 110 | if ($config->getValue('upgrade.disable-web', false)) { |
111 | - $eventSource->send('failure', (string)$l->t('Please use the command line updater because automatic updating is disabled in the config.php.')); |
|
111 | + $eventSource->send('failure', (string) $l->t('Please use the command line updater because automatic updating is disabled in the config.php.')); |
|
112 | 112 | $eventSource->close(); |
113 | 113 | exit(); |
114 | 114 | } |
@@ -128,14 +128,14 @@ discard block |
||
128 | 128 | $incompatibleApps = []; |
129 | 129 | |
130 | 130 | $dispatcher = \OC::$server->getEventDispatcher(); |
131 | - $dispatcher->addListener('\OC\DB\Migrator::executeSql', function ($event) use ($eventSource, $l) { |
|
131 | + $dispatcher->addListener('\OC\DB\Migrator::executeSql', function($event) use ($eventSource, $l) { |
|
132 | 132 | if ($event instanceof GenericEvent) { |
133 | - $eventSource->send('success', (string)$l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()])); |
|
133 | + $eventSource->send('success', (string) $l->t('[%d / %d]: %s', [$event[0], $event[1], $event->getSubject()])); |
|
134 | 134 | } |
135 | 135 | }); |
136 | - $dispatcher->addListener('\OC\DB\Migrator::checkTable', function ($event) use ($eventSource, $l) { |
|
136 | + $dispatcher->addListener('\OC\DB\Migrator::checkTable', function($event) use ($eventSource, $l) { |
|
137 | 137 | if ($event instanceof GenericEvent) { |
138 | - $eventSource->send('success', (string)$l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()])); |
|
138 | + $eventSource->send('success', (string) $l->t('[%d / %d]: Checking table %s', [$event[0], $event[1], $event->getSubject()])); |
|
139 | 139 | } |
140 | 140 | }); |
141 | 141 | $feedBack = new FeedBackHandler($eventSource, $l); |
@@ -147,67 +147,67 @@ discard block |
||
147 | 147 | $dispatcher->addListener('\OC\Repair::warning', [$feedBack, 'handleRepairFeedback']); |
148 | 148 | $dispatcher->addListener('\OC\Repair::error', [$feedBack, 'handleRepairFeedback']); |
149 | 149 | |
150 | - $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($eventSource, $l) { |
|
151 | - $eventSource->send('success', (string)$l->t('Turned on maintenance mode')); |
|
150 | + $updater->listen('\OC\Updater', 'maintenanceEnabled', function() use ($eventSource, $l) { |
|
151 | + $eventSource->send('success', (string) $l->t('Turned on maintenance mode')); |
|
152 | 152 | }); |
153 | - $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($eventSource, $l) { |
|
154 | - $eventSource->send('success', (string)$l->t('Turned off maintenance mode')); |
|
153 | + $updater->listen('\OC\Updater', 'maintenanceDisabled', function() use ($eventSource, $l) { |
|
154 | + $eventSource->send('success', (string) $l->t('Turned off maintenance mode')); |
|
155 | 155 | }); |
156 | - $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($eventSource, $l) { |
|
157 | - $eventSource->send('success', (string)$l->t('Maintenance mode is kept active')); |
|
156 | + $updater->listen('\OC\Updater', 'maintenanceActive', function() use ($eventSource, $l) { |
|
157 | + $eventSource->send('success', (string) $l->t('Maintenance mode is kept active')); |
|
158 | 158 | }); |
159 | - $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($eventSource, $l) { |
|
160 | - $eventSource->send('success', (string)$l->t('Updating database schema')); |
|
159 | + $updater->listen('\OC\Updater', 'dbUpgradeBefore', function() use ($eventSource, $l) { |
|
160 | + $eventSource->send('success', (string) $l->t('Updating database schema')); |
|
161 | 161 | }); |
162 | - $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) { |
|
163 | - $eventSource->send('success', (string)$l->t('Updated database')); |
|
162 | + $updater->listen('\OC\Updater', 'dbUpgrade', function() use ($eventSource, $l) { |
|
163 | + $eventSource->send('success', (string) $l->t('Updated database')); |
|
164 | 164 | }); |
165 | - $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use ($eventSource, $l) { |
|
166 | - $eventSource->send('success', (string)$l->t('Checking whether the database schema can be updated (this can take a long time depending on the database size)')); |
|
165 | + $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function() use ($eventSource, $l) { |
|
166 | + $eventSource->send('success', (string) $l->t('Checking whether the database schema can be updated (this can take a long time depending on the database size)')); |
|
167 | 167 | }); |
168 | - $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use ($eventSource, $l) { |
|
169 | - $eventSource->send('success', (string)$l->t('Checked database schema update')); |
|
168 | + $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function() use ($eventSource, $l) { |
|
169 | + $eventSource->send('success', (string) $l->t('Checked database schema update')); |
|
170 | 170 | }); |
171 | - $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($eventSource, $l) { |
|
172 | - $eventSource->send('success', (string)$l->t('Checking updates of apps')); |
|
171 | + $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function() use ($eventSource, $l) { |
|
172 | + $eventSource->send('success', (string) $l->t('Checking updates of apps')); |
|
173 | 173 | }); |
174 | - $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($eventSource, $l) { |
|
175 | - $eventSource->send('success', (string)$l->t('Checking for update of app "%s" in appstore', [$app])); |
|
174 | + $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function($app) use ($eventSource, $l) { |
|
175 | + $eventSource->send('success', (string) $l->t('Checking for update of app "%s" in appstore', [$app])); |
|
176 | 176 | }); |
177 | - $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($eventSource, $l) { |
|
178 | - $eventSource->send('success', (string)$l->t('Update app "%s" from appstore', [$app])); |
|
177 | + $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function($app) use ($eventSource, $l) { |
|
178 | + $eventSource->send('success', (string) $l->t('Update app "%s" from appstore', [$app])); |
|
179 | 179 | }); |
180 | - $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($eventSource, $l) { |
|
181 | - $eventSource->send('success', (string)$l->t('Checked for update of app "%s" in appstore', [$app])); |
|
180 | + $updater->listen('\OC\Updater', 'checkAppStoreApp', function($app) use ($eventSource, $l) { |
|
181 | + $eventSource->send('success', (string) $l->t('Checked for update of app "%s" in appstore', [$app])); |
|
182 | 182 | }); |
183 | - $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($eventSource, $l) { |
|
184 | - $eventSource->send('success', (string)$l->t('Checking whether the database schema for %s can be updated (this can take a long time depending on the database size)', [$app])); |
|
183 | + $updater->listen('\OC\Updater', 'appSimulateUpdate', function($app) use ($eventSource, $l) { |
|
184 | + $eventSource->send('success', (string) $l->t('Checking whether the database schema for %s can be updated (this can take a long time depending on the database size)', [$app])); |
|
185 | 185 | }); |
186 | - $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($eventSource, $l) { |
|
187 | - $eventSource->send('success', (string)$l->t('Checked database schema update for apps')); |
|
186 | + $updater->listen('\OC\Updater', 'appUpgradeCheck', function() use ($eventSource, $l) { |
|
187 | + $eventSource->send('success', (string) $l->t('Checked database schema update for apps')); |
|
188 | 188 | }); |
189 | - $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($eventSource, $l) { |
|
190 | - $eventSource->send('success', (string)$l->t('Updated "%1$s" to %2$s', [$app, $version])); |
|
189 | + $updater->listen('\OC\Updater', 'appUpgrade', function($app, $version) use ($eventSource, $l) { |
|
190 | + $eventSource->send('success', (string) $l->t('Updated "%1$s" to %2$s', [$app, $version])); |
|
191 | 191 | }); |
192 | - $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use (&$incompatibleApps) { |
|
193 | - $incompatibleApps[]= $app; |
|
192 | + $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function($app) use (&$incompatibleApps) { |
|
193 | + $incompatibleApps[] = $app; |
|
194 | 194 | }); |
195 | - $updater->listen('\OC\Updater', 'failure', function ($message) use ($eventSource, $config) { |
|
195 | + $updater->listen('\OC\Updater', 'failure', function($message) use ($eventSource, $config) { |
|
196 | 196 | $eventSource->send('failure', $message); |
197 | 197 | $eventSource->close(); |
198 | 198 | $config->setSystemValue('maintenance', false); |
199 | 199 | }); |
200 | - $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l) { |
|
201 | - $eventSource->send('success', (string)$l->t('Set log level to debug')); |
|
200 | + $updater->listen('\OC\Updater', 'setDebugLogLevel', function($logLevel, $logLevelName) use ($eventSource, $l) { |
|
201 | + $eventSource->send('success', (string) $l->t('Set log level to debug')); |
|
202 | 202 | }); |
203 | - $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($eventSource, $l) { |
|
204 | - $eventSource->send('success', (string)$l->t('Reset log level')); |
|
203 | + $updater->listen('\OC\Updater', 'resetLogLevel', function($logLevel, $logLevelName) use ($eventSource, $l) { |
|
204 | + $eventSource->send('success', (string) $l->t('Reset log level')); |
|
205 | 205 | }); |
206 | - $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($eventSource, $l) { |
|
207 | - $eventSource->send('success', (string)$l->t('Starting code integrity check')); |
|
206 | + $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function() use ($eventSource, $l) { |
|
207 | + $eventSource->send('success', (string) $l->t('Starting code integrity check')); |
|
208 | 208 | }); |
209 | - $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($eventSource, $l) { |
|
210 | - $eventSource->send('success', (string)$l->t('Finished code integrity check')); |
|
209 | + $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function() use ($eventSource, $l) { |
|
210 | + $eventSource->send('success', (string) $l->t('Finished code integrity check')); |
|
211 | 211 | }); |
212 | 212 | |
213 | 213 | try { |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | 'level' => ILogger::ERROR, |
218 | 218 | 'app' => 'update', |
219 | 219 | ]); |
220 | - $eventSource->send('failure', get_class($e) . ': ' . $e->getMessage()); |
|
220 | + $eventSource->send('failure', get_class($e).': '.$e->getMessage()); |
|
221 | 221 | $eventSource->close(); |
222 | 222 | exit(); |
223 | 223 | } |
@@ -229,10 +229,10 @@ discard block |
||
229 | 229 | |
230 | 230 | if (!empty($disabledApps)) { |
231 | 231 | $eventSource->send('notice', |
232 | - (string)$l->t('Following apps have been disabled: %s', [implode(', ', $disabledApps)])); |
|
232 | + (string) $l->t('Following apps have been disabled: %s', [implode(', ', $disabledApps)])); |
|
233 | 233 | } |
234 | 234 | } else { |
235 | - $eventSource->send('notice', (string)$l->t('Already up to date')); |
|
235 | + $eventSource->send('notice', (string) $l->t('Already up to date')); |
|
236 | 236 | } |
237 | 237 | |
238 | 238 | $eventSource->send('done', ''); |
@@ -69,348 +69,348 @@ |
||
69 | 69 | * @package OC\Core\Controller |
70 | 70 | */ |
71 | 71 | class LostController extends Controller { |
72 | - /** @var IURLGenerator */ |
|
73 | - protected $urlGenerator; |
|
74 | - /** @var IUserManager */ |
|
75 | - protected $userManager; |
|
76 | - /** @var Defaults */ |
|
77 | - protected $defaults; |
|
78 | - /** @var IL10N */ |
|
79 | - protected $l10n; |
|
80 | - /** @var string */ |
|
81 | - protected $from; |
|
82 | - /** @var IManager */ |
|
83 | - protected $encryptionManager; |
|
84 | - /** @var IConfig */ |
|
85 | - protected $config; |
|
86 | - /** @var ISecureRandom */ |
|
87 | - protected $secureRandom; |
|
88 | - /** @var IMailer */ |
|
89 | - protected $mailer; |
|
90 | - /** @var ITimeFactory */ |
|
91 | - protected $timeFactory; |
|
92 | - /** @var ICrypto */ |
|
93 | - protected $crypto; |
|
94 | - /** @var ILogger */ |
|
95 | - private $logger; |
|
96 | - /** @var Manager */ |
|
97 | - private $twoFactorManager; |
|
98 | - /** @var IInitialStateService */ |
|
99 | - private $initialStateService; |
|
100 | - |
|
101 | - /** |
|
102 | - * @param string $appName |
|
103 | - * @param IRequest $request |
|
104 | - * @param IURLGenerator $urlGenerator |
|
105 | - * @param IUserManager $userManager |
|
106 | - * @param Defaults $defaults |
|
107 | - * @param IL10N $l10n |
|
108 | - * @param IConfig $config |
|
109 | - * @param ISecureRandom $secureRandom |
|
110 | - * @param string $defaultMailAddress |
|
111 | - * @param IManager $encryptionManager |
|
112 | - * @param IMailer $mailer |
|
113 | - * @param ITimeFactory $timeFactory |
|
114 | - * @param ICrypto $crypto |
|
115 | - */ |
|
116 | - public function __construct($appName, |
|
117 | - IRequest $request, |
|
118 | - IURLGenerator $urlGenerator, |
|
119 | - IUserManager $userManager, |
|
120 | - Defaults $defaults, |
|
121 | - IL10N $l10n, |
|
122 | - IConfig $config, |
|
123 | - ISecureRandom $secureRandom, |
|
124 | - $defaultMailAddress, |
|
125 | - IManager $encryptionManager, |
|
126 | - IMailer $mailer, |
|
127 | - ITimeFactory $timeFactory, |
|
128 | - ICrypto $crypto, |
|
129 | - ILogger $logger, |
|
130 | - Manager $twoFactorManager, |
|
131 | - IInitialStateService $initialStateService) { |
|
132 | - parent::__construct($appName, $request); |
|
133 | - $this->urlGenerator = $urlGenerator; |
|
134 | - $this->userManager = $userManager; |
|
135 | - $this->defaults = $defaults; |
|
136 | - $this->l10n = $l10n; |
|
137 | - $this->secureRandom = $secureRandom; |
|
138 | - $this->from = $defaultMailAddress; |
|
139 | - $this->encryptionManager = $encryptionManager; |
|
140 | - $this->config = $config; |
|
141 | - $this->mailer = $mailer; |
|
142 | - $this->timeFactory = $timeFactory; |
|
143 | - $this->crypto = $crypto; |
|
144 | - $this->logger = $logger; |
|
145 | - $this->twoFactorManager = $twoFactorManager; |
|
146 | - $this->initialStateService = $initialStateService; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Someone wants to reset their password: |
|
151 | - * |
|
152 | - * @PublicPage |
|
153 | - * @NoCSRFRequired |
|
154 | - * |
|
155 | - * @param string $token |
|
156 | - * @param string $userId |
|
157 | - * @return TemplateResponse |
|
158 | - */ |
|
159 | - public function resetform($token, $userId) { |
|
160 | - if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
161 | - return new TemplateResponse('core', 'error', [ |
|
162 | - 'errors' => [['error' => $this->l10n->t('Password reset is disabled')]] |
|
163 | - ], |
|
164 | - 'guest' |
|
165 | - ); |
|
166 | - } |
|
167 | - |
|
168 | - try { |
|
169 | - $this->checkPasswordResetToken($token, $userId); |
|
170 | - } catch (\Exception $e) { |
|
171 | - return new TemplateResponse( |
|
172 | - 'core', 'error', [ |
|
173 | - "errors" => [["error" => $e->getMessage()]] |
|
174 | - ], |
|
175 | - 'guest' |
|
176 | - ); |
|
177 | - } |
|
178 | - $this->initialStateService->provideInitialState('core', 'resetPasswordUser', $userId); |
|
179 | - $this->initialStateService->provideInitialState('core', 'resetPasswordTarget', |
|
180 | - $this->urlGenerator->linkToRouteAbsolute('core.lost.setPassword', ['userId' => $userId, 'token' => $token]) |
|
181 | - ); |
|
182 | - |
|
183 | - return new TemplateResponse( |
|
184 | - 'core', |
|
185 | - 'login', |
|
186 | - [], |
|
187 | - 'guest' |
|
188 | - ); |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * @param string $token |
|
193 | - * @param string $userId |
|
194 | - * @throws \Exception |
|
195 | - */ |
|
196 | - protected function checkPasswordResetToken($token, $userId) { |
|
197 | - $user = $this->userManager->get($userId); |
|
198 | - if($user === null || !$user->isEnabled()) { |
|
199 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
200 | - } |
|
201 | - |
|
202 | - $encryptedToken = $this->config->getUserValue($userId, 'core', 'lostpassword', null); |
|
203 | - if ($encryptedToken === null) { |
|
204 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
205 | - } |
|
206 | - |
|
207 | - try { |
|
208 | - $mailAddress = !is_null($user->getEMailAddress()) ? $user->getEMailAddress() : ''; |
|
209 | - $decryptedToken = $this->crypto->decrypt($encryptedToken, $mailAddress.$this->config->getSystemValue('secret')); |
|
210 | - } catch (\Exception $e) { |
|
211 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
212 | - } |
|
213 | - |
|
214 | - $splittedToken = explode(':', $decryptedToken); |
|
215 | - if(count($splittedToken) !== 2) { |
|
216 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
217 | - } |
|
218 | - |
|
219 | - if ($splittedToken[0] < ($this->timeFactory->getTime() - 60*60*24*7) || |
|
220 | - $user->getLastLogin() > $splittedToken[0]) { |
|
221 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is expired')); |
|
222 | - } |
|
223 | - |
|
224 | - if (!hash_equals($splittedToken[1], $token)) { |
|
225 | - throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
226 | - } |
|
227 | - } |
|
228 | - |
|
229 | - /** |
|
230 | - * @param $message |
|
231 | - * @param array $additional |
|
232 | - * @return array |
|
233 | - */ |
|
234 | - private function error($message, array $additional=[]) { |
|
235 | - return array_merge(['status' => 'error', 'msg' => $message], $additional); |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * @param array $data |
|
240 | - * @return array |
|
241 | - */ |
|
242 | - private function success($data = []) { |
|
243 | - return array_merge($data, ['status'=>'success']); |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * @PublicPage |
|
248 | - * @BruteForceProtection(action=passwordResetEmail) |
|
249 | - * @AnonRateThrottle(limit=10, period=300) |
|
250 | - * |
|
251 | - * @param string $user |
|
252 | - * @return JSONResponse |
|
253 | - */ |
|
254 | - public function email($user) { |
|
255 | - if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
256 | - return new JSONResponse($this->error($this->l10n->t('Password reset is disabled'))); |
|
257 | - } |
|
258 | - |
|
259 | - \OCP\Util::emitHook( |
|
260 | - '\OCA\Files_Sharing\API\Server2Server', |
|
261 | - 'preLoginNameUsedAsUserName', |
|
262 | - ['uid' => &$user] |
|
263 | - ); |
|
264 | - |
|
265 | - // FIXME: use HTTP error codes |
|
266 | - try { |
|
267 | - $this->sendEmail($user); |
|
268 | - } catch (ResetPasswordException $e) { |
|
269 | - // Ignore the error since we do not want to leak this info |
|
270 | - $this->logger->warning('Could not send password reset email: ' . $e->getMessage()); |
|
271 | - } catch (\Exception $e) { |
|
272 | - $this->logger->logException($e); |
|
273 | - } |
|
274 | - |
|
275 | - $response = new JSONResponse($this->success()); |
|
276 | - $response->throttle(); |
|
277 | - return $response; |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * @PublicPage |
|
282 | - * @param string $token |
|
283 | - * @param string $userId |
|
284 | - * @param string $password |
|
285 | - * @param boolean $proceed |
|
286 | - * @return array |
|
287 | - */ |
|
288 | - public function setPassword($token, $userId, $password, $proceed) { |
|
289 | - if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
290 | - return $this->error($this->l10n->t('Password reset is disabled')); |
|
291 | - } |
|
292 | - |
|
293 | - if ($this->encryptionManager->isEnabled() && !$proceed) { |
|
294 | - $encryptionModules = $this->encryptionManager->getEncryptionModules(); |
|
295 | - foreach ($encryptionModules as $module) { |
|
296 | - /** @var IEncryptionModule $instance */ |
|
297 | - $instance = call_user_func($module['callback']); |
|
298 | - // this way we can find out whether per-user keys are used or a system wide encryption key |
|
299 | - if ($instance->needDetailedAccessList()) { |
|
300 | - return $this->error('', ['encryption' => true]); |
|
301 | - } |
|
302 | - } |
|
303 | - } |
|
304 | - |
|
305 | - try { |
|
306 | - $this->checkPasswordResetToken($token, $userId); |
|
307 | - $user = $this->userManager->get($userId); |
|
308 | - |
|
309 | - \OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'pre_passwordReset', ['uid' => $userId, 'password' => $password]); |
|
310 | - |
|
311 | - if (!$user->setPassword($password)) { |
|
312 | - throw new \Exception(); |
|
313 | - } |
|
314 | - |
|
315 | - \OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'post_passwordReset', ['uid' => $userId, 'password' => $password]); |
|
316 | - |
|
317 | - $this->twoFactorManager->clearTwoFactorPending($userId); |
|
318 | - |
|
319 | - $this->config->deleteUserValue($userId, 'core', 'lostpassword'); |
|
320 | - @\OC::$server->getUserSession()->unsetMagicInCookie(); |
|
321 | - } catch (HintException $e){ |
|
322 | - return $this->error($e->getHint()); |
|
323 | - } catch (\Exception $e){ |
|
324 | - return $this->error($e->getMessage()); |
|
325 | - } |
|
326 | - |
|
327 | - return $this->success(['user' => $userId]); |
|
328 | - } |
|
329 | - |
|
330 | - /** |
|
331 | - * @param string $input |
|
332 | - * @throws ResetPasswordException |
|
333 | - * @throws \OCP\PreConditionNotMetException |
|
334 | - */ |
|
335 | - protected function sendEmail($input) { |
|
336 | - $user = $this->findUserByIdOrMail($input); |
|
337 | - $email = $user->getEMailAddress(); |
|
338 | - |
|
339 | - if (empty($email)) { |
|
340 | - throw new ResetPasswordException('Could not send reset e-mail since there is no email for username ' . $input); |
|
341 | - } |
|
342 | - |
|
343 | - // Generate the token. It is stored encrypted in the database with the |
|
344 | - // secret being the users' email address appended with the system secret. |
|
345 | - // This makes the token automatically invalidate once the user changes |
|
346 | - // their email address. |
|
347 | - $token = $this->secureRandom->generate( |
|
348 | - 21, |
|
349 | - ISecureRandom::CHAR_DIGITS. |
|
350 | - ISecureRandom::CHAR_LOWER. |
|
351 | - ISecureRandom::CHAR_UPPER |
|
352 | - ); |
|
353 | - $tokenValue = $this->timeFactory->getTime() .':'. $token; |
|
354 | - $encryptedValue = $this->crypto->encrypt($tokenValue, $email . $this->config->getSystemValue('secret')); |
|
355 | - $this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue); |
|
356 | - |
|
357 | - $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', ['userId' => $user->getUID(), 'token' => $token]); |
|
358 | - |
|
359 | - $emailTemplate = $this->mailer->createEMailTemplate('core.ResetPassword', [ |
|
360 | - 'link' => $link, |
|
361 | - ]); |
|
362 | - |
|
363 | - $emailTemplate->setSubject($this->l10n->t('%s password reset', [$this->defaults->getName()])); |
|
364 | - $emailTemplate->addHeader(); |
|
365 | - $emailTemplate->addHeading($this->l10n->t('Password reset')); |
|
366 | - |
|
367 | - $emailTemplate->addBodyText( |
|
368 | - htmlspecialchars($this->l10n->t('Click the following button to reset your password. If you have not requested the password reset, then ignore this email.')), |
|
369 | - $this->l10n->t('Click the following link to reset your password. If you have not requested the password reset, then ignore this email.') |
|
370 | - ); |
|
371 | - |
|
372 | - $emailTemplate->addBodyButton( |
|
373 | - htmlspecialchars($this->l10n->t('Reset your password')), |
|
374 | - $link, |
|
375 | - false |
|
376 | - ); |
|
377 | - $emailTemplate->addFooter(); |
|
378 | - |
|
379 | - try { |
|
380 | - $message = $this->mailer->createMessage(); |
|
381 | - $message->setTo([$email => $user->getUID()]); |
|
382 | - $message->setFrom([$this->from => $this->defaults->getName()]); |
|
383 | - $message->useTemplate($emailTemplate); |
|
384 | - $this->mailer->send($message); |
|
385 | - } catch (\Exception $e) { |
|
386 | - // Log the exception and continue |
|
387 | - $this->logger->logException($e); |
|
388 | - } |
|
389 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * @param string $input |
|
393 | - * @return IUser |
|
394 | - * @throws ResetPasswordException |
|
395 | - */ |
|
396 | - protected function findUserByIdOrMail($input) { |
|
397 | - $user = $this->userManager->get($input); |
|
398 | - if ($user instanceof IUser) { |
|
399 | - if (!$user->isEnabled()) { |
|
400 | - throw new ResetPasswordException('User is disabled'); |
|
401 | - } |
|
402 | - |
|
403 | - return $user; |
|
404 | - } |
|
405 | - |
|
406 | - $users = array_filter($this->userManager->getByEmail($input), function (IUser $user) { |
|
407 | - return $user->isEnabled(); |
|
408 | - }); |
|
409 | - |
|
410 | - if (count($users) === 1) { |
|
411 | - return reset($users); |
|
412 | - } |
|
413 | - |
|
414 | - throw new ResetPasswordException('Could not find user'); |
|
415 | - } |
|
72 | + /** @var IURLGenerator */ |
|
73 | + protected $urlGenerator; |
|
74 | + /** @var IUserManager */ |
|
75 | + protected $userManager; |
|
76 | + /** @var Defaults */ |
|
77 | + protected $defaults; |
|
78 | + /** @var IL10N */ |
|
79 | + protected $l10n; |
|
80 | + /** @var string */ |
|
81 | + protected $from; |
|
82 | + /** @var IManager */ |
|
83 | + protected $encryptionManager; |
|
84 | + /** @var IConfig */ |
|
85 | + protected $config; |
|
86 | + /** @var ISecureRandom */ |
|
87 | + protected $secureRandom; |
|
88 | + /** @var IMailer */ |
|
89 | + protected $mailer; |
|
90 | + /** @var ITimeFactory */ |
|
91 | + protected $timeFactory; |
|
92 | + /** @var ICrypto */ |
|
93 | + protected $crypto; |
|
94 | + /** @var ILogger */ |
|
95 | + private $logger; |
|
96 | + /** @var Manager */ |
|
97 | + private $twoFactorManager; |
|
98 | + /** @var IInitialStateService */ |
|
99 | + private $initialStateService; |
|
100 | + |
|
101 | + /** |
|
102 | + * @param string $appName |
|
103 | + * @param IRequest $request |
|
104 | + * @param IURLGenerator $urlGenerator |
|
105 | + * @param IUserManager $userManager |
|
106 | + * @param Defaults $defaults |
|
107 | + * @param IL10N $l10n |
|
108 | + * @param IConfig $config |
|
109 | + * @param ISecureRandom $secureRandom |
|
110 | + * @param string $defaultMailAddress |
|
111 | + * @param IManager $encryptionManager |
|
112 | + * @param IMailer $mailer |
|
113 | + * @param ITimeFactory $timeFactory |
|
114 | + * @param ICrypto $crypto |
|
115 | + */ |
|
116 | + public function __construct($appName, |
|
117 | + IRequest $request, |
|
118 | + IURLGenerator $urlGenerator, |
|
119 | + IUserManager $userManager, |
|
120 | + Defaults $defaults, |
|
121 | + IL10N $l10n, |
|
122 | + IConfig $config, |
|
123 | + ISecureRandom $secureRandom, |
|
124 | + $defaultMailAddress, |
|
125 | + IManager $encryptionManager, |
|
126 | + IMailer $mailer, |
|
127 | + ITimeFactory $timeFactory, |
|
128 | + ICrypto $crypto, |
|
129 | + ILogger $logger, |
|
130 | + Manager $twoFactorManager, |
|
131 | + IInitialStateService $initialStateService) { |
|
132 | + parent::__construct($appName, $request); |
|
133 | + $this->urlGenerator = $urlGenerator; |
|
134 | + $this->userManager = $userManager; |
|
135 | + $this->defaults = $defaults; |
|
136 | + $this->l10n = $l10n; |
|
137 | + $this->secureRandom = $secureRandom; |
|
138 | + $this->from = $defaultMailAddress; |
|
139 | + $this->encryptionManager = $encryptionManager; |
|
140 | + $this->config = $config; |
|
141 | + $this->mailer = $mailer; |
|
142 | + $this->timeFactory = $timeFactory; |
|
143 | + $this->crypto = $crypto; |
|
144 | + $this->logger = $logger; |
|
145 | + $this->twoFactorManager = $twoFactorManager; |
|
146 | + $this->initialStateService = $initialStateService; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Someone wants to reset their password: |
|
151 | + * |
|
152 | + * @PublicPage |
|
153 | + * @NoCSRFRequired |
|
154 | + * |
|
155 | + * @param string $token |
|
156 | + * @param string $userId |
|
157 | + * @return TemplateResponse |
|
158 | + */ |
|
159 | + public function resetform($token, $userId) { |
|
160 | + if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
161 | + return new TemplateResponse('core', 'error', [ |
|
162 | + 'errors' => [['error' => $this->l10n->t('Password reset is disabled')]] |
|
163 | + ], |
|
164 | + 'guest' |
|
165 | + ); |
|
166 | + } |
|
167 | + |
|
168 | + try { |
|
169 | + $this->checkPasswordResetToken($token, $userId); |
|
170 | + } catch (\Exception $e) { |
|
171 | + return new TemplateResponse( |
|
172 | + 'core', 'error', [ |
|
173 | + "errors" => [["error" => $e->getMessage()]] |
|
174 | + ], |
|
175 | + 'guest' |
|
176 | + ); |
|
177 | + } |
|
178 | + $this->initialStateService->provideInitialState('core', 'resetPasswordUser', $userId); |
|
179 | + $this->initialStateService->provideInitialState('core', 'resetPasswordTarget', |
|
180 | + $this->urlGenerator->linkToRouteAbsolute('core.lost.setPassword', ['userId' => $userId, 'token' => $token]) |
|
181 | + ); |
|
182 | + |
|
183 | + return new TemplateResponse( |
|
184 | + 'core', |
|
185 | + 'login', |
|
186 | + [], |
|
187 | + 'guest' |
|
188 | + ); |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * @param string $token |
|
193 | + * @param string $userId |
|
194 | + * @throws \Exception |
|
195 | + */ |
|
196 | + protected function checkPasswordResetToken($token, $userId) { |
|
197 | + $user = $this->userManager->get($userId); |
|
198 | + if($user === null || !$user->isEnabled()) { |
|
199 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
200 | + } |
|
201 | + |
|
202 | + $encryptedToken = $this->config->getUserValue($userId, 'core', 'lostpassword', null); |
|
203 | + if ($encryptedToken === null) { |
|
204 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
205 | + } |
|
206 | + |
|
207 | + try { |
|
208 | + $mailAddress = !is_null($user->getEMailAddress()) ? $user->getEMailAddress() : ''; |
|
209 | + $decryptedToken = $this->crypto->decrypt($encryptedToken, $mailAddress.$this->config->getSystemValue('secret')); |
|
210 | + } catch (\Exception $e) { |
|
211 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
212 | + } |
|
213 | + |
|
214 | + $splittedToken = explode(':', $decryptedToken); |
|
215 | + if(count($splittedToken) !== 2) { |
|
216 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
217 | + } |
|
218 | + |
|
219 | + if ($splittedToken[0] < ($this->timeFactory->getTime() - 60*60*24*7) || |
|
220 | + $user->getLastLogin() > $splittedToken[0]) { |
|
221 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is expired')); |
|
222 | + } |
|
223 | + |
|
224 | + if (!hash_equals($splittedToken[1], $token)) { |
|
225 | + throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
|
226 | + } |
|
227 | + } |
|
228 | + |
|
229 | + /** |
|
230 | + * @param $message |
|
231 | + * @param array $additional |
|
232 | + * @return array |
|
233 | + */ |
|
234 | + private function error($message, array $additional=[]) { |
|
235 | + return array_merge(['status' => 'error', 'msg' => $message], $additional); |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * @param array $data |
|
240 | + * @return array |
|
241 | + */ |
|
242 | + private function success($data = []) { |
|
243 | + return array_merge($data, ['status'=>'success']); |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * @PublicPage |
|
248 | + * @BruteForceProtection(action=passwordResetEmail) |
|
249 | + * @AnonRateThrottle(limit=10, period=300) |
|
250 | + * |
|
251 | + * @param string $user |
|
252 | + * @return JSONResponse |
|
253 | + */ |
|
254 | + public function email($user) { |
|
255 | + if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
256 | + return new JSONResponse($this->error($this->l10n->t('Password reset is disabled'))); |
|
257 | + } |
|
258 | + |
|
259 | + \OCP\Util::emitHook( |
|
260 | + '\OCA\Files_Sharing\API\Server2Server', |
|
261 | + 'preLoginNameUsedAsUserName', |
|
262 | + ['uid' => &$user] |
|
263 | + ); |
|
264 | + |
|
265 | + // FIXME: use HTTP error codes |
|
266 | + try { |
|
267 | + $this->sendEmail($user); |
|
268 | + } catch (ResetPasswordException $e) { |
|
269 | + // Ignore the error since we do not want to leak this info |
|
270 | + $this->logger->warning('Could not send password reset email: ' . $e->getMessage()); |
|
271 | + } catch (\Exception $e) { |
|
272 | + $this->logger->logException($e); |
|
273 | + } |
|
274 | + |
|
275 | + $response = new JSONResponse($this->success()); |
|
276 | + $response->throttle(); |
|
277 | + return $response; |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * @PublicPage |
|
282 | + * @param string $token |
|
283 | + * @param string $userId |
|
284 | + * @param string $password |
|
285 | + * @param boolean $proceed |
|
286 | + * @return array |
|
287 | + */ |
|
288 | + public function setPassword($token, $userId, $password, $proceed) { |
|
289 | + if ($this->config->getSystemValue('lost_password_link', '') !== '') { |
|
290 | + return $this->error($this->l10n->t('Password reset is disabled')); |
|
291 | + } |
|
292 | + |
|
293 | + if ($this->encryptionManager->isEnabled() && !$proceed) { |
|
294 | + $encryptionModules = $this->encryptionManager->getEncryptionModules(); |
|
295 | + foreach ($encryptionModules as $module) { |
|
296 | + /** @var IEncryptionModule $instance */ |
|
297 | + $instance = call_user_func($module['callback']); |
|
298 | + // this way we can find out whether per-user keys are used or a system wide encryption key |
|
299 | + if ($instance->needDetailedAccessList()) { |
|
300 | + return $this->error('', ['encryption' => true]); |
|
301 | + } |
|
302 | + } |
|
303 | + } |
|
304 | + |
|
305 | + try { |
|
306 | + $this->checkPasswordResetToken($token, $userId); |
|
307 | + $user = $this->userManager->get($userId); |
|
308 | + |
|
309 | + \OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'pre_passwordReset', ['uid' => $userId, 'password' => $password]); |
|
310 | + |
|
311 | + if (!$user->setPassword($password)) { |
|
312 | + throw new \Exception(); |
|
313 | + } |
|
314 | + |
|
315 | + \OC_Hook::emit('\OC\Core\LostPassword\Controller\LostController', 'post_passwordReset', ['uid' => $userId, 'password' => $password]); |
|
316 | + |
|
317 | + $this->twoFactorManager->clearTwoFactorPending($userId); |
|
318 | + |
|
319 | + $this->config->deleteUserValue($userId, 'core', 'lostpassword'); |
|
320 | + @\OC::$server->getUserSession()->unsetMagicInCookie(); |
|
321 | + } catch (HintException $e){ |
|
322 | + return $this->error($e->getHint()); |
|
323 | + } catch (\Exception $e){ |
|
324 | + return $this->error($e->getMessage()); |
|
325 | + } |
|
326 | + |
|
327 | + return $this->success(['user' => $userId]); |
|
328 | + } |
|
329 | + |
|
330 | + /** |
|
331 | + * @param string $input |
|
332 | + * @throws ResetPasswordException |
|
333 | + * @throws \OCP\PreConditionNotMetException |
|
334 | + */ |
|
335 | + protected function sendEmail($input) { |
|
336 | + $user = $this->findUserByIdOrMail($input); |
|
337 | + $email = $user->getEMailAddress(); |
|
338 | + |
|
339 | + if (empty($email)) { |
|
340 | + throw new ResetPasswordException('Could not send reset e-mail since there is no email for username ' . $input); |
|
341 | + } |
|
342 | + |
|
343 | + // Generate the token. It is stored encrypted in the database with the |
|
344 | + // secret being the users' email address appended with the system secret. |
|
345 | + // This makes the token automatically invalidate once the user changes |
|
346 | + // their email address. |
|
347 | + $token = $this->secureRandom->generate( |
|
348 | + 21, |
|
349 | + ISecureRandom::CHAR_DIGITS. |
|
350 | + ISecureRandom::CHAR_LOWER. |
|
351 | + ISecureRandom::CHAR_UPPER |
|
352 | + ); |
|
353 | + $tokenValue = $this->timeFactory->getTime() .':'. $token; |
|
354 | + $encryptedValue = $this->crypto->encrypt($tokenValue, $email . $this->config->getSystemValue('secret')); |
|
355 | + $this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue); |
|
356 | + |
|
357 | + $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', ['userId' => $user->getUID(), 'token' => $token]); |
|
358 | + |
|
359 | + $emailTemplate = $this->mailer->createEMailTemplate('core.ResetPassword', [ |
|
360 | + 'link' => $link, |
|
361 | + ]); |
|
362 | + |
|
363 | + $emailTemplate->setSubject($this->l10n->t('%s password reset', [$this->defaults->getName()])); |
|
364 | + $emailTemplate->addHeader(); |
|
365 | + $emailTemplate->addHeading($this->l10n->t('Password reset')); |
|
366 | + |
|
367 | + $emailTemplate->addBodyText( |
|
368 | + htmlspecialchars($this->l10n->t('Click the following button to reset your password. If you have not requested the password reset, then ignore this email.')), |
|
369 | + $this->l10n->t('Click the following link to reset your password. If you have not requested the password reset, then ignore this email.') |
|
370 | + ); |
|
371 | + |
|
372 | + $emailTemplate->addBodyButton( |
|
373 | + htmlspecialchars($this->l10n->t('Reset your password')), |
|
374 | + $link, |
|
375 | + false |
|
376 | + ); |
|
377 | + $emailTemplate->addFooter(); |
|
378 | + |
|
379 | + try { |
|
380 | + $message = $this->mailer->createMessage(); |
|
381 | + $message->setTo([$email => $user->getUID()]); |
|
382 | + $message->setFrom([$this->from => $this->defaults->getName()]); |
|
383 | + $message->useTemplate($emailTemplate); |
|
384 | + $this->mailer->send($message); |
|
385 | + } catch (\Exception $e) { |
|
386 | + // Log the exception and continue |
|
387 | + $this->logger->logException($e); |
|
388 | + } |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * @param string $input |
|
393 | + * @return IUser |
|
394 | + * @throws ResetPasswordException |
|
395 | + */ |
|
396 | + protected function findUserByIdOrMail($input) { |
|
397 | + $user = $this->userManager->get($input); |
|
398 | + if ($user instanceof IUser) { |
|
399 | + if (!$user->isEnabled()) { |
|
400 | + throw new ResetPasswordException('User is disabled'); |
|
401 | + } |
|
402 | + |
|
403 | + return $user; |
|
404 | + } |
|
405 | + |
|
406 | + $users = array_filter($this->userManager->getByEmail($input), function (IUser $user) { |
|
407 | + return $user->isEnabled(); |
|
408 | + }); |
|
409 | + |
|
410 | + if (count($users) === 1) { |
|
411 | + return reset($users); |
|
412 | + } |
|
413 | + |
|
414 | + throw new ResetPasswordException('Could not find user'); |
|
415 | + } |
|
416 | 416 | } |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | */ |
196 | 196 | protected function checkPasswordResetToken($token, $userId) { |
197 | 197 | $user = $this->userManager->get($userId); |
198 | - if($user === null || !$user->isEnabled()) { |
|
198 | + if ($user === null || !$user->isEnabled()) { |
|
199 | 199 | throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
200 | 200 | } |
201 | 201 | |
@@ -212,11 +212,11 @@ discard block |
||
212 | 212 | } |
213 | 213 | |
214 | 214 | $splittedToken = explode(':', $decryptedToken); |
215 | - if(count($splittedToken) !== 2) { |
|
215 | + if (count($splittedToken) !== 2) { |
|
216 | 216 | throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is invalid')); |
217 | 217 | } |
218 | 218 | |
219 | - if ($splittedToken[0] < ($this->timeFactory->getTime() - 60*60*24*7) || |
|
219 | + if ($splittedToken[0] < ($this->timeFactory->getTime() - 60 * 60 * 24 * 7) || |
|
220 | 220 | $user->getLastLogin() > $splittedToken[0]) { |
221 | 221 | throw new \Exception($this->l10n->t('Couldn\'t reset password because the token is expired')); |
222 | 222 | } |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | * @param array $additional |
232 | 232 | * @return array |
233 | 233 | */ |
234 | - private function error($message, array $additional=[]) { |
|
234 | + private function error($message, array $additional = []) { |
|
235 | 235 | return array_merge(['status' => 'error', 'msg' => $message], $additional); |
236 | 236 | } |
237 | 237 | |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | $this->sendEmail($user); |
268 | 268 | } catch (ResetPasswordException $e) { |
269 | 269 | // Ignore the error since we do not want to leak this info |
270 | - $this->logger->warning('Could not send password reset email: ' . $e->getMessage()); |
|
270 | + $this->logger->warning('Could not send password reset email: '.$e->getMessage()); |
|
271 | 271 | } catch (\Exception $e) { |
272 | 272 | $this->logger->logException($e); |
273 | 273 | } |
@@ -318,9 +318,9 @@ discard block |
||
318 | 318 | |
319 | 319 | $this->config->deleteUserValue($userId, 'core', 'lostpassword'); |
320 | 320 | @\OC::$server->getUserSession()->unsetMagicInCookie(); |
321 | - } catch (HintException $e){ |
|
321 | + } catch (HintException $e) { |
|
322 | 322 | return $this->error($e->getHint()); |
323 | - } catch (\Exception $e){ |
|
323 | + } catch (\Exception $e) { |
|
324 | 324 | return $this->error($e->getMessage()); |
325 | 325 | } |
326 | 326 | |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | $email = $user->getEMailAddress(); |
338 | 338 | |
339 | 339 | if (empty($email)) { |
340 | - throw new ResetPasswordException('Could not send reset e-mail since there is no email for username ' . $input); |
|
340 | + throw new ResetPasswordException('Could not send reset e-mail since there is no email for username '.$input); |
|
341 | 341 | } |
342 | 342 | |
343 | 343 | // Generate the token. It is stored encrypted in the database with the |
@@ -350,8 +350,8 @@ discard block |
||
350 | 350 | ISecureRandom::CHAR_LOWER. |
351 | 351 | ISecureRandom::CHAR_UPPER |
352 | 352 | ); |
353 | - $tokenValue = $this->timeFactory->getTime() .':'. $token; |
|
354 | - $encryptedValue = $this->crypto->encrypt($tokenValue, $email . $this->config->getSystemValue('secret')); |
|
353 | + $tokenValue = $this->timeFactory->getTime().':'.$token; |
|
354 | + $encryptedValue = $this->crypto->encrypt($tokenValue, $email.$this->config->getSystemValue('secret')); |
|
355 | 355 | $this->config->setUserValue($user->getUID(), 'core', 'lostpassword', $encryptedValue); |
356 | 356 | |
357 | 357 | $link = $this->urlGenerator->linkToRouteAbsolute('core.lost.resetform', ['userId' => $user->getUID(), 'token' => $token]); |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | return $user; |
404 | 404 | } |
405 | 405 | |
406 | - $users = array_filter($this->userManager->getByEmail($input), function (IUser $user) { |
|
406 | + $users = array_filter($this->userManager->getByEmail($input), function(IUser $user) { |
|
407 | 407 | return $user->isEnabled(); |
408 | 408 | }); |
409 | 409 |
@@ -41,143 +41,143 @@ |
||
41 | 41 | |
42 | 42 | class PreviewController extends Controller { |
43 | 43 | |
44 | - /** @var string */ |
|
45 | - private $userId; |
|
46 | - |
|
47 | - /** @var IRootFolder */ |
|
48 | - private $root; |
|
49 | - |
|
50 | - /** @var IPreview */ |
|
51 | - private $preview; |
|
52 | - |
|
53 | - /** |
|
54 | - * PreviewController constructor. |
|
55 | - * |
|
56 | - * @param string $appName |
|
57 | - * @param IRequest $request |
|
58 | - * @param IPreview $preview |
|
59 | - * @param IRootFolder $root |
|
60 | - * @param string $userId |
|
61 | - * @param ITimeFactory $timeFactory |
|
62 | - */ |
|
63 | - public function __construct(string $appName, |
|
64 | - IRequest $request, |
|
65 | - IPreview $preview, |
|
66 | - IRootFolder $root, |
|
67 | - ?string $userId |
|
68 | - ) { |
|
69 | - parent::__construct($appName, $request); |
|
70 | - |
|
71 | - $this->preview = $preview; |
|
72 | - $this->root = $root; |
|
73 | - $this->userId = $userId; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * @NoAdminRequired |
|
78 | - * @NoCSRFRequired |
|
79 | - * |
|
80 | - * @param string $file |
|
81 | - * @param int $x |
|
82 | - * @param int $y |
|
83 | - * @param bool $a |
|
84 | - * @param bool $forceIcon |
|
85 | - * @param string $mode |
|
86 | - * @return DataResponse|FileDisplayResponse |
|
87 | - */ |
|
88 | - public function getPreview( |
|
89 | - string $file = '', |
|
90 | - int $x = 32, |
|
91 | - int $y = 32, |
|
92 | - bool $a = false, |
|
93 | - bool $forceIcon = true, |
|
94 | - string $mode = 'fill'): Http\Response { |
|
95 | - |
|
96 | - if ($file === '' || $x === 0 || $y === 0) { |
|
97 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
98 | - } |
|
99 | - |
|
100 | - try { |
|
101 | - $userFolder = $this->root->getUserFolder($this->userId); |
|
102 | - $node = $userFolder->get($file); |
|
103 | - } catch (NotFoundException $e) { |
|
104 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
105 | - } |
|
106 | - |
|
107 | - return $this->fetchPreview($node, $x, $y, $a, $forceIcon, $mode); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * @NoAdminRequired |
|
112 | - * @NoCSRFRequired |
|
113 | - * |
|
114 | - * @param int $fileId |
|
115 | - * @param int $x |
|
116 | - * @param int $y |
|
117 | - * @param bool $a |
|
118 | - * @param bool $forceIcon |
|
119 | - * @param string $mode |
|
120 | - * |
|
121 | - * @return DataResponse|FileDisplayResponse |
|
122 | - */ |
|
123 | - public function getPreviewByFileId( |
|
124 | - int $fileId = -1, |
|
125 | - int $x = 32, |
|
126 | - int $y = 32, |
|
127 | - bool $a = false, |
|
128 | - bool $forceIcon = true, |
|
129 | - string $mode = 'fill') { |
|
130 | - |
|
131 | - if ($fileId === -1 || $x === 0 || $y === 0) { |
|
132 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
133 | - } |
|
134 | - |
|
135 | - $userFolder = $this->root->getUserFolder($this->userId); |
|
136 | - $nodes = $userFolder->getById($fileId); |
|
137 | - |
|
138 | - if (\count($nodes) === 0) { |
|
139 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
140 | - } |
|
141 | - |
|
142 | - $node = array_pop($nodes); |
|
143 | - |
|
144 | - return $this->fetchPreview($node, $x, $y, $a, $forceIcon, $mode); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @param Node $node |
|
149 | - * @param int $x |
|
150 | - * @param int $y |
|
151 | - * @param bool $a |
|
152 | - * @param bool $forceIcon |
|
153 | - * @param string $mode |
|
154 | - * @return DataResponse|FileDisplayResponse |
|
155 | - */ |
|
156 | - private function fetchPreview( |
|
157 | - Node $node, |
|
158 | - int $x, |
|
159 | - int $y, |
|
160 | - bool $a = false, |
|
161 | - bool $forceIcon = true, |
|
162 | - string $mode) : Http\Response { |
|
163 | - |
|
164 | - if (!($node instanceof File) || (!$forceIcon && !$this->preview->isAvailable($node))) { |
|
165 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
166 | - } |
|
167 | - if (!$node->isReadable()) { |
|
168 | - return new DataResponse([], Http::STATUS_FORBIDDEN); |
|
169 | - } |
|
170 | - |
|
171 | - try { |
|
172 | - $f = $this->preview->getPreview($node, $x, $y, !$a, $mode); |
|
173 | - $response = new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]); |
|
174 | - $response->cacheFor(3600 * 24); |
|
175 | - return $response; |
|
176 | - } catch (NotFoundException $e) { |
|
177 | - return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
178 | - } catch (\InvalidArgumentException $e) { |
|
179 | - return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
180 | - } |
|
181 | - |
|
182 | - } |
|
44 | + /** @var string */ |
|
45 | + private $userId; |
|
46 | + |
|
47 | + /** @var IRootFolder */ |
|
48 | + private $root; |
|
49 | + |
|
50 | + /** @var IPreview */ |
|
51 | + private $preview; |
|
52 | + |
|
53 | + /** |
|
54 | + * PreviewController constructor. |
|
55 | + * |
|
56 | + * @param string $appName |
|
57 | + * @param IRequest $request |
|
58 | + * @param IPreview $preview |
|
59 | + * @param IRootFolder $root |
|
60 | + * @param string $userId |
|
61 | + * @param ITimeFactory $timeFactory |
|
62 | + */ |
|
63 | + public function __construct(string $appName, |
|
64 | + IRequest $request, |
|
65 | + IPreview $preview, |
|
66 | + IRootFolder $root, |
|
67 | + ?string $userId |
|
68 | + ) { |
|
69 | + parent::__construct($appName, $request); |
|
70 | + |
|
71 | + $this->preview = $preview; |
|
72 | + $this->root = $root; |
|
73 | + $this->userId = $userId; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * @NoAdminRequired |
|
78 | + * @NoCSRFRequired |
|
79 | + * |
|
80 | + * @param string $file |
|
81 | + * @param int $x |
|
82 | + * @param int $y |
|
83 | + * @param bool $a |
|
84 | + * @param bool $forceIcon |
|
85 | + * @param string $mode |
|
86 | + * @return DataResponse|FileDisplayResponse |
|
87 | + */ |
|
88 | + public function getPreview( |
|
89 | + string $file = '', |
|
90 | + int $x = 32, |
|
91 | + int $y = 32, |
|
92 | + bool $a = false, |
|
93 | + bool $forceIcon = true, |
|
94 | + string $mode = 'fill'): Http\Response { |
|
95 | + |
|
96 | + if ($file === '' || $x === 0 || $y === 0) { |
|
97 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
98 | + } |
|
99 | + |
|
100 | + try { |
|
101 | + $userFolder = $this->root->getUserFolder($this->userId); |
|
102 | + $node = $userFolder->get($file); |
|
103 | + } catch (NotFoundException $e) { |
|
104 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
105 | + } |
|
106 | + |
|
107 | + return $this->fetchPreview($node, $x, $y, $a, $forceIcon, $mode); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * @NoAdminRequired |
|
112 | + * @NoCSRFRequired |
|
113 | + * |
|
114 | + * @param int $fileId |
|
115 | + * @param int $x |
|
116 | + * @param int $y |
|
117 | + * @param bool $a |
|
118 | + * @param bool $forceIcon |
|
119 | + * @param string $mode |
|
120 | + * |
|
121 | + * @return DataResponse|FileDisplayResponse |
|
122 | + */ |
|
123 | + public function getPreviewByFileId( |
|
124 | + int $fileId = -1, |
|
125 | + int $x = 32, |
|
126 | + int $y = 32, |
|
127 | + bool $a = false, |
|
128 | + bool $forceIcon = true, |
|
129 | + string $mode = 'fill') { |
|
130 | + |
|
131 | + if ($fileId === -1 || $x === 0 || $y === 0) { |
|
132 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
133 | + } |
|
134 | + |
|
135 | + $userFolder = $this->root->getUserFolder($this->userId); |
|
136 | + $nodes = $userFolder->getById($fileId); |
|
137 | + |
|
138 | + if (\count($nodes) === 0) { |
|
139 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
140 | + } |
|
141 | + |
|
142 | + $node = array_pop($nodes); |
|
143 | + |
|
144 | + return $this->fetchPreview($node, $x, $y, $a, $forceIcon, $mode); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @param Node $node |
|
149 | + * @param int $x |
|
150 | + * @param int $y |
|
151 | + * @param bool $a |
|
152 | + * @param bool $forceIcon |
|
153 | + * @param string $mode |
|
154 | + * @return DataResponse|FileDisplayResponse |
|
155 | + */ |
|
156 | + private function fetchPreview( |
|
157 | + Node $node, |
|
158 | + int $x, |
|
159 | + int $y, |
|
160 | + bool $a = false, |
|
161 | + bool $forceIcon = true, |
|
162 | + string $mode) : Http\Response { |
|
163 | + |
|
164 | + if (!($node instanceof File) || (!$forceIcon && !$this->preview->isAvailable($node))) { |
|
165 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
166 | + } |
|
167 | + if (!$node->isReadable()) { |
|
168 | + return new DataResponse([], Http::STATUS_FORBIDDEN); |
|
169 | + } |
|
170 | + |
|
171 | + try { |
|
172 | + $f = $this->preview->getPreview($node, $x, $y, !$a, $mode); |
|
173 | + $response = new FileDisplayResponse($f, Http::STATUS_OK, ['Content-Type' => $f->getMimeType()]); |
|
174 | + $response->cacheFor(3600 * 24); |
|
175 | + return $response; |
|
176 | + } catch (NotFoundException $e) { |
|
177 | + return new DataResponse([], Http::STATUS_NOT_FOUND); |
|
178 | + } catch (\InvalidArgumentException $e) { |
|
179 | + return new DataResponse([], Http::STATUS_BAD_REQUEST); |
|
180 | + } |
|
181 | + |
|
182 | + } |
|
183 | 183 | } |
@@ -29,68 +29,68 @@ discard block |
||
29 | 29 | |
30 | 30 | class GenerateMimetypeFileBuilder |
31 | 31 | { |
32 | - /** |
|
33 | - * Generate mime type list file |
|
34 | - * @param $aliases |
|
35 | - * @return string |
|
36 | - */ |
|
37 | - public function generateFile(array $aliases): string { |
|
38 | - // Remove comments |
|
39 | - $keys = array_filter(array_keys($aliases), function ($k) { |
|
40 | - return $k[0] === '_'; |
|
41 | - }); |
|
42 | - foreach($keys as $key) { |
|
43 | - unset($aliases[$key]); |
|
44 | - } |
|
32 | + /** |
|
33 | + * Generate mime type list file |
|
34 | + * @param $aliases |
|
35 | + * @return string |
|
36 | + */ |
|
37 | + public function generateFile(array $aliases): string { |
|
38 | + // Remove comments |
|
39 | + $keys = array_filter(array_keys($aliases), function ($k) { |
|
40 | + return $k[0] === '_'; |
|
41 | + }); |
|
42 | + foreach($keys as $key) { |
|
43 | + unset($aliases[$key]); |
|
44 | + } |
|
45 | 45 | |
46 | - // Fetch all files |
|
47 | - $dir = new \DirectoryIterator(\OC::$SERVERROOT.'/core/img/filetypes'); |
|
46 | + // Fetch all files |
|
47 | + $dir = new \DirectoryIterator(\OC::$SERVERROOT.'/core/img/filetypes'); |
|
48 | 48 | |
49 | - $files = []; |
|
50 | - foreach($dir as $fileInfo) { |
|
51 | - if ($fileInfo->isFile()) { |
|
52 | - $file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename()); |
|
53 | - $files[] = $file; |
|
54 | - } |
|
55 | - } |
|
49 | + $files = []; |
|
50 | + foreach($dir as $fileInfo) { |
|
51 | + if ($fileInfo->isFile()) { |
|
52 | + $file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename()); |
|
53 | + $files[] = $file; |
|
54 | + } |
|
55 | + } |
|
56 | 56 | |
57 | - //Remove duplicates |
|
58 | - $files = array_values(array_unique($files)); |
|
59 | - sort($files); |
|
57 | + //Remove duplicates |
|
58 | + $files = array_values(array_unique($files)); |
|
59 | + sort($files); |
|
60 | 60 | |
61 | - // Fetch all themes! |
|
62 | - $themes = []; |
|
63 | - $dirs = new \DirectoryIterator(\OC::$SERVERROOT.'/themes/'); |
|
64 | - foreach($dirs as $dir) { |
|
65 | - //Valid theme dir |
|
66 | - if ($dir->isFile() || $dir->isDot()) { |
|
67 | - continue; |
|
68 | - } |
|
61 | + // Fetch all themes! |
|
62 | + $themes = []; |
|
63 | + $dirs = new \DirectoryIterator(\OC::$SERVERROOT.'/themes/'); |
|
64 | + foreach($dirs as $dir) { |
|
65 | + //Valid theme dir |
|
66 | + if ($dir->isFile() || $dir->isDot()) { |
|
67 | + continue; |
|
68 | + } |
|
69 | 69 | |
70 | - $theme = $dir->getFilename(); |
|
71 | - $themeDir = $dir->getPath() . '/' . $theme . '/core/img/filetypes/'; |
|
72 | - // Check if this theme has its own filetype icons |
|
73 | - if (!file_exists($themeDir)) { |
|
74 | - continue; |
|
75 | - } |
|
70 | + $theme = $dir->getFilename(); |
|
71 | + $themeDir = $dir->getPath() . '/' . $theme . '/core/img/filetypes/'; |
|
72 | + // Check if this theme has its own filetype icons |
|
73 | + if (!file_exists($themeDir)) { |
|
74 | + continue; |
|
75 | + } |
|
76 | 76 | |
77 | - $themes[$theme] = []; |
|
78 | - // Fetch all the theme icons! |
|
79 | - $themeIt = new \DirectoryIterator($themeDir); |
|
80 | - foreach ($themeIt as $fileInfo) { |
|
81 | - if ($fileInfo->isFile()) { |
|
82 | - $file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename()); |
|
83 | - $themes[$theme][] = $file; |
|
84 | - } |
|
85 | - } |
|
77 | + $themes[$theme] = []; |
|
78 | + // Fetch all the theme icons! |
|
79 | + $themeIt = new \DirectoryIterator($themeDir); |
|
80 | + foreach ($themeIt as $fileInfo) { |
|
81 | + if ($fileInfo->isFile()) { |
|
82 | + $file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename()); |
|
83 | + $themes[$theme][] = $file; |
|
84 | + } |
|
85 | + } |
|
86 | 86 | |
87 | - //Remove Duplicates |
|
88 | - $themes[$theme] = array_values(array_unique($themes[$theme])); |
|
89 | - sort($themes[$theme]); |
|
90 | - } |
|
87 | + //Remove Duplicates |
|
88 | + $themes[$theme] = array_values(array_unique($themes[$theme])); |
|
89 | + sort($themes[$theme]); |
|
90 | + } |
|
91 | 91 | |
92 | - //Generate the JS |
|
93 | - return '/** |
|
92 | + //Generate the JS |
|
93 | + return '/** |
|
94 | 94 | * This file is automatically generated |
95 | 95 | * DO NOT EDIT MANUALLY! |
96 | 96 | * |
@@ -104,6 +104,6 @@ discard block |
||
104 | 104 | themes: ' . json_encode($themes, JSON_PRETTY_PRINT) . ' |
105 | 105 | }; |
106 | 106 | '; |
107 | - } |
|
107 | + } |
|
108 | 108 | |
109 | 109 | } |
@@ -36,10 +36,10 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function generateFile(array $aliases): string { |
38 | 38 | // Remove comments |
39 | - $keys = array_filter(array_keys($aliases), function ($k) { |
|
39 | + $keys = array_filter(array_keys($aliases), function($k) { |
|
40 | 40 | return $k[0] === '_'; |
41 | 41 | }); |
42 | - foreach($keys as $key) { |
|
42 | + foreach ($keys as $key) { |
|
43 | 43 | unset($aliases[$key]); |
44 | 44 | } |
45 | 45 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | $dir = new \DirectoryIterator(\OC::$SERVERROOT.'/core/img/filetypes'); |
48 | 48 | |
49 | 49 | $files = []; |
50 | - foreach($dir as $fileInfo) { |
|
50 | + foreach ($dir as $fileInfo) { |
|
51 | 51 | if ($fileInfo->isFile()) { |
52 | 52 | $file = preg_replace('/.[^.]*$/', '', $fileInfo->getFilename()); |
53 | 53 | $files[] = $file; |
@@ -61,14 +61,14 @@ discard block |
||
61 | 61 | // Fetch all themes! |
62 | 62 | $themes = []; |
63 | 63 | $dirs = new \DirectoryIterator(\OC::$SERVERROOT.'/themes/'); |
64 | - foreach($dirs as $dir) { |
|
64 | + foreach ($dirs as $dir) { |
|
65 | 65 | //Valid theme dir |
66 | 66 | if ($dir->isFile() || $dir->isDot()) { |
67 | 67 | continue; |
68 | 68 | } |
69 | 69 | |
70 | 70 | $theme = $dir->getFilename(); |
71 | - $themeDir = $dir->getPath() . '/' . $theme . '/core/img/filetypes/'; |
|
71 | + $themeDir = $dir->getPath().'/'.$theme.'/core/img/filetypes/'; |
|
72 | 72 | // Check if this theme has its own filetype icons |
73 | 73 | if (!file_exists($themeDir)) { |
74 | 74 | continue; |
@@ -99,9 +99,9 @@ discard block |
||
99 | 99 | * To regenerate this file run ./occ maintenance:mimetype:update-js |
100 | 100 | */ |
101 | 101 | OC.MimeTypeList={ |
102 | - aliases: ' . json_encode($aliases, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) . ', |
|
103 | - files: ' . json_encode($files, JSON_PRETTY_PRINT) . ', |
|
104 | - themes: ' . json_encode($themes, JSON_PRETTY_PRINT) . ' |
|
102 | + aliases: ' . json_encode($aliases, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES).', |
|
103 | + files: ' . json_encode($files, JSON_PRETTY_PRINT).', |
|
104 | + themes: ' . json_encode($themes, JSON_PRETTY_PRINT).' |
|
105 | 105 | }; |
106 | 106 | '; |
107 | 107 | } |
@@ -44,167 +44,167 @@ |
||
44 | 44 | |
45 | 45 | class CheckCode extends Command implements CompletionAwareInterface { |
46 | 46 | |
47 | - protected $checkers = [ |
|
48 | - 'private' => PrivateCheck::class, |
|
49 | - 'deprecation' => DeprecationCheck::class, |
|
50 | - 'strong-comparison' => StrongComparisonCheck::class, |
|
51 | - ]; |
|
52 | - |
|
53 | - protected function configure() { |
|
54 | - $this |
|
55 | - ->setName('app:check-code') |
|
56 | - ->setDescription('check code to be compliant') |
|
57 | - ->addArgument( |
|
58 | - 'app-id', |
|
59 | - InputArgument::REQUIRED, |
|
60 | - 'check the specified app' |
|
61 | - ) |
|
62 | - ->addOption( |
|
63 | - 'checker', |
|
64 | - 'c', |
|
65 | - InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
|
66 | - 'enable the specified checker(s)', |
|
67 | - [ 'private', 'deprecation', 'strong-comparison' ] |
|
68 | - ) |
|
69 | - ->addOption( |
|
70 | - '--skip-checkers', |
|
71 | - null, |
|
72 | - InputOption::VALUE_NONE, |
|
73 | - 'skips the the code checkers to only check info.xml, language and database schema' |
|
74 | - ) |
|
75 | - ->addOption( |
|
76 | - '--skip-validate-info', |
|
77 | - null, |
|
78 | - InputOption::VALUE_NONE, |
|
79 | - 'skips the info.xml/version check' |
|
80 | - ); |
|
81 | - } |
|
82 | - |
|
83 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
84 | - $appId = $input->getArgument('app-id'); |
|
85 | - |
|
86 | - $checkList = new EmptyCheck(); |
|
87 | - foreach ($input->getOption('checker') as $checker) { |
|
88 | - if (!isset($this->checkers[$checker])) { |
|
89 | - throw new \InvalidArgumentException('Invalid checker: '.$checker); |
|
90 | - } |
|
91 | - $checkerClass = $this->checkers[$checker]; |
|
92 | - $checkList = new $checkerClass($checkList); |
|
93 | - } |
|
94 | - |
|
95 | - $codeChecker = new CodeChecker($checkList, !$input->getOption('skip-validate-info')); |
|
96 | - |
|
97 | - $codeChecker->listen('CodeChecker', 'analyseFileBegin', function ($params) use ($output) { |
|
98 | - if(OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
99 | - $output->writeln("<info>Analysing {$params}</info>"); |
|
100 | - } |
|
101 | - }); |
|
102 | - $codeChecker->listen('CodeChecker', 'analyseFileFinished', function ($filename, $errors) use ($output) { |
|
103 | - $count = count($errors); |
|
104 | - |
|
105 | - // show filename if the verbosity is low, but there are errors in a file |
|
106 | - if($count > 0 && OutputInterface::VERBOSITY_VERBOSE > $output->getVerbosity()) { |
|
107 | - $output->writeln("<info>Analysing {$filename}</info>"); |
|
108 | - } |
|
109 | - |
|
110 | - // show error count if there are errors present or the verbosity is high |
|
111 | - if($count > 0 || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
112 | - $output->writeln(" {$count} errors"); |
|
113 | - } |
|
114 | - usort($errors, function ($a, $b) { |
|
115 | - return $a['line'] >$b['line']; |
|
116 | - }); |
|
117 | - |
|
118 | - foreach($errors as $p) { |
|
119 | - $line = sprintf("%' 4d", $p['line']); |
|
120 | - $output->writeln(" <error>line $line: {$p['disallowedToken']} - {$p['reason']}</error>"); |
|
121 | - } |
|
122 | - }); |
|
123 | - $errors = []; |
|
124 | - if(!$input->getOption('skip-checkers')) { |
|
125 | - $errors = $codeChecker->analyse($appId); |
|
126 | - } |
|
127 | - |
|
128 | - if(!$input->getOption('skip-validate-info')) { |
|
129 | - $infoChecker = new InfoChecker(); |
|
130 | - $infoChecker->listen('InfoChecker', 'parseError', function ($error) use ($output) { |
|
131 | - $output->writeln("<error>Invalid appinfo.xml file found: $error</error>"); |
|
132 | - }); |
|
133 | - |
|
134 | - $infoErrors = $infoChecker->analyse($appId); |
|
135 | - |
|
136 | - $errors = array_merge($errors, $infoErrors); |
|
137 | - |
|
138 | - $languageParser = new LanguageParseChecker(); |
|
139 | - $languageErrors = $languageParser->analyse($appId); |
|
140 | - |
|
141 | - foreach ($languageErrors as $languageError) { |
|
142 | - $output->writeln("<error>$languageError</error>"); |
|
143 | - } |
|
144 | - |
|
145 | - $errors = array_merge($errors, $languageErrors); |
|
146 | - |
|
147 | - $databaseSchema = new DatabaseSchemaChecker(); |
|
148 | - $schemaErrors = $databaseSchema->analyse($appId); |
|
149 | - |
|
150 | - foreach ($schemaErrors['errors'] as $schemaError) { |
|
151 | - $output->writeln("<error>$schemaError</error>"); |
|
152 | - } |
|
153 | - foreach ($schemaErrors['warnings'] as $schemaWarning) { |
|
154 | - $output->writeln("<comment>$schemaWarning</comment>"); |
|
155 | - } |
|
156 | - |
|
157 | - $errors = array_merge($errors, $schemaErrors['errors']); |
|
158 | - } |
|
159 | - |
|
160 | - $this->analyseUpdateFile($appId, $output); |
|
161 | - |
|
162 | - if (empty($errors)) { |
|
163 | - $output->writeln('<info>App is compliant - awesome job!</info>'); |
|
164 | - return 0; |
|
165 | - } else { |
|
166 | - $output->writeln('<error>App is not compliant</error>'); |
|
167 | - return 101; |
|
168 | - } |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * @param string $appId |
|
173 | - * @param $output |
|
174 | - */ |
|
175 | - private function analyseUpdateFile($appId, OutputInterface $output) { |
|
176 | - $appPath = \OC_App::getAppPath($appId); |
|
177 | - if ($appPath === false) { |
|
178 | - throw new \RuntimeException("No app with given id <$appId> known."); |
|
179 | - } |
|
180 | - |
|
181 | - $updatePhp = $appPath . '/appinfo/update.php'; |
|
182 | - if (file_exists($updatePhp)) { |
|
183 | - $output->writeln("<info>Deprecated file found: $updatePhp - please use repair steps</info>"); |
|
184 | - } |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * @param string $optionName |
|
189 | - * @param CompletionContext $context |
|
190 | - * @return string[] |
|
191 | - */ |
|
192 | - public function completeOptionValues($optionName, CompletionContext $context) { |
|
193 | - if ($optionName === 'checker') { |
|
194 | - return ['private', 'deprecation', 'strong-comparison']; |
|
195 | - } |
|
196 | - return []; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * @param string $argumentName |
|
201 | - * @param CompletionContext $context |
|
202 | - * @return string[] |
|
203 | - */ |
|
204 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
205 | - if ($argumentName === 'app-id') { |
|
206 | - return \OC_App::getAllApps(); |
|
207 | - } |
|
208 | - return []; |
|
209 | - } |
|
47 | + protected $checkers = [ |
|
48 | + 'private' => PrivateCheck::class, |
|
49 | + 'deprecation' => DeprecationCheck::class, |
|
50 | + 'strong-comparison' => StrongComparisonCheck::class, |
|
51 | + ]; |
|
52 | + |
|
53 | + protected function configure() { |
|
54 | + $this |
|
55 | + ->setName('app:check-code') |
|
56 | + ->setDescription('check code to be compliant') |
|
57 | + ->addArgument( |
|
58 | + 'app-id', |
|
59 | + InputArgument::REQUIRED, |
|
60 | + 'check the specified app' |
|
61 | + ) |
|
62 | + ->addOption( |
|
63 | + 'checker', |
|
64 | + 'c', |
|
65 | + InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
|
66 | + 'enable the specified checker(s)', |
|
67 | + [ 'private', 'deprecation', 'strong-comparison' ] |
|
68 | + ) |
|
69 | + ->addOption( |
|
70 | + '--skip-checkers', |
|
71 | + null, |
|
72 | + InputOption::VALUE_NONE, |
|
73 | + 'skips the the code checkers to only check info.xml, language and database schema' |
|
74 | + ) |
|
75 | + ->addOption( |
|
76 | + '--skip-validate-info', |
|
77 | + null, |
|
78 | + InputOption::VALUE_NONE, |
|
79 | + 'skips the info.xml/version check' |
|
80 | + ); |
|
81 | + } |
|
82 | + |
|
83 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
84 | + $appId = $input->getArgument('app-id'); |
|
85 | + |
|
86 | + $checkList = new EmptyCheck(); |
|
87 | + foreach ($input->getOption('checker') as $checker) { |
|
88 | + if (!isset($this->checkers[$checker])) { |
|
89 | + throw new \InvalidArgumentException('Invalid checker: '.$checker); |
|
90 | + } |
|
91 | + $checkerClass = $this->checkers[$checker]; |
|
92 | + $checkList = new $checkerClass($checkList); |
|
93 | + } |
|
94 | + |
|
95 | + $codeChecker = new CodeChecker($checkList, !$input->getOption('skip-validate-info')); |
|
96 | + |
|
97 | + $codeChecker->listen('CodeChecker', 'analyseFileBegin', function ($params) use ($output) { |
|
98 | + if(OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
99 | + $output->writeln("<info>Analysing {$params}</info>"); |
|
100 | + } |
|
101 | + }); |
|
102 | + $codeChecker->listen('CodeChecker', 'analyseFileFinished', function ($filename, $errors) use ($output) { |
|
103 | + $count = count($errors); |
|
104 | + |
|
105 | + // show filename if the verbosity is low, but there are errors in a file |
|
106 | + if($count > 0 && OutputInterface::VERBOSITY_VERBOSE > $output->getVerbosity()) { |
|
107 | + $output->writeln("<info>Analysing {$filename}</info>"); |
|
108 | + } |
|
109 | + |
|
110 | + // show error count if there are errors present or the verbosity is high |
|
111 | + if($count > 0 || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
112 | + $output->writeln(" {$count} errors"); |
|
113 | + } |
|
114 | + usort($errors, function ($a, $b) { |
|
115 | + return $a['line'] >$b['line']; |
|
116 | + }); |
|
117 | + |
|
118 | + foreach($errors as $p) { |
|
119 | + $line = sprintf("%' 4d", $p['line']); |
|
120 | + $output->writeln(" <error>line $line: {$p['disallowedToken']} - {$p['reason']}</error>"); |
|
121 | + } |
|
122 | + }); |
|
123 | + $errors = []; |
|
124 | + if(!$input->getOption('skip-checkers')) { |
|
125 | + $errors = $codeChecker->analyse($appId); |
|
126 | + } |
|
127 | + |
|
128 | + if(!$input->getOption('skip-validate-info')) { |
|
129 | + $infoChecker = new InfoChecker(); |
|
130 | + $infoChecker->listen('InfoChecker', 'parseError', function ($error) use ($output) { |
|
131 | + $output->writeln("<error>Invalid appinfo.xml file found: $error</error>"); |
|
132 | + }); |
|
133 | + |
|
134 | + $infoErrors = $infoChecker->analyse($appId); |
|
135 | + |
|
136 | + $errors = array_merge($errors, $infoErrors); |
|
137 | + |
|
138 | + $languageParser = new LanguageParseChecker(); |
|
139 | + $languageErrors = $languageParser->analyse($appId); |
|
140 | + |
|
141 | + foreach ($languageErrors as $languageError) { |
|
142 | + $output->writeln("<error>$languageError</error>"); |
|
143 | + } |
|
144 | + |
|
145 | + $errors = array_merge($errors, $languageErrors); |
|
146 | + |
|
147 | + $databaseSchema = new DatabaseSchemaChecker(); |
|
148 | + $schemaErrors = $databaseSchema->analyse($appId); |
|
149 | + |
|
150 | + foreach ($schemaErrors['errors'] as $schemaError) { |
|
151 | + $output->writeln("<error>$schemaError</error>"); |
|
152 | + } |
|
153 | + foreach ($schemaErrors['warnings'] as $schemaWarning) { |
|
154 | + $output->writeln("<comment>$schemaWarning</comment>"); |
|
155 | + } |
|
156 | + |
|
157 | + $errors = array_merge($errors, $schemaErrors['errors']); |
|
158 | + } |
|
159 | + |
|
160 | + $this->analyseUpdateFile($appId, $output); |
|
161 | + |
|
162 | + if (empty($errors)) { |
|
163 | + $output->writeln('<info>App is compliant - awesome job!</info>'); |
|
164 | + return 0; |
|
165 | + } else { |
|
166 | + $output->writeln('<error>App is not compliant</error>'); |
|
167 | + return 101; |
|
168 | + } |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * @param string $appId |
|
173 | + * @param $output |
|
174 | + */ |
|
175 | + private function analyseUpdateFile($appId, OutputInterface $output) { |
|
176 | + $appPath = \OC_App::getAppPath($appId); |
|
177 | + if ($appPath === false) { |
|
178 | + throw new \RuntimeException("No app with given id <$appId> known."); |
|
179 | + } |
|
180 | + |
|
181 | + $updatePhp = $appPath . '/appinfo/update.php'; |
|
182 | + if (file_exists($updatePhp)) { |
|
183 | + $output->writeln("<info>Deprecated file found: $updatePhp - please use repair steps</info>"); |
|
184 | + } |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * @param string $optionName |
|
189 | + * @param CompletionContext $context |
|
190 | + * @return string[] |
|
191 | + */ |
|
192 | + public function completeOptionValues($optionName, CompletionContext $context) { |
|
193 | + if ($optionName === 'checker') { |
|
194 | + return ['private', 'deprecation', 'strong-comparison']; |
|
195 | + } |
|
196 | + return []; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * @param string $argumentName |
|
201 | + * @param CompletionContext $context |
|
202 | + * @return string[] |
|
203 | + */ |
|
204 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
205 | + if ($argumentName === 'app-id') { |
|
206 | + return \OC_App::getAllApps(); |
|
207 | + } |
|
208 | + return []; |
|
209 | + } |
|
210 | 210 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | use Symfony\Component\Console\Input\InputOption; |
43 | 43 | use Symfony\Component\Console\Output\OutputInterface; |
44 | 44 | |
45 | -class CheckCode extends Command implements CompletionAwareInterface { |
|
45 | +class CheckCode extends Command implements CompletionAwareInterface { |
|
46 | 46 | |
47 | 47 | protected $checkers = [ |
48 | 48 | 'private' => PrivateCheck::class, |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | 'c', |
65 | 65 | InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
66 | 66 | 'enable the specified checker(s)', |
67 | - [ 'private', 'deprecation', 'strong-comparison' ] |
|
67 | + ['private', 'deprecation', 'strong-comparison'] |
|
68 | 68 | ) |
69 | 69 | ->addOption( |
70 | 70 | '--skip-checkers', |
@@ -94,40 +94,40 @@ discard block |
||
94 | 94 | |
95 | 95 | $codeChecker = new CodeChecker($checkList, !$input->getOption('skip-validate-info')); |
96 | 96 | |
97 | - $codeChecker->listen('CodeChecker', 'analyseFileBegin', function ($params) use ($output) { |
|
98 | - if(OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
97 | + $codeChecker->listen('CodeChecker', 'analyseFileBegin', function($params) use ($output) { |
|
98 | + if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
99 | 99 | $output->writeln("<info>Analysing {$params}</info>"); |
100 | 100 | } |
101 | 101 | }); |
102 | - $codeChecker->listen('CodeChecker', 'analyseFileFinished', function ($filename, $errors) use ($output) { |
|
102 | + $codeChecker->listen('CodeChecker', 'analyseFileFinished', function($filename, $errors) use ($output) { |
|
103 | 103 | $count = count($errors); |
104 | 104 | |
105 | 105 | // show filename if the verbosity is low, but there are errors in a file |
106 | - if($count > 0 && OutputInterface::VERBOSITY_VERBOSE > $output->getVerbosity()) { |
|
106 | + if ($count > 0 && OutputInterface::VERBOSITY_VERBOSE > $output->getVerbosity()) { |
|
107 | 107 | $output->writeln("<info>Analysing {$filename}</info>"); |
108 | 108 | } |
109 | 109 | |
110 | 110 | // show error count if there are errors present or the verbosity is high |
111 | - if($count > 0 || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
111 | + if ($count > 0 || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
|
112 | 112 | $output->writeln(" {$count} errors"); |
113 | 113 | } |
114 | - usort($errors, function ($a, $b) { |
|
115 | - return $a['line'] >$b['line']; |
|
114 | + usort($errors, function($a, $b) { |
|
115 | + return $a['line'] > $b['line']; |
|
116 | 116 | }); |
117 | 117 | |
118 | - foreach($errors as $p) { |
|
118 | + foreach ($errors as $p) { |
|
119 | 119 | $line = sprintf("%' 4d", $p['line']); |
120 | 120 | $output->writeln(" <error>line $line: {$p['disallowedToken']} - {$p['reason']}</error>"); |
121 | 121 | } |
122 | 122 | }); |
123 | 123 | $errors = []; |
124 | - if(!$input->getOption('skip-checkers')) { |
|
124 | + if (!$input->getOption('skip-checkers')) { |
|
125 | 125 | $errors = $codeChecker->analyse($appId); |
126 | 126 | } |
127 | 127 | |
128 | - if(!$input->getOption('skip-validate-info')) { |
|
128 | + if (!$input->getOption('skip-validate-info')) { |
|
129 | 129 | $infoChecker = new InfoChecker(); |
130 | - $infoChecker->listen('InfoChecker', 'parseError', function ($error) use ($output) { |
|
130 | + $infoChecker->listen('InfoChecker', 'parseError', function($error) use ($output) { |
|
131 | 131 | $output->writeln("<error>Invalid appinfo.xml file found: $error</error>"); |
132 | 132 | }); |
133 | 133 | |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | throw new \RuntimeException("No app with given id <$appId> known."); |
179 | 179 | } |
180 | 180 | |
181 | - $updatePhp = $appPath . '/appinfo/update.php'; |
|
181 | + $updatePhp = $appPath.'/appinfo/update.php'; |
|
182 | 182 | if (file_exists($updatePhp)) { |
183 | 183 | $output->writeln("<info>Deprecated file found: $updatePhp - please use repair steps</info>"); |
184 | 184 | } |
@@ -48,251 +48,251 @@ |
||
48 | 48 | |
49 | 49 | class Upgrade extends Command { |
50 | 50 | |
51 | - const ERROR_SUCCESS = 0; |
|
52 | - const ERROR_NOT_INSTALLED = 1; |
|
53 | - const ERROR_MAINTENANCE_MODE = 2; |
|
54 | - const ERROR_UP_TO_DATE = 0; |
|
55 | - const ERROR_INVALID_ARGUMENTS = 4; |
|
56 | - const ERROR_FAILURE = 5; |
|
51 | + const ERROR_SUCCESS = 0; |
|
52 | + const ERROR_NOT_INSTALLED = 1; |
|
53 | + const ERROR_MAINTENANCE_MODE = 2; |
|
54 | + const ERROR_UP_TO_DATE = 0; |
|
55 | + const ERROR_INVALID_ARGUMENTS = 4; |
|
56 | + const ERROR_FAILURE = 5; |
|
57 | 57 | |
58 | - /** @var IConfig */ |
|
59 | - private $config; |
|
58 | + /** @var IConfig */ |
|
59 | + private $config; |
|
60 | 60 | |
61 | - /** @var ILogger */ |
|
62 | - private $logger; |
|
61 | + /** @var ILogger */ |
|
62 | + private $logger; |
|
63 | 63 | |
64 | - /** |
|
65 | - * @param IConfig $config |
|
66 | - * @param ILogger $logger |
|
67 | - * @param Installer $installer |
|
68 | - */ |
|
69 | - public function __construct(IConfig $config, ILogger $logger, Installer $installer) { |
|
70 | - parent::__construct(); |
|
71 | - $this->config = $config; |
|
72 | - $this->logger = $logger; |
|
73 | - $this->installer = $installer; |
|
74 | - } |
|
64 | + /** |
|
65 | + * @param IConfig $config |
|
66 | + * @param ILogger $logger |
|
67 | + * @param Installer $installer |
|
68 | + */ |
|
69 | + public function __construct(IConfig $config, ILogger $logger, Installer $installer) { |
|
70 | + parent::__construct(); |
|
71 | + $this->config = $config; |
|
72 | + $this->logger = $logger; |
|
73 | + $this->installer = $installer; |
|
74 | + } |
|
75 | 75 | |
76 | - protected function configure() { |
|
77 | - $this |
|
78 | - ->setName('upgrade') |
|
79 | - ->setDescription('run upgrade routines after installation of a new release. The release has to be installed before.'); |
|
80 | - } |
|
76 | + protected function configure() { |
|
77 | + $this |
|
78 | + ->setName('upgrade') |
|
79 | + ->setDescription('run upgrade routines after installation of a new release. The release has to be installed before.'); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Execute the upgrade command |
|
84 | - * |
|
85 | - * @param InputInterface $input input interface |
|
86 | - * @param OutputInterface $output output interface |
|
87 | - */ |
|
88 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
82 | + /** |
|
83 | + * Execute the upgrade command |
|
84 | + * |
|
85 | + * @param InputInterface $input input interface |
|
86 | + * @param OutputInterface $output output interface |
|
87 | + */ |
|
88 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
89 | 89 | |
90 | - if(Util::needUpgrade()) { |
|
91 | - if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
92 | - // Prepend each line with a little timestamp |
|
93 | - $timestampFormatter = new TimestampFormatter($this->config, $output->getFormatter()); |
|
94 | - $output->setFormatter($timestampFormatter); |
|
95 | - } |
|
90 | + if(Util::needUpgrade()) { |
|
91 | + if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
92 | + // Prepend each line with a little timestamp |
|
93 | + $timestampFormatter = new TimestampFormatter($this->config, $output->getFormatter()); |
|
94 | + $output->setFormatter($timestampFormatter); |
|
95 | + } |
|
96 | 96 | |
97 | - $self = $this; |
|
98 | - $updater = new Updater( |
|
99 | - $this->config, |
|
100 | - \OC::$server->getIntegrityCodeChecker(), |
|
101 | - $this->logger, |
|
102 | - $this->installer |
|
103 | - ); |
|
97 | + $self = $this; |
|
98 | + $updater = new Updater( |
|
99 | + $this->config, |
|
100 | + \OC::$server->getIntegrityCodeChecker(), |
|
101 | + $this->logger, |
|
102 | + $this->installer |
|
103 | + ); |
|
104 | 104 | |
105 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
106 | - $progress = new ProgressBar($output); |
|
107 | - $progress->setFormat(" %message%\n %current%/%max% [%bar%] %percent:3s%%"); |
|
108 | - $listener = function ($event) use ($progress, $output) { |
|
109 | - if ($event instanceof GenericEvent) { |
|
110 | - $message = $event->getSubject(); |
|
111 | - if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
112 | - $output->writeln(' Checking table ' . $message); |
|
113 | - } else { |
|
114 | - if (strlen($message) > 60) { |
|
115 | - $message = substr($message, 0, 57) . '...'; |
|
116 | - } |
|
117 | - $progress->setMessage($message); |
|
118 | - if ($event[0] === 1) { |
|
119 | - $output->writeln(''); |
|
120 | - $progress->start($event[1]); |
|
121 | - } |
|
122 | - $progress->setProgress($event[0]); |
|
123 | - if ($event[0] === $event[1]) { |
|
124 | - $progress->setMessage('Done'); |
|
125 | - $progress->finish(); |
|
126 | - $output->writeln(''); |
|
127 | - } |
|
128 | - } |
|
129 | - } |
|
130 | - }; |
|
131 | - $repairListener = function ($event) use ($progress, $output) { |
|
132 | - if (!$event instanceof GenericEvent) { |
|
133 | - return; |
|
134 | - } |
|
135 | - switch ($event->getSubject()) { |
|
136 | - case '\OC\Repair::startProgress': |
|
137 | - $progress->setMessage('Starting ...'); |
|
138 | - $output->writeln($event->getArgument(1)); |
|
139 | - $output->writeln(''); |
|
140 | - $progress->start($event->getArgument(0)); |
|
141 | - break; |
|
142 | - case '\OC\Repair::advance': |
|
143 | - $desc = $event->getArgument(1); |
|
144 | - if (!empty($desc)) { |
|
145 | - $progress->setMessage($desc); |
|
146 | - } |
|
147 | - $progress->advance($event->getArgument(0)); |
|
105 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
106 | + $progress = new ProgressBar($output); |
|
107 | + $progress->setFormat(" %message%\n %current%/%max% [%bar%] %percent:3s%%"); |
|
108 | + $listener = function ($event) use ($progress, $output) { |
|
109 | + if ($event instanceof GenericEvent) { |
|
110 | + $message = $event->getSubject(); |
|
111 | + if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
112 | + $output->writeln(' Checking table ' . $message); |
|
113 | + } else { |
|
114 | + if (strlen($message) > 60) { |
|
115 | + $message = substr($message, 0, 57) . '...'; |
|
116 | + } |
|
117 | + $progress->setMessage($message); |
|
118 | + if ($event[0] === 1) { |
|
119 | + $output->writeln(''); |
|
120 | + $progress->start($event[1]); |
|
121 | + } |
|
122 | + $progress->setProgress($event[0]); |
|
123 | + if ($event[0] === $event[1]) { |
|
124 | + $progress->setMessage('Done'); |
|
125 | + $progress->finish(); |
|
126 | + $output->writeln(''); |
|
127 | + } |
|
128 | + } |
|
129 | + } |
|
130 | + }; |
|
131 | + $repairListener = function ($event) use ($progress, $output) { |
|
132 | + if (!$event instanceof GenericEvent) { |
|
133 | + return; |
|
134 | + } |
|
135 | + switch ($event->getSubject()) { |
|
136 | + case '\OC\Repair::startProgress': |
|
137 | + $progress->setMessage('Starting ...'); |
|
138 | + $output->writeln($event->getArgument(1)); |
|
139 | + $output->writeln(''); |
|
140 | + $progress->start($event->getArgument(0)); |
|
141 | + break; |
|
142 | + case '\OC\Repair::advance': |
|
143 | + $desc = $event->getArgument(1); |
|
144 | + if (!empty($desc)) { |
|
145 | + $progress->setMessage($desc); |
|
146 | + } |
|
147 | + $progress->advance($event->getArgument(0)); |
|
148 | 148 | |
149 | - break; |
|
150 | - case '\OC\Repair::finishProgress': |
|
151 | - $progress->setMessage('Done'); |
|
152 | - $progress->finish(); |
|
153 | - $output->writeln(''); |
|
154 | - break; |
|
155 | - case '\OC\Repair::step': |
|
156 | - if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
157 | - $output->writeln('<info>Repair step: ' . $event->getArgument(0) . '</info>'); |
|
158 | - } |
|
159 | - break; |
|
160 | - case '\OC\Repair::info': |
|
161 | - if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
162 | - $output->writeln('<info>Repair info: ' . $event->getArgument(0) . '</info>'); |
|
163 | - } |
|
164 | - break; |
|
165 | - case '\OC\Repair::warning': |
|
166 | - $output->writeln('<error>Repair warning: ' . $event->getArgument(0) . '</error>'); |
|
167 | - break; |
|
168 | - case '\OC\Repair::error': |
|
169 | - $output->writeln('<error>Repair error: ' . $event->getArgument(0) . '</error>'); |
|
170 | - break; |
|
171 | - } |
|
172 | - }; |
|
149 | + break; |
|
150 | + case '\OC\Repair::finishProgress': |
|
151 | + $progress->setMessage('Done'); |
|
152 | + $progress->finish(); |
|
153 | + $output->writeln(''); |
|
154 | + break; |
|
155 | + case '\OC\Repair::step': |
|
156 | + if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
157 | + $output->writeln('<info>Repair step: ' . $event->getArgument(0) . '</info>'); |
|
158 | + } |
|
159 | + break; |
|
160 | + case '\OC\Repair::info': |
|
161 | + if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
162 | + $output->writeln('<info>Repair info: ' . $event->getArgument(0) . '</info>'); |
|
163 | + } |
|
164 | + break; |
|
165 | + case '\OC\Repair::warning': |
|
166 | + $output->writeln('<error>Repair warning: ' . $event->getArgument(0) . '</error>'); |
|
167 | + break; |
|
168 | + case '\OC\Repair::error': |
|
169 | + $output->writeln('<error>Repair error: ' . $event->getArgument(0) . '</error>'); |
|
170 | + break; |
|
171 | + } |
|
172 | + }; |
|
173 | 173 | |
174 | - $dispatcher->addListener('\OC\DB\Migrator::executeSql', $listener); |
|
175 | - $dispatcher->addListener('\OC\DB\Migrator::checkTable', $listener); |
|
176 | - $dispatcher->addListener('\OC\Repair::startProgress', $repairListener); |
|
177 | - $dispatcher->addListener('\OC\Repair::advance', $repairListener); |
|
178 | - $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener); |
|
179 | - $dispatcher->addListener('\OC\Repair::step', $repairListener); |
|
180 | - $dispatcher->addListener('\OC\Repair::info', $repairListener); |
|
181 | - $dispatcher->addListener('\OC\Repair::warning', $repairListener); |
|
182 | - $dispatcher->addListener('\OC\Repair::error', $repairListener); |
|
174 | + $dispatcher->addListener('\OC\DB\Migrator::executeSql', $listener); |
|
175 | + $dispatcher->addListener('\OC\DB\Migrator::checkTable', $listener); |
|
176 | + $dispatcher->addListener('\OC\Repair::startProgress', $repairListener); |
|
177 | + $dispatcher->addListener('\OC\Repair::advance', $repairListener); |
|
178 | + $dispatcher->addListener('\OC\Repair::finishProgress', $repairListener); |
|
179 | + $dispatcher->addListener('\OC\Repair::step', $repairListener); |
|
180 | + $dispatcher->addListener('\OC\Repair::info', $repairListener); |
|
181 | + $dispatcher->addListener('\OC\Repair::warning', $repairListener); |
|
182 | + $dispatcher->addListener('\OC\Repair::error', $repairListener); |
|
183 | 183 | |
184 | 184 | |
185 | - $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($output) { |
|
186 | - $output->writeln('<info>Turned on maintenance mode</info>'); |
|
187 | - }); |
|
188 | - $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($output) { |
|
189 | - $output->writeln('<info>Turned off maintenance mode</info>'); |
|
190 | - }); |
|
191 | - $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($output) { |
|
192 | - $output->writeln('<info>Maintenance mode is kept active</info>'); |
|
193 | - }); |
|
194 | - $updater->listen('\OC\Updater', 'updateEnd', |
|
195 | - function ($success) use ($output, $self) { |
|
196 | - if ($success) { |
|
197 | - $message = "<info>Update successful</info>"; |
|
198 | - } else { |
|
199 | - $message = "<error>Update failed</error>"; |
|
200 | - } |
|
201 | - $output->writeln($message); |
|
202 | - }); |
|
203 | - $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($output) { |
|
204 | - $output->writeln('<info>Updating database schema</info>'); |
|
205 | - }); |
|
206 | - $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($output) { |
|
207 | - $output->writeln('<info>Updated database</info>'); |
|
208 | - }); |
|
209 | - $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use ($output) { |
|
210 | - $output->writeln('<info>Checking whether the database schema can be updated (this can take a long time depending on the database size)</info>'); |
|
211 | - }); |
|
212 | - $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use ($output) { |
|
213 | - $output->writeln('<info>Checked database schema update</info>'); |
|
214 | - }); |
|
215 | - $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use ($output) { |
|
216 | - $output->writeln('<comment>Disabled incompatible app: ' . $app . '</comment>'); |
|
217 | - }); |
|
218 | - $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($output) { |
|
219 | - $output->writeln('<info>Checking for update of app ' . $app . ' in appstore</info>'); |
|
220 | - }); |
|
221 | - $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($output) { |
|
222 | - $output->writeln('<info>Update app ' . $app . ' from appstore</info>'); |
|
223 | - }); |
|
224 | - $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($output) { |
|
225 | - $output->writeln('<info>Checked for update of app "' . $app . '" in appstore </info>'); |
|
226 | - }); |
|
227 | - $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($output) { |
|
228 | - $output->writeln('<info>Checking updates of apps</info>'); |
|
229 | - }); |
|
230 | - $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($output) { |
|
231 | - $output->writeln("<info>Checking whether the database schema for <$app> can be updated (this can take a long time depending on the database size)</info>"); |
|
232 | - }); |
|
233 | - $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($output) { |
|
234 | - $output->writeln('<info>Checked database schema update for apps</info>'); |
|
235 | - }); |
|
236 | - $updater->listen('\OC\Updater', 'appUpgradeStarted', function ($app, $version) use ($output) { |
|
237 | - $output->writeln("<info>Updating <$app> ...</info>"); |
|
238 | - }); |
|
239 | - $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($output) { |
|
240 | - $output->writeln("<info>Updated <$app> to $version</info>"); |
|
241 | - }); |
|
242 | - $updater->listen('\OC\Updater', 'failure', function ($message) use ($output, $self) { |
|
243 | - $output->writeln("<error>$message</error>"); |
|
244 | - }); |
|
245 | - $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use ($output) { |
|
246 | - $output->writeln("<info>Set log level to debug</info>"); |
|
247 | - }); |
|
248 | - $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($output) { |
|
249 | - $output->writeln("<info>Reset log level</info>"); |
|
250 | - }); |
|
251 | - $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($output) { |
|
252 | - $output->writeln("<info>Starting code integrity check...</info>"); |
|
253 | - }); |
|
254 | - $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($output) { |
|
255 | - $output->writeln("<info>Finished code integrity check</info>"); |
|
256 | - }); |
|
185 | + $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($output) { |
|
186 | + $output->writeln('<info>Turned on maintenance mode</info>'); |
|
187 | + }); |
|
188 | + $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($output) { |
|
189 | + $output->writeln('<info>Turned off maintenance mode</info>'); |
|
190 | + }); |
|
191 | + $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($output) { |
|
192 | + $output->writeln('<info>Maintenance mode is kept active</info>'); |
|
193 | + }); |
|
194 | + $updater->listen('\OC\Updater', 'updateEnd', |
|
195 | + function ($success) use ($output, $self) { |
|
196 | + if ($success) { |
|
197 | + $message = "<info>Update successful</info>"; |
|
198 | + } else { |
|
199 | + $message = "<error>Update failed</error>"; |
|
200 | + } |
|
201 | + $output->writeln($message); |
|
202 | + }); |
|
203 | + $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($output) { |
|
204 | + $output->writeln('<info>Updating database schema</info>'); |
|
205 | + }); |
|
206 | + $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($output) { |
|
207 | + $output->writeln('<info>Updated database</info>'); |
|
208 | + }); |
|
209 | + $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use ($output) { |
|
210 | + $output->writeln('<info>Checking whether the database schema can be updated (this can take a long time depending on the database size)</info>'); |
|
211 | + }); |
|
212 | + $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use ($output) { |
|
213 | + $output->writeln('<info>Checked database schema update</info>'); |
|
214 | + }); |
|
215 | + $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use ($output) { |
|
216 | + $output->writeln('<comment>Disabled incompatible app: ' . $app . '</comment>'); |
|
217 | + }); |
|
218 | + $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($output) { |
|
219 | + $output->writeln('<info>Checking for update of app ' . $app . ' in appstore</info>'); |
|
220 | + }); |
|
221 | + $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($output) { |
|
222 | + $output->writeln('<info>Update app ' . $app . ' from appstore</info>'); |
|
223 | + }); |
|
224 | + $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($output) { |
|
225 | + $output->writeln('<info>Checked for update of app "' . $app . '" in appstore </info>'); |
|
226 | + }); |
|
227 | + $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($output) { |
|
228 | + $output->writeln('<info>Checking updates of apps</info>'); |
|
229 | + }); |
|
230 | + $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($output) { |
|
231 | + $output->writeln("<info>Checking whether the database schema for <$app> can be updated (this can take a long time depending on the database size)</info>"); |
|
232 | + }); |
|
233 | + $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($output) { |
|
234 | + $output->writeln('<info>Checked database schema update for apps</info>'); |
|
235 | + }); |
|
236 | + $updater->listen('\OC\Updater', 'appUpgradeStarted', function ($app, $version) use ($output) { |
|
237 | + $output->writeln("<info>Updating <$app> ...</info>"); |
|
238 | + }); |
|
239 | + $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($output) { |
|
240 | + $output->writeln("<info>Updated <$app> to $version</info>"); |
|
241 | + }); |
|
242 | + $updater->listen('\OC\Updater', 'failure', function ($message) use ($output, $self) { |
|
243 | + $output->writeln("<error>$message</error>"); |
|
244 | + }); |
|
245 | + $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use ($output) { |
|
246 | + $output->writeln("<info>Set log level to debug</info>"); |
|
247 | + }); |
|
248 | + $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($output) { |
|
249 | + $output->writeln("<info>Reset log level</info>"); |
|
250 | + }); |
|
251 | + $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($output) { |
|
252 | + $output->writeln("<info>Starting code integrity check...</info>"); |
|
253 | + }); |
|
254 | + $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($output) { |
|
255 | + $output->writeln("<info>Finished code integrity check</info>"); |
|
256 | + }); |
|
257 | 257 | |
258 | - $success = $updater->upgrade(); |
|
258 | + $success = $updater->upgrade(); |
|
259 | 259 | |
260 | - $this->postUpgradeCheck($input, $output); |
|
260 | + $this->postUpgradeCheck($input, $output); |
|
261 | 261 | |
262 | - if(!$success) { |
|
263 | - return self::ERROR_FAILURE; |
|
264 | - } |
|
262 | + if(!$success) { |
|
263 | + return self::ERROR_FAILURE; |
|
264 | + } |
|
265 | 265 | |
266 | - return self::ERROR_SUCCESS; |
|
267 | - } else if($this->config->getSystemValueBool('maintenance')) { |
|
268 | - //Possible scenario: Nextcloud core is updated but an app failed |
|
269 | - $output->writeln('<warning>Nextcloud is in maintenance mode</warning>'); |
|
270 | - $output->write('<comment>Maybe an upgrade is already in process. Please check the ' |
|
271 | - . 'logfile (data/nextcloud.log). If you want to re-run the ' |
|
272 | - . 'upgrade procedure, remove the "maintenance mode" from ' |
|
273 | - . 'config.php and call this script again.</comment>' |
|
274 | - , true); |
|
275 | - return self::ERROR_MAINTENANCE_MODE; |
|
276 | - } else { |
|
277 | - $output->writeln('<info>Nextcloud is already latest version</info>'); |
|
278 | - return self::ERROR_UP_TO_DATE; |
|
279 | - } |
|
280 | - } |
|
266 | + return self::ERROR_SUCCESS; |
|
267 | + } else if($this->config->getSystemValueBool('maintenance')) { |
|
268 | + //Possible scenario: Nextcloud core is updated but an app failed |
|
269 | + $output->writeln('<warning>Nextcloud is in maintenance mode</warning>'); |
|
270 | + $output->write('<comment>Maybe an upgrade is already in process. Please check the ' |
|
271 | + . 'logfile (data/nextcloud.log). If you want to re-run the ' |
|
272 | + . 'upgrade procedure, remove the "maintenance mode" from ' |
|
273 | + . 'config.php and call this script again.</comment>' |
|
274 | + , true); |
|
275 | + return self::ERROR_MAINTENANCE_MODE; |
|
276 | + } else { |
|
277 | + $output->writeln('<info>Nextcloud is already latest version</info>'); |
|
278 | + return self::ERROR_UP_TO_DATE; |
|
279 | + } |
|
280 | + } |
|
281 | 281 | |
282 | - /** |
|
283 | - * Perform a post upgrade check (specific to the command line tool) |
|
284 | - * |
|
285 | - * @param InputInterface $input input interface |
|
286 | - * @param OutputInterface $output output interface |
|
287 | - */ |
|
288 | - protected function postUpgradeCheck(InputInterface $input, OutputInterface $output) { |
|
289 | - $trustedDomains = $this->config->getSystemValue('trusted_domains', []); |
|
290 | - if (empty($trustedDomains)) { |
|
291 | - $output->write( |
|
292 | - '<warning>The setting "trusted_domains" could not be ' . |
|
293 | - 'set automatically by the upgrade script, ' . |
|
294 | - 'please set it manually</warning>' |
|
295 | - ); |
|
296 | - } |
|
297 | - } |
|
282 | + /** |
|
283 | + * Perform a post upgrade check (specific to the command line tool) |
|
284 | + * |
|
285 | + * @param InputInterface $input input interface |
|
286 | + * @param OutputInterface $output output interface |
|
287 | + */ |
|
288 | + protected function postUpgradeCheck(InputInterface $input, OutputInterface $output) { |
|
289 | + $trustedDomains = $this->config->getSystemValue('trusted_domains', []); |
|
290 | + if (empty($trustedDomains)) { |
|
291 | + $output->write( |
|
292 | + '<warning>The setting "trusted_domains" could not be ' . |
|
293 | + 'set automatically by the upgrade script, ' . |
|
294 | + 'please set it manually</warning>' |
|
295 | + ); |
|
296 | + } |
|
297 | + } |
|
298 | 298 | } |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | */ |
88 | 88 | protected function execute(InputInterface $input, OutputInterface $output) { |
89 | 89 | |
90 | - if(Util::needUpgrade()) { |
|
90 | + if (Util::needUpgrade()) { |
|
91 | 91 | if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
92 | 92 | // Prepend each line with a little timestamp |
93 | 93 | $timestampFormatter = new TimestampFormatter($this->config, $output->getFormatter()); |
@@ -105,14 +105,14 @@ discard block |
||
105 | 105 | $dispatcher = \OC::$server->getEventDispatcher(); |
106 | 106 | $progress = new ProgressBar($output); |
107 | 107 | $progress->setFormat(" %message%\n %current%/%max% [%bar%] %percent:3s%%"); |
108 | - $listener = function ($event) use ($progress, $output) { |
|
108 | + $listener = function($event) use ($progress, $output) { |
|
109 | 109 | if ($event instanceof GenericEvent) { |
110 | 110 | $message = $event->getSubject(); |
111 | 111 | if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
112 | - $output->writeln(' Checking table ' . $message); |
|
112 | + $output->writeln(' Checking table '.$message); |
|
113 | 113 | } else { |
114 | 114 | if (strlen($message) > 60) { |
115 | - $message = substr($message, 0, 57) . '...'; |
|
115 | + $message = substr($message, 0, 57).'...'; |
|
116 | 116 | } |
117 | 117 | $progress->setMessage($message); |
118 | 118 | if ($event[0] === 1) { |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | } |
129 | 129 | } |
130 | 130 | }; |
131 | - $repairListener = function ($event) use ($progress, $output) { |
|
131 | + $repairListener = function($event) use ($progress, $output) { |
|
132 | 132 | if (!$event instanceof GenericEvent) { |
133 | 133 | return; |
134 | 134 | } |
@@ -153,20 +153,20 @@ discard block |
||
153 | 153 | $output->writeln(''); |
154 | 154 | break; |
155 | 155 | case '\OC\Repair::step': |
156 | - if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
157 | - $output->writeln('<info>Repair step: ' . $event->getArgument(0) . '</info>'); |
|
156 | + if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
157 | + $output->writeln('<info>Repair step: '.$event->getArgument(0).'</info>'); |
|
158 | 158 | } |
159 | 159 | break; |
160 | 160 | case '\OC\Repair::info': |
161 | - if(OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
162 | - $output->writeln('<info>Repair info: ' . $event->getArgument(0) . '</info>'); |
|
161 | + if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { |
|
162 | + $output->writeln('<info>Repair info: '.$event->getArgument(0).'</info>'); |
|
163 | 163 | } |
164 | 164 | break; |
165 | 165 | case '\OC\Repair::warning': |
166 | - $output->writeln('<error>Repair warning: ' . $event->getArgument(0) . '</error>'); |
|
166 | + $output->writeln('<error>Repair warning: '.$event->getArgument(0).'</error>'); |
|
167 | 167 | break; |
168 | 168 | case '\OC\Repair::error': |
169 | - $output->writeln('<error>Repair error: ' . $event->getArgument(0) . '</error>'); |
|
169 | + $output->writeln('<error>Repair error: '.$event->getArgument(0).'</error>'); |
|
170 | 170 | break; |
171 | 171 | } |
172 | 172 | }; |
@@ -182,17 +182,17 @@ discard block |
||
182 | 182 | $dispatcher->addListener('\OC\Repair::error', $repairListener); |
183 | 183 | |
184 | 184 | |
185 | - $updater->listen('\OC\Updater', 'maintenanceEnabled', function () use ($output) { |
|
185 | + $updater->listen('\OC\Updater', 'maintenanceEnabled', function() use ($output) { |
|
186 | 186 | $output->writeln('<info>Turned on maintenance mode</info>'); |
187 | 187 | }); |
188 | - $updater->listen('\OC\Updater', 'maintenanceDisabled', function () use ($output) { |
|
188 | + $updater->listen('\OC\Updater', 'maintenanceDisabled', function() use ($output) { |
|
189 | 189 | $output->writeln('<info>Turned off maintenance mode</info>'); |
190 | 190 | }); |
191 | - $updater->listen('\OC\Updater', 'maintenanceActive', function () use ($output) { |
|
191 | + $updater->listen('\OC\Updater', 'maintenanceActive', function() use ($output) { |
|
192 | 192 | $output->writeln('<info>Maintenance mode is kept active</info>'); |
193 | 193 | }); |
194 | 194 | $updater->listen('\OC\Updater', 'updateEnd', |
195 | - function ($success) use ($output, $self) { |
|
195 | + function($success) use ($output, $self) { |
|
196 | 196 | if ($success) { |
197 | 197 | $message = "<info>Update successful</info>"; |
198 | 198 | } else { |
@@ -200,58 +200,58 @@ discard block |
||
200 | 200 | } |
201 | 201 | $output->writeln($message); |
202 | 202 | }); |
203 | - $updater->listen('\OC\Updater', 'dbUpgradeBefore', function () use ($output) { |
|
203 | + $updater->listen('\OC\Updater', 'dbUpgradeBefore', function() use ($output) { |
|
204 | 204 | $output->writeln('<info>Updating database schema</info>'); |
205 | 205 | }); |
206 | - $updater->listen('\OC\Updater', 'dbUpgrade', function () use ($output) { |
|
206 | + $updater->listen('\OC\Updater', 'dbUpgrade', function() use ($output) { |
|
207 | 207 | $output->writeln('<info>Updated database</info>'); |
208 | 208 | }); |
209 | - $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function () use ($output) { |
|
209 | + $updater->listen('\OC\Updater', 'dbSimulateUpgradeBefore', function() use ($output) { |
|
210 | 210 | $output->writeln('<info>Checking whether the database schema can be updated (this can take a long time depending on the database size)</info>'); |
211 | 211 | }); |
212 | - $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use ($output) { |
|
212 | + $updater->listen('\OC\Updater', 'dbSimulateUpgrade', function() use ($output) { |
|
213 | 213 | $output->writeln('<info>Checked database schema update</info>'); |
214 | 214 | }); |
215 | - $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function ($app) use ($output) { |
|
216 | - $output->writeln('<comment>Disabled incompatible app: ' . $app . '</comment>'); |
|
215 | + $updater->listen('\OC\Updater', 'incompatibleAppDisabled', function($app) use ($output) { |
|
216 | + $output->writeln('<comment>Disabled incompatible app: '.$app.'</comment>'); |
|
217 | 217 | }); |
218 | - $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function ($app) use ($output) { |
|
219 | - $output->writeln('<info>Checking for update of app ' . $app . ' in appstore</info>'); |
|
218 | + $updater->listen('\OC\Updater', 'checkAppStoreAppBefore', function($app) use ($output) { |
|
219 | + $output->writeln('<info>Checking for update of app '.$app.' in appstore</info>'); |
|
220 | 220 | }); |
221 | - $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function ($app) use ($output) { |
|
222 | - $output->writeln('<info>Update app ' . $app . ' from appstore</info>'); |
|
221 | + $updater->listen('\OC\Updater', 'upgradeAppStoreApp', function($app) use ($output) { |
|
222 | + $output->writeln('<info>Update app '.$app.' from appstore</info>'); |
|
223 | 223 | }); |
224 | - $updater->listen('\OC\Updater', 'checkAppStoreApp', function ($app) use ($output) { |
|
225 | - $output->writeln('<info>Checked for update of app "' . $app . '" in appstore </info>'); |
|
224 | + $updater->listen('\OC\Updater', 'checkAppStoreApp', function($app) use ($output) { |
|
225 | + $output->writeln('<info>Checked for update of app "'.$app.'" in appstore </info>'); |
|
226 | 226 | }); |
227 | - $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function () use ($output) { |
|
227 | + $updater->listen('\OC\Updater', 'appUpgradeCheckBefore', function() use ($output) { |
|
228 | 228 | $output->writeln('<info>Checking updates of apps</info>'); |
229 | 229 | }); |
230 | - $updater->listen('\OC\Updater', 'appSimulateUpdate', function ($app) use ($output) { |
|
230 | + $updater->listen('\OC\Updater', 'appSimulateUpdate', function($app) use ($output) { |
|
231 | 231 | $output->writeln("<info>Checking whether the database schema for <$app> can be updated (this can take a long time depending on the database size)</info>"); |
232 | 232 | }); |
233 | - $updater->listen('\OC\Updater', 'appUpgradeCheck', function () use ($output) { |
|
233 | + $updater->listen('\OC\Updater', 'appUpgradeCheck', function() use ($output) { |
|
234 | 234 | $output->writeln('<info>Checked database schema update for apps</info>'); |
235 | 235 | }); |
236 | - $updater->listen('\OC\Updater', 'appUpgradeStarted', function ($app, $version) use ($output) { |
|
236 | + $updater->listen('\OC\Updater', 'appUpgradeStarted', function($app, $version) use ($output) { |
|
237 | 237 | $output->writeln("<info>Updating <$app> ...</info>"); |
238 | 238 | }); |
239 | - $updater->listen('\OC\Updater', 'appUpgrade', function ($app, $version) use ($output) { |
|
239 | + $updater->listen('\OC\Updater', 'appUpgrade', function($app, $version) use ($output) { |
|
240 | 240 | $output->writeln("<info>Updated <$app> to $version</info>"); |
241 | 241 | }); |
242 | - $updater->listen('\OC\Updater', 'failure', function ($message) use ($output, $self) { |
|
242 | + $updater->listen('\OC\Updater', 'failure', function($message) use ($output, $self) { |
|
243 | 243 | $output->writeln("<error>$message</error>"); |
244 | 244 | }); |
245 | - $updater->listen('\OC\Updater', 'setDebugLogLevel', function ($logLevel, $logLevelName) use ($output) { |
|
245 | + $updater->listen('\OC\Updater', 'setDebugLogLevel', function($logLevel, $logLevelName) use ($output) { |
|
246 | 246 | $output->writeln("<info>Set log level to debug</info>"); |
247 | 247 | }); |
248 | - $updater->listen('\OC\Updater', 'resetLogLevel', function ($logLevel, $logLevelName) use ($output) { |
|
248 | + $updater->listen('\OC\Updater', 'resetLogLevel', function($logLevel, $logLevelName) use ($output) { |
|
249 | 249 | $output->writeln("<info>Reset log level</info>"); |
250 | 250 | }); |
251 | - $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function () use ($output) { |
|
251 | + $updater->listen('\OC\Updater', 'startCheckCodeIntegrity', function() use ($output) { |
|
252 | 252 | $output->writeln("<info>Starting code integrity check...</info>"); |
253 | 253 | }); |
254 | - $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function () use ($output) { |
|
254 | + $updater->listen('\OC\Updater', 'finishedCheckCodeIntegrity', function() use ($output) { |
|
255 | 255 | $output->writeln("<info>Finished code integrity check</info>"); |
256 | 256 | }); |
257 | 257 | |
@@ -259,12 +259,12 @@ discard block |
||
259 | 259 | |
260 | 260 | $this->postUpgradeCheck($input, $output); |
261 | 261 | |
262 | - if(!$success) { |
|
262 | + if (!$success) { |
|
263 | 263 | return self::ERROR_FAILURE; |
264 | 264 | } |
265 | 265 | |
266 | 266 | return self::ERROR_SUCCESS; |
267 | - } else if($this->config->getSystemValueBool('maintenance')) { |
|
267 | + } else if ($this->config->getSystemValueBool('maintenance')) { |
|
268 | 268 | //Possible scenario: Nextcloud core is updated but an app failed |
269 | 269 | $output->writeln('<warning>Nextcloud is in maintenance mode</warning>'); |
270 | 270 | $output->write('<comment>Maybe an upgrade is already in process. Please check the ' |
@@ -289,8 +289,8 @@ discard block |
||
289 | 289 | $trustedDomains = $this->config->getSystemValue('trusted_domains', []); |
290 | 290 | if (empty($trustedDomains)) { |
291 | 291 | $output->write( |
292 | - '<warning>The setting "trusted_domains" could not be ' . |
|
293 | - 'set automatically by the upgrade script, ' . |
|
292 | + '<warning>The setting "trusted_domains" could not be '. |
|
293 | + 'set automatically by the upgrade script, '. |
|
294 | 294 | 'please set it manually</warning>' |
295 | 295 | ); |
296 | 296 | } |