2626use OC \BackgroundJob \TimedJob ;
2727use OC \ServerNotAvailableException ;
2828use OCA \User_LDAP \Access ;
29+ use OCA \User_LDAP \AccessFactory ;
2930use OCA \User_LDAP \Configuration ;
3031use OCA \User_LDAP \Connection ;
32+ use OCA \User_LDAP \ConnectionFactory ;
3133use OCA \User_LDAP \FilesystemHelper ;
3234use OCA \User_LDAP \Helper ;
3335use OCA \User_LDAP \LDAP ;
@@ -62,6 +64,10 @@ class Sync extends TimedJob {
6264 protected $ ncUserManager ;
6365 /** @var IManager */
6466 protected $ notificationManager ;
67+ /** @var ConnectionFactory */
68+ protected $ connectionFactory ;
69+ /** @var AccessFactory */
70+ protected $ accessFactory ;
6571
6672 public function __construct () {
6773 $ this ->setInterval (
@@ -112,7 +118,7 @@ protected function getMinPagingSize() {
112118 /**
113119 * @param array $argument
114120 */
115- protected function run ($ argument ) {
121+ public function run ($ argument ) {
116122 $ this ->setArgument ($ argument );
117123
118124 $ isBackgroundJobModeAjax = $ this ->config
@@ -140,11 +146,11 @@ protected function run($argument) {
140146 if ($ expectMoreResults ) {
141147 $ this ->increaseOffset ($ cycleData );
142148 } else {
143- $ this ->determineNextCycle ();
149+ $ this ->determineNextCycle ($ cycleData );
144150 }
145151 $ this ->updateInterval ();
146152 } catch (ServerNotAvailableException $ e ) {
147- $ this ->determineNextCycle ();
153+ $ this ->determineNextCycle ($ cycleData );
148154 }
149155 }
150156
@@ -153,8 +159,8 @@ protected function run($argument) {
153159 * @return bool whether more results are expected from the same configuration
154160 */
155161 public function runCycle ($ cycleData ) {
156- $ connection = new Connection ( $ this ->ldap , $ cycleData ['prefix ' ]);
157- $ access = new Access ( $ connection , $ this ->ldap , $ this -> userManager , $ this -> ldapHelper , $ this -> config );
162+ $ connection = $ this ->connectionFactory -> get ( $ cycleData ['prefix ' ]);
163+ $ access = $ this ->accessFactory -> get ( $ connection );
158164 $ access ->setUserMapper ($ this ->mapper );
159165
160166 $ filter = $ access ->combineFilterWithAnd (array (
@@ -173,7 +179,7 @@ public function runCycle($cycleData) {
173179 if ($ connection ->ldapPagingSize === 0 ) {
174180 return true ;
175181 }
176- return count ($ results ) != = $ connection ->ldapPagingSize ;
182+ return count ($ results ) > = $ connection ->ldapPagingSize ;
177183 }
178184
179185 /**
@@ -246,7 +252,7 @@ public function determineNextCycle(array $cycleData = null) {
246252 * @param $cycleData
247253 * @return bool
248254 */
249- protected function qualifiesToRun ($ cycleData ) {
255+ public function qualifiesToRun ($ cycleData ) {
250256 $ lastChange = $ this ->config ->getAppValue ('user_ldap ' , $ cycleData ['prefix ' ] . '_lastChange ' , 0 );
251257 if ((time () - $ lastChange ) > 60 * 30 ) {
252258 return true ;
@@ -358,5 +364,22 @@ public function setArgument($argument) {
358364 } else {
359365 $ this ->mapper = new UserMapping ($ this ->dbc );
360366 }
367+
368+ if (isset ($ argument ['connectionFactory ' ])) {
369+ $ this ->connectionFactory = $ argument ['connectionFactory ' ];
370+ } else {
371+ $ this ->connectionFactory = new ConnectionFactory ($ this ->ldap );
372+ }
373+
374+ if (isset ($ argument ['accessFactory ' ])) {
375+ $ this ->accessFactory = $ argument ['accessFactory ' ];
376+ } else {
377+ $ this ->accessFactory = new AccessFactory (
378+ $ this ->ldap ,
379+ $ this ->userManager ,
380+ $ this ->ldapHelper ,
381+ $ this ->config
382+ );
383+ }
361384 }
362385}
0 commit comments