@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | protected function getSettings($section) { |
| 68 | 68 | $settings = $this->settingsManager->getPersonalSettings($section); |
| 69 | 69 | $formatted = $this->formatSettings($settings); |
| 70 | - if($section === 'additional') { |
|
| 70 | + if ($section === 'additional') { |
|
| 71 | 71 | $formatted['content'] .= $this->getLegacyForms(); |
| 72 | 72 | } |
| 73 | 73 | return $formatted; |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | private function getLegacyForms() { |
| 80 | 80 | $forms = \OC_App::getForms('personal'); |
| 81 | 81 | |
| 82 | - $forms = array_map(function ($form) { |
|
| 82 | + $forms = array_map(function($form) { |
|
| 83 | 83 | if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) { |
| 84 | - $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]); |
|
| 84 | + $sectionName = str_replace('<h2'.$regs['class'].'>', '', $regs[0]); |
|
| 85 | 85 | $sectionName = str_replace('</h2>', '', $sectionName); |
| 86 | 86 | $anchor = strtolower($sectionName); |
| 87 | 87 | $anchor = str_replace(' ', '-', $anchor); |
@@ -32,72 +32,72 @@ |
||
| 32 | 32 | use OCP\Template; |
| 33 | 33 | |
| 34 | 34 | class PersonalSettingsController extends Controller { |
| 35 | - use CommonSettingsTrait; |
|
| 35 | + use CommonSettingsTrait; |
|
| 36 | 36 | |
| 37 | - public function __construct( |
|
| 38 | - $appName, |
|
| 39 | - IRequest $request, |
|
| 40 | - INavigationManager $navigationManager, |
|
| 41 | - ISettingsManager $settingsManager |
|
| 42 | - ) { |
|
| 43 | - parent::__construct($appName, $request); |
|
| 44 | - $this->navigationManager = $navigationManager; |
|
| 45 | - $this->settingsManager = $settingsManager; |
|
| 46 | - } |
|
| 37 | + public function __construct( |
|
| 38 | + $appName, |
|
| 39 | + IRequest $request, |
|
| 40 | + INavigationManager $navigationManager, |
|
| 41 | + ISettingsManager $settingsManager |
|
| 42 | + ) { |
|
| 43 | + parent::__construct($appName, $request); |
|
| 44 | + $this->navigationManager = $navigationManager; |
|
| 45 | + $this->settingsManager = $settingsManager; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @param string $section |
|
| 50 | - * @return TemplateResponse |
|
| 51 | - * |
|
| 52 | - * @NoCSRFRequired |
|
| 53 | - * @NoAdminRequired |
|
| 54 | - * @NoSubadminRequired |
|
| 55 | - */ |
|
| 56 | - public function index($section) { |
|
| 57 | - return $this->getIndexResponse('personal', $section); |
|
| 48 | + /** |
|
| 49 | + * @param string $section |
|
| 50 | + * @return TemplateResponse |
|
| 51 | + * |
|
| 52 | + * @NoCSRFRequired |
|
| 53 | + * @NoAdminRequired |
|
| 54 | + * @NoSubadminRequired |
|
| 55 | + */ |
|
| 56 | + public function index($section) { |
|
| 57 | + return $this->getIndexResponse('personal', $section); |
|
| 58 | 58 | |
| 59 | - } |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @param string $section |
|
| 63 | - * @return array |
|
| 64 | - */ |
|
| 65 | - protected function getSettings($section) { |
|
| 66 | - $settings = $this->settingsManager->getPersonalSettings($section); |
|
| 67 | - $formatted = $this->formatSettings($settings); |
|
| 68 | - if($section === 'additional') { |
|
| 69 | - $formatted['content'] .= $this->getLegacyForms(); |
|
| 70 | - } |
|
| 71 | - return $formatted; |
|
| 72 | - } |
|
| 61 | + /** |
|
| 62 | + * @param string $section |
|
| 63 | + * @return array |
|
| 64 | + */ |
|
| 65 | + protected function getSettings($section) { |
|
| 66 | + $settings = $this->settingsManager->getPersonalSettings($section); |
|
| 67 | + $formatted = $this->formatSettings($settings); |
|
| 68 | + if($section === 'additional') { |
|
| 69 | + $formatted['content'] .= $this->getLegacyForms(); |
|
| 70 | + } |
|
| 71 | + return $formatted; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * @return bool|string |
|
| 76 | - */ |
|
| 77 | - private function getLegacyForms() { |
|
| 78 | - $forms = \OC_App::getForms('personal'); |
|
| 74 | + /** |
|
| 75 | + * @return bool|string |
|
| 76 | + */ |
|
| 77 | + private function getLegacyForms() { |
|
| 78 | + $forms = \OC_App::getForms('personal'); |
|
| 79 | 79 | |
| 80 | - $forms = array_map(function ($form) { |
|
| 81 | - if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) { |
|
| 82 | - $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]); |
|
| 83 | - $sectionName = str_replace('</h2>', '', $sectionName); |
|
| 84 | - $anchor = strtolower($sectionName); |
|
| 85 | - $anchor = str_replace(' ', '-', $anchor); |
|
| 80 | + $forms = array_map(function ($form) { |
|
| 81 | + if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) { |
|
| 82 | + $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]); |
|
| 83 | + $sectionName = str_replace('</h2>', '', $sectionName); |
|
| 84 | + $anchor = strtolower($sectionName); |
|
| 85 | + $anchor = str_replace(' ', '-', $anchor); |
|
| 86 | 86 | |
| 87 | - return array( |
|
| 88 | - 'anchor' => $anchor, |
|
| 89 | - 'section-name' => $sectionName, |
|
| 90 | - 'form' => $form |
|
| 91 | - ); |
|
| 92 | - } |
|
| 93 | - return array( |
|
| 94 | - 'form' => $form |
|
| 95 | - ); |
|
| 96 | - }, $forms); |
|
| 87 | + return array( |
|
| 88 | + 'anchor' => $anchor, |
|
| 89 | + 'section-name' => $sectionName, |
|
| 90 | + 'form' => $form |
|
| 91 | + ); |
|
| 92 | + } |
|
| 93 | + return array( |
|
| 94 | + 'form' => $form |
|
| 95 | + ); |
|
| 96 | + }, $forms); |
|
| 97 | 97 | |
| 98 | - $out = new Template('settings', 'settings/additional'); |
|
| 99 | - $out->assign('forms', $forms); |
|
| 98 | + $out = new Template('settings', 'settings/additional'); |
|
| 99 | + $out->assign('forms', $forms); |
|
| 100 | 100 | |
| 101 | - return $out->fetchPage(); |
|
| 102 | - } |
|
| 101 | + return $out->fetchPage(); |
|
| 102 | + } |
|
| 103 | 103 | } |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | protected function getSettings($section) { |
| 78 | 78 | $settings = $this->settingsManager->getAdminSettings($section); |
| 79 | 79 | $formatted = $this->formatSettings($settings); |
| 80 | - if($section === 'additional') { |
|
| 80 | + if ($section === 'additional') { |
|
| 81 | 81 | $formatted['content'] .= $this->getLegacyForms(); |
| 82 | 82 | } |
| 83 | 83 | return $formatted; |
@@ -89,9 +89,9 @@ discard block |
||
| 89 | 89 | private function getLegacyForms() { |
| 90 | 90 | $forms = \OC_App::getForms('admin'); |
| 91 | 91 | |
| 92 | - $forms = array_map(function ($form) { |
|
| 92 | + $forms = array_map(function($form) { |
|
| 93 | 93 | if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) { |
| 94 | - $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]); |
|
| 94 | + $sectionName = str_replace('<h2'.$regs['class'].'>', '', $regs[0]); |
|
| 95 | 95 | $sectionName = str_replace('</h2>', '', $sectionName); |
| 96 | 96 | $anchor = strtolower($sectionName); |
| 97 | 97 | $anchor = str_replace(' ', '-', $anchor); |
@@ -36,77 +36,77 @@ |
||
| 36 | 36 | * @package OC\Settings\Controller |
| 37 | 37 | */ |
| 38 | 38 | class AdminSettingsController extends Controller { |
| 39 | - use CommonSettingsTrait; |
|
| 39 | + use CommonSettingsTrait; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @param string $appName |
|
| 43 | - * @param IRequest $request |
|
| 44 | - * @param INavigationManager $navigationManager |
|
| 45 | - * @param ISettingsManager $settingsManager |
|
| 46 | - */ |
|
| 47 | - public function __construct( |
|
| 48 | - $appName, |
|
| 49 | - IRequest $request, |
|
| 50 | - INavigationManager $navigationManager, |
|
| 51 | - ISettingsManager $settingsManager |
|
| 52 | - ) { |
|
| 53 | - parent::__construct($appName, $request); |
|
| 54 | - $this->navigationManager = $navigationManager; |
|
| 55 | - $this->settingsManager = $settingsManager; |
|
| 56 | - } |
|
| 41 | + /** |
|
| 42 | + * @param string $appName |
|
| 43 | + * @param IRequest $request |
|
| 44 | + * @param INavigationManager $navigationManager |
|
| 45 | + * @param ISettingsManager $settingsManager |
|
| 46 | + */ |
|
| 47 | + public function __construct( |
|
| 48 | + $appName, |
|
| 49 | + IRequest $request, |
|
| 50 | + INavigationManager $navigationManager, |
|
| 51 | + ISettingsManager $settingsManager |
|
| 52 | + ) { |
|
| 53 | + parent::__construct($appName, $request); |
|
| 54 | + $this->navigationManager = $navigationManager; |
|
| 55 | + $this->settingsManager = $settingsManager; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * @param string $section |
|
| 60 | - * @return TemplateResponse |
|
| 61 | - * |
|
| 62 | - * @NoCSRFRequired |
|
| 63 | - */ |
|
| 64 | - public function index($section) { |
|
| 65 | - return $this->getIndexResponse('admin', $section); |
|
| 66 | - } |
|
| 58 | + /** |
|
| 59 | + * @param string $section |
|
| 60 | + * @return TemplateResponse |
|
| 61 | + * |
|
| 62 | + * @NoCSRFRequired |
|
| 63 | + */ |
|
| 64 | + public function index($section) { |
|
| 65 | + return $this->getIndexResponse('admin', $section); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @param string $section |
|
| 70 | - * @return array |
|
| 71 | - */ |
|
| 72 | - protected function getSettings($section) { |
|
| 73 | - $settings = $this->settingsManager->getAdminSettings($section); |
|
| 74 | - $formatted = $this->formatSettings($settings); |
|
| 75 | - if($section === 'additional') { |
|
| 76 | - $formatted['content'] .= $this->getLegacyForms(); |
|
| 77 | - } |
|
| 78 | - return $formatted; |
|
| 79 | - } |
|
| 68 | + /** |
|
| 69 | + * @param string $section |
|
| 70 | + * @return array |
|
| 71 | + */ |
|
| 72 | + protected function getSettings($section) { |
|
| 73 | + $settings = $this->settingsManager->getAdminSettings($section); |
|
| 74 | + $formatted = $this->formatSettings($settings); |
|
| 75 | + if($section === 'additional') { |
|
| 76 | + $formatted['content'] .= $this->getLegacyForms(); |
|
| 77 | + } |
|
| 78 | + return $formatted; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * @return bool|string |
|
| 83 | - */ |
|
| 84 | - private function getLegacyForms() { |
|
| 85 | - $forms = \OC_App::getForms('admin'); |
|
| 81 | + /** |
|
| 82 | + * @return bool|string |
|
| 83 | + */ |
|
| 84 | + private function getLegacyForms() { |
|
| 85 | + $forms = \OC_App::getForms('admin'); |
|
| 86 | 86 | |
| 87 | - $forms = array_map(function ($form) { |
|
| 88 | - if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) { |
|
| 89 | - $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]); |
|
| 90 | - $sectionName = str_replace('</h2>', '', $sectionName); |
|
| 91 | - $anchor = strtolower($sectionName); |
|
| 92 | - $anchor = str_replace(' ', '-', $anchor); |
|
| 87 | + $forms = array_map(function ($form) { |
|
| 88 | + if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) { |
|
| 89 | + $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]); |
|
| 90 | + $sectionName = str_replace('</h2>', '', $sectionName); |
|
| 91 | + $anchor = strtolower($sectionName); |
|
| 92 | + $anchor = str_replace(' ', '-', $anchor); |
|
| 93 | 93 | |
| 94 | - return array( |
|
| 95 | - 'anchor' => $anchor, |
|
| 96 | - 'section-name' => $sectionName, |
|
| 97 | - 'form' => $form |
|
| 98 | - ); |
|
| 99 | - } |
|
| 100 | - return array( |
|
| 101 | - 'form' => $form |
|
| 102 | - ); |
|
| 103 | - }, $forms); |
|
| 94 | + return array( |
|
| 95 | + 'anchor' => $anchor, |
|
| 96 | + 'section-name' => $sectionName, |
|
| 97 | + 'form' => $form |
|
| 98 | + ); |
|
| 99 | + } |
|
| 100 | + return array( |
|
| 101 | + 'form' => $form |
|
| 102 | + ); |
|
| 103 | + }, $forms); |
|
| 104 | 104 | |
| 105 | - $out = new Template('settings', 'settings/additional'); |
|
| 106 | - $out->assign('forms', $forms); |
|
| 105 | + $out = new Template('settings', 'settings/additional'); |
|
| 106 | + $out->assign('forms', $forms); |
|
| 107 | 107 | |
| 108 | - return $out->fetchPage(); |
|
| 109 | - } |
|
| 108 | + return $out->fetchPage(); |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | 111 | |
| 112 | 112 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | $this->uid = $uid; |
| 85 | 85 | $this->backend = $backend; |
| 86 | 86 | $this->emitter = $emitter; |
| 87 | - if(is_null($config)) { |
|
| 87 | + if (is_null($config)) { |
|
| 88 | 88 | $config = \OC::$server->getConfig(); |
| 89 | 89 | } |
| 90 | 90 | $this->config = $config; |
@@ -160,12 +160,12 @@ discard block |
||
| 160 | 160 | */ |
| 161 | 161 | public function setEMailAddress($mailAddress) { |
| 162 | 162 | $oldMailAddress = $this->getEMailAddress(); |
| 163 | - if($mailAddress === '') { |
|
| 163 | + if ($mailAddress === '') { |
|
| 164 | 164 | $this->config->deleteUserValue($this->uid, 'settings', 'email'); |
| 165 | 165 | } else { |
| 166 | 166 | $this->config->setUserValue($this->uid, 'settings', 'email', $mailAddress); |
| 167 | 167 | } |
| 168 | - if($oldMailAddress !== $mailAddress) { |
|
| 168 | + if ($oldMailAddress !== $mailAddress) { |
|
| 169 | 169 | $this->triggerChange('eMailAddress', $mailAddress, $oldMailAddress); |
| 170 | 170 | } |
| 171 | 171 | } |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | // Delete the users entry in the storage table |
| 232 | - Storage::remove('home::' . $this->uid); |
|
| 232 | + Storage::remove('home::'.$this->uid); |
|
| 233 | 233 | |
| 234 | 234 | \OC::$server->getCommentsManager()->deleteReferencesOfActor('users', $this->uid); |
| 235 | 235 | \OC::$server->getCommentsManager()->deleteReadMarksFromUser($this); |
@@ -281,9 +281,9 @@ discard block |
||
| 281 | 281 | if ($this->backend->implementsActions(Backend::GET_HOME) and $home = $this->backend->getHome($this->uid)) { |
| 282 | 282 | $this->home = $home; |
| 283 | 283 | } elseif ($this->config) { |
| 284 | - $this->home = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $this->uid; |
|
| 284 | + $this->home = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data').'/'.$this->uid; |
|
| 285 | 285 | } else { |
| 286 | - $this->home = \OC::$SERVERROOT . '/data/' . $this->uid; |
|
| 286 | + $this->home = \OC::$SERVERROOT.'/data/'.$this->uid; |
|
| 287 | 287 | } |
| 288 | 288 | } |
| 289 | 289 | return $this->home; |
@@ -295,7 +295,7 @@ discard block |
||
| 295 | 295 | * @return string |
| 296 | 296 | */ |
| 297 | 297 | public function getBackendClassName() { |
| 298 | - if($this->backend instanceof IUserBackend) { |
|
| 298 | + if ($this->backend instanceof IUserBackend) { |
|
| 299 | 299 | return $this->backend->getBackendName(); |
| 300 | 300 | } |
| 301 | 301 | return get_class($this->backend); |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | */ |
| 377 | 377 | public function getQuota() { |
| 378 | 378 | $quota = $this->config->getUserValue($this->uid, 'files', 'quota', 'default'); |
| 379 | - if($quota === 'default') { |
|
| 379 | + if ($quota === 'default') { |
|
| 380 | 380 | $quota = $this->config->getAppValue('files', 'default_quota', 'none'); |
| 381 | 381 | } |
| 382 | 382 | return $quota; |
@@ -391,12 +391,12 @@ discard block |
||
| 391 | 391 | */ |
| 392 | 392 | public function setQuota($quota) { |
| 393 | 393 | $oldQuota = $this->config->getUserValue($this->uid, 'files', 'quota', ''); |
| 394 | - if($quota !== 'none' and $quota !== 'default') { |
|
| 394 | + if ($quota !== 'none' and $quota !== 'default') { |
|
| 395 | 395 | $quota = OC_Helper::computerFileSize($quota); |
| 396 | 396 | $quota = OC_Helper::humanFileSize($quota); |
| 397 | 397 | } |
| 398 | 398 | $this->config->setUserValue($this->uid, 'files', 'quota', $quota); |
| 399 | - if($quota !== $oldQuota) { |
|
| 399 | + if ($quota !== $oldQuota) { |
|
| 400 | 400 | $this->triggerChange('quota', $quota); |
| 401 | 401 | } |
| 402 | 402 | } |
@@ -432,7 +432,7 @@ discard block |
||
| 432 | 432 | public function getCloudId() { |
| 433 | 433 | $uid = $this->getUID(); |
| 434 | 434 | $server = $this->urlGenerator->getAbsoluteURL('/'); |
| 435 | - $server = rtrim( $this->removeProtocolFromUrl($server), '/'); |
|
| 435 | + $server = rtrim($this->removeProtocolFromUrl($server), '/'); |
|
| 436 | 436 | return \OC::$server->getCloudIdManager()->getCloudId($uid, $server)->getId(); |
| 437 | 437 | } |
| 438 | 438 | |
@@ -450,6 +450,10 @@ |
||
| 450 | 450 | return $url; |
| 451 | 451 | } |
| 452 | 452 | |
| 453 | + /** |
|
| 454 | + * @param string $feature |
|
| 455 | + * @param string $oldValue |
|
| 456 | + */ |
|
| 453 | 457 | public function triggerChange($feature, $value = null, $oldValue = null) { |
| 454 | 458 | if ($this->emitter) { |
| 455 | 459 | $this->emitter->emit('\OC\User', 'changeUser', array($this, $feature, $value, $oldValue)); |
@@ -44,415 +44,415 @@ |
||
| 44 | 44 | use \OCP\IUserBackend; |
| 45 | 45 | |
| 46 | 46 | class User implements IUser { |
| 47 | - /** @var string $uid */ |
|
| 48 | - private $uid; |
|
| 49 | - |
|
| 50 | - /** @var string $displayName */ |
|
| 51 | - private $displayName; |
|
| 52 | - |
|
| 53 | - /** @var UserInterface $backend */ |
|
| 54 | - private $backend; |
|
| 55 | - |
|
| 56 | - /** @var bool $enabled */ |
|
| 57 | - private $enabled; |
|
| 58 | - |
|
| 59 | - /** @var Emitter|Manager $emitter */ |
|
| 60 | - private $emitter; |
|
| 61 | - |
|
| 62 | - /** @var string $home */ |
|
| 63 | - private $home; |
|
| 64 | - |
|
| 65 | - /** @var int $lastLogin */ |
|
| 66 | - private $lastLogin; |
|
| 67 | - |
|
| 68 | - /** @var \OCP\IConfig $config */ |
|
| 69 | - private $config; |
|
| 70 | - |
|
| 71 | - /** @var IAvatarManager */ |
|
| 72 | - private $avatarManager; |
|
| 73 | - |
|
| 74 | - /** @var IURLGenerator */ |
|
| 75 | - private $urlGenerator; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @param string $uid |
|
| 79 | - * @param UserInterface $backend |
|
| 80 | - * @param \OC\Hooks\Emitter $emitter |
|
| 81 | - * @param IConfig|null $config |
|
| 82 | - * @param IURLGenerator $urlGenerator |
|
| 83 | - */ |
|
| 84 | - public function __construct($uid, $backend, $emitter = null, IConfig $config = null, $urlGenerator = null) { |
|
| 85 | - $this->uid = $uid; |
|
| 86 | - $this->backend = $backend; |
|
| 87 | - $this->emitter = $emitter; |
|
| 88 | - if(is_null($config)) { |
|
| 89 | - $config = \OC::$server->getConfig(); |
|
| 90 | - } |
|
| 91 | - $this->config = $config; |
|
| 92 | - $this->urlGenerator = $urlGenerator; |
|
| 93 | - $enabled = $this->config->getUserValue($uid, 'core', 'enabled', 'true'); |
|
| 94 | - $this->enabled = ($enabled === 'true'); |
|
| 95 | - $this->lastLogin = $this->config->getUserValue($uid, 'login', 'lastLogin', 0); |
|
| 96 | - if (is_null($this->urlGenerator)) { |
|
| 97 | - $this->urlGenerator = \OC::$server->getURLGenerator(); |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * get the user id |
|
| 103 | - * |
|
| 104 | - * @return string |
|
| 105 | - */ |
|
| 106 | - public function getUID() { |
|
| 107 | - return $this->uid; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * get the display name for the user, if no specific display name is set it will fallback to the user id |
|
| 112 | - * |
|
| 113 | - * @return string |
|
| 114 | - */ |
|
| 115 | - public function getDisplayName() { |
|
| 116 | - if (!isset($this->displayName)) { |
|
| 117 | - $displayName = ''; |
|
| 118 | - if ($this->backend and $this->backend->implementsActions(Backend::GET_DISPLAYNAME)) { |
|
| 119 | - // get display name and strip whitespace from the beginning and end of it |
|
| 120 | - $backendDisplayName = $this->backend->getDisplayName($this->uid); |
|
| 121 | - if (is_string($backendDisplayName)) { |
|
| 122 | - $displayName = trim($backendDisplayName); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - if (!empty($displayName)) { |
|
| 127 | - $this->displayName = $displayName; |
|
| 128 | - } else { |
|
| 129 | - $this->displayName = $this->uid; |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - return $this->displayName; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * set the displayname for the user |
|
| 137 | - * |
|
| 138 | - * @param string $displayName |
|
| 139 | - * @return bool |
|
| 140 | - */ |
|
| 141 | - public function setDisplayName($displayName) { |
|
| 142 | - $displayName = trim($displayName); |
|
| 143 | - if ($this->backend->implementsActions(Backend::SET_DISPLAYNAME) && !empty($displayName)) { |
|
| 144 | - $result = $this->backend->setDisplayName($this->uid, $displayName); |
|
| 145 | - if ($result) { |
|
| 146 | - $this->displayName = $displayName; |
|
| 147 | - $this->triggerChange('displayName', $displayName); |
|
| 148 | - } |
|
| 149 | - return $result !== false; |
|
| 150 | - } else { |
|
| 151 | - return false; |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * set the email address of the user |
|
| 157 | - * |
|
| 158 | - * @param string|null $mailAddress |
|
| 159 | - * @return void |
|
| 160 | - * @since 9.0.0 |
|
| 161 | - */ |
|
| 162 | - public function setEMailAddress($mailAddress) { |
|
| 163 | - $oldMailAddress = $this->getEMailAddress(); |
|
| 164 | - if($mailAddress === '') { |
|
| 165 | - $this->config->deleteUserValue($this->uid, 'settings', 'email'); |
|
| 166 | - } else { |
|
| 167 | - $this->config->setUserValue($this->uid, 'settings', 'email', $mailAddress); |
|
| 168 | - } |
|
| 169 | - if($oldMailAddress !== $mailAddress) { |
|
| 170 | - $this->triggerChange('eMailAddress', $mailAddress, $oldMailAddress); |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * returns the timestamp of the user's last login or 0 if the user did never |
|
| 176 | - * login |
|
| 177 | - * |
|
| 178 | - * @return int |
|
| 179 | - */ |
|
| 180 | - public function getLastLogin() { |
|
| 181 | - return $this->lastLogin; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * updates the timestamp of the most recent login of this user |
|
| 186 | - */ |
|
| 187 | - public function updateLastLoginTimestamp() { |
|
| 188 | - $firstTimeLogin = ($this->lastLogin === 0); |
|
| 189 | - $this->lastLogin = time(); |
|
| 190 | - $this->config->setUserValue( |
|
| 191 | - $this->uid, 'login', 'lastLogin', $this->lastLogin); |
|
| 192 | - |
|
| 193 | - return $firstTimeLogin; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * Delete the user |
|
| 198 | - * |
|
| 199 | - * @return bool |
|
| 200 | - */ |
|
| 201 | - public function delete() { |
|
| 202 | - if ($this->emitter) { |
|
| 203 | - $this->emitter->emit('\OC\User', 'preDelete', array($this)); |
|
| 204 | - } |
|
| 205 | - // get the home now because it won't return it after user deletion |
|
| 206 | - $homePath = $this->getHome(); |
|
| 207 | - $result = $this->backend->deleteUser($this->uid); |
|
| 208 | - if ($result) { |
|
| 209 | - |
|
| 210 | - // FIXME: Feels like an hack - suggestions? |
|
| 211 | - |
|
| 212 | - $groupManager = \OC::$server->getGroupManager(); |
|
| 213 | - // We have to delete the user from all groups |
|
| 214 | - foreach ($groupManager->getUserGroupIds($this) as $groupId) { |
|
| 215 | - $group = $groupManager->get($groupId); |
|
| 216 | - if ($group) { |
|
| 217 | - \OC_Hook::emit("OC_Group", "pre_removeFromGroup", ["run" => true, "uid" => $this->uid, "gid" => $groupId]); |
|
| 218 | - $group->removeUser($this); |
|
| 219 | - \OC_Hook::emit("OC_User", "post_removeFromGroup", ["uid" => $this->uid, "gid" => $groupId]); |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - // Delete the user's keys in preferences |
|
| 223 | - \OC::$server->getConfig()->deleteAllUserValues($this->uid); |
|
| 224 | - |
|
| 225 | - // Delete user files in /data/ |
|
| 226 | - if ($homePath !== false) { |
|
| 227 | - // FIXME: this operates directly on FS, should use View instead... |
|
| 228 | - // also this is not testable/mockable... |
|
| 229 | - \OC_Helper::rmdirr($homePath); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - // Delete the users entry in the storage table |
|
| 233 | - Storage::remove('home::' . $this->uid); |
|
| 234 | - |
|
| 235 | - \OC::$server->getCommentsManager()->deleteReferencesOfActor('users', $this->uid); |
|
| 236 | - \OC::$server->getCommentsManager()->deleteReadMarksFromUser($this); |
|
| 237 | - |
|
| 238 | - $notification = \OC::$server->getNotificationManager()->createNotification(); |
|
| 239 | - $notification->setUser($this->uid); |
|
| 240 | - \OC::$server->getNotificationManager()->markProcessed($notification); |
|
| 241 | - |
|
| 242 | - /** @var AccountManager $accountManager */ |
|
| 243 | - $accountManager = \OC::$server->query(AccountManager::class); |
|
| 244 | - $accountManager->deleteUser($this); |
|
| 245 | - |
|
| 246 | - if ($this->emitter) { |
|
| 247 | - $this->emitter->emit('\OC\User', 'postDelete', array($this)); |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - return !($result === false); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - /** |
|
| 254 | - * Set the password of the user |
|
| 255 | - * |
|
| 256 | - * @param string $password |
|
| 257 | - * @param string $recoveryPassword for the encryption app to reset encryption keys |
|
| 258 | - * @return bool |
|
| 259 | - */ |
|
| 260 | - public function setPassword($password, $recoveryPassword = null) { |
|
| 261 | - if ($this->emitter) { |
|
| 262 | - $this->emitter->emit('\OC\User', 'preSetPassword', array($this, $password, $recoveryPassword)); |
|
| 263 | - } |
|
| 264 | - if ($this->backend->implementsActions(Backend::SET_PASSWORD)) { |
|
| 265 | - $result = $this->backend->setPassword($this->uid, $password); |
|
| 266 | - if ($this->emitter) { |
|
| 267 | - $this->emitter->emit('\OC\User', 'postSetPassword', array($this, $password, $recoveryPassword)); |
|
| 268 | - } |
|
| 269 | - return !($result === false); |
|
| 270 | - } else { |
|
| 271 | - return false; |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * get the users home folder to mount |
|
| 277 | - * |
|
| 278 | - * @return string |
|
| 279 | - */ |
|
| 280 | - public function getHome() { |
|
| 281 | - if (!$this->home) { |
|
| 282 | - if ($this->backend->implementsActions(Backend::GET_HOME) and $home = $this->backend->getHome($this->uid)) { |
|
| 283 | - $this->home = $home; |
|
| 284 | - } elseif ($this->config) { |
|
| 285 | - $this->home = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $this->uid; |
|
| 286 | - } else { |
|
| 287 | - $this->home = \OC::$SERVERROOT . '/data/' . $this->uid; |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - return $this->home; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * Get the name of the backend class the user is connected with |
|
| 295 | - * |
|
| 296 | - * @return string |
|
| 297 | - */ |
|
| 298 | - public function getBackendClassName() { |
|
| 299 | - if($this->backend instanceof IUserBackend) { |
|
| 300 | - return $this->backend->getBackendName(); |
|
| 301 | - } |
|
| 302 | - return get_class($this->backend); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - /** |
|
| 306 | - * check if the backend allows the user to change his avatar on Personal page |
|
| 307 | - * |
|
| 308 | - * @return bool |
|
| 309 | - */ |
|
| 310 | - public function canChangeAvatar() { |
|
| 311 | - if ($this->backend->implementsActions(Backend::PROVIDE_AVATAR)) { |
|
| 312 | - return $this->backend->canChangeAvatar($this->uid); |
|
| 313 | - } |
|
| 314 | - return true; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * check if the backend supports changing passwords |
|
| 319 | - * |
|
| 320 | - * @return bool |
|
| 321 | - */ |
|
| 322 | - public function canChangePassword() { |
|
| 323 | - return $this->backend->implementsActions(Backend::SET_PASSWORD); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * check if the backend supports changing display names |
|
| 328 | - * |
|
| 329 | - * @return bool |
|
| 330 | - */ |
|
| 331 | - public function canChangeDisplayName() { |
|
| 332 | - if ($this->config->getSystemValue('allow_user_to_change_display_name') === false) { |
|
| 333 | - return false; |
|
| 334 | - } |
|
| 335 | - return $this->backend->implementsActions(Backend::SET_DISPLAYNAME); |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - /** |
|
| 339 | - * check if the user is enabled |
|
| 340 | - * |
|
| 341 | - * @return bool |
|
| 342 | - */ |
|
| 343 | - public function isEnabled() { |
|
| 344 | - return $this->enabled; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * set the enabled status for the user |
|
| 349 | - * |
|
| 350 | - * @param bool $enabled |
|
| 351 | - */ |
|
| 352 | - public function setEnabled(bool $enabled = true) { |
|
| 353 | - $oldStatus = $this->isEnabled(); |
|
| 354 | - $this->enabled = $enabled; |
|
| 355 | - if ($oldStatus !== $this->enabled) { |
|
| 356 | - $this->triggerChange('enabled', $enabled); |
|
| 357 | - $this->config->setUserValue($this->uid, 'core', 'enabled', $enabled ? 'true' : 'false'); |
|
| 358 | - } |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * get the users email address |
|
| 363 | - * |
|
| 364 | - * @return string|null |
|
| 365 | - * @since 9.0.0 |
|
| 366 | - */ |
|
| 367 | - public function getEMailAddress() { |
|
| 368 | - return $this->config->getUserValue($this->uid, 'settings', 'email', null); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - /** |
|
| 372 | - * get the users' quota |
|
| 373 | - * |
|
| 374 | - * @return string |
|
| 375 | - * @since 9.0.0 |
|
| 376 | - */ |
|
| 377 | - public function getQuota() { |
|
| 378 | - $quota = $this->config->getUserValue($this->uid, 'files', 'quota', 'default'); |
|
| 379 | - if($quota === 'default') { |
|
| 380 | - $quota = $this->config->getAppValue('files', 'default_quota', 'none'); |
|
| 381 | - } |
|
| 382 | - return $quota; |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * set the users' quota |
|
| 387 | - * |
|
| 388 | - * @param string $quota |
|
| 389 | - * @return void |
|
| 390 | - * @since 9.0.0 |
|
| 391 | - */ |
|
| 392 | - public function setQuota($quota) { |
|
| 393 | - $oldQuota = $this->config->getUserValue($this->uid, 'files', 'quota', ''); |
|
| 394 | - if($quota !== 'none' and $quota !== 'default') { |
|
| 395 | - $quota = OC_Helper::computerFileSize($quota); |
|
| 396 | - $quota = OC_Helper::humanFileSize($quota); |
|
| 397 | - } |
|
| 398 | - $this->config->setUserValue($this->uid, 'files', 'quota', $quota); |
|
| 399 | - if($quota !== $oldQuota) { |
|
| 400 | - $this->triggerChange('quota', $quota); |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * get the avatar image if it exists |
|
| 406 | - * |
|
| 407 | - * @param int $size |
|
| 408 | - * @return IImage|null |
|
| 409 | - * @since 9.0.0 |
|
| 410 | - */ |
|
| 411 | - public function getAvatarImage($size) { |
|
| 412 | - // delay the initialization |
|
| 413 | - if (is_null($this->avatarManager)) { |
|
| 414 | - $this->avatarManager = \OC::$server->getAvatarManager(); |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - $avatar = $this->avatarManager->getAvatar($this->uid); |
|
| 418 | - $image = $avatar->get(-1); |
|
| 419 | - if ($image) { |
|
| 420 | - return $image; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - return null; |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * get the federation cloud id |
|
| 428 | - * |
|
| 429 | - * @return string |
|
| 430 | - * @since 9.0.0 |
|
| 431 | - */ |
|
| 432 | - public function getCloudId() { |
|
| 433 | - $uid = $this->getUID(); |
|
| 434 | - $server = $this->urlGenerator->getAbsoluteURL('/'); |
|
| 435 | - $server = rtrim( $this->removeProtocolFromUrl($server), '/'); |
|
| 436 | - return \OC::$server->getCloudIdManager()->getCloudId($uid, $server)->getId(); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - /** |
|
| 440 | - * @param string $url |
|
| 441 | - * @return string |
|
| 442 | - */ |
|
| 443 | - private function removeProtocolFromUrl($url) { |
|
| 444 | - if (strpos($url, 'https://') === 0) { |
|
| 445 | - return substr($url, strlen('https://')); |
|
| 446 | - } else if (strpos($url, 'http://') === 0) { |
|
| 447 | - return substr($url, strlen('http://')); |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - return $url; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - public function triggerChange($feature, $value = null, $oldValue = null) { |
|
| 454 | - if ($this->emitter) { |
|
| 455 | - $this->emitter->emit('\OC\User', 'changeUser', array($this, $feature, $value, $oldValue)); |
|
| 456 | - } |
|
| 457 | - } |
|
| 47 | + /** @var string $uid */ |
|
| 48 | + private $uid; |
|
| 49 | + |
|
| 50 | + /** @var string $displayName */ |
|
| 51 | + private $displayName; |
|
| 52 | + |
|
| 53 | + /** @var UserInterface $backend */ |
|
| 54 | + private $backend; |
|
| 55 | + |
|
| 56 | + /** @var bool $enabled */ |
|
| 57 | + private $enabled; |
|
| 58 | + |
|
| 59 | + /** @var Emitter|Manager $emitter */ |
|
| 60 | + private $emitter; |
|
| 61 | + |
|
| 62 | + /** @var string $home */ |
|
| 63 | + private $home; |
|
| 64 | + |
|
| 65 | + /** @var int $lastLogin */ |
|
| 66 | + private $lastLogin; |
|
| 67 | + |
|
| 68 | + /** @var \OCP\IConfig $config */ |
|
| 69 | + private $config; |
|
| 70 | + |
|
| 71 | + /** @var IAvatarManager */ |
|
| 72 | + private $avatarManager; |
|
| 73 | + |
|
| 74 | + /** @var IURLGenerator */ |
|
| 75 | + private $urlGenerator; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @param string $uid |
|
| 79 | + * @param UserInterface $backend |
|
| 80 | + * @param \OC\Hooks\Emitter $emitter |
|
| 81 | + * @param IConfig|null $config |
|
| 82 | + * @param IURLGenerator $urlGenerator |
|
| 83 | + */ |
|
| 84 | + public function __construct($uid, $backend, $emitter = null, IConfig $config = null, $urlGenerator = null) { |
|
| 85 | + $this->uid = $uid; |
|
| 86 | + $this->backend = $backend; |
|
| 87 | + $this->emitter = $emitter; |
|
| 88 | + if(is_null($config)) { |
|
| 89 | + $config = \OC::$server->getConfig(); |
|
| 90 | + } |
|
| 91 | + $this->config = $config; |
|
| 92 | + $this->urlGenerator = $urlGenerator; |
|
| 93 | + $enabled = $this->config->getUserValue($uid, 'core', 'enabled', 'true'); |
|
| 94 | + $this->enabled = ($enabled === 'true'); |
|
| 95 | + $this->lastLogin = $this->config->getUserValue($uid, 'login', 'lastLogin', 0); |
|
| 96 | + if (is_null($this->urlGenerator)) { |
|
| 97 | + $this->urlGenerator = \OC::$server->getURLGenerator(); |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * get the user id |
|
| 103 | + * |
|
| 104 | + * @return string |
|
| 105 | + */ |
|
| 106 | + public function getUID() { |
|
| 107 | + return $this->uid; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * get the display name for the user, if no specific display name is set it will fallback to the user id |
|
| 112 | + * |
|
| 113 | + * @return string |
|
| 114 | + */ |
|
| 115 | + public function getDisplayName() { |
|
| 116 | + if (!isset($this->displayName)) { |
|
| 117 | + $displayName = ''; |
|
| 118 | + if ($this->backend and $this->backend->implementsActions(Backend::GET_DISPLAYNAME)) { |
|
| 119 | + // get display name and strip whitespace from the beginning and end of it |
|
| 120 | + $backendDisplayName = $this->backend->getDisplayName($this->uid); |
|
| 121 | + if (is_string($backendDisplayName)) { |
|
| 122 | + $displayName = trim($backendDisplayName); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + if (!empty($displayName)) { |
|
| 127 | + $this->displayName = $displayName; |
|
| 128 | + } else { |
|
| 129 | + $this->displayName = $this->uid; |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + return $this->displayName; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * set the displayname for the user |
|
| 137 | + * |
|
| 138 | + * @param string $displayName |
|
| 139 | + * @return bool |
|
| 140 | + */ |
|
| 141 | + public function setDisplayName($displayName) { |
|
| 142 | + $displayName = trim($displayName); |
|
| 143 | + if ($this->backend->implementsActions(Backend::SET_DISPLAYNAME) && !empty($displayName)) { |
|
| 144 | + $result = $this->backend->setDisplayName($this->uid, $displayName); |
|
| 145 | + if ($result) { |
|
| 146 | + $this->displayName = $displayName; |
|
| 147 | + $this->triggerChange('displayName', $displayName); |
|
| 148 | + } |
|
| 149 | + return $result !== false; |
|
| 150 | + } else { |
|
| 151 | + return false; |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * set the email address of the user |
|
| 157 | + * |
|
| 158 | + * @param string|null $mailAddress |
|
| 159 | + * @return void |
|
| 160 | + * @since 9.0.0 |
|
| 161 | + */ |
|
| 162 | + public function setEMailAddress($mailAddress) { |
|
| 163 | + $oldMailAddress = $this->getEMailAddress(); |
|
| 164 | + if($mailAddress === '') { |
|
| 165 | + $this->config->deleteUserValue($this->uid, 'settings', 'email'); |
|
| 166 | + } else { |
|
| 167 | + $this->config->setUserValue($this->uid, 'settings', 'email', $mailAddress); |
|
| 168 | + } |
|
| 169 | + if($oldMailAddress !== $mailAddress) { |
|
| 170 | + $this->triggerChange('eMailAddress', $mailAddress, $oldMailAddress); |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * returns the timestamp of the user's last login or 0 if the user did never |
|
| 176 | + * login |
|
| 177 | + * |
|
| 178 | + * @return int |
|
| 179 | + */ |
|
| 180 | + public function getLastLogin() { |
|
| 181 | + return $this->lastLogin; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * updates the timestamp of the most recent login of this user |
|
| 186 | + */ |
|
| 187 | + public function updateLastLoginTimestamp() { |
|
| 188 | + $firstTimeLogin = ($this->lastLogin === 0); |
|
| 189 | + $this->lastLogin = time(); |
|
| 190 | + $this->config->setUserValue( |
|
| 191 | + $this->uid, 'login', 'lastLogin', $this->lastLogin); |
|
| 192 | + |
|
| 193 | + return $firstTimeLogin; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * Delete the user |
|
| 198 | + * |
|
| 199 | + * @return bool |
|
| 200 | + */ |
|
| 201 | + public function delete() { |
|
| 202 | + if ($this->emitter) { |
|
| 203 | + $this->emitter->emit('\OC\User', 'preDelete', array($this)); |
|
| 204 | + } |
|
| 205 | + // get the home now because it won't return it after user deletion |
|
| 206 | + $homePath = $this->getHome(); |
|
| 207 | + $result = $this->backend->deleteUser($this->uid); |
|
| 208 | + if ($result) { |
|
| 209 | + |
|
| 210 | + // FIXME: Feels like an hack - suggestions? |
|
| 211 | + |
|
| 212 | + $groupManager = \OC::$server->getGroupManager(); |
|
| 213 | + // We have to delete the user from all groups |
|
| 214 | + foreach ($groupManager->getUserGroupIds($this) as $groupId) { |
|
| 215 | + $group = $groupManager->get($groupId); |
|
| 216 | + if ($group) { |
|
| 217 | + \OC_Hook::emit("OC_Group", "pre_removeFromGroup", ["run" => true, "uid" => $this->uid, "gid" => $groupId]); |
|
| 218 | + $group->removeUser($this); |
|
| 219 | + \OC_Hook::emit("OC_User", "post_removeFromGroup", ["uid" => $this->uid, "gid" => $groupId]); |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + // Delete the user's keys in preferences |
|
| 223 | + \OC::$server->getConfig()->deleteAllUserValues($this->uid); |
|
| 224 | + |
|
| 225 | + // Delete user files in /data/ |
|
| 226 | + if ($homePath !== false) { |
|
| 227 | + // FIXME: this operates directly on FS, should use View instead... |
|
| 228 | + // also this is not testable/mockable... |
|
| 229 | + \OC_Helper::rmdirr($homePath); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + // Delete the users entry in the storage table |
|
| 233 | + Storage::remove('home::' . $this->uid); |
|
| 234 | + |
|
| 235 | + \OC::$server->getCommentsManager()->deleteReferencesOfActor('users', $this->uid); |
|
| 236 | + \OC::$server->getCommentsManager()->deleteReadMarksFromUser($this); |
|
| 237 | + |
|
| 238 | + $notification = \OC::$server->getNotificationManager()->createNotification(); |
|
| 239 | + $notification->setUser($this->uid); |
|
| 240 | + \OC::$server->getNotificationManager()->markProcessed($notification); |
|
| 241 | + |
|
| 242 | + /** @var AccountManager $accountManager */ |
|
| 243 | + $accountManager = \OC::$server->query(AccountManager::class); |
|
| 244 | + $accountManager->deleteUser($this); |
|
| 245 | + |
|
| 246 | + if ($this->emitter) { |
|
| 247 | + $this->emitter->emit('\OC\User', 'postDelete', array($this)); |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + return !($result === false); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + /** |
|
| 254 | + * Set the password of the user |
|
| 255 | + * |
|
| 256 | + * @param string $password |
|
| 257 | + * @param string $recoveryPassword for the encryption app to reset encryption keys |
|
| 258 | + * @return bool |
|
| 259 | + */ |
|
| 260 | + public function setPassword($password, $recoveryPassword = null) { |
|
| 261 | + if ($this->emitter) { |
|
| 262 | + $this->emitter->emit('\OC\User', 'preSetPassword', array($this, $password, $recoveryPassword)); |
|
| 263 | + } |
|
| 264 | + if ($this->backend->implementsActions(Backend::SET_PASSWORD)) { |
|
| 265 | + $result = $this->backend->setPassword($this->uid, $password); |
|
| 266 | + if ($this->emitter) { |
|
| 267 | + $this->emitter->emit('\OC\User', 'postSetPassword', array($this, $password, $recoveryPassword)); |
|
| 268 | + } |
|
| 269 | + return !($result === false); |
|
| 270 | + } else { |
|
| 271 | + return false; |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * get the users home folder to mount |
|
| 277 | + * |
|
| 278 | + * @return string |
|
| 279 | + */ |
|
| 280 | + public function getHome() { |
|
| 281 | + if (!$this->home) { |
|
| 282 | + if ($this->backend->implementsActions(Backend::GET_HOME) and $home = $this->backend->getHome($this->uid)) { |
|
| 283 | + $this->home = $home; |
|
| 284 | + } elseif ($this->config) { |
|
| 285 | + $this->home = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/' . $this->uid; |
|
| 286 | + } else { |
|
| 287 | + $this->home = \OC::$SERVERROOT . '/data/' . $this->uid; |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + return $this->home; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * Get the name of the backend class the user is connected with |
|
| 295 | + * |
|
| 296 | + * @return string |
|
| 297 | + */ |
|
| 298 | + public function getBackendClassName() { |
|
| 299 | + if($this->backend instanceof IUserBackend) { |
|
| 300 | + return $this->backend->getBackendName(); |
|
| 301 | + } |
|
| 302 | + return get_class($this->backend); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + /** |
|
| 306 | + * check if the backend allows the user to change his avatar on Personal page |
|
| 307 | + * |
|
| 308 | + * @return bool |
|
| 309 | + */ |
|
| 310 | + public function canChangeAvatar() { |
|
| 311 | + if ($this->backend->implementsActions(Backend::PROVIDE_AVATAR)) { |
|
| 312 | + return $this->backend->canChangeAvatar($this->uid); |
|
| 313 | + } |
|
| 314 | + return true; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * check if the backend supports changing passwords |
|
| 319 | + * |
|
| 320 | + * @return bool |
|
| 321 | + */ |
|
| 322 | + public function canChangePassword() { |
|
| 323 | + return $this->backend->implementsActions(Backend::SET_PASSWORD); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * check if the backend supports changing display names |
|
| 328 | + * |
|
| 329 | + * @return bool |
|
| 330 | + */ |
|
| 331 | + public function canChangeDisplayName() { |
|
| 332 | + if ($this->config->getSystemValue('allow_user_to_change_display_name') === false) { |
|
| 333 | + return false; |
|
| 334 | + } |
|
| 335 | + return $this->backend->implementsActions(Backend::SET_DISPLAYNAME); |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + /** |
|
| 339 | + * check if the user is enabled |
|
| 340 | + * |
|
| 341 | + * @return bool |
|
| 342 | + */ |
|
| 343 | + public function isEnabled() { |
|
| 344 | + return $this->enabled; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * set the enabled status for the user |
|
| 349 | + * |
|
| 350 | + * @param bool $enabled |
|
| 351 | + */ |
|
| 352 | + public function setEnabled(bool $enabled = true) { |
|
| 353 | + $oldStatus = $this->isEnabled(); |
|
| 354 | + $this->enabled = $enabled; |
|
| 355 | + if ($oldStatus !== $this->enabled) { |
|
| 356 | + $this->triggerChange('enabled', $enabled); |
|
| 357 | + $this->config->setUserValue($this->uid, 'core', 'enabled', $enabled ? 'true' : 'false'); |
|
| 358 | + } |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * get the users email address |
|
| 363 | + * |
|
| 364 | + * @return string|null |
|
| 365 | + * @since 9.0.0 |
|
| 366 | + */ |
|
| 367 | + public function getEMailAddress() { |
|
| 368 | + return $this->config->getUserValue($this->uid, 'settings', 'email', null); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + /** |
|
| 372 | + * get the users' quota |
|
| 373 | + * |
|
| 374 | + * @return string |
|
| 375 | + * @since 9.0.0 |
|
| 376 | + */ |
|
| 377 | + public function getQuota() { |
|
| 378 | + $quota = $this->config->getUserValue($this->uid, 'files', 'quota', 'default'); |
|
| 379 | + if($quota === 'default') { |
|
| 380 | + $quota = $this->config->getAppValue('files', 'default_quota', 'none'); |
|
| 381 | + } |
|
| 382 | + return $quota; |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * set the users' quota |
|
| 387 | + * |
|
| 388 | + * @param string $quota |
|
| 389 | + * @return void |
|
| 390 | + * @since 9.0.0 |
|
| 391 | + */ |
|
| 392 | + public function setQuota($quota) { |
|
| 393 | + $oldQuota = $this->config->getUserValue($this->uid, 'files', 'quota', ''); |
|
| 394 | + if($quota !== 'none' and $quota !== 'default') { |
|
| 395 | + $quota = OC_Helper::computerFileSize($quota); |
|
| 396 | + $quota = OC_Helper::humanFileSize($quota); |
|
| 397 | + } |
|
| 398 | + $this->config->setUserValue($this->uid, 'files', 'quota', $quota); |
|
| 399 | + if($quota !== $oldQuota) { |
|
| 400 | + $this->triggerChange('quota', $quota); |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * get the avatar image if it exists |
|
| 406 | + * |
|
| 407 | + * @param int $size |
|
| 408 | + * @return IImage|null |
|
| 409 | + * @since 9.0.0 |
|
| 410 | + */ |
|
| 411 | + public function getAvatarImage($size) { |
|
| 412 | + // delay the initialization |
|
| 413 | + if (is_null($this->avatarManager)) { |
|
| 414 | + $this->avatarManager = \OC::$server->getAvatarManager(); |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + $avatar = $this->avatarManager->getAvatar($this->uid); |
|
| 418 | + $image = $avatar->get(-1); |
|
| 419 | + if ($image) { |
|
| 420 | + return $image; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + return null; |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * get the federation cloud id |
|
| 428 | + * |
|
| 429 | + * @return string |
|
| 430 | + * @since 9.0.0 |
|
| 431 | + */ |
|
| 432 | + public function getCloudId() { |
|
| 433 | + $uid = $this->getUID(); |
|
| 434 | + $server = $this->urlGenerator->getAbsoluteURL('/'); |
|
| 435 | + $server = rtrim( $this->removeProtocolFromUrl($server), '/'); |
|
| 436 | + return \OC::$server->getCloudIdManager()->getCloudId($uid, $server)->getId(); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + /** |
|
| 440 | + * @param string $url |
|
| 441 | + * @return string |
|
| 442 | + */ |
|
| 443 | + private function removeProtocolFromUrl($url) { |
|
| 444 | + if (strpos($url, 'https://') === 0) { |
|
| 445 | + return substr($url, strlen('https://')); |
|
| 446 | + } else if (strpos($url, 'http://') === 0) { |
|
| 447 | + return substr($url, strlen('http://')); |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + return $url; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + public function triggerChange($feature, $value = null, $oldValue = null) { |
|
| 454 | + if ($this->emitter) { |
|
| 455 | + $this->emitter->emit('\OC\User', 'changeUser', array($this, $feature, $value, $oldValue)); |
|
| 456 | + } |
|
| 457 | + } |
|
| 458 | 458 | } |
@@ -32,72 +32,72 @@ |
||
| 32 | 32 | |
| 33 | 33 | class Personal implements ISettings { |
| 34 | 34 | |
| 35 | - /** @var IManager */ |
|
| 36 | - private $encryptionManager; |
|
| 35 | + /** @var IManager */ |
|
| 36 | + private $encryptionManager; |
|
| 37 | 37 | |
| 38 | - /** @var UserGlobalStoragesService */ |
|
| 39 | - private $userGlobalStoragesService; |
|
| 38 | + /** @var UserGlobalStoragesService */ |
|
| 39 | + private $userGlobalStoragesService; |
|
| 40 | 40 | |
| 41 | - /** @var BackendService */ |
|
| 42 | - private $backendService; |
|
| 41 | + /** @var BackendService */ |
|
| 42 | + private $backendService; |
|
| 43 | 43 | |
| 44 | - /** @var GlobalAuth */ |
|
| 45 | - private $globalAuth; |
|
| 44 | + /** @var GlobalAuth */ |
|
| 45 | + private $globalAuth; |
|
| 46 | 46 | |
| 47 | - /** @var IUserSession */ |
|
| 48 | - private $userSession; |
|
| 47 | + /** @var IUserSession */ |
|
| 48 | + private $userSession; |
|
| 49 | 49 | |
| 50 | - public function __construct( |
|
| 51 | - IManager $encryptionManager, |
|
| 52 | - UserGlobalStoragesService $userGlobalStoragesService, |
|
| 53 | - BackendService $backendService, |
|
| 54 | - GlobalAuth $globalAuth, |
|
| 55 | - IUserSession $userSession |
|
| 56 | - ) { |
|
| 57 | - $this->encryptionManager = $encryptionManager; |
|
| 58 | - $this->userGlobalStoragesService = $userGlobalStoragesService; |
|
| 59 | - $this->backendService = $backendService; |
|
| 60 | - $this->globalAuth = $globalAuth; |
|
| 61 | - $this->userSession = $userSession; |
|
| 62 | - } |
|
| 50 | + public function __construct( |
|
| 51 | + IManager $encryptionManager, |
|
| 52 | + UserGlobalStoragesService $userGlobalStoragesService, |
|
| 53 | + BackendService $backendService, |
|
| 54 | + GlobalAuth $globalAuth, |
|
| 55 | + IUserSession $userSession |
|
| 56 | + ) { |
|
| 57 | + $this->encryptionManager = $encryptionManager; |
|
| 58 | + $this->userGlobalStoragesService = $userGlobalStoragesService; |
|
| 59 | + $this->backendService = $backendService; |
|
| 60 | + $this->globalAuth = $globalAuth; |
|
| 61 | + $this->userSession = $userSession; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @return TemplateResponse |
|
| 66 | - */ |
|
| 67 | - public function getForm() { |
|
| 68 | - $uid = $this->userSession->getUser()->getUID(); |
|
| 64 | + /** |
|
| 65 | + * @return TemplateResponse |
|
| 66 | + */ |
|
| 67 | + public function getForm() { |
|
| 68 | + $uid = $this->userSession->getUser()->getUID(); |
|
| 69 | 69 | |
| 70 | - $parameters = [ |
|
| 71 | - 'encryptionEnabled' => $this->encryptionManager->isEnabled(), |
|
| 72 | - 'visibilityType' => BackendService::VISIBILITY_PERSONAL, |
|
| 73 | - 'storages' => $this->userGlobalStoragesService->getStorages(), |
|
| 74 | - 'backends' => $this->backendService->getAvailableBackends(), |
|
| 75 | - 'authMechanisms' => $this->backendService->getAuthMechanisms(), |
|
| 76 | - 'dependencies' => \OC_Mount_Config::dependencyMessage($this->backendService->getBackends()), |
|
| 77 | - 'allowUserMounting' => $this->backendService->isUserMountingAllowed(), |
|
| 78 | - 'globalCredentials' => $this->globalAuth->getAuth($uid), |
|
| 79 | - 'globalCredentialsUid' => $uid, |
|
| 80 | - ]; |
|
| 70 | + $parameters = [ |
|
| 71 | + 'encryptionEnabled' => $this->encryptionManager->isEnabled(), |
|
| 72 | + 'visibilityType' => BackendService::VISIBILITY_PERSONAL, |
|
| 73 | + 'storages' => $this->userGlobalStoragesService->getStorages(), |
|
| 74 | + 'backends' => $this->backendService->getAvailableBackends(), |
|
| 75 | + 'authMechanisms' => $this->backendService->getAuthMechanisms(), |
|
| 76 | + 'dependencies' => \OC_Mount_Config::dependencyMessage($this->backendService->getBackends()), |
|
| 77 | + 'allowUserMounting' => $this->backendService->isUserMountingAllowed(), |
|
| 78 | + 'globalCredentials' => $this->globalAuth->getAuth($uid), |
|
| 79 | + 'globalCredentialsUid' => $uid, |
|
| 80 | + ]; |
|
| 81 | 81 | |
| 82 | - return new TemplateResponse('files_external', 'settings', $parameters, ''); |
|
| 83 | - } |
|
| 82 | + return new TemplateResponse('files_external', 'settings', $parameters, ''); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * @return string the section ID, e.g. 'sharing' |
|
| 87 | - */ |
|
| 88 | - public function getSection() { |
|
| 89 | - return 'externalstorages'; |
|
| 90 | - } |
|
| 85 | + /** |
|
| 86 | + * @return string the section ID, e.g. 'sharing' |
|
| 87 | + */ |
|
| 88 | + public function getSection() { |
|
| 89 | + return 'externalstorages'; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * @return int whether the form should be rather on the top or bottom of |
|
| 94 | - * the admin section. The forms are arranged in ascending order of the |
|
| 95 | - * priority values. It is required to return a value between 0 and 100. |
|
| 96 | - * |
|
| 97 | - * E.g.: 70 |
|
| 98 | - */ |
|
| 99 | - public function getPriority() { |
|
| 100 | - return 40; |
|
| 101 | - } |
|
| 92 | + /** |
|
| 93 | + * @return int whether the form should be rather on the top or bottom of |
|
| 94 | + * the admin section. The forms are arranged in ascending order of the |
|
| 95 | + * priority values. It is required to return a value between 0 and 100. |
|
| 96 | + * |
|
| 97 | + * E.g.: 70 |
|
| 98 | + */ |
|
| 99 | + public function getPriority() { |
|
| 100 | + return 40; |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | 103 | } |
@@ -29,13 +29,13 @@ |
||
| 29 | 29 | |
| 30 | 30 | OC::$CLASSPATH['OC_Mount_Config'] = 'files_external/lib/config.php'; |
| 31 | 31 | |
| 32 | -require_once __DIR__ . '/../3rdparty/autoload.php'; |
|
| 32 | +require_once __DIR__.'/../3rdparty/autoload.php'; |
|
| 33 | 33 | |
| 34 | 34 | // register Application object singleton |
| 35 | 35 | \OC_Mount_Config::$app = new \OCA\Files_External\AppInfo\Application(); |
| 36 | 36 | $appContainer = \OC_Mount_Config::$app->getContainer(); |
| 37 | 37 | |
| 38 | -\OCA\Files\App::getNavigationManager()->add(function () { |
|
| 38 | +\OCA\Files\App::getNavigationManager()->add(function() { |
|
| 39 | 39 | $l = \OC::$server->getL10N('files_external'); |
| 40 | 40 | return [ |
| 41 | 41 | 'id' => 'extstoragemounts', |
@@ -37,14 +37,14 @@ |
||
| 37 | 37 | $appContainer = \OC_Mount_Config::$app->getContainer(); |
| 38 | 38 | |
| 39 | 39 | \OCA\Files\App::getNavigationManager()->add(function () { |
| 40 | - $l = \OC::$server->getL10N('files_external'); |
|
| 41 | - return [ |
|
| 42 | - 'id' => 'extstoragemounts', |
|
| 43 | - 'appname' => 'files_external', |
|
| 44 | - 'script' => 'list.php', |
|
| 45 | - 'order' => 30, |
|
| 46 | - 'name' => $l->t('External storages'), |
|
| 47 | - ]; |
|
| 40 | + $l = \OC::$server->getL10N('files_external'); |
|
| 41 | + return [ |
|
| 42 | + 'id' => 'extstoragemounts', |
|
| 43 | + 'appname' => 'files_external', |
|
| 44 | + 'script' => 'list.php', |
|
| 45 | + 'order' => 30, |
|
| 46 | + 'name' => $l->t('External storages'), |
|
| 47 | + ]; |
|
| 48 | 48 | }); |
| 49 | 49 | |
| 50 | 50 | $mountProvider = $appContainer->query(ConfigAdapter::class); |
@@ -78,7 +78,7 @@ |
||
| 78 | 78 | $olderVersions = $ms->getMigratedVersions(); |
| 79 | 79 | $olderVersions[] = '0'; |
| 80 | 80 | $olderVersions[] = 'prev'; |
| 81 | - if (in_array($version, $olderVersions, true)) { |
|
| 81 | + if (in_array($version, $olderVersions, true)) { |
|
| 82 | 82 | $output->writeln('<error>Can not go back to previous migration without debug enabled</error>'); |
| 83 | 83 | return 1; |
| 84 | 84 | } |
@@ -38,95 +38,95 @@ |
||
| 38 | 38 | |
| 39 | 39 | class ExecuteCommand extends Command implements CompletionAwareInterface { |
| 40 | 40 | |
| 41 | - /** @var IDBConnection */ |
|
| 42 | - private $connection; |
|
| 43 | - |
|
| 44 | - /** @var IConfig */ |
|
| 45 | - private $config; |
|
| 46 | - |
|
| 47 | - /** @var IAppManager */ |
|
| 48 | - protected $appManager; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * ExecuteCommand constructor. |
|
| 52 | - * |
|
| 53 | - * @param IDBConnection $connection |
|
| 54 | - * @param IConfig $config |
|
| 55 | - * @param IAppManager $appManager |
|
| 56 | - */ |
|
| 57 | - public function __construct(IDBConnection $connection, IAppManager $appManager, IConfig $config) { |
|
| 58 | - $this->connection = $connection; |
|
| 59 | - $this->config = $config; |
|
| 60 | - |
|
| 61 | - parent::__construct(); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - protected function configure() { |
|
| 65 | - $this |
|
| 66 | - ->setName('migrations:execute') |
|
| 67 | - ->setDescription('Execute a single migration version manually.') |
|
| 68 | - ->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on') |
|
| 69 | - ->addArgument('version', InputArgument::REQUIRED, 'The version to execute.', null); |
|
| 70 | - |
|
| 71 | - parent::configure(); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @param InputInterface $input |
|
| 76 | - * @param OutputInterface $output |
|
| 77 | - * @return int |
|
| 78 | - */ |
|
| 79 | - public function execute(InputInterface $input, OutputInterface $output) { |
|
| 80 | - $appName = $input->getArgument('app'); |
|
| 81 | - $ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output)); |
|
| 82 | - $version = $input->getArgument('version'); |
|
| 83 | - |
|
| 84 | - if ($this->config->getSystemValue('debug', false) === false) { |
|
| 85 | - $olderVersions = $ms->getMigratedVersions(); |
|
| 86 | - $olderVersions[] = '0'; |
|
| 87 | - $olderVersions[] = 'prev'; |
|
| 88 | - if (in_array($version, $olderVersions, true)) { |
|
| 89 | - $output->writeln('<error>Can not go back to previous migration without debug enabled</error>'); |
|
| 90 | - return 1; |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - $ms->executeStep($version); |
|
| 96 | - return 0; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @param string $optionName |
|
| 101 | - * @param CompletionContext $context |
|
| 102 | - * @return string[] |
|
| 103 | - */ |
|
| 104 | - public function completeOptionValues($optionName, CompletionContext $context) { |
|
| 105 | - return []; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @param string $argumentName |
|
| 110 | - * @param CompletionContext $context |
|
| 111 | - * @return string[] |
|
| 112 | - */ |
|
| 113 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
| 114 | - if ($argumentName === 'app') { |
|
| 115 | - $allApps = \OC_App::getAllApps(); |
|
| 116 | - return array_diff($allApps, \OC_App::getEnabledApps(true, true)); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - if ($argumentName === 'version') { |
|
| 120 | - $appName = $context->getWordAtIndex($context->getWordIndex() - 1); |
|
| 121 | - |
|
| 122 | - $ms = new MigrationService($appName, $this->connection); |
|
| 123 | - $migrations = $ms->getAvailableVersions(); |
|
| 124 | - |
|
| 125 | - array_unshift($migrations, 'next', 'latest'); |
|
| 126 | - return $migrations; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - return []; |
|
| 130 | - } |
|
| 41 | + /** @var IDBConnection */ |
|
| 42 | + private $connection; |
|
| 43 | + |
|
| 44 | + /** @var IConfig */ |
|
| 45 | + private $config; |
|
| 46 | + |
|
| 47 | + /** @var IAppManager */ |
|
| 48 | + protected $appManager; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * ExecuteCommand constructor. |
|
| 52 | + * |
|
| 53 | + * @param IDBConnection $connection |
|
| 54 | + * @param IConfig $config |
|
| 55 | + * @param IAppManager $appManager |
|
| 56 | + */ |
|
| 57 | + public function __construct(IDBConnection $connection, IAppManager $appManager, IConfig $config) { |
|
| 58 | + $this->connection = $connection; |
|
| 59 | + $this->config = $config; |
|
| 60 | + |
|
| 61 | + parent::__construct(); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + protected function configure() { |
|
| 65 | + $this |
|
| 66 | + ->setName('migrations:execute') |
|
| 67 | + ->setDescription('Execute a single migration version manually.') |
|
| 68 | + ->addArgument('app', InputArgument::REQUIRED, 'Name of the app this migration command shall work on') |
|
| 69 | + ->addArgument('version', InputArgument::REQUIRED, 'The version to execute.', null); |
|
| 70 | + |
|
| 71 | + parent::configure(); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @param InputInterface $input |
|
| 76 | + * @param OutputInterface $output |
|
| 77 | + * @return int |
|
| 78 | + */ |
|
| 79 | + public function execute(InputInterface $input, OutputInterface $output) { |
|
| 80 | + $appName = $input->getArgument('app'); |
|
| 81 | + $ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output)); |
|
| 82 | + $version = $input->getArgument('version'); |
|
| 83 | + |
|
| 84 | + if ($this->config->getSystemValue('debug', false) === false) { |
|
| 85 | + $olderVersions = $ms->getMigratedVersions(); |
|
| 86 | + $olderVersions[] = '0'; |
|
| 87 | + $olderVersions[] = 'prev'; |
|
| 88 | + if (in_array($version, $olderVersions, true)) { |
|
| 89 | + $output->writeln('<error>Can not go back to previous migration without debug enabled</error>'); |
|
| 90 | + return 1; |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + $ms->executeStep($version); |
|
| 96 | + return 0; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @param string $optionName |
|
| 101 | + * @param CompletionContext $context |
|
| 102 | + * @return string[] |
|
| 103 | + */ |
|
| 104 | + public function completeOptionValues($optionName, CompletionContext $context) { |
|
| 105 | + return []; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @param string $argumentName |
|
| 110 | + * @param CompletionContext $context |
|
| 111 | + * @return string[] |
|
| 112 | + */ |
|
| 113 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
| 114 | + if ($argumentName === 'app') { |
|
| 115 | + $allApps = \OC_App::getAllApps(); |
|
| 116 | + return array_diff($allApps, \OC_App::getEnabledApps(true, true)); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + if ($argumentName === 'version') { |
|
| 120 | + $appName = $context->getWordAtIndex($context->getWordIndex() - 1); |
|
| 121 | + |
|
| 122 | + $ms = new MigrationService($appName, $this->connection); |
|
| 123 | + $migrations = $ms->getAvailableVersions(); |
|
| 124 | + |
|
| 125 | + array_unshift($migrations, 'next', 'latest'); |
|
| 126 | + return $migrations; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + return []; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | 132 | } |
@@ -26,80 +26,80 @@ |
||
| 26 | 26 | namespace OC\DB; |
| 27 | 27 | |
| 28 | 28 | class OracleConnection extends Connection { |
| 29 | - /** |
|
| 30 | - * Quote the keys of the array |
|
| 31 | - */ |
|
| 32 | - private function quoteKeys(array $data) { |
|
| 33 | - $return = []; |
|
| 34 | - $c = $this->getDatabasePlatform()->getIdentifierQuoteCharacter(); |
|
| 35 | - foreach($data as $key => $value) { |
|
| 36 | - if ($key[0] !== $c) { |
|
| 37 | - $return[$this->quoteIdentifier($key)] = $value; |
|
| 38 | - } else { |
|
| 39 | - $return[$key] = $value; |
|
| 40 | - } |
|
| 41 | - } |
|
| 42 | - return $return; |
|
| 43 | - } |
|
| 29 | + /** |
|
| 30 | + * Quote the keys of the array |
|
| 31 | + */ |
|
| 32 | + private function quoteKeys(array $data) { |
|
| 33 | + $return = []; |
|
| 34 | + $c = $this->getDatabasePlatform()->getIdentifierQuoteCharacter(); |
|
| 35 | + foreach($data as $key => $value) { |
|
| 36 | + if ($key[0] !== $c) { |
|
| 37 | + $return[$this->quoteIdentifier($key)] = $value; |
|
| 38 | + } else { |
|
| 39 | + $return[$key] = $value; |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | + return $return; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * {@inheritDoc} |
|
| 47 | - */ |
|
| 48 | - public function insert($tableName, array $data, array $types = array()) { |
|
| 49 | - if ($tableName[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
| 50 | - $tableName = $this->quoteIdentifier($tableName); |
|
| 51 | - } |
|
| 52 | - $data = $this->quoteKeys($data); |
|
| 53 | - return parent::insert($tableName, $data, $types); |
|
| 54 | - } |
|
| 45 | + /** |
|
| 46 | + * {@inheritDoc} |
|
| 47 | + */ |
|
| 48 | + public function insert($tableName, array $data, array $types = array()) { |
|
| 49 | + if ($tableName[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
| 50 | + $tableName = $this->quoteIdentifier($tableName); |
|
| 51 | + } |
|
| 52 | + $data = $this->quoteKeys($data); |
|
| 53 | + return parent::insert($tableName, $data, $types); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * {@inheritDoc} |
|
| 58 | - */ |
|
| 59 | - public function update($tableName, array $data, array $identifier, array $types = array()) { |
|
| 60 | - if ($tableName[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
| 61 | - $tableName = $this->quoteIdentifier($tableName); |
|
| 62 | - } |
|
| 63 | - $data = $this->quoteKeys($data); |
|
| 64 | - $identifier = $this->quoteKeys($identifier); |
|
| 65 | - return parent::update($tableName, $data, $identifier, $types); |
|
| 66 | - } |
|
| 56 | + /** |
|
| 57 | + * {@inheritDoc} |
|
| 58 | + */ |
|
| 59 | + public function update($tableName, array $data, array $identifier, array $types = array()) { |
|
| 60 | + if ($tableName[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
| 61 | + $tableName = $this->quoteIdentifier($tableName); |
|
| 62 | + } |
|
| 63 | + $data = $this->quoteKeys($data); |
|
| 64 | + $identifier = $this->quoteKeys($identifier); |
|
| 65 | + return parent::update($tableName, $data, $identifier, $types); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * {@inheritDoc} |
|
| 70 | - */ |
|
| 71 | - public function delete($tableExpression, array $identifier, array $types = array()) { |
|
| 72 | - if ($tableExpression[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
| 73 | - $tableExpression = $this->quoteIdentifier($tableExpression); |
|
| 74 | - } |
|
| 75 | - $identifier = $this->quoteKeys($identifier); |
|
| 76 | - return parent::delete($tableExpression, $identifier); |
|
| 77 | - } |
|
| 68 | + /** |
|
| 69 | + * {@inheritDoc} |
|
| 70 | + */ |
|
| 71 | + public function delete($tableExpression, array $identifier, array $types = array()) { |
|
| 72 | + if ($tableExpression[0] !== $this->getDatabasePlatform()->getIdentifierQuoteCharacter()) { |
|
| 73 | + $tableExpression = $this->quoteIdentifier($tableExpression); |
|
| 74 | + } |
|
| 75 | + $identifier = $this->quoteKeys($identifier); |
|
| 76 | + return parent::delete($tableExpression, $identifier); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Drop a table from the database if it exists |
|
| 81 | - * |
|
| 82 | - * @param string $table table name without the prefix |
|
| 83 | - */ |
|
| 84 | - public function dropTable($table) { |
|
| 85 | - $table = $this->tablePrefix . trim($table); |
|
| 86 | - $table = $this->quoteIdentifier($table); |
|
| 87 | - $schema = $this->getSchemaManager(); |
|
| 88 | - if($schema->tablesExist(array($table))) { |
|
| 89 | - $schema->dropTable($table); |
|
| 90 | - } |
|
| 91 | - } |
|
| 79 | + /** |
|
| 80 | + * Drop a table from the database if it exists |
|
| 81 | + * |
|
| 82 | + * @param string $table table name without the prefix |
|
| 83 | + */ |
|
| 84 | + public function dropTable($table) { |
|
| 85 | + $table = $this->tablePrefix . trim($table); |
|
| 86 | + $table = $this->quoteIdentifier($table); |
|
| 87 | + $schema = $this->getSchemaManager(); |
|
| 88 | + if($schema->tablesExist(array($table))) { |
|
| 89 | + $schema->dropTable($table); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * Check if a table exists |
|
| 95 | - * |
|
| 96 | - * @param string $table table name without the prefix |
|
| 97 | - * @return bool |
|
| 98 | - */ |
|
| 99 | - public function tableExists($table){ |
|
| 100 | - $table = $this->tablePrefix . trim($table); |
|
| 101 | - $table = $this->quoteIdentifier($table); |
|
| 102 | - $schema = $this->getSchemaManager(); |
|
| 103 | - return $schema->tablesExist(array($table)); |
|
| 104 | - } |
|
| 93 | + /** |
|
| 94 | + * Check if a table exists |
|
| 95 | + * |
|
| 96 | + * @param string $table table name without the prefix |
|
| 97 | + * @return bool |
|
| 98 | + */ |
|
| 99 | + public function tableExists($table){ |
|
| 100 | + $table = $this->tablePrefix . trim($table); |
|
| 101 | + $table = $this->quoteIdentifier($table); |
|
| 102 | + $schema = $this->getSchemaManager(); |
|
| 103 | + return $schema->tablesExist(array($table)); |
|
| 104 | + } |
|
| 105 | 105 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | private function quoteKeys(array $data) { |
| 33 | 33 | $return = []; |
| 34 | 34 | $c = $this->getDatabasePlatform()->getIdentifierQuoteCharacter(); |
| 35 | - foreach($data as $key => $value) { |
|
| 35 | + foreach ($data as $key => $value) { |
|
| 36 | 36 | if ($key[0] !== $c) { |
| 37 | 37 | $return[$this->quoteIdentifier($key)] = $value; |
| 38 | 38 | } else { |
@@ -82,10 +82,10 @@ discard block |
||
| 82 | 82 | * @param string $table table name without the prefix |
| 83 | 83 | */ |
| 84 | 84 | public function dropTable($table) { |
| 85 | - $table = $this->tablePrefix . trim($table); |
|
| 85 | + $table = $this->tablePrefix.trim($table); |
|
| 86 | 86 | $table = $this->quoteIdentifier($table); |
| 87 | 87 | $schema = $this->getSchemaManager(); |
| 88 | - if($schema->tablesExist(array($table))) { |
|
| 88 | + if ($schema->tablesExist(array($table))) { |
|
| 89 | 89 | $schema->dropTable($table); |
| 90 | 90 | } |
| 91 | 91 | } |
@@ -96,8 +96,8 @@ discard block |
||
| 96 | 96 | * @param string $table table name without the prefix |
| 97 | 97 | * @return bool |
| 98 | 98 | */ |
| 99 | - public function tableExists($table){ |
|
| 100 | - $table = $this->tablePrefix . trim($table); |
|
| 99 | + public function tableExists($table) { |
|
| 100 | + $table = $this->tablePrefix.trim($table); |
|
| 101 | 101 | $table = $this->quoteIdentifier($table); |
| 102 | 102 | $schema = $this->getSchemaManager(); |
| 103 | 103 | return $schema->tablesExist(array($table)); |
@@ -36,49 +36,49 @@ |
||
| 36 | 36 | */ |
| 37 | 37 | class SimpleOutput implements IOutput { |
| 38 | 38 | |
| 39 | - /** @var ILogger */ |
|
| 40 | - private $logger; |
|
| 41 | - private $appName; |
|
| 39 | + /** @var ILogger */ |
|
| 40 | + private $logger; |
|
| 41 | + private $appName; |
|
| 42 | 42 | |
| 43 | - public function __construct(ILogger $logger, $appName) { |
|
| 44 | - $this->logger = $logger; |
|
| 45 | - $this->appName = $appName; |
|
| 46 | - } |
|
| 43 | + public function __construct(ILogger $logger, $appName) { |
|
| 44 | + $this->logger = $logger; |
|
| 45 | + $this->appName = $appName; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @param string $message |
|
| 50 | - * @since 9.1.0 |
|
| 51 | - */ |
|
| 52 | - public function info($message) { |
|
| 53 | - $this->logger->info($message, ['app' => $this->appName]); |
|
| 54 | - } |
|
| 48 | + /** |
|
| 49 | + * @param string $message |
|
| 50 | + * @since 9.1.0 |
|
| 51 | + */ |
|
| 52 | + public function info($message) { |
|
| 53 | + $this->logger->info($message, ['app' => $this->appName]); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @param string $message |
|
| 58 | - * @since 9.1.0 |
|
| 59 | - */ |
|
| 60 | - public function warning($message) { |
|
| 61 | - $this->logger->warning($message, ['app' => $this->appName]); |
|
| 62 | - } |
|
| 56 | + /** |
|
| 57 | + * @param string $message |
|
| 58 | + * @since 9.1.0 |
|
| 59 | + */ |
|
| 60 | + public function warning($message) { |
|
| 61 | + $this->logger->warning($message, ['app' => $this->appName]); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @param int $max |
|
| 66 | - * @since 9.1.0 |
|
| 67 | - */ |
|
| 68 | - public function startProgress($max = 0) { |
|
| 69 | - } |
|
| 64 | + /** |
|
| 65 | + * @param int $max |
|
| 66 | + * @since 9.1.0 |
|
| 67 | + */ |
|
| 68 | + public function startProgress($max = 0) { |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @param int $step |
|
| 73 | - * @param string $description |
|
| 74 | - * @since 9.1.0 |
|
| 75 | - */ |
|
| 76 | - public function advance($step = 1, $description = '') { |
|
| 77 | - } |
|
| 71 | + /** |
|
| 72 | + * @param int $step |
|
| 73 | + * @param string $description |
|
| 74 | + * @since 9.1.0 |
|
| 75 | + */ |
|
| 76 | + public function advance($step = 1, $description = '') { |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * @since 9.1.0 |
|
| 81 | - */ |
|
| 82 | - public function finishProgress() { |
|
| 83 | - } |
|
| 79 | + /** |
|
| 80 | + * @since 9.1.0 |
|
| 81 | + */ |
|
| 82 | + public function finishProgress() { |
|
| 83 | + } |
|
| 84 | 84 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | * @throws \Doctrine\DBAL\Schema\SchemaException |
| 81 | 81 | */ |
| 82 | 82 | public function getTable($tableName) { |
| 83 | - return $this->schema->getTable($this->connection->getPrefix() . $tableName); |
|
| 83 | + return $this->schema->getTable($this->connection->getPrefix().$tableName); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * @return boolean |
| 92 | 92 | */ |
| 93 | 93 | public function hasTable($tableName) { |
| 94 | - return $this->schema->hasTable($this->connection->getPrefix() . $tableName); |
|
| 94 | + return $this->schema->hasTable($this->connection->getPrefix().$tableName); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | * @return \Doctrine\DBAL\Schema\Table |
| 102 | 102 | */ |
| 103 | 103 | public function createTable($tableName) { |
| 104 | - return $this->schema->createTable($this->connection->getPrefix() . $tableName); |
|
| 104 | + return $this->schema->createTable($this->connection->getPrefix().$tableName); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | */ |
| 126 | 126 | public function dropTable($tableName) { |
| 127 | 127 | $this->tablesToDelete[$tableName] = true; |
| 128 | - return $this->schema->dropTable($this->connection->getPrefix() . $tableName); |
|
| 128 | + return $this->schema->dropTable($this->connection->getPrefix().$tableName); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -30,107 +30,107 @@ |
||
| 30 | 30 | |
| 31 | 31 | class SchemaWrapper implements ISchemaWrapper { |
| 32 | 32 | |
| 33 | - /** @var IDBConnection|Connection */ |
|
| 34 | - protected $connection; |
|
| 35 | - |
|
| 36 | - /** @var Schema */ |
|
| 37 | - protected $schema; |
|
| 38 | - |
|
| 39 | - /** @var array */ |
|
| 40 | - protected $tablesToDelete = []; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @param IDBConnection $connection |
|
| 44 | - */ |
|
| 45 | - public function __construct(IDBConnection $connection) { |
|
| 46 | - $this->connection = $connection; |
|
| 47 | - $this->schema = $this->connection->createSchema(); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - public function getWrappedSchema() { |
|
| 51 | - return $this->schema; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - public function performDropTableCalls() { |
|
| 55 | - foreach ($this->tablesToDelete as $tableName => $true) { |
|
| 56 | - $this->connection->dropTable($tableName); |
|
| 57 | - unset($this->tablesToDelete[$tableName]); |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Gets all table names |
|
| 63 | - * |
|
| 64 | - * @return array |
|
| 65 | - */ |
|
| 66 | - public function getTableNamesWithoutPrefix() { |
|
| 67 | - $tableNames = $this->schema->getTableNames(); |
|
| 68 | - return array_map(function($tableName) { |
|
| 69 | - if (strpos($tableName, $this->connection->getPrefix()) === 0) { |
|
| 70 | - return substr($tableName, strlen($this->connection->getPrefix())); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return $tableName; |
|
| 74 | - }, $tableNames); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - // Overwritten methods |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * @return array |
|
| 81 | - */ |
|
| 82 | - public function getTableNames() { |
|
| 83 | - return $this->schema->getTableNames(); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @param string $tableName |
|
| 88 | - * |
|
| 89 | - * @return \Doctrine\DBAL\Schema\Table |
|
| 90 | - * @throws \Doctrine\DBAL\Schema\SchemaException |
|
| 91 | - */ |
|
| 92 | - public function getTable($tableName) { |
|
| 93 | - return $this->schema->getTable($this->connection->getPrefix() . $tableName); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Does this schema have a table with the given name? |
|
| 98 | - * |
|
| 99 | - * @param string $tableName |
|
| 100 | - * |
|
| 101 | - * @return boolean |
|
| 102 | - */ |
|
| 103 | - public function hasTable($tableName) { |
|
| 104 | - return $this->schema->hasTable($this->connection->getPrefix() . $tableName); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Creates a new table. |
|
| 109 | - * |
|
| 110 | - * @param string $tableName |
|
| 111 | - * @return \Doctrine\DBAL\Schema\Table |
|
| 112 | - */ |
|
| 113 | - public function createTable($tableName) { |
|
| 114 | - return $this->schema->createTable($this->connection->getPrefix() . $tableName); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Drops a table from the schema. |
|
| 119 | - * |
|
| 120 | - * @param string $tableName |
|
| 121 | - * @return \Doctrine\DBAL\Schema\Schema |
|
| 122 | - */ |
|
| 123 | - public function dropTable($tableName) { |
|
| 124 | - $this->tablesToDelete[$tableName] = true; |
|
| 125 | - return $this->schema->dropTable($this->connection->getPrefix() . $tableName); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Gets all tables of this schema. |
|
| 130 | - * |
|
| 131 | - * @return \Doctrine\DBAL\Schema\Table[] |
|
| 132 | - */ |
|
| 133 | - public function getTables() { |
|
| 134 | - return $this->schema->getTables(); |
|
| 135 | - } |
|
| 33 | + /** @var IDBConnection|Connection */ |
|
| 34 | + protected $connection; |
|
| 35 | + |
|
| 36 | + /** @var Schema */ |
|
| 37 | + protected $schema; |
|
| 38 | + |
|
| 39 | + /** @var array */ |
|
| 40 | + protected $tablesToDelete = []; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @param IDBConnection $connection |
|
| 44 | + */ |
|
| 45 | + public function __construct(IDBConnection $connection) { |
|
| 46 | + $this->connection = $connection; |
|
| 47 | + $this->schema = $this->connection->createSchema(); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + public function getWrappedSchema() { |
|
| 51 | + return $this->schema; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + public function performDropTableCalls() { |
|
| 55 | + foreach ($this->tablesToDelete as $tableName => $true) { |
|
| 56 | + $this->connection->dropTable($tableName); |
|
| 57 | + unset($this->tablesToDelete[$tableName]); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Gets all table names |
|
| 63 | + * |
|
| 64 | + * @return array |
|
| 65 | + */ |
|
| 66 | + public function getTableNamesWithoutPrefix() { |
|
| 67 | + $tableNames = $this->schema->getTableNames(); |
|
| 68 | + return array_map(function($tableName) { |
|
| 69 | + if (strpos($tableName, $this->connection->getPrefix()) === 0) { |
|
| 70 | + return substr($tableName, strlen($this->connection->getPrefix())); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return $tableName; |
|
| 74 | + }, $tableNames); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + // Overwritten methods |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * @return array |
|
| 81 | + */ |
|
| 82 | + public function getTableNames() { |
|
| 83 | + return $this->schema->getTableNames(); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @param string $tableName |
|
| 88 | + * |
|
| 89 | + * @return \Doctrine\DBAL\Schema\Table |
|
| 90 | + * @throws \Doctrine\DBAL\Schema\SchemaException |
|
| 91 | + */ |
|
| 92 | + public function getTable($tableName) { |
|
| 93 | + return $this->schema->getTable($this->connection->getPrefix() . $tableName); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Does this schema have a table with the given name? |
|
| 98 | + * |
|
| 99 | + * @param string $tableName |
|
| 100 | + * |
|
| 101 | + * @return boolean |
|
| 102 | + */ |
|
| 103 | + public function hasTable($tableName) { |
|
| 104 | + return $this->schema->hasTable($this->connection->getPrefix() . $tableName); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Creates a new table. |
|
| 109 | + * |
|
| 110 | + * @param string $tableName |
|
| 111 | + * @return \Doctrine\DBAL\Schema\Table |
|
| 112 | + */ |
|
| 113 | + public function createTable($tableName) { |
|
| 114 | + return $this->schema->createTable($this->connection->getPrefix() . $tableName); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Drops a table from the schema. |
|
| 119 | + * |
|
| 120 | + * @param string $tableName |
|
| 121 | + * @return \Doctrine\DBAL\Schema\Schema |
|
| 122 | + */ |
|
| 123 | + public function dropTable($tableName) { |
|
| 124 | + $this->tablesToDelete[$tableName] = true; |
|
| 125 | + return $this->schema->dropTable($this->connection->getPrefix() . $tableName); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Gets all tables of this schema. |
|
| 130 | + * |
|
| 131 | + * @return \Doctrine\DBAL\Schema\Table[] |
|
| 132 | + */ |
|
| 133 | + public function getTables() { |
|
| 134 | + return $this->schema->getTables(); |
|
| 135 | + } |
|
| 136 | 136 | } |