@@ -30,10 +30,10 @@ |
||
30 | 30 | use OCP\IConfig; |
31 | 31 | |
32 | 32 | class UUIDFixGroup extends UUIDFix { |
33 | - public function __construct(GroupMapping $mapper, LDAP $ldap, IConfig $config, Helper $helper) { |
|
34 | - $this->mapper = $mapper; |
|
35 | - $this->proxy = new User_Proxy($helper->getServerConfigurationPrefixes(true), $ldap, $config, |
|
36 | - \OC::$server->getNotificationManager(), \OC::$server->getUserSession(), |
|
37 | - \OC::$server->query('LDAPUserPluginManager')); |
|
38 | - } |
|
33 | + public function __construct(GroupMapping $mapper, LDAP $ldap, IConfig $config, Helper $helper) { |
|
34 | + $this->mapper = $mapper; |
|
35 | + $this->proxy = new User_Proxy($helper->getServerConfigurationPrefixes(true), $ldap, $config, |
|
36 | + \OC::$server->getNotificationManager(), \OC::$server->getUserSession(), |
|
37 | + \OC::$server->query('LDAPUserPluginManager')); |
|
38 | + } |
|
39 | 39 | } |
@@ -28,54 +28,54 @@ |
||
28 | 28 | use OCP\IServerContainer; |
29 | 29 | |
30 | 30 | class Manager implements IManager { |
31 | - /** @var string[] */ |
|
32 | - protected $sorters =[]; |
|
31 | + /** @var string[] */ |
|
32 | + protected $sorters =[]; |
|
33 | 33 | |
34 | - /** @var ISorter[] */ |
|
35 | - protected $sorterInstances = []; |
|
36 | - /** @var IServerContainer */ |
|
37 | - private $c; |
|
34 | + /** @var ISorter[] */ |
|
35 | + protected $sorterInstances = []; |
|
36 | + /** @var IServerContainer */ |
|
37 | + private $c; |
|
38 | 38 | |
39 | - public function __construct(IServerContainer $container) { |
|
40 | - $this->c = $container; |
|
41 | - } |
|
39 | + public function __construct(IServerContainer $container) { |
|
40 | + $this->c = $container; |
|
41 | + } |
|
42 | 42 | |
43 | - public function runSorters(array $sorters, array &$sortArray, array $context) { |
|
44 | - $sorterInstances = $this->getSorters(); |
|
45 | - while($sorter = array_shift($sorters)) { |
|
46 | - if(isset($sorterInstances[$sorter])) { |
|
47 | - $sorterInstances[$sorter]->sort($sortArray, $context); |
|
48 | - } else { |
|
49 | - $this->c->getLogger()->warning('No sorter for ID "{id}", skipping', [ |
|
50 | - 'app' => 'core', 'id' => $sorter |
|
51 | - ]); |
|
52 | - } |
|
53 | - } |
|
54 | - } |
|
43 | + public function runSorters(array $sorters, array &$sortArray, array $context) { |
|
44 | + $sorterInstances = $this->getSorters(); |
|
45 | + while($sorter = array_shift($sorters)) { |
|
46 | + if(isset($sorterInstances[$sorter])) { |
|
47 | + $sorterInstances[$sorter]->sort($sortArray, $context); |
|
48 | + } else { |
|
49 | + $this->c->getLogger()->warning('No sorter for ID "{id}", skipping', [ |
|
50 | + 'app' => 'core', 'id' => $sorter |
|
51 | + ]); |
|
52 | + } |
|
53 | + } |
|
54 | + } |
|
55 | 55 | |
56 | - public function registerSorter($className) { |
|
57 | - $this->sorters[] = $className; |
|
58 | - } |
|
56 | + public function registerSorter($className) { |
|
57 | + $this->sorters[] = $className; |
|
58 | + } |
|
59 | 59 | |
60 | - protected function getSorters() { |
|
61 | - if(count($this->sorterInstances) === 0) { |
|
62 | - foreach ($this->sorters as $sorter) { |
|
63 | - /** @var ISorter $instance */ |
|
64 | - $instance = $this->c->resolve($sorter); |
|
65 | - if(!$instance instanceof ISorter) { |
|
66 | - $this->c->getLogger()->notice('Skipping sorter which is not an instance of ISorter. Class name: {class}', |
|
67 | - ['app' => 'core', 'class' => $sorter]); |
|
68 | - continue; |
|
69 | - } |
|
70 | - $sorterId = trim($instance->getId()); |
|
71 | - if(trim($sorterId) === '') { |
|
72 | - $this->c->getLogger()->notice('Skipping sorter with empty ID. Class name: {class}', |
|
73 | - ['app' => 'core', 'class' => $sorter]); |
|
74 | - continue; |
|
75 | - } |
|
76 | - $this->sorterInstances[$sorterId] = $instance; |
|
77 | - } |
|
78 | - } |
|
79 | - return $this->sorterInstances; |
|
80 | - } |
|
60 | + protected function getSorters() { |
|
61 | + if(count($this->sorterInstances) === 0) { |
|
62 | + foreach ($this->sorters as $sorter) { |
|
63 | + /** @var ISorter $instance */ |
|
64 | + $instance = $this->c->resolve($sorter); |
|
65 | + if(!$instance instanceof ISorter) { |
|
66 | + $this->c->getLogger()->notice('Skipping sorter which is not an instance of ISorter. Class name: {class}', |
|
67 | + ['app' => 'core', 'class' => $sorter]); |
|
68 | + continue; |
|
69 | + } |
|
70 | + $sorterId = trim($instance->getId()); |
|
71 | + if(trim($sorterId) === '') { |
|
72 | + $this->c->getLogger()->notice('Skipping sorter with empty ID. Class name: {class}', |
|
73 | + ['app' => 'core', 'class' => $sorter]); |
|
74 | + continue; |
|
75 | + } |
|
76 | + $this->sorterInstances[$sorterId] = $instance; |
|
77 | + } |
|
78 | + } |
|
79 | + return $this->sorterInstances; |
|
80 | + } |
|
81 | 81 | } |
@@ -27,19 +27,19 @@ |
||
27 | 27 | use OCP\IServerContainer; |
28 | 28 | |
29 | 29 | class JSSettingsHelper { |
30 | - /** @var IServerContainer */ |
|
31 | - private $c; |
|
30 | + /** @var IServerContainer */ |
|
31 | + private $c; |
|
32 | 32 | |
33 | - public function __construct(IServerContainer $c) { |
|
34 | - $this->c = $c; |
|
35 | - } |
|
33 | + public function __construct(IServerContainer $c) { |
|
34 | + $this->c = $c; |
|
35 | + } |
|
36 | 36 | |
37 | - public function extend(array $settings) { |
|
38 | - $appConfig = json_decode($settings['array']['oc_appconfig'], true); |
|
37 | + public function extend(array $settings) { |
|
38 | + $appConfig = json_decode($settings['array']['oc_appconfig'], true); |
|
39 | 39 | |
40 | - $value = (int)$this->c->getConfig()->getAppValue('comments', 'maxAutoCompleteResults', 10); |
|
41 | - $appConfig['comments']['maxAutoCompleteResults'] = $value; |
|
40 | + $value = (int)$this->c->getConfig()->getAppValue('comments', 'maxAutoCompleteResults', 10); |
|
41 | + $appConfig['comments']['maxAutoCompleteResults'] = $value; |
|
42 | 42 | |
43 | - $settings['array']['oc_appconfig'] = json_encode($appConfig); |
|
44 | - } |
|
43 | + $settings['array']['oc_appconfig'] = json_encode($appConfig); |
|
44 | + } |
|
45 | 45 | } |
@@ -33,78 +33,78 @@ |
||
33 | 33 | |
34 | 34 | class ShareRecipientSorter implements ISorter { |
35 | 35 | |
36 | - /** @var IManager */ |
|
37 | - private $shareManager; |
|
38 | - /** @var Folder */ |
|
39 | - private $rootFolder; |
|
40 | - /** @var IUserSession */ |
|
41 | - private $userSession; |
|
36 | + /** @var IManager */ |
|
37 | + private $shareManager; |
|
38 | + /** @var Folder */ |
|
39 | + private $rootFolder; |
|
40 | + /** @var IUserSession */ |
|
41 | + private $userSession; |
|
42 | 42 | |
43 | - public function __construct(IManager $shareManager, IRootFolder $rootFolder, IUserSession $userSession) { |
|
44 | - $this->shareManager = $shareManager; |
|
45 | - $this->rootFolder = $rootFolder; |
|
46 | - $this->userSession = $userSession; |
|
47 | - } |
|
43 | + public function __construct(IManager $shareManager, IRootFolder $rootFolder, IUserSession $userSession) { |
|
44 | + $this->shareManager = $shareManager; |
|
45 | + $this->rootFolder = $rootFolder; |
|
46 | + $this->userSession = $userSession; |
|
47 | + } |
|
48 | 48 | |
49 | - public function getId() { |
|
50 | - return 'share-recipients'; |
|
51 | - } |
|
49 | + public function getId() { |
|
50 | + return 'share-recipients'; |
|
51 | + } |
|
52 | 52 | |
53 | - public function sort(array &$sortArray, array $context) { |
|
54 | - // let's be tolerant. Comments uses "files" by default, other usages are often singular |
|
55 | - if($context['itemType'] !== 'files' && $context['itemType'] !== 'file') { |
|
56 | - return; |
|
57 | - } |
|
58 | - $user = $this->userSession->getUser(); |
|
59 | - if($user === null) { |
|
60 | - return; |
|
61 | - } |
|
62 | - $userFolder = $this->rootFolder->getUserFolder($user->getUID()); |
|
63 | - /** @var Node[] $nodes */ |
|
64 | - $nodes = $userFolder->getById((int)$context['itemId']); |
|
65 | - if(count($nodes) === 0) { |
|
66 | - return; |
|
67 | - } |
|
68 | - $al = $this->shareManager->getAccessList($nodes[0]); |
|
53 | + public function sort(array &$sortArray, array $context) { |
|
54 | + // let's be tolerant. Comments uses "files" by default, other usages are often singular |
|
55 | + if($context['itemType'] !== 'files' && $context['itemType'] !== 'file') { |
|
56 | + return; |
|
57 | + } |
|
58 | + $user = $this->userSession->getUser(); |
|
59 | + if($user === null) { |
|
60 | + return; |
|
61 | + } |
|
62 | + $userFolder = $this->rootFolder->getUserFolder($user->getUID()); |
|
63 | + /** @var Node[] $nodes */ |
|
64 | + $nodes = $userFolder->getById((int)$context['itemId']); |
|
65 | + if(count($nodes) === 0) { |
|
66 | + return; |
|
67 | + } |
|
68 | + $al = $this->shareManager->getAccessList($nodes[0]); |
|
69 | 69 | |
70 | - foreach ($sortArray as $type => &$byType) { |
|
71 | - if(!isset($al[$type]) || !is_array($al[$type])) { |
|
72 | - continue; |
|
73 | - } |
|
70 | + foreach ($sortArray as $type => &$byType) { |
|
71 | + if(!isset($al[$type]) || !is_array($al[$type])) { |
|
72 | + continue; |
|
73 | + } |
|
74 | 74 | |
75 | - // at least on PHP 5.6 usort turned out to be not stable. So we add |
|
76 | - // the current index to the value and compare it on a draw |
|
77 | - $i = 0; |
|
78 | - $workArray = array_map(function($element) use (&$i) { |
|
79 | - return [$i++, $element]; |
|
80 | - }, $byType); |
|
75 | + // at least on PHP 5.6 usort turned out to be not stable. So we add |
|
76 | + // the current index to the value and compare it on a draw |
|
77 | + $i = 0; |
|
78 | + $workArray = array_map(function($element) use (&$i) { |
|
79 | + return [$i++, $element]; |
|
80 | + }, $byType); |
|
81 | 81 | |
82 | - usort($workArray, function ($a, $b) use ($al, $type) { |
|
83 | - $result = $this->compare($a[1], $b[1], $al[$type]); |
|
84 | - if($result === 0) { |
|
85 | - $result = $a[0] - $b[0]; |
|
86 | - } |
|
87 | - return $result; |
|
88 | - }); |
|
82 | + usort($workArray, function ($a, $b) use ($al, $type) { |
|
83 | + $result = $this->compare($a[1], $b[1], $al[$type]); |
|
84 | + if($result === 0) { |
|
85 | + $result = $a[0] - $b[0]; |
|
86 | + } |
|
87 | + return $result; |
|
88 | + }); |
|
89 | 89 | |
90 | - // and remove the index values again |
|
91 | - $byType = array_column($workArray, 1); |
|
92 | - } |
|
93 | - } |
|
90 | + // and remove the index values again |
|
91 | + $byType = array_column($workArray, 1); |
|
92 | + } |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * @param array $a |
|
97 | - * @param array $b |
|
98 | - * @param array $al |
|
99 | - * @return int |
|
100 | - */ |
|
101 | - protected function compare(array $a, array $b, array $al) { |
|
102 | - $a = $a['value']['shareWith']; |
|
103 | - $b = $b['value']['shareWith']; |
|
95 | + /** |
|
96 | + * @param array $a |
|
97 | + * @param array $b |
|
98 | + * @param array $al |
|
99 | + * @return int |
|
100 | + */ |
|
101 | + protected function compare(array $a, array $b, array $al) { |
|
102 | + $a = $a['value']['shareWith']; |
|
103 | + $b = $b['value']['shareWith']; |
|
104 | 104 | |
105 | - $valueA = (int)in_array($a, $al, true); |
|
106 | - $valueB = (int)in_array($b, $al, true); |
|
105 | + $valueA = (int)in_array($a, $al, true); |
|
106 | + $valueB = (int)in_array($b, $al, true); |
|
107 | 107 | |
108 | - return $valueB - $valueA; |
|
109 | - } |
|
108 | + return $valueB - $valueA; |
|
109 | + } |
|
110 | 110 | } |
@@ -29,87 +29,87 @@ |
||
29 | 29 | |
30 | 30 | class CommentersSorter implements ISorter { |
31 | 31 | |
32 | - /** @var ICommentsManager */ |
|
33 | - private $commentsManager; |
|
34 | - |
|
35 | - public function __construct(ICommentsManager $commentsManager) { |
|
36 | - $this->commentsManager = $commentsManager; |
|
37 | - } |
|
38 | - |
|
39 | - public function getId() { |
|
40 | - return 'commenters'; |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Sorts people who commented on the given item atop (descelating) of the |
|
45 | - * others |
|
46 | - * |
|
47 | - * @param array $sortArray |
|
48 | - * @param array $context |
|
49 | - */ |
|
50 | - public function sort(array &$sortArray, array $context) { |
|
51 | - $commenters = $this->retrieveCommentsInformation($context['itemType'], $context['itemId']); |
|
52 | - if(count($commenters) === 0) { |
|
53 | - return; |
|
54 | - } |
|
55 | - |
|
56 | - foreach ($sortArray as $type => &$byType) { |
|
57 | - if(!isset($commenters[$type])) { |
|
58 | - continue; |
|
59 | - } |
|
60 | - |
|
61 | - // at least on PHP 5.6 usort turned out to be not stable. So we add |
|
62 | - // the current index to the value and compare it on a draw |
|
63 | - $i = 0; |
|
64 | - $workArray = array_map(function($element) use (&$i) { |
|
65 | - return [$i++, $element]; |
|
66 | - }, $byType); |
|
67 | - |
|
68 | - usort($workArray, function ($a, $b) use ($commenters, $type) { |
|
69 | - $r = $this->compare($a[1], $b[1], $commenters[$type]); |
|
70 | - if($r === 0) { |
|
71 | - $r = $a[0] - $b[0]; |
|
72 | - } |
|
73 | - return $r; |
|
74 | - }); |
|
75 | - |
|
76 | - // and remove the index values again |
|
77 | - $byType = array_column($workArray, 1); |
|
78 | - } |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * @param $type |
|
83 | - * @param $id |
|
84 | - * @return array |
|
85 | - */ |
|
86 | - protected function retrieveCommentsInformation($type, $id) { |
|
87 | - $comments = $this->commentsManager->getForObject($type, $id); |
|
88 | - if(count($comments) === 0) { |
|
89 | - return []; |
|
90 | - } |
|
91 | - |
|
92 | - $actors = []; |
|
93 | - foreach ($comments as $comment) { |
|
94 | - if(!isset($actors[$comment->getActorType()])) { |
|
95 | - $actors[$comment->getActorType()] = []; |
|
96 | - } |
|
97 | - if(!isset($actors[$comment->getActorType()][$comment->getActorId()])) { |
|
98 | - $actors[$comment->getActorType()][$comment->getActorId()] = 1; |
|
99 | - } else { |
|
100 | - $actors[$comment->getActorType()][$comment->getActorId()]++; |
|
101 | - } |
|
102 | - } |
|
103 | - return $actors; |
|
104 | - } |
|
105 | - |
|
106 | - protected function compare(array $a, array $b, array $commenters) { |
|
107 | - $a = $a['value']['shareWith']; |
|
108 | - $b = $b['value']['shareWith']; |
|
109 | - |
|
110 | - $valueA = isset($commenters[$a]) ? $commenters[$a] : 0; |
|
111 | - $valueB = isset($commenters[$b]) ? $commenters[$b] : 0; |
|
112 | - |
|
113 | - return $valueB - $valueA; |
|
114 | - } |
|
32 | + /** @var ICommentsManager */ |
|
33 | + private $commentsManager; |
|
34 | + |
|
35 | + public function __construct(ICommentsManager $commentsManager) { |
|
36 | + $this->commentsManager = $commentsManager; |
|
37 | + } |
|
38 | + |
|
39 | + public function getId() { |
|
40 | + return 'commenters'; |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Sorts people who commented on the given item atop (descelating) of the |
|
45 | + * others |
|
46 | + * |
|
47 | + * @param array $sortArray |
|
48 | + * @param array $context |
|
49 | + */ |
|
50 | + public function sort(array &$sortArray, array $context) { |
|
51 | + $commenters = $this->retrieveCommentsInformation($context['itemType'], $context['itemId']); |
|
52 | + if(count($commenters) === 0) { |
|
53 | + return; |
|
54 | + } |
|
55 | + |
|
56 | + foreach ($sortArray as $type => &$byType) { |
|
57 | + if(!isset($commenters[$type])) { |
|
58 | + continue; |
|
59 | + } |
|
60 | + |
|
61 | + // at least on PHP 5.6 usort turned out to be not stable. So we add |
|
62 | + // the current index to the value and compare it on a draw |
|
63 | + $i = 0; |
|
64 | + $workArray = array_map(function($element) use (&$i) { |
|
65 | + return [$i++, $element]; |
|
66 | + }, $byType); |
|
67 | + |
|
68 | + usort($workArray, function ($a, $b) use ($commenters, $type) { |
|
69 | + $r = $this->compare($a[1], $b[1], $commenters[$type]); |
|
70 | + if($r === 0) { |
|
71 | + $r = $a[0] - $b[0]; |
|
72 | + } |
|
73 | + return $r; |
|
74 | + }); |
|
75 | + |
|
76 | + // and remove the index values again |
|
77 | + $byType = array_column($workArray, 1); |
|
78 | + } |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * @param $type |
|
83 | + * @param $id |
|
84 | + * @return array |
|
85 | + */ |
|
86 | + protected function retrieveCommentsInformation($type, $id) { |
|
87 | + $comments = $this->commentsManager->getForObject($type, $id); |
|
88 | + if(count($comments) === 0) { |
|
89 | + return []; |
|
90 | + } |
|
91 | + |
|
92 | + $actors = []; |
|
93 | + foreach ($comments as $comment) { |
|
94 | + if(!isset($actors[$comment->getActorType()])) { |
|
95 | + $actors[$comment->getActorType()] = []; |
|
96 | + } |
|
97 | + if(!isset($actors[$comment->getActorType()][$comment->getActorId()])) { |
|
98 | + $actors[$comment->getActorType()][$comment->getActorId()] = 1; |
|
99 | + } else { |
|
100 | + $actors[$comment->getActorType()][$comment->getActorId()]++; |
|
101 | + } |
|
102 | + } |
|
103 | + return $actors; |
|
104 | + } |
|
105 | + |
|
106 | + protected function compare(array $a, array $b, array $commenters) { |
|
107 | + $a = $a['value']['shareWith']; |
|
108 | + $b = $b['value']['shareWith']; |
|
109 | + |
|
110 | + $valueA = isset($commenters[$a]) ? $commenters[$a] : 0; |
|
111 | + $valueB = isset($commenters[$b]) ? $commenters[$b] : 0; |
|
112 | + |
|
113 | + return $valueB - $valueA; |
|
114 | + } |
|
115 | 115 | } |
@@ -31,41 +31,41 @@ |
||
31 | 31 | */ |
32 | 32 | interface ICalendar { |
33 | 33 | |
34 | - /** |
|
35 | - * @return string defining the technical unique key |
|
36 | - * @since 13.0.0 |
|
37 | - */ |
|
38 | - public function getKey(); |
|
34 | + /** |
|
35 | + * @return string defining the technical unique key |
|
36 | + * @since 13.0.0 |
|
37 | + */ |
|
38 | + public function getKey(); |
|
39 | 39 | |
40 | - /** |
|
41 | - * In comparison to getKey() this function returns a human readable (maybe translated) name |
|
42 | - * @return null|string |
|
43 | - * @since 13.0.0 |
|
44 | - */ |
|
45 | - public function getDisplayName(); |
|
40 | + /** |
|
41 | + * In comparison to getKey() this function returns a human readable (maybe translated) name |
|
42 | + * @return null|string |
|
43 | + * @since 13.0.0 |
|
44 | + */ |
|
45 | + public function getDisplayName(); |
|
46 | 46 | |
47 | - /** |
|
48 | - * Calendar color |
|
49 | - * @return null|string |
|
50 | - * @since 13.0.0 |
|
51 | - */ |
|
52 | - public function getDisplayColor(); |
|
47 | + /** |
|
48 | + * Calendar color |
|
49 | + * @return null|string |
|
50 | + * @since 13.0.0 |
|
51 | + */ |
|
52 | + public function getDisplayColor(); |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param string $pattern which should match within the $searchProperties |
|
56 | - * @param array $searchProperties defines the properties within the query pattern should match |
|
57 | - * @param array $options - optional parameters: |
|
58 | - * ['timerange' => ['start' => new DateTime(...), 'end' => new DateTime(...)]] |
|
59 | - * @param integer|null $limit - limit number of search results |
|
60 | - * @param integer|null $offset - offset for paging of search results |
|
61 | - * @return array an array of events/journals/todos which are arrays of key-value-pairs |
|
62 | - * @since 13.0.0 |
|
63 | - */ |
|
64 | - public function search($pattern, array $searchProperties=[], array $options=[], $limit=null, $offset=null); |
|
54 | + /** |
|
55 | + * @param string $pattern which should match within the $searchProperties |
|
56 | + * @param array $searchProperties defines the properties within the query pattern should match |
|
57 | + * @param array $options - optional parameters: |
|
58 | + * ['timerange' => ['start' => new DateTime(...), 'end' => new DateTime(...)]] |
|
59 | + * @param integer|null $limit - limit number of search results |
|
60 | + * @param integer|null $offset - offset for paging of search results |
|
61 | + * @return array an array of events/journals/todos which are arrays of key-value-pairs |
|
62 | + * @since 13.0.0 |
|
63 | + */ |
|
64 | + public function search($pattern, array $searchProperties=[], array $options=[], $limit=null, $offset=null); |
|
65 | 65 | |
66 | - /** |
|
67 | - * @return integer build up using \OCP\Constants |
|
68 | - * @since 13.0.0 |
|
69 | - */ |
|
70 | - public function getPermissions(); |
|
66 | + /** |
|
67 | + * @return integer build up using \OCP\Constants |
|
68 | + * @since 13.0.0 |
|
69 | + */ |
|
70 | + public function getPermissions(); |
|
71 | 71 | } |
@@ -34,194 +34,194 @@ |
||
34 | 34 | |
35 | 35 | class OracleMigrator extends Migrator { |
36 | 36 | |
37 | - /** |
|
38 | - * Quote a column's name but changing the name requires recreating |
|
39 | - * the column instance and copying over all properties. |
|
40 | - * |
|
41 | - * @param Column $column old column |
|
42 | - * @return Column new column instance with new name |
|
43 | - */ |
|
44 | - protected function quoteColumn(Column $column) { |
|
45 | - $newColumn = new Column( |
|
46 | - $this->connection->quoteIdentifier($column->getName()), |
|
47 | - $column->getType() |
|
48 | - ); |
|
49 | - $newColumn->setAutoincrement($column->getAutoincrement()); |
|
50 | - $newColumn->setColumnDefinition($column->getColumnDefinition()); |
|
51 | - $newColumn->setComment($column->getComment()); |
|
52 | - $newColumn->setDefault($column->getDefault()); |
|
53 | - $newColumn->setFixed($column->getFixed()); |
|
54 | - $newColumn->setLength($column->getLength()); |
|
55 | - $newColumn->setNotnull($column->getNotnull()); |
|
56 | - $newColumn->setPrecision($column->getPrecision()); |
|
57 | - $newColumn->setScale($column->getScale()); |
|
58 | - $newColumn->setUnsigned($column->getUnsigned()); |
|
59 | - $newColumn->setPlatformOptions($column->getPlatformOptions()); |
|
60 | - $newColumn->setCustomSchemaOptions($column->getPlatformOptions()); |
|
61 | - return $newColumn; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Quote an index's name but changing the name requires recreating |
|
66 | - * the index instance and copying over all properties. |
|
67 | - * |
|
68 | - * @param Index $index old index |
|
69 | - * @return Index new index instance with new name |
|
70 | - */ |
|
71 | - protected function quoteIndex($index) { |
|
72 | - return new Index( |
|
73 | - //TODO migrate existing uppercase indexes, then $this->connection->quoteIdentifier($index->getName()), |
|
74 | - $index->getName(), |
|
75 | - array_map(function($columnName) { |
|
76 | - return $this->connection->quoteIdentifier($columnName); |
|
77 | - }, $index->getColumns()), |
|
78 | - $index->isUnique(), |
|
79 | - $index->isPrimary(), |
|
80 | - $index->getFlags(), |
|
81 | - $index->getOptions() |
|
82 | - ); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Quote an ForeignKeyConstraint's name but changing the name requires recreating |
|
87 | - * the ForeignKeyConstraint instance and copying over all properties. |
|
88 | - * |
|
89 | - * @param ForeignKeyConstraint $fkc old fkc |
|
90 | - * @return ForeignKeyConstraint new fkc instance with new name |
|
91 | - */ |
|
92 | - protected function quoteForeignKeyConstraint($fkc) { |
|
93 | - return new ForeignKeyConstraint( |
|
94 | - array_map(function($columnName) { |
|
95 | - return $this->connection->quoteIdentifier($columnName); |
|
96 | - }, $fkc->getLocalColumns()), |
|
97 | - $this->connection->quoteIdentifier($fkc->getForeignTableName()), |
|
98 | - array_map(function($columnName) { |
|
99 | - return $this->connection->quoteIdentifier($columnName); |
|
100 | - }, $fkc->getForeignColumns()), |
|
101 | - $fkc->getName(), |
|
102 | - $fkc->getOptions() |
|
103 | - ); |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * @param Schema $targetSchema |
|
108 | - * @param \Doctrine\DBAL\Connection $connection |
|
109 | - * @return \Doctrine\DBAL\Schema\SchemaDiff |
|
110 | - * @throws DBALException |
|
111 | - */ |
|
112 | - protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { |
|
113 | - $schemaDiff = parent::getDiff($targetSchema, $connection); |
|
114 | - |
|
115 | - // oracle forces us to quote the identifiers |
|
116 | - $schemaDiff->newTables = array_map(function(Table $table) { |
|
117 | - return new Table( |
|
118 | - $this->connection->quoteIdentifier($table->getName()), |
|
119 | - array_map(function(Column $column) { |
|
120 | - return $this->quoteColumn($column); |
|
121 | - }, $table->getColumns()), |
|
122 | - array_map(function(Index $index) { |
|
123 | - return $this->quoteIndex($index); |
|
124 | - }, $table->getIndexes()), |
|
125 | - array_map(function(ForeignKeyConstraint $fck) { |
|
126 | - return $this->quoteForeignKeyConstraint($fck); |
|
127 | - }, $table->getForeignKeys()), |
|
128 | - 0, |
|
129 | - $table->getOptions() |
|
130 | - ); |
|
131 | - }, $schemaDiff->newTables); |
|
132 | - |
|
133 | - $schemaDiff->removedTables = array_map(function(Table $table) { |
|
134 | - return new Table( |
|
135 | - $this->connection->quoteIdentifier($table->getName()), |
|
136 | - $table->getColumns(), |
|
137 | - $table->getIndexes(), |
|
138 | - $table->getForeignKeys(), |
|
139 | - 0, |
|
140 | - $table->getOptions() |
|
141 | - ); |
|
142 | - }, $schemaDiff->removedTables); |
|
143 | - |
|
144 | - foreach ($schemaDiff->changedTables as $tableDiff) { |
|
145 | - $tableDiff->name = $this->connection->quoteIdentifier($tableDiff->name); |
|
146 | - |
|
147 | - $tableDiff->addedColumns = array_map(function(Column $column) { |
|
148 | - return $this->quoteColumn($column); |
|
149 | - }, $tableDiff->addedColumns); |
|
150 | - |
|
151 | - foreach ($tableDiff->changedColumns as $column) { |
|
152 | - $column->oldColumnName = $this->connection->quoteIdentifier($column->oldColumnName); |
|
153 | - // auto increment is not relevant for oracle and can anyhow not be applied on change |
|
154 | - $column->changedProperties = array_diff($column->changedProperties, ['autoincrement', 'unsigned']); |
|
155 | - } |
|
156 | - // remove columns that no longer have changed (because autoincrement and unsigned are not supported) |
|
157 | - $tableDiff->changedColumns = array_filter($tableDiff->changedColumns, function (ColumnDiff $column) { |
|
158 | - return count($column->changedProperties) > 0; |
|
159 | - }); |
|
160 | - |
|
161 | - $tableDiff->removedColumns = array_map(function(Column $column) { |
|
162 | - return $this->quoteColumn($column); |
|
163 | - }, $tableDiff->removedColumns); |
|
164 | - |
|
165 | - $tableDiff->renamedColumns = array_map(function(Column $column) { |
|
166 | - return $this->quoteColumn($column); |
|
167 | - }, $tableDiff->renamedColumns); |
|
168 | - |
|
169 | - $tableDiff->addedIndexes = array_map(function(Index $index) { |
|
170 | - return $this->quoteIndex($index); |
|
171 | - }, $tableDiff->addedIndexes); |
|
172 | - |
|
173 | - $tableDiff->changedIndexes = array_map(function(Index $index) { |
|
174 | - return $this->quoteIndex($index); |
|
175 | - }, $tableDiff->changedIndexes); |
|
176 | - |
|
177 | - $tableDiff->removedIndexes = array_map(function(Index $index) { |
|
178 | - return $this->quoteIndex($index); |
|
179 | - }, $tableDiff->removedIndexes); |
|
180 | - |
|
181 | - $tableDiff->renamedIndexes = array_map(function(Index $index) { |
|
182 | - return $this->quoteIndex($index); |
|
183 | - }, $tableDiff->renamedIndexes); |
|
184 | - |
|
185 | - $tableDiff->addedForeignKeys = array_map(function(ForeignKeyConstraint $fkc) { |
|
186 | - return $this->quoteForeignKeyConstraint($fkc); |
|
187 | - }, $tableDiff->addedForeignKeys); |
|
188 | - |
|
189 | - $tableDiff->changedForeignKeys = array_map(function(ForeignKeyConstraint $fkc) { |
|
190 | - return $this->quoteForeignKeyConstraint($fkc); |
|
191 | - }, $tableDiff->changedForeignKeys); |
|
192 | - |
|
193 | - $tableDiff->removedForeignKeys = array_map(function(ForeignKeyConstraint $fkc) { |
|
194 | - return $this->quoteForeignKeyConstraint($fkc); |
|
195 | - }, $tableDiff->removedForeignKeys); |
|
196 | - } |
|
197 | - |
|
198 | - return $schemaDiff; |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * @param string $name |
|
203 | - * @return string |
|
204 | - */ |
|
205 | - protected function generateTemporaryTableName($name) { |
|
206 | - return 'oc_' . uniqid(); |
|
207 | - } |
|
208 | - |
|
209 | - /** |
|
210 | - * @param $statement |
|
211 | - * @return string |
|
212 | - */ |
|
213 | - protected function convertStatementToScript($statement) { |
|
214 | - if (substr($statement, -1) === ';') { |
|
215 | - return $statement . PHP_EOL . '/' . PHP_EOL; |
|
216 | - } |
|
217 | - $script = $statement . ';'; |
|
218 | - $script .= PHP_EOL; |
|
219 | - $script .= PHP_EOL; |
|
220 | - return $script; |
|
221 | - } |
|
222 | - |
|
223 | - protected function getFilterExpression() { |
|
224 | - return '/^"' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/'; |
|
225 | - } |
|
37 | + /** |
|
38 | + * Quote a column's name but changing the name requires recreating |
|
39 | + * the column instance and copying over all properties. |
|
40 | + * |
|
41 | + * @param Column $column old column |
|
42 | + * @return Column new column instance with new name |
|
43 | + */ |
|
44 | + protected function quoteColumn(Column $column) { |
|
45 | + $newColumn = new Column( |
|
46 | + $this->connection->quoteIdentifier($column->getName()), |
|
47 | + $column->getType() |
|
48 | + ); |
|
49 | + $newColumn->setAutoincrement($column->getAutoincrement()); |
|
50 | + $newColumn->setColumnDefinition($column->getColumnDefinition()); |
|
51 | + $newColumn->setComment($column->getComment()); |
|
52 | + $newColumn->setDefault($column->getDefault()); |
|
53 | + $newColumn->setFixed($column->getFixed()); |
|
54 | + $newColumn->setLength($column->getLength()); |
|
55 | + $newColumn->setNotnull($column->getNotnull()); |
|
56 | + $newColumn->setPrecision($column->getPrecision()); |
|
57 | + $newColumn->setScale($column->getScale()); |
|
58 | + $newColumn->setUnsigned($column->getUnsigned()); |
|
59 | + $newColumn->setPlatformOptions($column->getPlatformOptions()); |
|
60 | + $newColumn->setCustomSchemaOptions($column->getPlatformOptions()); |
|
61 | + return $newColumn; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Quote an index's name but changing the name requires recreating |
|
66 | + * the index instance and copying over all properties. |
|
67 | + * |
|
68 | + * @param Index $index old index |
|
69 | + * @return Index new index instance with new name |
|
70 | + */ |
|
71 | + protected function quoteIndex($index) { |
|
72 | + return new Index( |
|
73 | + //TODO migrate existing uppercase indexes, then $this->connection->quoteIdentifier($index->getName()), |
|
74 | + $index->getName(), |
|
75 | + array_map(function($columnName) { |
|
76 | + return $this->connection->quoteIdentifier($columnName); |
|
77 | + }, $index->getColumns()), |
|
78 | + $index->isUnique(), |
|
79 | + $index->isPrimary(), |
|
80 | + $index->getFlags(), |
|
81 | + $index->getOptions() |
|
82 | + ); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Quote an ForeignKeyConstraint's name but changing the name requires recreating |
|
87 | + * the ForeignKeyConstraint instance and copying over all properties. |
|
88 | + * |
|
89 | + * @param ForeignKeyConstraint $fkc old fkc |
|
90 | + * @return ForeignKeyConstraint new fkc instance with new name |
|
91 | + */ |
|
92 | + protected function quoteForeignKeyConstraint($fkc) { |
|
93 | + return new ForeignKeyConstraint( |
|
94 | + array_map(function($columnName) { |
|
95 | + return $this->connection->quoteIdentifier($columnName); |
|
96 | + }, $fkc->getLocalColumns()), |
|
97 | + $this->connection->quoteIdentifier($fkc->getForeignTableName()), |
|
98 | + array_map(function($columnName) { |
|
99 | + return $this->connection->quoteIdentifier($columnName); |
|
100 | + }, $fkc->getForeignColumns()), |
|
101 | + $fkc->getName(), |
|
102 | + $fkc->getOptions() |
|
103 | + ); |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * @param Schema $targetSchema |
|
108 | + * @param \Doctrine\DBAL\Connection $connection |
|
109 | + * @return \Doctrine\DBAL\Schema\SchemaDiff |
|
110 | + * @throws DBALException |
|
111 | + */ |
|
112 | + protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { |
|
113 | + $schemaDiff = parent::getDiff($targetSchema, $connection); |
|
114 | + |
|
115 | + // oracle forces us to quote the identifiers |
|
116 | + $schemaDiff->newTables = array_map(function(Table $table) { |
|
117 | + return new Table( |
|
118 | + $this->connection->quoteIdentifier($table->getName()), |
|
119 | + array_map(function(Column $column) { |
|
120 | + return $this->quoteColumn($column); |
|
121 | + }, $table->getColumns()), |
|
122 | + array_map(function(Index $index) { |
|
123 | + return $this->quoteIndex($index); |
|
124 | + }, $table->getIndexes()), |
|
125 | + array_map(function(ForeignKeyConstraint $fck) { |
|
126 | + return $this->quoteForeignKeyConstraint($fck); |
|
127 | + }, $table->getForeignKeys()), |
|
128 | + 0, |
|
129 | + $table->getOptions() |
|
130 | + ); |
|
131 | + }, $schemaDiff->newTables); |
|
132 | + |
|
133 | + $schemaDiff->removedTables = array_map(function(Table $table) { |
|
134 | + return new Table( |
|
135 | + $this->connection->quoteIdentifier($table->getName()), |
|
136 | + $table->getColumns(), |
|
137 | + $table->getIndexes(), |
|
138 | + $table->getForeignKeys(), |
|
139 | + 0, |
|
140 | + $table->getOptions() |
|
141 | + ); |
|
142 | + }, $schemaDiff->removedTables); |
|
143 | + |
|
144 | + foreach ($schemaDiff->changedTables as $tableDiff) { |
|
145 | + $tableDiff->name = $this->connection->quoteIdentifier($tableDiff->name); |
|
146 | + |
|
147 | + $tableDiff->addedColumns = array_map(function(Column $column) { |
|
148 | + return $this->quoteColumn($column); |
|
149 | + }, $tableDiff->addedColumns); |
|
150 | + |
|
151 | + foreach ($tableDiff->changedColumns as $column) { |
|
152 | + $column->oldColumnName = $this->connection->quoteIdentifier($column->oldColumnName); |
|
153 | + // auto increment is not relevant for oracle and can anyhow not be applied on change |
|
154 | + $column->changedProperties = array_diff($column->changedProperties, ['autoincrement', 'unsigned']); |
|
155 | + } |
|
156 | + // remove columns that no longer have changed (because autoincrement and unsigned are not supported) |
|
157 | + $tableDiff->changedColumns = array_filter($tableDiff->changedColumns, function (ColumnDiff $column) { |
|
158 | + return count($column->changedProperties) > 0; |
|
159 | + }); |
|
160 | + |
|
161 | + $tableDiff->removedColumns = array_map(function(Column $column) { |
|
162 | + return $this->quoteColumn($column); |
|
163 | + }, $tableDiff->removedColumns); |
|
164 | + |
|
165 | + $tableDiff->renamedColumns = array_map(function(Column $column) { |
|
166 | + return $this->quoteColumn($column); |
|
167 | + }, $tableDiff->renamedColumns); |
|
168 | + |
|
169 | + $tableDiff->addedIndexes = array_map(function(Index $index) { |
|
170 | + return $this->quoteIndex($index); |
|
171 | + }, $tableDiff->addedIndexes); |
|
172 | + |
|
173 | + $tableDiff->changedIndexes = array_map(function(Index $index) { |
|
174 | + return $this->quoteIndex($index); |
|
175 | + }, $tableDiff->changedIndexes); |
|
176 | + |
|
177 | + $tableDiff->removedIndexes = array_map(function(Index $index) { |
|
178 | + return $this->quoteIndex($index); |
|
179 | + }, $tableDiff->removedIndexes); |
|
180 | + |
|
181 | + $tableDiff->renamedIndexes = array_map(function(Index $index) { |
|
182 | + return $this->quoteIndex($index); |
|
183 | + }, $tableDiff->renamedIndexes); |
|
184 | + |
|
185 | + $tableDiff->addedForeignKeys = array_map(function(ForeignKeyConstraint $fkc) { |
|
186 | + return $this->quoteForeignKeyConstraint($fkc); |
|
187 | + }, $tableDiff->addedForeignKeys); |
|
188 | + |
|
189 | + $tableDiff->changedForeignKeys = array_map(function(ForeignKeyConstraint $fkc) { |
|
190 | + return $this->quoteForeignKeyConstraint($fkc); |
|
191 | + }, $tableDiff->changedForeignKeys); |
|
192 | + |
|
193 | + $tableDiff->removedForeignKeys = array_map(function(ForeignKeyConstraint $fkc) { |
|
194 | + return $this->quoteForeignKeyConstraint($fkc); |
|
195 | + }, $tableDiff->removedForeignKeys); |
|
196 | + } |
|
197 | + |
|
198 | + return $schemaDiff; |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * @param string $name |
|
203 | + * @return string |
|
204 | + */ |
|
205 | + protected function generateTemporaryTableName($name) { |
|
206 | + return 'oc_' . uniqid(); |
|
207 | + } |
|
208 | + |
|
209 | + /** |
|
210 | + * @param $statement |
|
211 | + * @return string |
|
212 | + */ |
|
213 | + protected function convertStatementToScript($statement) { |
|
214 | + if (substr($statement, -1) === ';') { |
|
215 | + return $statement . PHP_EOL . '/' . PHP_EOL; |
|
216 | + } |
|
217 | + $script = $statement . ';'; |
|
218 | + $script .= PHP_EOL; |
|
219 | + $script .= PHP_EOL; |
|
220 | + return $script; |
|
221 | + } |
|
222 | + |
|
223 | + protected function getFilterExpression() { |
|
224 | + return '/^"' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/'; |
|
225 | + } |
|
226 | 226 | |
227 | 227 | } |
@@ -37,136 +37,136 @@ |
||
37 | 37 | use OCP\IDBConnection; |
38 | 38 | |
39 | 39 | class MDB2SchemaManager { |
40 | - /** @var \OC\DB\Connection $conn */ |
|
41 | - protected $conn; |
|
40 | + /** @var \OC\DB\Connection $conn */ |
|
41 | + protected $conn; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param IDBConnection $conn |
|
45 | - */ |
|
46 | - public function __construct($conn) { |
|
47 | - $this->conn = $conn; |
|
48 | - } |
|
43 | + /** |
|
44 | + * @param IDBConnection $conn |
|
45 | + */ |
|
46 | + public function __construct($conn) { |
|
47 | + $this->conn = $conn; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * saves database scheme to xml file |
|
52 | - * @param string $file name of file |
|
53 | - * @return bool |
|
54 | - * |
|
55 | - * TODO: write more documentation |
|
56 | - */ |
|
57 | - public function getDbStructure($file) { |
|
58 | - return \OC\DB\MDB2SchemaWriter::saveSchemaToFile($file, $this->conn); |
|
59 | - } |
|
50 | + /** |
|
51 | + * saves database scheme to xml file |
|
52 | + * @param string $file name of file |
|
53 | + * @return bool |
|
54 | + * |
|
55 | + * TODO: write more documentation |
|
56 | + */ |
|
57 | + public function getDbStructure($file) { |
|
58 | + return \OC\DB\MDB2SchemaWriter::saveSchemaToFile($file, $this->conn); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Creates tables from XML file |
|
63 | - * @param string $file file to read structure from |
|
64 | - * @return bool |
|
65 | - * |
|
66 | - * TODO: write more documentation |
|
67 | - */ |
|
68 | - public function createDbFromStructure($file) { |
|
69 | - $schemaReader = new MDB2SchemaReader(\OC::$server->getConfig(), $this->conn->getDatabasePlatform()); |
|
70 | - $toSchema = new Schema([], [], $this->conn->getSchemaManager()->createSchemaConfig()); |
|
71 | - $toSchema = $schemaReader->loadSchemaFromFile($file, $toSchema); |
|
72 | - return $this->executeSchemaChange($toSchema); |
|
73 | - } |
|
61 | + /** |
|
62 | + * Creates tables from XML file |
|
63 | + * @param string $file file to read structure from |
|
64 | + * @return bool |
|
65 | + * |
|
66 | + * TODO: write more documentation |
|
67 | + */ |
|
68 | + public function createDbFromStructure($file) { |
|
69 | + $schemaReader = new MDB2SchemaReader(\OC::$server->getConfig(), $this->conn->getDatabasePlatform()); |
|
70 | + $toSchema = new Schema([], [], $this->conn->getSchemaManager()->createSchemaConfig()); |
|
71 | + $toSchema = $schemaReader->loadSchemaFromFile($file, $toSchema); |
|
72 | + return $this->executeSchemaChange($toSchema); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @return \OC\DB\Migrator |
|
77 | - */ |
|
78 | - public function getMigrator() { |
|
79 | - $random = \OC::$server->getSecureRandom(); |
|
80 | - $platform = $this->conn->getDatabasePlatform(); |
|
81 | - $config = \OC::$server->getConfig(); |
|
82 | - $dispatcher = \OC::$server->getEventDispatcher(); |
|
83 | - if ($platform instanceof SqlitePlatform) { |
|
84 | - return new SQLiteMigrator($this->conn, $random, $config, $dispatcher); |
|
85 | - } else if ($platform instanceof OraclePlatform) { |
|
86 | - return new OracleMigrator($this->conn, $random, $config, $dispatcher); |
|
87 | - } else if ($platform instanceof MySqlPlatform) { |
|
88 | - return new MySQLMigrator($this->conn, $random, $config, $dispatcher); |
|
89 | - } else if ($platform instanceof PostgreSqlPlatform) { |
|
90 | - return new PostgreSqlMigrator($this->conn, $random, $config, $dispatcher); |
|
91 | - } else { |
|
92 | - return new Migrator($this->conn, $random, $config, $dispatcher); |
|
93 | - } |
|
94 | - } |
|
75 | + /** |
|
76 | + * @return \OC\DB\Migrator |
|
77 | + */ |
|
78 | + public function getMigrator() { |
|
79 | + $random = \OC::$server->getSecureRandom(); |
|
80 | + $platform = $this->conn->getDatabasePlatform(); |
|
81 | + $config = \OC::$server->getConfig(); |
|
82 | + $dispatcher = \OC::$server->getEventDispatcher(); |
|
83 | + if ($platform instanceof SqlitePlatform) { |
|
84 | + return new SQLiteMigrator($this->conn, $random, $config, $dispatcher); |
|
85 | + } else if ($platform instanceof OraclePlatform) { |
|
86 | + return new OracleMigrator($this->conn, $random, $config, $dispatcher); |
|
87 | + } else if ($platform instanceof MySqlPlatform) { |
|
88 | + return new MySQLMigrator($this->conn, $random, $config, $dispatcher); |
|
89 | + } else if ($platform instanceof PostgreSqlPlatform) { |
|
90 | + return new PostgreSqlMigrator($this->conn, $random, $config, $dispatcher); |
|
91 | + } else { |
|
92 | + return new Migrator($this->conn, $random, $config, $dispatcher); |
|
93 | + } |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Reads database schema from file |
|
98 | - * |
|
99 | - * @param string $file file to read from |
|
100 | - * @return \Doctrine\DBAL\Schema\Schema |
|
101 | - */ |
|
102 | - private function readSchemaFromFile($file) { |
|
103 | - $platform = $this->conn->getDatabasePlatform(); |
|
104 | - $schemaReader = new MDB2SchemaReader(\OC::$server->getConfig(), $platform); |
|
105 | - $toSchema = new Schema([], [], $this->conn->getSchemaManager()->createSchemaConfig()); |
|
106 | - return $schemaReader->loadSchemaFromFile($file, $toSchema); |
|
107 | - } |
|
96 | + /** |
|
97 | + * Reads database schema from file |
|
98 | + * |
|
99 | + * @param string $file file to read from |
|
100 | + * @return \Doctrine\DBAL\Schema\Schema |
|
101 | + */ |
|
102 | + private function readSchemaFromFile($file) { |
|
103 | + $platform = $this->conn->getDatabasePlatform(); |
|
104 | + $schemaReader = new MDB2SchemaReader(\OC::$server->getConfig(), $platform); |
|
105 | + $toSchema = new Schema([], [], $this->conn->getSchemaManager()->createSchemaConfig()); |
|
106 | + return $schemaReader->loadSchemaFromFile($file, $toSchema); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * update the database scheme |
|
111 | - * @param string $file file to read structure from |
|
112 | - * @param bool $generateSql only return the sql needed for the upgrade |
|
113 | - * @return string|boolean |
|
114 | - */ |
|
115 | - public function updateDbFromStructure($file, $generateSql = false) { |
|
116 | - $toSchema = $this->readSchemaFromFile($file); |
|
117 | - $migrator = $this->getMigrator(); |
|
109 | + /** |
|
110 | + * update the database scheme |
|
111 | + * @param string $file file to read structure from |
|
112 | + * @param bool $generateSql only return the sql needed for the upgrade |
|
113 | + * @return string|boolean |
|
114 | + */ |
|
115 | + public function updateDbFromStructure($file, $generateSql = false) { |
|
116 | + $toSchema = $this->readSchemaFromFile($file); |
|
117 | + $migrator = $this->getMigrator(); |
|
118 | 118 | |
119 | - if ($generateSql) { |
|
120 | - return $migrator->generateChangeScript($toSchema); |
|
121 | - } else { |
|
122 | - $migrator->migrate($toSchema); |
|
123 | - return true; |
|
124 | - } |
|
125 | - } |
|
119 | + if ($generateSql) { |
|
120 | + return $migrator->generateChangeScript($toSchema); |
|
121 | + } else { |
|
122 | + $migrator->migrate($toSchema); |
|
123 | + return true; |
|
124 | + } |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * @param \Doctrine\DBAL\Schema\Schema $schema |
|
129 | - * @return string |
|
130 | - */ |
|
131 | - public function generateChangeScript($schema) { |
|
132 | - $migrator = $this->getMigrator(); |
|
133 | - return $migrator->generateChangeScript($schema); |
|
134 | - } |
|
127 | + /** |
|
128 | + * @param \Doctrine\DBAL\Schema\Schema $schema |
|
129 | + * @return string |
|
130 | + */ |
|
131 | + public function generateChangeScript($schema) { |
|
132 | + $migrator = $this->getMigrator(); |
|
133 | + return $migrator->generateChangeScript($schema); |
|
134 | + } |
|
135 | 135 | |
136 | - /** |
|
137 | - * remove all tables defined in a database structure xml file |
|
138 | - * |
|
139 | - * @param string $file the xml file describing the tables |
|
140 | - */ |
|
141 | - public function removeDBStructure($file) { |
|
142 | - $schemaReader = new MDB2SchemaReader(\OC::$server->getConfig(), $this->conn->getDatabasePlatform()); |
|
143 | - $toSchema = new Schema([], [], $this->conn->getSchemaManager()->createSchemaConfig()); |
|
144 | - $fromSchema = $schemaReader->loadSchemaFromFile($file, $toSchema); |
|
145 | - $toSchema = clone $fromSchema; |
|
146 | - /** @var $table \Doctrine\DBAL\Schema\Table */ |
|
147 | - foreach ($toSchema->getTables() as $table) { |
|
148 | - $toSchema->dropTable($table->getName()); |
|
149 | - } |
|
150 | - $comparator = new \Doctrine\DBAL\Schema\Comparator(); |
|
151 | - $schemaDiff = $comparator->compare($fromSchema, $toSchema); |
|
152 | - $this->executeSchemaChange($schemaDiff); |
|
153 | - } |
|
136 | + /** |
|
137 | + * remove all tables defined in a database structure xml file |
|
138 | + * |
|
139 | + * @param string $file the xml file describing the tables |
|
140 | + */ |
|
141 | + public function removeDBStructure($file) { |
|
142 | + $schemaReader = new MDB2SchemaReader(\OC::$server->getConfig(), $this->conn->getDatabasePlatform()); |
|
143 | + $toSchema = new Schema([], [], $this->conn->getSchemaManager()->createSchemaConfig()); |
|
144 | + $fromSchema = $schemaReader->loadSchemaFromFile($file, $toSchema); |
|
145 | + $toSchema = clone $fromSchema; |
|
146 | + /** @var $table \Doctrine\DBAL\Schema\Table */ |
|
147 | + foreach ($toSchema->getTables() as $table) { |
|
148 | + $toSchema->dropTable($table->getName()); |
|
149 | + } |
|
150 | + $comparator = new \Doctrine\DBAL\Schema\Comparator(); |
|
151 | + $schemaDiff = $comparator->compare($fromSchema, $toSchema); |
|
152 | + $this->executeSchemaChange($schemaDiff); |
|
153 | + } |
|
154 | 154 | |
155 | - /** |
|
156 | - * @param \Doctrine\DBAL\Schema\Schema|\Doctrine\DBAL\Schema\SchemaDiff $schema |
|
157 | - * @return bool |
|
158 | - */ |
|
159 | - private function executeSchemaChange($schema) { |
|
160 | - $this->conn->beginTransaction(); |
|
161 | - foreach ($schema->toSql($this->conn->getDatabasePlatform()) as $sql) { |
|
162 | - $this->conn->query($sql); |
|
163 | - } |
|
164 | - $this->conn->commit(); |
|
155 | + /** |
|
156 | + * @param \Doctrine\DBAL\Schema\Schema|\Doctrine\DBAL\Schema\SchemaDiff $schema |
|
157 | + * @return bool |
|
158 | + */ |
|
159 | + private function executeSchemaChange($schema) { |
|
160 | + $this->conn->beginTransaction(); |
|
161 | + foreach ($schema->toSql($this->conn->getDatabasePlatform()) as $sql) { |
|
162 | + $this->conn->query($sql); |
|
163 | + } |
|
164 | + $this->conn->commit(); |
|
165 | 165 | |
166 | - if ($this->conn->getDatabasePlatform() instanceof SqlitePlatform) { |
|
167 | - $this->conn->close(); |
|
168 | - $this->conn->connect(); |
|
169 | - } |
|
170 | - return true; |
|
171 | - } |
|
166 | + if ($this->conn->getDatabasePlatform() instanceof SqlitePlatform) { |
|
167 | + $this->conn->close(); |
|
168 | + $this->conn->connect(); |
|
169 | + } |
|
170 | + return true; |
|
171 | + } |
|
172 | 172 | } |
@@ -28,15 +28,15 @@ |
||
28 | 28 | |
29 | 29 | class WalledGardenController extends Controller { |
30 | 30 | |
31 | - /** |
|
32 | - * @PublicPage |
|
33 | - * @NoCSRFRequired |
|
34 | - * |
|
35 | - * @return Response |
|
36 | - */ |
|
37 | - function get() { |
|
38 | - $resp = new Response(); |
|
39 | - $resp->setStatus(Http::STATUS_NO_CONTENT); |
|
40 | - return $resp; |
|
41 | - } |
|
31 | + /** |
|
32 | + * @PublicPage |
|
33 | + * @NoCSRFRequired |
|
34 | + * |
|
35 | + * @return Response |
|
36 | + */ |
|
37 | + function get() { |
|
38 | + $resp = new Response(); |
|
39 | + $resp->setStatus(Http::STATUS_NO_CONTENT); |
|
40 | + return $resp; |
|
41 | + } |
|
42 | 42 | } |