Completed
Push — master ( eba447...1a7516 )
by Blizzz
18:31
created
apps/user_ldap/templates/settings.php 3 patches
Braces   +13 added lines, -1 removed lines patch added patch discarded remove patch
@@ -97,7 +97,19 @@
 block discarded – undo
97 97
 				<p><label for="ldap_group_display_name"><?php p($l->t('Group Display Name Field'));?></label><input type="text" id="ldap_group_display_name" name="ldap_group_display_name" data-default="<?php p($_['ldap_group_display_name_default']); ?>" title="<?php p($l->t('The LDAP attribute to use to generate the groups\'s display name.'));?>" /></p>
98 98
 				<p><label for="ldap_base_groups"><?php p($l->t('Base Group Tree'));?></label><textarea id="ldap_base_groups" name="ldap_base_groups" placeholder="<?php p($l->t('One Group Base DN per line'));?>" data-default="<?php p($_['ldap_base_groups_default']); ?>" title="<?php p($l->t('Base Group Tree'));?>"></textarea></p>
99 99
 				<p><label for="ldap_attributes_for_group_search"><?php p($l->t('Group Search Attributes'));?></label><textarea id="ldap_attributes_for_group_search" name="ldap_attributes_for_group_search" placeholder="<?php p($l->t('Optional; one attribute per line'));?>" data-default="<?php p($_['ldap_attributes_for_group_search_default']); ?>" title="<?php p($l->t('Group Search Attributes'));?>"></textarea></p>
100
-				<p><label for="ldap_group_member_assoc_attribute"><?php p($l->t('Group-Member association'));?></label><select id="ldap_group_member_assoc_attribute" name="ldap_group_member_assoc_attribute" data-default="<?php p($_['ldap_group_member_assoc_attribute_default']); ?>" ><option value="uniqueMember"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'uniqueMember')) p(' selected'); ?>>uniqueMember</option><option value="memberUid"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'memberUid')) p(' selected'); ?>>memberUid</option><option value="member"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'member')) p(' selected'); ?>>member (AD)</option><option value="gidNumber"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'gidNumber')) p(' selected'); ?>>gidNumber</option></select></p>				<p><label for="ldap_dynamic_group_member_url"><?php p($l->t('Dynamic Group Member URL'));?></label><input type="text" id="ldap_dynamic_group_member_url" name="ldap_dynamic_group_member_url" title="<?php p($l->t('The LDAP attribute that on group objects contains an LDAP search URL that determines what objects belong to the group. (An empty setting disables dynamic group membership functionality.)'));?>" data-default="<?php p($_['ldap_dynamic_group_member_url_default']); ?>" /></p>
100
+				<p><label for="ldap_group_member_assoc_attribute"><?php p($l->t('Group-Member association'));?></label><select id="ldap_group_member_assoc_attribute" name="ldap_group_member_assoc_attribute" data-default="<?php p($_['ldap_group_member_assoc_attribute_default']); ?>" ><option value="uniqueMember"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'uniqueMember')) {
101
+    p(' selected');
102
+}
103
+?>>uniqueMember</option><option value="memberUid"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'memberUid')) {
104
+    p(' selected');
105
+}
106
+?>>memberUid</option><option value="member"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'member')) {
107
+    p(' selected');
108
+}
109
+?>>member (AD)</option><option value="gidNumber"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'gidNumber')) {
110
+    p(' selected');
111
+}
112
+?>>gidNumber</option></select></p>				<p><label for="ldap_dynamic_group_member_url"><?php p($l->t('Dynamic Group Member URL'));?></label><input type="text" id="ldap_dynamic_group_member_url" name="ldap_dynamic_group_member_url" title="<?php p($l->t('The LDAP attribute that on group objects contains an LDAP search URL that determines what objects belong to the group. (An empty setting disables dynamic group membership functionality.)'));?>" data-default="<?php p($_['ldap_dynamic_group_member_url_default']); ?>" /></p>
101 113
 				<p><label for="ldap_nested_groups"><?php p($l->t('Nested Groups'));?></label><input type="checkbox" id="ldap_nested_groups" name="ldap_nested_groups" value="1" data-default="<?php p($_['ldap_nested_groups_default']); ?>"  title="<?php p($l->t('When switched on, groups that contain groups are supported. (Only works if the group member attribute contains DNs.)'));?>" /></p>
102 114
 				<p><label for="ldap_paging_size"><?php p($l->t('Paging chunksize'));?></label><input type="number" id="ldap_paging_size" name="ldap_paging_size" title="<?php p($l->t('Chunksize used for paged LDAP searches that may return bulky results like user or group enumeration. (Setting it 0 disables paged LDAP searches in those situations.)'));?>" data-default="<?php p($_['ldap_paging_size_default']); ?>" /></p>
103 115
 				<p><label for="ldap_turn_on_pwd_change"><?php p($l->t('Enable LDAP password changes per user'));?></label><span class="inlinetable"><span class="tablerow left"><input type="checkbox" id="ldap_turn_on_pwd_change" name="ldap_turn_on_pwd_change" value="1" data-default="<?php p($_['ldap_turn_on_pwd_change_default']); ?>" title="<?php p($l->t('Allow LDAP users to change their password and allow Super Administrators and Group Administrators to change the password of their LDAP users. Only works when access control policies are configured accordingly on the LDAP server. As passwords are sent in plaintext to the LDAP server, transport encryption must be used and password hashing should be configured on the LDAP server.'));?>" /><span class="tablecell"><?php p($l->t('(New password is sent as plain text to LDAP)'));?></span></span>
Please login to merge, or discard this patch.
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -5,46 +5,46 @@  discard block
 block discarded – undo
5 5
 vendor_style('user_ldap', 'ui-multiselect/jquery.multiselect');
6 6
 
7 7
 script('user_ldap', [
8
-	'wizard/controller',
9
-	'wizard/configModel',
10
-	'wizard/view',
11
-	'wizard/wizardObject',
12
-	'wizard/wizardTabGeneric',
13
-	'wizard/wizardTabElementary',
14
-	'wizard/wizardTabAbstractFilter',
15
-	'wizard/wizardTabUserFilter',
16
-	'wizard/wizardTabLoginFilter',
17
-	'wizard/wizardTabGroupFilter',
18
-	'wizard/wizardTabAdvanced',
19
-	'wizard/wizardTabExpert',
20
-	'wizard/wizardDetectorQueue',
21
-	'wizard/wizardDetectorGeneric',
22
-	'wizard/wizardDetectorPort',
23
-	'wizard/wizardDetectorBaseDN',
24
-	'wizard/wizardDetectorFeatureAbstract',
25
-	'wizard/wizardDetectorUserObjectClasses',
26
-	'wizard/wizardDetectorGroupObjectClasses',
27
-	'wizard/wizardDetectorGroupsForUsers',
28
-	'wizard/wizardDetectorGroupsForGroups',
29
-	'wizard/wizardDetectorSimpleRequestAbstract',
30
-	'wizard/wizardDetectorFilterUser',
31
-	'wizard/wizardDetectorFilterLogin',
32
-	'wizard/wizardDetectorFilterGroup',
33
-	'wizard/wizardDetectorUserCount',
34
-	'wizard/wizardDetectorGroupCount',
35
-	'wizard/wizardDetectorEmailAttribute',
36
-	'wizard/wizardDetectorUserDisplayNameAttribute',
37
-	'wizard/wizardDetectorUserGroupAssociation',
38
-	'wizard/wizardDetectorAvailableAttributes',
39
-	'wizard/wizardDetectorTestAbstract',
40
-	'wizard/wizardDetectorTestLoginName',
41
-	'wizard/wizardDetectorTestBaseDN',
42
-	'wizard/wizardDetectorTestConfiguration',
43
-	'wizard/wizardDetectorClearUserMappings',
44
-	'wizard/wizardDetectorClearGroupMappings',
45
-	'wizard/wizardFilterOnType',
46
-	'wizard/wizardFilterOnTypeFactory',
47
-	'wizard/wizard'
8
+    'wizard/controller',
9
+    'wizard/configModel',
10
+    'wizard/view',
11
+    'wizard/wizardObject',
12
+    'wizard/wizardTabGeneric',
13
+    'wizard/wizardTabElementary',
14
+    'wizard/wizardTabAbstractFilter',
15
+    'wizard/wizardTabUserFilter',
16
+    'wizard/wizardTabLoginFilter',
17
+    'wizard/wizardTabGroupFilter',
18
+    'wizard/wizardTabAdvanced',
19
+    'wizard/wizardTabExpert',
20
+    'wizard/wizardDetectorQueue',
21
+    'wizard/wizardDetectorGeneric',
22
+    'wizard/wizardDetectorPort',
23
+    'wizard/wizardDetectorBaseDN',
24
+    'wizard/wizardDetectorFeatureAbstract',
25
+    'wizard/wizardDetectorUserObjectClasses',
26
+    'wizard/wizardDetectorGroupObjectClasses',
27
+    'wizard/wizardDetectorGroupsForUsers',
28
+    'wizard/wizardDetectorGroupsForGroups',
29
+    'wizard/wizardDetectorSimpleRequestAbstract',
30
+    'wizard/wizardDetectorFilterUser',
31
+    'wizard/wizardDetectorFilterLogin',
32
+    'wizard/wizardDetectorFilterGroup',
33
+    'wizard/wizardDetectorUserCount',
34
+    'wizard/wizardDetectorGroupCount',
35
+    'wizard/wizardDetectorEmailAttribute',
36
+    'wizard/wizardDetectorUserDisplayNameAttribute',
37
+    'wizard/wizardDetectorUserGroupAssociation',
38
+    'wizard/wizardDetectorAvailableAttributes',
39
+    'wizard/wizardDetectorTestAbstract',
40
+    'wizard/wizardDetectorTestLoginName',
41
+    'wizard/wizardDetectorTestBaseDN',
42
+    'wizard/wizardDetectorTestConfiguration',
43
+    'wizard/wizardDetectorClearUserMappings',
44
+    'wizard/wizardDetectorClearGroupMappings',
45
+    'wizard/wizardFilterOnType',
46
+    'wizard/wizardFilterOnTypeFactory',
47
+    'wizard/wizard'
48 48
 ]);
49 49
 
50 50
 style('user_ldap', 'settings');
@@ -67,10 +67,10 @@  discard block
 block discarded – undo
67 67
 		<li class="ldapSettingsTabs"><a href="#ldapSettings-1"><?php p($l->t('Advanced'));?></a></li>
68 68
 	</ul>
69 69
 	<?php
70
-	if(!function_exists('ldap_connect')) {
71
-		print_unescaped('<p class="ldapwarning">'.$l->t('<b>Warning:</b> The PHP LDAP module is not installed, the backend will not work. Please ask your system administrator to install it.').'</p>');
72
-	}
73
-	?>
70
+    if(!function_exists('ldap_connect')) {
71
+        print_unescaped('<p class="ldapwarning">'.$l->t('<b>Warning:</b> The PHP LDAP module is not installed, the backend will not work. Please ask your system administrator to install it.').'</p>');
72
+    }
73
+    ?>
74 74
 	<?php require_once __DIR__ . '/part.wizard-server.php'; ?>
75 75
 	<?php require_once __DIR__ . '/part.wizard-userfilter.php'; ?>
76 76
 	<?php require_once __DIR__ . '/part.wizard-loginfilter.php'; ?>
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -59,70 +59,70 @@
 block discarded – undo
59 59
 
60 60
 	<div id="ldapSettings">
61 61
 	<ul>
62
-		<li id="#ldapWizard1"><a href="#ldapWizard1"><?php p($l->t('Server'));?></a></li>
63
-		<li id="#ldapWizard2"><a href="#ldapWizard2"><?php p($l->t('Users'));?></a></li>
64
-		<li id="#ldapWizard3"><a href="#ldapWizard3"><?php p($l->t('Login Attributes'));?></a></li>
65
-		<li id="#ldapWizard4"><a href="#ldapWizard4"><?php p($l->t('Groups'));?></a></li>
66
-		<li class="ldapSettingsTabs"><a href="#ldapSettings-2"><?php p($l->t('Expert'));?></a></li>
67
-		<li class="ldapSettingsTabs"><a href="#ldapSettings-1"><?php p($l->t('Advanced'));?></a></li>
62
+		<li id="#ldapWizard1"><a href="#ldapWizard1"><?php p($l->t('Server')); ?></a></li>
63
+		<li id="#ldapWizard2"><a href="#ldapWizard2"><?php p($l->t('Users')); ?></a></li>
64
+		<li id="#ldapWizard3"><a href="#ldapWizard3"><?php p($l->t('Login Attributes')); ?></a></li>
65
+		<li id="#ldapWizard4"><a href="#ldapWizard4"><?php p($l->t('Groups')); ?></a></li>
66
+		<li class="ldapSettingsTabs"><a href="#ldapSettings-2"><?php p($l->t('Expert')); ?></a></li>
67
+		<li class="ldapSettingsTabs"><a href="#ldapSettings-1"><?php p($l->t('Advanced')); ?></a></li>
68 68
 	</ul>
69 69
 	<?php
70
-	if(!function_exists('ldap_connect')) {
70
+	if (!function_exists('ldap_connect')) {
71 71
 		print_unescaped('<p class="ldapwarning">'.$l->t('<b>Warning:</b> The PHP LDAP module is not installed, the backend will not work. Please ask your system administrator to install it.').'</p>');
72 72
 	}
73 73
 	?>
74
-	<?php require_once __DIR__ . '/part.wizard-server.php'; ?>
75
-	<?php require_once __DIR__ . '/part.wizard-userfilter.php'; ?>
76
-	<?php require_once __DIR__ . '/part.wizard-loginfilter.php'; ?>
77
-	<?php require_once __DIR__ . '/part.wizard-groupfilter.php'; ?>
74
+	<?php require_once __DIR__.'/part.wizard-server.php'; ?>
75
+	<?php require_once __DIR__.'/part.wizard-userfilter.php'; ?>
76
+	<?php require_once __DIR__.'/part.wizard-loginfilter.php'; ?>
77
+	<?php require_once __DIR__.'/part.wizard-groupfilter.php'; ?>
78 78
 	<fieldset id="ldapSettings-1">
79 79
 		<div id="ldapAdvancedAccordion">
80
-			<h3><?php p($l->t('Connection Settings'));?></h3>
80
+			<h3><?php p($l->t('Connection Settings')); ?></h3>
81 81
 			<div>
82
-				<p><label for="ldap_configuration_active"><?php p($l->t('Configuration Active'));?></label><input type="checkbox" id="ldap_configuration_active" name="ldap_configuration_active" value="1" data-default="<?php p($_['ldap_configuration_active_default']); ?>"  title="<?php p($l->t('When unchecked, this configuration will be skipped.'));?>" /></p>
83
-				<p><label for="ldap_backup_host"><?php p($l->t('Backup (Replica) Host'));?></label><input type="text" id="ldap_backup_host" name="ldap_backup_host" data-default="<?php p($_['ldap_backup_host_default']); ?>" title="<?php p($l->t('Give an optional backup host. It must be a replica of the main LDAP/AD server.'));?>"></p>
84
-				<p><label for="ldap_backup_port"><?php p($l->t('Backup (Replica) Port'));?></label><input type="number" id="ldap_backup_port" name="ldap_backup_port" data-default="<?php p($_['ldap_backup_port_default']); ?>"  /></p>
85
-				<p><label for="ldap_override_main_server"><?php p($l->t('Disable Main Server'));?></label><input type="checkbox" id="ldap_override_main_server" name="ldap_override_main_server" value="1" data-default="<?php p($_['ldap_override_main_server_default']); ?>"  title="<?php p($l->t('Only connect to the replica server.'));?>" /></p>
86
-				<p><label for="ldap_turn_off_cert_check"><?php p($l->t('Turn off SSL certificate validation.'));?></label><input type="checkbox" id="ldap_turn_off_cert_check" name="ldap_turn_off_cert_check" title="<?php p($l->t('Not recommended, use it for testing only! If connection only works with this option, import the LDAP server\'s SSL certificate in your %s server.', [$theme->getName()] ));?>" data-default="<?php p($_['ldap_turn_off_cert_check_default']); ?>" value="1"><br/></p>
87
-				<p><label for="ldap_cache_ttl"><?php p($l->t('Cache Time-To-Live'));?></label><input type="number" id="ldap_cache_ttl" name="ldap_cache_ttl" title="<?php p($l->t('in seconds. A change empties the cache.'));?>" data-default="<?php p($_['ldap_cache_ttl_default']); ?>" /></p>
82
+				<p><label for="ldap_configuration_active"><?php p($l->t('Configuration Active')); ?></label><input type="checkbox" id="ldap_configuration_active" name="ldap_configuration_active" value="1" data-default="<?php p($_['ldap_configuration_active_default']); ?>"  title="<?php p($l->t('When unchecked, this configuration will be skipped.')); ?>" /></p>
83
+				<p><label for="ldap_backup_host"><?php p($l->t('Backup (Replica) Host')); ?></label><input type="text" id="ldap_backup_host" name="ldap_backup_host" data-default="<?php p($_['ldap_backup_host_default']); ?>" title="<?php p($l->t('Give an optional backup host. It must be a replica of the main LDAP/AD server.')); ?>"></p>
84
+				<p><label for="ldap_backup_port"><?php p($l->t('Backup (Replica) Port')); ?></label><input type="number" id="ldap_backup_port" name="ldap_backup_port" data-default="<?php p($_['ldap_backup_port_default']); ?>"  /></p>
85
+				<p><label for="ldap_override_main_server"><?php p($l->t('Disable Main Server')); ?></label><input type="checkbox" id="ldap_override_main_server" name="ldap_override_main_server" value="1" data-default="<?php p($_['ldap_override_main_server_default']); ?>"  title="<?php p($l->t('Only connect to the replica server.')); ?>" /></p>
86
+				<p><label for="ldap_turn_off_cert_check"><?php p($l->t('Turn off SSL certificate validation.')); ?></label><input type="checkbox" id="ldap_turn_off_cert_check" name="ldap_turn_off_cert_check" title="<?php p($l->t('Not recommended, use it for testing only! If connection only works with this option, import the LDAP server\'s SSL certificate in your %s server.', [$theme->getName()])); ?>" data-default="<?php p($_['ldap_turn_off_cert_check_default']); ?>" value="1"><br/></p>
87
+				<p><label for="ldap_cache_ttl"><?php p($l->t('Cache Time-To-Live')); ?></label><input type="number" id="ldap_cache_ttl" name="ldap_cache_ttl" title="<?php p($l->t('in seconds. A change empties the cache.')); ?>" data-default="<?php p($_['ldap_cache_ttl_default']); ?>" /></p>
88 88
 			</div>
89
-			<h3><?php p($l->t('Directory Settings'));?></h3>
89
+			<h3><?php p($l->t('Directory Settings')); ?></h3>
90 90
 			<div>
91
-				<p><label for="ldap_display_name"><?php p($l->t('User Display Name Field'));?></label><input type="text" id="ldap_display_name" name="ldap_display_name" data-default="<?php p($_['ldap_display_name_default']); ?>" title="<?php p($l->t('The LDAP attribute to use to generate the user\'s display name.'));?>" /></p>
92
-				<p><label for="ldap_user_display_name_2"><?php p($l->t('2nd User Display Name Field'));?></label><input type="text" id="ldap_user_display_name_2" name="ldap_user_display_name_2" data-default="<?php p($_['ldap_user_display_name_2_default']); ?>" title="<?php p($l->t('Optional. An LDAP attribute to be added to the display name in brackets. Results in e.g. »John Doe ([email protected])«.'));?>" /></p>
93
-				<p><label for="ldap_base_users"><?php p($l->t('Base User Tree'));?></label><textarea id="ldap_base_users" name="ldap_base_users" placeholder="<?php p($l->t('One User Base DN per line'));?>" data-default="<?php p($_['ldap_base_users_default']); ?>" title="<?php p($l->t('Base User Tree'));?>"></textarea></p>
94
-				<p><label for="ldap_attributes_for_user_search"><?php p($l->t('User Search Attributes'));?></label><textarea id="ldap_attributes_for_user_search" name="ldap_attributes_for_user_search" placeholder="<?php p($l->t('Optional; one attribute per line'));?>" data-default="<?php p($_['ldap_attributes_for_user_search_default']); ?>" title="<?php p($l->t('User Search Attributes'));?>"></textarea></p>
95
-				<p><label for="ldap_group_display_name"><?php p($l->t('Group Display Name Field'));?></label><input type="text" id="ldap_group_display_name" name="ldap_group_display_name" data-default="<?php p($_['ldap_group_display_name_default']); ?>" title="<?php p($l->t('The LDAP attribute to use to generate the groups\'s display name.'));?>" /></p>
96
-				<p><label for="ldap_base_groups"><?php p($l->t('Base Group Tree'));?></label><textarea id="ldap_base_groups" name="ldap_base_groups" placeholder="<?php p($l->t('One Group Base DN per line'));?>" data-default="<?php p($_['ldap_base_groups_default']); ?>" title="<?php p($l->t('Base Group Tree'));?>"></textarea></p>
97
-				<p><label for="ldap_attributes_for_group_search"><?php p($l->t('Group Search Attributes'));?></label><textarea id="ldap_attributes_for_group_search" name="ldap_attributes_for_group_search" placeholder="<?php p($l->t('Optional; one attribute per line'));?>" data-default="<?php p($_['ldap_attributes_for_group_search_default']); ?>" title="<?php p($l->t('Group Search Attributes'));?>"></textarea></p>
98
-				<p><label for="ldap_group_member_assoc_attribute"><?php p($l->t('Group-Member association'));?></label><select id="ldap_group_member_assoc_attribute" name="ldap_group_member_assoc_attribute" data-default="<?php p($_['ldap_group_member_assoc_attribute_default']); ?>" ><option value="uniqueMember"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'uniqueMember')) p(' selected'); ?>>uniqueMember</option><option value="memberUid"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'memberUid')) p(' selected'); ?>>memberUid</option><option value="member"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'member')) p(' selected'); ?>>member (AD)</option><option value="gidNumber"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'gidNumber')) p(' selected'); ?>>gidNumber</option></select></p>				<p><label for="ldap_dynamic_group_member_url"><?php p($l->t('Dynamic Group Member URL'));?></label><input type="text" id="ldap_dynamic_group_member_url" name="ldap_dynamic_group_member_url" title="<?php p($l->t('The LDAP attribute that on group objects contains an LDAP search URL that determines what objects belong to the group. (An empty setting disables dynamic group membership functionality.)'));?>" data-default="<?php p($_['ldap_dynamic_group_member_url_default']); ?>" /></p>
99
-				<p><label for="ldap_nested_groups"><?php p($l->t('Nested Groups'));?></label><input type="checkbox" id="ldap_nested_groups" name="ldap_nested_groups" value="1" data-default="<?php p($_['ldap_nested_groups_default']); ?>"  title="<?php p($l->t('When switched on, groups that contain groups are supported. (Only works if the group member attribute contains DNs.)'));?>" /></p>
100
-				<p><label for="ldap_paging_size"><?php p($l->t('Paging chunksize'));?></label><input type="number" id="ldap_paging_size" name="ldap_paging_size" title="<?php p($l->t('Chunksize used for paged LDAP searches that may return bulky results like user or group enumeration. (Setting it 0 disables paged LDAP searches in those situations.)'));?>" data-default="<?php p($_['ldap_paging_size_default']); ?>" /></p>
101
-				<p><label for="ldap_turn_on_pwd_change"><?php p($l->t('Enable LDAP password changes per user'));?></label><span class="inlinetable"><span class="tablerow left"><input type="checkbox" id="ldap_turn_on_pwd_change" name="ldap_turn_on_pwd_change" value="1" data-default="<?php p($_['ldap_turn_on_pwd_change_default']); ?>" title="<?php p($l->t('Allow LDAP users to change their password and allow Super Administrators and Group Administrators to change the password of their LDAP users. Only works when access control policies are configured accordingly on the LDAP server. As passwords are sent in plaintext to the LDAP server, transport encryption must be used and password hashing should be configured on the LDAP server.'));?>" /><span class="tablecell"><?php p($l->t('(New password is sent as plain text to LDAP)'));?></span></span>
91
+				<p><label for="ldap_display_name"><?php p($l->t('User Display Name Field')); ?></label><input type="text" id="ldap_display_name" name="ldap_display_name" data-default="<?php p($_['ldap_display_name_default']); ?>" title="<?php p($l->t('The LDAP attribute to use to generate the user\'s display name.')); ?>" /></p>
92
+				<p><label for="ldap_user_display_name_2"><?php p($l->t('2nd User Display Name Field')); ?></label><input type="text" id="ldap_user_display_name_2" name="ldap_user_display_name_2" data-default="<?php p($_['ldap_user_display_name_2_default']); ?>" title="<?php p($l->t('Optional. An LDAP attribute to be added to the display name in brackets. Results in e.g. »John Doe ([email protected])«.')); ?>" /></p>
93
+				<p><label for="ldap_base_users"><?php p($l->t('Base User Tree')); ?></label><textarea id="ldap_base_users" name="ldap_base_users" placeholder="<?php p($l->t('One User Base DN per line')); ?>" data-default="<?php p($_['ldap_base_users_default']); ?>" title="<?php p($l->t('Base User Tree')); ?>"></textarea></p>
94
+				<p><label for="ldap_attributes_for_user_search"><?php p($l->t('User Search Attributes')); ?></label><textarea id="ldap_attributes_for_user_search" name="ldap_attributes_for_user_search" placeholder="<?php p($l->t('Optional; one attribute per line')); ?>" data-default="<?php p($_['ldap_attributes_for_user_search_default']); ?>" title="<?php p($l->t('User Search Attributes')); ?>"></textarea></p>
95
+				<p><label for="ldap_group_display_name"><?php p($l->t('Group Display Name Field')); ?></label><input type="text" id="ldap_group_display_name" name="ldap_group_display_name" data-default="<?php p($_['ldap_group_display_name_default']); ?>" title="<?php p($l->t('The LDAP attribute to use to generate the groups\'s display name.')); ?>" /></p>
96
+				<p><label for="ldap_base_groups"><?php p($l->t('Base Group Tree')); ?></label><textarea id="ldap_base_groups" name="ldap_base_groups" placeholder="<?php p($l->t('One Group Base DN per line')); ?>" data-default="<?php p($_['ldap_base_groups_default']); ?>" title="<?php p($l->t('Base Group Tree')); ?>"></textarea></p>
97
+				<p><label for="ldap_attributes_for_group_search"><?php p($l->t('Group Search Attributes')); ?></label><textarea id="ldap_attributes_for_group_search" name="ldap_attributes_for_group_search" placeholder="<?php p($l->t('Optional; one attribute per line')); ?>" data-default="<?php p($_['ldap_attributes_for_group_search_default']); ?>" title="<?php p($l->t('Group Search Attributes')); ?>"></textarea></p>
98
+				<p><label for="ldap_group_member_assoc_attribute"><?php p($l->t('Group-Member association')); ?></label><select id="ldap_group_member_assoc_attribute" name="ldap_group_member_assoc_attribute" data-default="<?php p($_['ldap_group_member_assoc_attribute_default']); ?>" ><option value="uniqueMember"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'uniqueMember')) p(' selected'); ?>>uniqueMember</option><option value="memberUid"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'memberUid')) p(' selected'); ?>>memberUid</option><option value="member"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'member')) p(' selected'); ?>>member (AD)</option><option value="gidNumber"<?php if (isset($_['ldap_group_member_assoc_attribute']) && ($_['ldap_group_member_assoc_attribute'] === 'gidNumber')) p(' selected'); ?>>gidNumber</option></select></p>				<p><label for="ldap_dynamic_group_member_url"><?php p($l->t('Dynamic Group Member URL')); ?></label><input type="text" id="ldap_dynamic_group_member_url" name="ldap_dynamic_group_member_url" title="<?php p($l->t('The LDAP attribute that on group objects contains an LDAP search URL that determines what objects belong to the group. (An empty setting disables dynamic group membership functionality.)')); ?>" data-default="<?php p($_['ldap_dynamic_group_member_url_default']); ?>" /></p>
99
+				<p><label for="ldap_nested_groups"><?php p($l->t('Nested Groups')); ?></label><input type="checkbox" id="ldap_nested_groups" name="ldap_nested_groups" value="1" data-default="<?php p($_['ldap_nested_groups_default']); ?>"  title="<?php p($l->t('When switched on, groups that contain groups are supported. (Only works if the group member attribute contains DNs.)')); ?>" /></p>
100
+				<p><label for="ldap_paging_size"><?php p($l->t('Paging chunksize')); ?></label><input type="number" id="ldap_paging_size" name="ldap_paging_size" title="<?php p($l->t('Chunksize used for paged LDAP searches that may return bulky results like user or group enumeration. (Setting it 0 disables paged LDAP searches in those situations.)')); ?>" data-default="<?php p($_['ldap_paging_size_default']); ?>" /></p>
101
+				<p><label for="ldap_turn_on_pwd_change"><?php p($l->t('Enable LDAP password changes per user')); ?></label><span class="inlinetable"><span class="tablerow left"><input type="checkbox" id="ldap_turn_on_pwd_change" name="ldap_turn_on_pwd_change" value="1" data-default="<?php p($_['ldap_turn_on_pwd_change_default']); ?>" title="<?php p($l->t('Allow LDAP users to change their password and allow Super Administrators and Group Administrators to change the password of their LDAP users. Only works when access control policies are configured accordingly on the LDAP server. As passwords are sent in plaintext to the LDAP server, transport encryption must be used and password hashing should be configured on the LDAP server.')); ?>" /><span class="tablecell"><?php p($l->t('(New password is sent as plain text to LDAP)')); ?></span></span>
102 102
 			</span><br/></p>
103
-				<p><label for="ldap_default_ppolicy_dn"><?php p($l->t('Default password policy DN'));?></label><input type="text" id="ldap_default_ppolicy_dn" name="ldap_default_ppolicy_dn" title="<?php p($l->t('The DN of a default password policy that will be used for password expiry handling. Works only when LDAP password changes per user are enabled and is only supported by OpenLDAP. Leave empty to disable password expiry handling.'));?>" data-default="<?php p($_['ldap_default_ppolicy_dn_default']); ?>" /></p>
103
+				<p><label for="ldap_default_ppolicy_dn"><?php p($l->t('Default password policy DN')); ?></label><input type="text" id="ldap_default_ppolicy_dn" name="ldap_default_ppolicy_dn" title="<?php p($l->t('The DN of a default password policy that will be used for password expiry handling. Works only when LDAP password changes per user are enabled and is only supported by OpenLDAP. Leave empty to disable password expiry handling.')); ?>" data-default="<?php p($_['ldap_default_ppolicy_dn_default']); ?>" /></p>
104 104
 			</div>
105
-			<h3><?php p($l->t('Special Attributes'));?></h3>
105
+			<h3><?php p($l->t('Special Attributes')); ?></h3>
106 106
 			<div>
107
-				<p><label for="ldap_quota_attr"><?php p($l->t('Quota Field'));?></label><input type="text" id="ldap_quota_attr" name="ldap_quota_attr" data-default="<?php p($_['ldap_quota_attr_default']); ?>" title="<?php p($l->t('Leave empty for user\'s default quota. Otherwise, specify an LDAP/AD attribute.'));?>" /></p>
108
-				<p><label for="ldap_quota_def"><?php p($l->t('Quota Default'));?></label><input type="text" id="ldap_quota_def" name="ldap_quota_def" data-default="<?php p($_['ldap_quota_def_default']); ?>" title="<?php p($l->t('Override default quota for LDAP users who do not have a quota set in the Quota Field.'));?>" /></p>
109
-				<p><label for="ldap_email_attr"><?php p($l->t('Email Field'));?></label><input type="text" id="ldap_email_attr" name="ldap_email_attr" data-default="<?php p($_['ldap_email_attr_default']); ?>" title="<?php p($l->t('Set the user\'s email from their LDAP attribute. Leave it empty for default behaviour.'));?>" /></p>
110
-				<p><label for="home_folder_naming_rule"><?php p($l->t('User Home Folder Naming Rule'));?></label><input type="text" id="home_folder_naming_rule" name="home_folder_naming_rule" title="<?php p($l->t('Leave empty for user name (default). Otherwise, specify an LDAP/AD attribute.'));?>" data-default="<?php p($_['home_folder_naming_rule_default']); ?>" /></p>
107
+				<p><label for="ldap_quota_attr"><?php p($l->t('Quota Field')); ?></label><input type="text" id="ldap_quota_attr" name="ldap_quota_attr" data-default="<?php p($_['ldap_quota_attr_default']); ?>" title="<?php p($l->t('Leave empty for user\'s default quota. Otherwise, specify an LDAP/AD attribute.')); ?>" /></p>
108
+				<p><label for="ldap_quota_def"><?php p($l->t('Quota Default')); ?></label><input type="text" id="ldap_quota_def" name="ldap_quota_def" data-default="<?php p($_['ldap_quota_def_default']); ?>" title="<?php p($l->t('Override default quota for LDAP users who do not have a quota set in the Quota Field.')); ?>" /></p>
109
+				<p><label for="ldap_email_attr"><?php p($l->t('Email Field')); ?></label><input type="text" id="ldap_email_attr" name="ldap_email_attr" data-default="<?php p($_['ldap_email_attr_default']); ?>" title="<?php p($l->t('Set the user\'s email from their LDAP attribute. Leave it empty for default behaviour.')); ?>" /></p>
110
+				<p><label for="home_folder_naming_rule"><?php p($l->t('User Home Folder Naming Rule')); ?></label><input type="text" id="home_folder_naming_rule" name="home_folder_naming_rule" title="<?php p($l->t('Leave empty for user name (default). Otherwise, specify an LDAP/AD attribute.')); ?>" data-default="<?php p($_['home_folder_naming_rule_default']); ?>" /></p>
111 111
 			</div>
112 112
 		</div>
113 113
 		<?php print_unescaped($_['settingControls']); ?>
114 114
 	</fieldset>
115 115
 	<fieldset id="ldapSettings-2">
116
-		<p><strong><?php p($l->t('Internal Username'));?></strong></p>
117
-		<p class="ldapIndent"><?php p($l->t('By default the internal username will be created from the UUID attribute. It makes sure that the username is unique and characters do not need to be converted. The internal username has the restriction that only these characters are allowed: [ a-zA-Z0-9_.@- ].  Other characters are replaced with their ASCII correspondence or simply omitted. On collisions a number will be added/increased. The internal username is used to identify a user internally. It is also the default name for the user home folder. It is also a part of remote URLs, for instance for all *DAV services. With this setting, the default behavior can be overridden. Leave it empty for default behavior. Changes will have effect only on newly mapped (added) LDAP users.'));?></p>
118
-		<p class="ldapIndent"><label for="ldap_expert_username_attr"><?php p($l->t('Internal Username Attribute:'));?></label><input type="text" id="ldap_expert_username_attr" name="ldap_expert_username_attr" data-default="<?php p($_['ldap_expert_username_attr_default']); ?>" /></p>
119
-		<p><strong><?php p($l->t('Override UUID detection'));?></strong></p>
120
-		<p class="ldapIndent"><?php p($l->t('By default, the UUID attribute is automatically detected. The UUID attribute is used to doubtlessly identify LDAP users and groups. Also, the internal username will be created based on the UUID, if not specified otherwise above. You can override the setting and pass an attribute of your choice. You must make sure that the attribute of your choice can be fetched for both users and groups and it is unique. Leave it empty for default behavior. Changes will have effect only on newly mapped (added) LDAP users and groups.'));?></p>
121
-		<p class="ldapIndent"><label for="ldap_expert_uuid_user_attr"><?php p($l->t('UUID Attribute for Users:'));?></label><input type="text" id="ldap_expert_uuid_user_attr" name="ldap_expert_uuid_user_attr" data-default="<?php p($_['ldap_expert_uuid_user_attr_default']); ?>" /></p>
122
-		<p class="ldapIndent"><label for="ldap_expert_uuid_group_attr"><?php p($l->t('UUID Attribute for Groups:'));?></label><input type="text" id="ldap_expert_uuid_group_attr" name="ldap_expert_uuid_group_attr" data-default="<?php p($_['ldap_expert_uuid_group_attr_default']); ?>" /></p>
123
-		<p><strong><?php p($l->t('Username-LDAP User Mapping'));?></strong></p>
124
-		<p class="ldapIndent"><?php p($l->t('Usernames are used to store and assign metadata. In order to precisely identify and recognize users, each LDAP user will have an internal username. This requires a mapping from username to LDAP user. The created username is mapped to the UUID of the LDAP user. Additionally the DN is cached as well to reduce LDAP interaction, but it is not used for identification. If the DN changes, the changes will be found. The internal username is used all over. Clearing the mappings will have leftovers everywhere. Clearing the mappings is not configuration sensitive, it affects all LDAP configurations! Never clear the mappings in a production environment, only in a testing or experimental stage.'));?></p>
125
-		<p class="ldapIndent"><button type="button" id="ldap_action_clear_user_mappings" name="ldap_action_clear_user_mappings"><?php p($l->t('Clear Username-LDAP User Mapping'));?></button><br/><button type="button" id="ldap_action_clear_group_mappings" name="ldap_action_clear_group_mappings"><?php p($l->t('Clear Groupname-LDAP Group Mapping'));?></button></p>
116
+		<p><strong><?php p($l->t('Internal Username')); ?></strong></p>
117
+		<p class="ldapIndent"><?php p($l->t('By default the internal username will be created from the UUID attribute. It makes sure that the username is unique and characters do not need to be converted. The internal username has the restriction that only these characters are allowed: [ a-zA-Z0-9_.@- ].  Other characters are replaced with their ASCII correspondence or simply omitted. On collisions a number will be added/increased. The internal username is used to identify a user internally. It is also the default name for the user home folder. It is also a part of remote URLs, for instance for all *DAV services. With this setting, the default behavior can be overridden. Leave it empty for default behavior. Changes will have effect only on newly mapped (added) LDAP users.')); ?></p>
118
+		<p class="ldapIndent"><label for="ldap_expert_username_attr"><?php p($l->t('Internal Username Attribute:')); ?></label><input type="text" id="ldap_expert_username_attr" name="ldap_expert_username_attr" data-default="<?php p($_['ldap_expert_username_attr_default']); ?>" /></p>
119
+		<p><strong><?php p($l->t('Override UUID detection')); ?></strong></p>
120
+		<p class="ldapIndent"><?php p($l->t('By default, the UUID attribute is automatically detected. The UUID attribute is used to doubtlessly identify LDAP users and groups. Also, the internal username will be created based on the UUID, if not specified otherwise above. You can override the setting and pass an attribute of your choice. You must make sure that the attribute of your choice can be fetched for both users and groups and it is unique. Leave it empty for default behavior. Changes will have effect only on newly mapped (added) LDAP users and groups.')); ?></p>
121
+		<p class="ldapIndent"><label for="ldap_expert_uuid_user_attr"><?php p($l->t('UUID Attribute for Users:')); ?></label><input type="text" id="ldap_expert_uuid_user_attr" name="ldap_expert_uuid_user_attr" data-default="<?php p($_['ldap_expert_uuid_user_attr_default']); ?>" /></p>
122
+		<p class="ldapIndent"><label for="ldap_expert_uuid_group_attr"><?php p($l->t('UUID Attribute for Groups:')); ?></label><input type="text" id="ldap_expert_uuid_group_attr" name="ldap_expert_uuid_group_attr" data-default="<?php p($_['ldap_expert_uuid_group_attr_default']); ?>" /></p>
123
+		<p><strong><?php p($l->t('Username-LDAP User Mapping')); ?></strong></p>
124
+		<p class="ldapIndent"><?php p($l->t('Usernames are used to store and assign metadata. In order to precisely identify and recognize users, each LDAP user will have an internal username. This requires a mapping from username to LDAP user. The created username is mapped to the UUID of the LDAP user. Additionally the DN is cached as well to reduce LDAP interaction, but it is not used for identification. If the DN changes, the changes will be found. The internal username is used all over. Clearing the mappings will have leftovers everywhere. Clearing the mappings is not configuration sensitive, it affects all LDAP configurations! Never clear the mappings in a production environment, only in a testing or experimental stage.')); ?></p>
125
+		<p class="ldapIndent"><button type="button" id="ldap_action_clear_user_mappings" name="ldap_action_clear_user_mappings"><?php p($l->t('Clear Username-LDAP User Mapping')); ?></button><br/><button type="button" id="ldap_action_clear_group_mappings" name="ldap_action_clear_group_mappings"><?php p($l->t('Clear Groupname-LDAP Group Mapping')); ?></button></p>
126 126
 		<?php print_unescaped($_['settingControls']); ?>
127 127
 	</fieldset>
128 128
 	</div>
Please login to merge, or discard this patch.
apps/dav/lib/Migration/BuildCalendarSearchIndexBackgroundJob.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 		$offset = $arguments['offset'];
70 70
 		$stopAt = $arguments['stopAt'];
71 71
 
72
-		$this->logger->info('Building calendar index (' . $offset .'/' . $stopAt . ')');
72
+		$this->logger->info('Building calendar index ('.$offset.'/'.$stopAt.')');
73 73
 
74 74
 		$offset = $this->buildIndex($offset, $stopAt);
75 75
 
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 				'offset' => $offset,
81 81
 				'stopAt' => $stopAt
82 82
 			]);
83
-			$this->logger->info('New building calendar index job scheduled with offset ' . $offset);
83
+			$this->logger->info('New building calendar index job scheduled with offset '.$offset);
84 84
 		}
85 85
 	}
86 86
 
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 			->orderBy('id', 'ASC');
101 101
 
102 102
 		$stmt = $query->execute();
103
-		while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
103
+		while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
104 104
 			$offset = $row['id'];
105 105
 
106 106
 			$calendarData = $row['calendardata'];
Please login to merge, or discard this patch.
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -31,90 +31,90 @@
 block discarded – undo
31 31
 
32 32
 class BuildCalendarSearchIndexBackgroundJob extends QueuedJob {
33 33
 
34
-	/** @var IDBConnection */
35
-	private $db;
36
-
37
-	/** @var CalDavBackend */
38
-	private $calDavBackend;
39
-
40
-	/** @var ILogger */
41
-	private $logger;
42
-
43
-	/** @var IJobList */
44
-	private $jobList;
45
-
46
-	/** @var ITimeFactory */
47
-	private $timeFactory;
48
-
49
-	/**
50
-	 * @param IDBConnection $db
51
-	 * @param CalDavBackend $calDavBackend
52
-	 * @param ILogger $logger
53
-	 * @param IJobList $jobList
54
-	 * @param ITimeFactory $timeFactory
55
-	 */
56
-	public function __construct(IDBConnection $db,
57
-								CalDavBackend $calDavBackend,
58
-								ILogger $logger,
59
-								IJobList $jobList,
60
-								ITimeFactory $timeFactory) {
61
-		$this->db = $db;
62
-		$this->calDavBackend = $calDavBackend;
63
-		$this->logger = $logger;
64
-		$this->jobList = $jobList;
65
-		$this->timeFactory = $timeFactory;
66
-	}
67
-
68
-	public function run($arguments) {
69
-		$offset = $arguments['offset'];
70
-		$stopAt = $arguments['stopAt'];
71
-
72
-		$this->logger->info('Building calendar index (' . $offset .'/' . $stopAt . ')');
73
-
74
-		$offset = $this->buildIndex($offset, $stopAt);
75
-
76
-		if ($offset >= $stopAt) {
77
-			$this->logger->info('Building calendar index done');
78
-		} else {
79
-			$this->jobList->add(self::class, [
80
-				'offset' => $offset,
81
-				'stopAt' => $stopAt
82
-			]);
83
-			$this->logger->info('New building calendar index job scheduled with offset ' . $offset);
84
-		}
85
-	}
86
-
87
-	/**
88
-	 * @param int $offset
89
-	 * @param int $stopAt
90
-	 * @return int
91
-	 */
92
-	private function buildIndex($offset, $stopAt) {
93
-		$startTime = $this->timeFactory->getTime();
94
-
95
-		$query = $this->db->getQueryBuilder();
96
-		$query->select(['id', 'calendarid', 'uri', 'calendardata'])
97
-			->from('calendarobjects')
98
-			->where($query->expr()->lte('id', $query->createNamedParameter($stopAt)))
99
-			->andWhere($query->expr()->gt('id', $query->createNamedParameter($offset)))
100
-			->orderBy('id', 'ASC');
101
-
102
-		$stmt = $query->execute();
103
-		while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
104
-			$offset = $row['id'];
105
-
106
-			$calendarData = $row['calendardata'];
107
-			if (is_resource($calendarData)) {
108
-				$calendarData = stream_get_contents($calendarData);
109
-			}
110
-
111
-			$this->calDavBackend->updateProperties($row['calendarid'], $row['uri'], $calendarData);
112
-
113
-			if (($this->timeFactory->getTime() - $startTime) > 15) {
114
-				return $offset;
115
-			}
116
-		}
117
-
118
-		return $stopAt;
119
-	}
34
+    /** @var IDBConnection */
35
+    private $db;
36
+
37
+    /** @var CalDavBackend */
38
+    private $calDavBackend;
39
+
40
+    /** @var ILogger */
41
+    private $logger;
42
+
43
+    /** @var IJobList */
44
+    private $jobList;
45
+
46
+    /** @var ITimeFactory */
47
+    private $timeFactory;
48
+
49
+    /**
50
+     * @param IDBConnection $db
51
+     * @param CalDavBackend $calDavBackend
52
+     * @param ILogger $logger
53
+     * @param IJobList $jobList
54
+     * @param ITimeFactory $timeFactory
55
+     */
56
+    public function __construct(IDBConnection $db,
57
+                                CalDavBackend $calDavBackend,
58
+                                ILogger $logger,
59
+                                IJobList $jobList,
60
+                                ITimeFactory $timeFactory) {
61
+        $this->db = $db;
62
+        $this->calDavBackend = $calDavBackend;
63
+        $this->logger = $logger;
64
+        $this->jobList = $jobList;
65
+        $this->timeFactory = $timeFactory;
66
+    }
67
+
68
+    public function run($arguments) {
69
+        $offset = $arguments['offset'];
70
+        $stopAt = $arguments['stopAt'];
71
+
72
+        $this->logger->info('Building calendar index (' . $offset .'/' . $stopAt . ')');
73
+
74
+        $offset = $this->buildIndex($offset, $stopAt);
75
+
76
+        if ($offset >= $stopAt) {
77
+            $this->logger->info('Building calendar index done');
78
+        } else {
79
+            $this->jobList->add(self::class, [
80
+                'offset' => $offset,
81
+                'stopAt' => $stopAt
82
+            ]);
83
+            $this->logger->info('New building calendar index job scheduled with offset ' . $offset);
84
+        }
85
+    }
86
+
87
+    /**
88
+     * @param int $offset
89
+     * @param int $stopAt
90
+     * @return int
91
+     */
92
+    private function buildIndex($offset, $stopAt) {
93
+        $startTime = $this->timeFactory->getTime();
94
+
95
+        $query = $this->db->getQueryBuilder();
96
+        $query->select(['id', 'calendarid', 'uri', 'calendardata'])
97
+            ->from('calendarobjects')
98
+            ->where($query->expr()->lte('id', $query->createNamedParameter($stopAt)))
99
+            ->andWhere($query->expr()->gt('id', $query->createNamedParameter($offset)))
100
+            ->orderBy('id', 'ASC');
101
+
102
+        $stmt = $query->execute();
103
+        while($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
104
+            $offset = $row['id'];
105
+
106
+            $calendarData = $row['calendardata'];
107
+            if (is_resource($calendarData)) {
108
+                $calendarData = stream_get_contents($calendarData);
109
+            }
110
+
111
+            $this->calDavBackend->updateProperties($row['calendarid'], $row['uri'], $calendarData);
112
+
113
+            if (($this->timeFactory->getTime() - $startTime) > 15) {
114
+                return $offset;
115
+            }
116
+        }
117
+
118
+        return $stopAt;
119
+    }
120 120
 }
Please login to merge, or discard this patch.
apps/dav/lib/Migration/BuildCalendarSearchIndex.php 2 patches
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -30,57 +30,57 @@
 block discarded – undo
30 30
 
31 31
 class BuildCalendarSearchIndex implements IRepairStep {
32 32
 
33
-	/** @var IDBConnection */
34
-	private $db;
33
+    /** @var IDBConnection */
34
+    private $db;
35 35
 
36
-	/** @var IJobList */
37
-	private $jobList;
36
+    /** @var IJobList */
37
+    private $jobList;
38 38
 
39
-	/** @var IConfig */
40
-	private $config;
39
+    /** @var IConfig */
40
+    private $config;
41 41
 
42
-	/**
43
-	 * @param IDBConnection $db
44
-	 * @param IJobList $jobList
45
-	 * @param IConfig $config
46
-	 */
47
-	public function __construct(IDBConnection $db,
48
-								IJobList $jobList,
49
-								IConfig $config) {
50
-		$this->db = $db;
51
-		$this->jobList = $jobList;
52
-		$this->config = $config;
53
-	}
42
+    /**
43
+     * @param IDBConnection $db
44
+     * @param IJobList $jobList
45
+     * @param IConfig $config
46
+     */
47
+    public function __construct(IDBConnection $db,
48
+                                IJobList $jobList,
49
+                                IConfig $config) {
50
+        $this->db = $db;
51
+        $this->jobList = $jobList;
52
+        $this->config = $config;
53
+    }
54 54
 
55
-	/**
56
-	 * @return string
57
-	 */
58
-	public function getName() {
59
-		return 'Registering building of calendar search index as background job';
60
-	}
55
+    /**
56
+     * @return string
57
+     */
58
+    public function getName() {
59
+        return 'Registering building of calendar search index as background job';
60
+    }
61 61
 
62
-	/**
63
-	 * @param IOutput $output
64
-	 */
65
-	public function run(IOutput $output) {
66
-		// only run once
67
-		if ($this->config->getAppValue('dav', 'buildCalendarSearchIndex') === 'yes') {
68
-			$output->info('Repair step already executed');
69
-			return;
70
-		}
62
+    /**
63
+     * @param IOutput $output
64
+     */
65
+    public function run(IOutput $output) {
66
+        // only run once
67
+        if ($this->config->getAppValue('dav', 'buildCalendarSearchIndex') === 'yes') {
68
+            $output->info('Repair step already executed');
69
+            return;
70
+        }
71 71
 
72
-		$query = $this->db->getQueryBuilder();
73
-		$query->select($query->createFunction('MAX(id)'))
74
-			->from('calendarobjects');
75
-		$maxId = (int)$query->execute()->fetchColumn();
72
+        $query = $this->db->getQueryBuilder();
73
+        $query->select($query->createFunction('MAX(id)'))
74
+            ->from('calendarobjects');
75
+        $maxId = (int)$query->execute()->fetchColumn();
76 76
 
77
-		$output->info('Add background job');
78
-		$this->jobList->add(BuildCalendarSearchIndexBackgroundJob::class, [
79
-			'offset' => 0,
80
-			'stopAt' => $maxId
81
-		]);
77
+        $output->info('Add background job');
78
+        $this->jobList->add(BuildCalendarSearchIndexBackgroundJob::class, [
79
+            'offset' => 0,
80
+            'stopAt' => $maxId
81
+        ]);
82 82
 
83
-		// if all were done, no need to redo the repair during next upgrade
84
-		$this->config->setAppValue('dav', 'buildCalendarSearchIndex', 'yes');
85
-	}
83
+        // if all were done, no need to redo the repair during next upgrade
84
+        $this->config->setAppValue('dav', 'buildCalendarSearchIndex', 'yes');
85
+    }
86 86
 }
87 87
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@
 block discarded – undo
72 72
 		$query = $this->db->getQueryBuilder();
73 73
 		$query->select($query->createFunction('MAX(id)'))
74 74
 			->from('calendarobjects');
75
-		$maxId = (int)$query->execute()->fetchColumn();
75
+		$maxId = (int) $query->execute()->fetchColumn();
76 76
 
77 77
 		$output->info('Add background job');
78 78
 		$this->jobList->add(BuildCalendarSearchIndexBackgroundJob::class, [
Please login to merge, or discard this patch.
apps/sharebymail/templates/settings-admin.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,9 +11,9 @@
 block discarded – undo
11 11
 	<p class="settings-hint"><?php p($l->t('Allows users to share a personalized link to a file or folder by putting in an email address.')); ?></p>
12 12
 
13 13
 	<p>
14
-		<input id="sendPasswordMail" type="checkbox" class="checkbox" <?php if($_['sendPasswordMail']) p('checked'); ?> />
14
+		<input id="sendPasswordMail" type="checkbox" class="checkbox" <?php if ($_['sendPasswordMail']) p('checked'); ?> />
15 15
 		<label for="sendPasswordMail"><?php p($l->t('Send password by mail')); ?></label><br/>
16
-		<input id="enforcePasswordProtection" type="checkbox" class="checkbox" <?php if($_['enforcePasswordProtection']) p('checked'); ?> />
16
+		<input id="enforcePasswordProtection" type="checkbox" class="checkbox" <?php if ($_['enforcePasswordProtection']) p('checked'); ?> />
17 17
 		<label for="enforcePasswordProtection"><?php p($l->t('Enforce password protection')); ?></label>
18 18
 	</p>
19 19
 
Please login to merge, or discard this patch.
Braces   +8 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,9 +11,15 @@
 block discarded – undo
11 11
 	<p class="settings-hint"><?php p($l->t('Allows users to share a personalized link to a file or folder by putting in an email address.')); ?></p>
12 12
 
13 13
 	<p>
14
-		<input id="sendPasswordMail" type="checkbox" class="checkbox" <?php if($_['sendPasswordMail']) p('checked'); ?> />
14
+		<input id="sendPasswordMail" type="checkbox" class="checkbox" <?php if($_['sendPasswordMail']) {
15
+    p('checked');
16
+}
17
+?> />
15 18
 		<label for="sendPasswordMail"><?php p($l->t('Send password by mail')); ?></label><br/>
16
-		<input id="enforcePasswordProtection" type="checkbox" class="checkbox" <?php if($_['enforcePasswordProtection']) p('checked'); ?> />
19
+		<input id="enforcePasswordProtection" type="checkbox" class="checkbox" <?php if($_['enforcePasswordProtection']) {
20
+    p('checked');
21
+}
22
+?> />
17 23
 		<label for="enforcePasswordProtection"><?php p($l->t('Enforce password protection')); ?></label>
18 24
 	</p>
19 25
 
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/TagsPlugin.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -220,9 +220,9 @@  discard block
 block discarded – undo
220 220
 		)) {
221 221
 			// note: pre-fetching only supported for depth <= 1
222 222
 			$folderContent = $node->getChildren();
223
-			$fileIds[] = (int)$node->getId();
223
+			$fileIds[] = (int) $node->getId();
224 224
 			foreach ($folderContent as $info) {
225
-				$fileIds[] = (int)$info->getId();
225
+				$fileIds[] = (int) $info->getId();
226 226
 			}
227 227
 			$tags = $this->getTagger()->getTagsForObjects($fileIds);
228 228
 			if ($tags === false) {
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 		});
279 279
 
280 280
 		$propPatch->handle(self::FAVORITE_PROPERTYNAME, function($favState) use ($node) {
281
-			if ((int)$favState === 1 || $favState === 'true') {
281
+			if ((int) $favState === 1 || $favState === 'true') {
282 282
 				$this->getTagger()->tagAs($node->getId(), self::TAG_FAVORITE);
283 283
 			} else {
284 284
 				$this->getTagger()->unTag($node->getId(), self::TAG_FAVORITE);
Please login to merge, or discard this patch.
Indentation   +217 added lines, -217 removed lines patch added patch discarded remove patch
@@ -51,246 +51,246 @@
 block discarded – undo
51 51
 class TagsPlugin extends \Sabre\DAV\ServerPlugin
52 52
 {
53 53
 
54
-	// namespace
55
-	const NS_OWNCLOUD = 'http://owncloud.org/ns';
56
-	const TAGS_PROPERTYNAME = '{http://owncloud.org/ns}tags';
57
-	const FAVORITE_PROPERTYNAME = '{http://owncloud.org/ns}favorite';
58
-	const TAG_FAVORITE = '_$!<Favorite>!$_';
54
+    // namespace
55
+    const NS_OWNCLOUD = 'http://owncloud.org/ns';
56
+    const TAGS_PROPERTYNAME = '{http://owncloud.org/ns}tags';
57
+    const FAVORITE_PROPERTYNAME = '{http://owncloud.org/ns}favorite';
58
+    const TAG_FAVORITE = '_$!<Favorite>!$_';
59 59
 
60
-	/**
61
-	 * Reference to main server object
62
-	 *
63
-	 * @var \Sabre\DAV\Server
64
-	 */
65
-	private $server;
60
+    /**
61
+     * Reference to main server object
62
+     *
63
+     * @var \Sabre\DAV\Server
64
+     */
65
+    private $server;
66 66
 
67
-	/**
68
-	 * @var \OCP\ITagManager
69
-	 */
70
-	private $tagManager;
67
+    /**
68
+     * @var \OCP\ITagManager
69
+     */
70
+    private $tagManager;
71 71
 
72
-	/**
73
-	 * @var \OCP\ITags
74
-	 */
75
-	private $tagger;
72
+    /**
73
+     * @var \OCP\ITags
74
+     */
75
+    private $tagger;
76 76
 
77
-	/**
78
-	 * Array of file id to tags array
79
-	 * The null value means the cache wasn't initialized.
80
-	 *
81
-	 * @var array
82
-	 */
83
-	private $cachedTags;
77
+    /**
78
+     * Array of file id to tags array
79
+     * The null value means the cache wasn't initialized.
80
+     *
81
+     * @var array
82
+     */
83
+    private $cachedTags;
84 84
 
85
-	/**
86
-	 * @var \Sabre\DAV\Tree
87
-	 */
88
-	private $tree;
85
+    /**
86
+     * @var \Sabre\DAV\Tree
87
+     */
88
+    private $tree;
89 89
 
90
-	/**
91
-	 * @param \Sabre\DAV\Tree $tree tree
92
-	 * @param \OCP\ITagManager $tagManager tag manager
93
-	 */
94
-	public function __construct(\Sabre\DAV\Tree $tree, \OCP\ITagManager $tagManager) {
95
-		$this->tree = $tree;
96
-		$this->tagManager = $tagManager;
97
-		$this->tagger = null;
98
-		$this->cachedTags = array();
99
-	}
90
+    /**
91
+     * @param \Sabre\DAV\Tree $tree tree
92
+     * @param \OCP\ITagManager $tagManager tag manager
93
+     */
94
+    public function __construct(\Sabre\DAV\Tree $tree, \OCP\ITagManager $tagManager) {
95
+        $this->tree = $tree;
96
+        $this->tagManager = $tagManager;
97
+        $this->tagger = null;
98
+        $this->cachedTags = array();
99
+    }
100 100
 
101
-	/**
102
-	 * This initializes the plugin.
103
-	 *
104
-	 * This function is called by \Sabre\DAV\Server, after
105
-	 * addPlugin is called.
106
-	 *
107
-	 * This method should set up the required event subscriptions.
108
-	 *
109
-	 * @param \Sabre\DAV\Server $server
110
-	 * @return void
111
-	 */
112
-	public function initialize(\Sabre\DAV\Server $server) {
101
+    /**
102
+     * This initializes the plugin.
103
+     *
104
+     * This function is called by \Sabre\DAV\Server, after
105
+     * addPlugin is called.
106
+     *
107
+     * This method should set up the required event subscriptions.
108
+     *
109
+     * @param \Sabre\DAV\Server $server
110
+     * @return void
111
+     */
112
+    public function initialize(\Sabre\DAV\Server $server) {
113 113
 
114
-		$server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc';
115
-		$server->xml->elementMap[self::TAGS_PROPERTYNAME] = TagList::class;
114
+        $server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc';
115
+        $server->xml->elementMap[self::TAGS_PROPERTYNAME] = TagList::class;
116 116
 
117
-		$this->server = $server;
118
-		$this->server->on('propFind', array($this, 'handleGetProperties'));
119
-		$this->server->on('propPatch', array($this, 'handleUpdateProperties'));
120
-	}
117
+        $this->server = $server;
118
+        $this->server->on('propFind', array($this, 'handleGetProperties'));
119
+        $this->server->on('propPatch', array($this, 'handleUpdateProperties'));
120
+    }
121 121
 
122
-	/**
123
-	 * Returns the tagger
124
-	 *
125
-	 * @return \OCP\ITags tagger
126
-	 */
127
-	private function getTagger() {
128
-		if (!$this->tagger) {
129
-			$this->tagger = $this->tagManager->load('files');
130
-		}
131
-		return $this->tagger;
132
-	}
122
+    /**
123
+     * Returns the tagger
124
+     *
125
+     * @return \OCP\ITags tagger
126
+     */
127
+    private function getTagger() {
128
+        if (!$this->tagger) {
129
+            $this->tagger = $this->tagManager->load('files');
130
+        }
131
+        return $this->tagger;
132
+    }
133 133
 
134
-	/**
135
-	 * Returns tags and favorites.
136
-	 *
137
-	 * @param integer $fileId file id
138
-	 * @return array list($tags, $favorite) with $tags as tag array
139
-	 * and $favorite is a boolean whether the file was favorited
140
-	 */
141
-	private function getTagsAndFav($fileId) {
142
-		$isFav = false;
143
-		$tags = $this->getTags($fileId);
144
-		if ($tags) {
145
-			$favPos = array_search(self::TAG_FAVORITE, $tags);
146
-			if ($favPos !== false) {
147
-				$isFav = true;
148
-				unset($tags[$favPos]);
149
-			}
150
-		}
151
-		return array($tags, $isFav);
152
-	}
134
+    /**
135
+     * Returns tags and favorites.
136
+     *
137
+     * @param integer $fileId file id
138
+     * @return array list($tags, $favorite) with $tags as tag array
139
+     * and $favorite is a boolean whether the file was favorited
140
+     */
141
+    private function getTagsAndFav($fileId) {
142
+        $isFav = false;
143
+        $tags = $this->getTags($fileId);
144
+        if ($tags) {
145
+            $favPos = array_search(self::TAG_FAVORITE, $tags);
146
+            if ($favPos !== false) {
147
+                $isFav = true;
148
+                unset($tags[$favPos]);
149
+            }
150
+        }
151
+        return array($tags, $isFav);
152
+    }
153 153
 
154
-	/**
155
-	 * Returns tags for the given file id
156
-	 *
157
-	 * @param integer $fileId file id
158
-	 * @return array list of tags for that file
159
-	 */
160
-	private function getTags($fileId) {
161
-		if (isset($this->cachedTags[$fileId])) {
162
-			return $this->cachedTags[$fileId];
163
-		} else {
164
-			$tags = $this->getTagger()->getTagsForObjects(array($fileId));
165
-			if ($tags !== false) {
166
-				if (empty($tags)) {
167
-					return array();
168
-				}
169
-				return current($tags);
170
-			}
171
-		}
172
-		return null;
173
-	}
154
+    /**
155
+     * Returns tags for the given file id
156
+     *
157
+     * @param integer $fileId file id
158
+     * @return array list of tags for that file
159
+     */
160
+    private function getTags($fileId) {
161
+        if (isset($this->cachedTags[$fileId])) {
162
+            return $this->cachedTags[$fileId];
163
+        } else {
164
+            $tags = $this->getTagger()->getTagsForObjects(array($fileId));
165
+            if ($tags !== false) {
166
+                if (empty($tags)) {
167
+                    return array();
168
+                }
169
+                return current($tags);
170
+            }
171
+        }
172
+        return null;
173
+    }
174 174
 
175
-	/**
176
-	 * Updates the tags of the given file id
177
-	 *
178
-	 * @param int $fileId
179
-	 * @param array $tags array of tag strings
180
-	 */
181
-	private function updateTags($fileId, $tags) {
182
-		$tagger = $this->getTagger();
183
-		$currentTags = $this->getTags($fileId);
175
+    /**
176
+     * Updates the tags of the given file id
177
+     *
178
+     * @param int $fileId
179
+     * @param array $tags array of tag strings
180
+     */
181
+    private function updateTags($fileId, $tags) {
182
+        $tagger = $this->getTagger();
183
+        $currentTags = $this->getTags($fileId);
184 184
 
185
-		$newTags = array_diff($tags, $currentTags);
186
-		foreach ($newTags as $tag) {
187
-			if ($tag === self::TAG_FAVORITE) {
188
-				continue;
189
-			}
190
-			$tagger->tagAs($fileId, $tag);
191
-		}
192
-		$deletedTags = array_diff($currentTags, $tags);
193
-		foreach ($deletedTags as $tag) {
194
-			if ($tag === self::TAG_FAVORITE) {
195
-				continue;
196
-			}
197
-			$tagger->unTag($fileId, $tag);
198
-		}
199
-	}
185
+        $newTags = array_diff($tags, $currentTags);
186
+        foreach ($newTags as $tag) {
187
+            if ($tag === self::TAG_FAVORITE) {
188
+                continue;
189
+            }
190
+            $tagger->tagAs($fileId, $tag);
191
+        }
192
+        $deletedTags = array_diff($currentTags, $tags);
193
+        foreach ($deletedTags as $tag) {
194
+            if ($tag === self::TAG_FAVORITE) {
195
+                continue;
196
+            }
197
+            $tagger->unTag($fileId, $tag);
198
+        }
199
+    }
200 200
 
201
-	/**
202
-	 * Adds tags and favorites properties to the response,
203
-	 * if requested.
204
-	 *
205
-	 * @param PropFind $propFind
206
-	 * @param \Sabre\DAV\INode $node
207
-	 * @return void
208
-	 */
209
-	public function handleGetProperties(
210
-		PropFind $propFind,
211
-		\Sabre\DAV\INode $node
212
-	) {
213
-		if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) {
214
-			return;
215
-		}
201
+    /**
202
+     * Adds tags and favorites properties to the response,
203
+     * if requested.
204
+     *
205
+     * @param PropFind $propFind
206
+     * @param \Sabre\DAV\INode $node
207
+     * @return void
208
+     */
209
+    public function handleGetProperties(
210
+        PropFind $propFind,
211
+        \Sabre\DAV\INode $node
212
+    ) {
213
+        if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) {
214
+            return;
215
+        }
216 216
 
217
-		// need prefetch ?
218
-		if ($node instanceof \OCA\DAV\Connector\Sabre\Directory
219
-			&& $propFind->getDepth() !== 0
220
-			&& (!is_null($propFind->getStatus(self::TAGS_PROPERTYNAME))
221
-			|| !is_null($propFind->getStatus(self::FAVORITE_PROPERTYNAME))
222
-		)) {
223
-			// note: pre-fetching only supported for depth <= 1
224
-			$folderContent = $node->getChildren();
225
-			$fileIds[] = (int)$node->getId();
226
-			foreach ($folderContent as $info) {
227
-				$fileIds[] = (int)$info->getId();
228
-			}
229
-			$tags = $this->getTagger()->getTagsForObjects($fileIds);
230
-			if ($tags === false) {
231
-				// the tags API returns false on error...
232
-				$tags = array();
233
-			}
217
+        // need prefetch ?
218
+        if ($node instanceof \OCA\DAV\Connector\Sabre\Directory
219
+            && $propFind->getDepth() !== 0
220
+            && (!is_null($propFind->getStatus(self::TAGS_PROPERTYNAME))
221
+            || !is_null($propFind->getStatus(self::FAVORITE_PROPERTYNAME))
222
+        )) {
223
+            // note: pre-fetching only supported for depth <= 1
224
+            $folderContent = $node->getChildren();
225
+            $fileIds[] = (int)$node->getId();
226
+            foreach ($folderContent as $info) {
227
+                $fileIds[] = (int)$info->getId();
228
+            }
229
+            $tags = $this->getTagger()->getTagsForObjects($fileIds);
230
+            if ($tags === false) {
231
+                // the tags API returns false on error...
232
+                $tags = array();
233
+            }
234 234
 
235
-			$this->cachedTags = $this->cachedTags + $tags;
236
-			$emptyFileIds = array_diff($fileIds, array_keys($tags));
237
-			// also cache the ones that were not found
238
-			foreach ($emptyFileIds as $fileId) {
239
-				$this->cachedTags[$fileId] = [];
240
-			}
241
-		}
235
+            $this->cachedTags = $this->cachedTags + $tags;
236
+            $emptyFileIds = array_diff($fileIds, array_keys($tags));
237
+            // also cache the ones that were not found
238
+            foreach ($emptyFileIds as $fileId) {
239
+                $this->cachedTags[$fileId] = [];
240
+            }
241
+        }
242 242
 
243
-		$isFav = null;
243
+        $isFav = null;
244 244
 
245
-		$propFind->handle(self::TAGS_PROPERTYNAME, function() use (&$isFav, $node) {
246
-			list($tags, $isFav) = $this->getTagsAndFav($node->getId());
247
-			return new TagList($tags);
248
-		});
245
+        $propFind->handle(self::TAGS_PROPERTYNAME, function() use (&$isFav, $node) {
246
+            list($tags, $isFav) = $this->getTagsAndFav($node->getId());
247
+            return new TagList($tags);
248
+        });
249 249
 
250
-		$propFind->handle(self::FAVORITE_PROPERTYNAME, function() use ($isFav, $node) {
251
-			if (is_null($isFav)) {
252
-				list(, $isFav) = $this->getTagsAndFav($node->getId());
253
-			}
254
-			if ($isFav) {
255
-				return 1;
256
-			} else {
257
-				return 0;
258
-			}
259
-		});
260
-	}
250
+        $propFind->handle(self::FAVORITE_PROPERTYNAME, function() use ($isFav, $node) {
251
+            if (is_null($isFav)) {
252
+                list(, $isFav) = $this->getTagsAndFav($node->getId());
253
+            }
254
+            if ($isFav) {
255
+                return 1;
256
+            } else {
257
+                return 0;
258
+            }
259
+        });
260
+    }
261 261
 
262
-	/**
263
-	 * Updates tags and favorites properties, if applicable.
264
-	 *
265
-	 * @param string $path
266
-	 * @param PropPatch $propPatch
267
-	 *
268
-	 * @return void
269
-	 */
270
-	public function handleUpdateProperties($path, PropPatch $propPatch) {
271
-		$node = $this->tree->getNodeForPath($path);
272
-		if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) {
273
-			return;
274
-		}
262
+    /**
263
+     * Updates tags and favorites properties, if applicable.
264
+     *
265
+     * @param string $path
266
+     * @param PropPatch $propPatch
267
+     *
268
+     * @return void
269
+     */
270
+    public function handleUpdateProperties($path, PropPatch $propPatch) {
271
+        $node = $this->tree->getNodeForPath($path);
272
+        if (!($node instanceof \OCA\DAV\Connector\Sabre\Node)) {
273
+            return;
274
+        }
275 275
 
276
-		$propPatch->handle(self::TAGS_PROPERTYNAME, function($tagList) use ($node) {
277
-			$this->updateTags($node->getId(), $tagList->getTags());
278
-			return true;
279
-		});
276
+        $propPatch->handle(self::TAGS_PROPERTYNAME, function($tagList) use ($node) {
277
+            $this->updateTags($node->getId(), $tagList->getTags());
278
+            return true;
279
+        });
280 280
 
281
-		$propPatch->handle(self::FAVORITE_PROPERTYNAME, function($favState) use ($node) {
282
-			if ((int)$favState === 1 || $favState === 'true') {
283
-				$this->getTagger()->tagAs($node->getId(), self::TAG_FAVORITE);
284
-			} else {
285
-				$this->getTagger()->unTag($node->getId(), self::TAG_FAVORITE);
286
-			}
281
+        $propPatch->handle(self::FAVORITE_PROPERTYNAME, function($favState) use ($node) {
282
+            if ((int)$favState === 1 || $favState === 'true') {
283
+                $this->getTagger()->tagAs($node->getId(), self::TAG_FAVORITE);
284
+            } else {
285
+                $this->getTagger()->unTag($node->getId(), self::TAG_FAVORITE);
286
+            }
287 287
 
288
-			if (is_null($favState)) {
289
-				// confirm deletion
290
-				return 204;
291
-			}
288
+            if (is_null($favState)) {
289
+                // confirm deletion
290
+                return 204;
291
+            }
292 292
 
293
-			return 200;
294
-		});
295
-	}
293
+            return 200;
294
+        });
295
+    }
296 296
 }
Please login to merge, or discard this patch.
lib/private/App/AppStore/Bundles/BundleFetcher.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -68,8 +68,8 @@
 block discarded – undo
68 68
 			$this->getBundles(),
69 69
 			$this->getDefaultInstallationBundle()
70 70
 		);
71
-		foreach($bundles as $bundle) {
72
-			if($bundle->getIdentifier() === $identifier) {
71
+		foreach ($bundles as $bundle) {
72
+			if ($bundle->getIdentifier() === $identifier) {
73 73
 				return $bundle;
74 74
 			}
75 75
 		}
Please login to merge, or discard this patch.
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -24,58 +24,58 @@
 block discarded – undo
24 24
 use OCP\IL10N;
25 25
 
26 26
 class BundleFetcher {
27
-	/** @var IL10N */
28
-	private $l10n;
27
+    /** @var IL10N */
28
+    private $l10n;
29 29
 
30
-	/**
31
-	 * @param IL10N $l10n
32
-	 */
33
-	public function __construct(IL10N $l10n) {
34
-		$this->l10n = $l10n;
35
-	}
30
+    /**
31
+     * @param IL10N $l10n
32
+     */
33
+    public function __construct(IL10N $l10n) {
34
+        $this->l10n = $l10n;
35
+    }
36 36
 
37
-	/**
38
-	 * @return Bundle[]
39
-	 */
40
-	public function getBundles() {
41
-		return [
42
-			new EnterpriseBundle($this->l10n),
43
-			new GroupwareBundle($this->l10n),
44
-			new SocialSharingBundle($this->l10n),
45
-			new EducationBundle($this->l10n),
46
-		];
47
-	}
37
+    /**
38
+     * @return Bundle[]
39
+     */
40
+    public function getBundles() {
41
+        return [
42
+            new EnterpriseBundle($this->l10n),
43
+            new GroupwareBundle($this->l10n),
44
+            new SocialSharingBundle($this->l10n),
45
+            new EducationBundle($this->l10n),
46
+        ];
47
+    }
48 48
 
49
-	/**
50
-	 * Bundles that should be installed by default after installation
51
-	 *
52
-	 * @return Bundle[]
53
-	 */
54
-	public function getDefaultInstallationBundle() {
55
-		return [
56
-			new CoreBundle($this->l10n),
57
-		];
58
-	}
49
+    /**
50
+     * Bundles that should be installed by default after installation
51
+     *
52
+     * @return Bundle[]
53
+     */
54
+    public function getDefaultInstallationBundle() {
55
+        return [
56
+            new CoreBundle($this->l10n),
57
+        ];
58
+    }
59 59
 
60
-	/**
61
-	 * Get the bundle with the specified identifier
62
-	 *
63
-	 * @param string $identifier
64
-	 * @return Bundle
65
-	 * @throws \BadMethodCallException If the bundle does not exist
66
-	 */
67
-	public function getBundleByIdentifier($identifier) {
68
-		/** @var Bundle[] $bundles */
69
-		$bundles = array_merge(
70
-			$this->getBundles(),
71
-			$this->getDefaultInstallationBundle()
72
-		);
73
-		foreach($bundles as $bundle) {
74
-			if($bundle->getIdentifier() === $identifier) {
75
-				return $bundle;
76
-			}
77
-		}
60
+    /**
61
+     * Get the bundle with the specified identifier
62
+     *
63
+     * @param string $identifier
64
+     * @return Bundle
65
+     * @throws \BadMethodCallException If the bundle does not exist
66
+     */
67
+    public function getBundleByIdentifier($identifier) {
68
+        /** @var Bundle[] $bundles */
69
+        $bundles = array_merge(
70
+            $this->getBundles(),
71
+            $this->getDefaultInstallationBundle()
72
+        );
73
+        foreach($bundles as $bundle) {
74
+            if($bundle->getIdentifier() === $identifier) {
75
+                return $bundle;
76
+            }
77
+        }
78 78
 
79
-		throw new \BadMethodCallException('Bundle with specified identifier does not exist');
80
-	}
79
+        throw new \BadMethodCallException('Bundle with specified identifier does not exist');
80
+    }
81 81
 }
Please login to merge, or discard this patch.
lib/private/BackgroundJob/JobList.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -320,7 +320,7 @@
 block discarded – undo
320 320
 
321 321
 	/**
322 322
 	 * @param IJob $job
323
-	 * @param $timeTaken
323
+	 * @param integer $timeTaken
324 324
 	 */
325 325
 	public function setExecutionTime(IJob $job, $timeTaken) {
326 326
 		$query = $this->connection->getQueryBuilder();
Please login to merge, or discard this patch.
Indentation   +342 added lines, -342 removed lines patch added patch discarded remove patch
@@ -39,346 +39,346 @@
 block discarded – undo
39 39
 
40 40
 class JobList implements IJobList {
41 41
 
42
-	/** @var IDBConnection */
43
-	protected $connection;
44
-
45
-	/**@var IConfig */
46
-	protected $config;
47
-
48
-	/**@var ITimeFactory */
49
-	protected $timeFactory;
50
-
51
-	/** @var int - 12 hours * 3600 seconds*/
52
-	private $jobTimeOut = 43200;
53
-
54
-	/**
55
-	 * @param IDBConnection $connection
56
-	 * @param IConfig $config
57
-	 * @param ITimeFactory $timeFactory
58
-	 */
59
-	public function __construct(IDBConnection $connection, IConfig $config, ITimeFactory $timeFactory) {
60
-		$this->connection = $connection;
61
-		$this->config = $config;
62
-		$this->timeFactory = $timeFactory;
63
-	}
64
-
65
-	/**
66
-	 * @param IJob|string $job
67
-	 * @param mixed $argument
68
-	 */
69
-	public function add($job, $argument = null) {
70
-		if (!$this->has($job, $argument)) {
71
-			if ($job instanceof IJob) {
72
-				$class = get_class($job);
73
-			} else {
74
-				$class = $job;
75
-			}
76
-
77
-			$argument = json_encode($argument);
78
-			if (strlen($argument) > 4000) {
79
-				throw new \InvalidArgumentException('Background job arguments can\'t exceed 4000 characters (json encoded)');
80
-			}
81
-
82
-			$query = $this->connection->getQueryBuilder();
83
-			$query->insert('jobs')
84
-				->values([
85
-					'class' => $query->createNamedParameter($class),
86
-					'argument' => $query->createNamedParameter($argument),
87
-					'last_run' => $query->createNamedParameter(0, IQueryBuilder::PARAM_INT),
88
-					'last_checked' => $query->createNamedParameter($this->timeFactory->getTime(), IQueryBuilder::PARAM_INT),
89
-				]);
90
-			$query->execute();
91
-		}
92
-	}
93
-
94
-	/**
95
-	 * @param IJob|string $job
96
-	 * @param mixed $argument
97
-	 */
98
-	public function remove($job, $argument = null) {
99
-		if ($job instanceof IJob) {
100
-			$class = get_class($job);
101
-		} else {
102
-			$class = $job;
103
-		}
104
-
105
-		$query = $this->connection->getQueryBuilder();
106
-		$query->delete('jobs')
107
-			->where($query->expr()->eq('class', $query->createNamedParameter($class)));
108
-		if (!is_null($argument)) {
109
-			$argument = json_encode($argument);
110
-			$query->andWhere($query->expr()->eq('argument', $query->createNamedParameter($argument)));
111
-		}
112
-		$query->execute();
113
-	}
114
-
115
-	/**
116
-	 * @param int $id
117
-	 */
118
-	protected function removeById($id) {
119
-		$query = $this->connection->getQueryBuilder();
120
-		$query->delete('jobs')
121
-			->where($query->expr()->eq('id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
122
-		$query->execute();
123
-	}
124
-
125
-	/**
126
-	 * check if a job is in the list
127
-	 *
128
-	 * @param IJob|string $job
129
-	 * @param mixed $argument
130
-	 * @return bool
131
-	 */
132
-	public function has($job, $argument) {
133
-		if ($job instanceof IJob) {
134
-			$class = get_class($job);
135
-		} else {
136
-			$class = $job;
137
-		}
138
-		$argument = json_encode($argument);
139
-
140
-		$query = $this->connection->getQueryBuilder();
141
-		$query->select('id')
142
-			->from('jobs')
143
-			->where($query->expr()->eq('class', $query->createNamedParameter($class)))
144
-			->andWhere($query->expr()->eq('argument', $query->createNamedParameter($argument)))
145
-			->setMaxResults(1);
146
-
147
-		$result = $query->execute();
148
-		$row = $result->fetch();
149
-		$result->closeCursor();
150
-
151
-		return (bool) $row;
152
-	}
153
-
154
-	/**
155
-	 * get all jobs in the list
156
-	 *
157
-	 * @return IJob[]
158
-	 * @deprecated 9.0.0 - This method is dangerous since it can cause load and
159
-	 * memory problems when creating too many instances.
160
-	 */
161
-	public function getAll() {
162
-		$query = $this->connection->getQueryBuilder();
163
-		$query->select('*')
164
-			->from('jobs');
165
-		$result = $query->execute();
166
-
167
-		$jobs = [];
168
-		while ($row = $result->fetch()) {
169
-			$job = $this->buildJob($row);
170
-			if ($job) {
171
-				$jobs[] = $job;
172
-			}
173
-		}
174
-		$result->closeCursor();
175
-
176
-		return $jobs;
177
-	}
178
-
179
-	/**
180
-	 * get the next job in the list
181
-	 *
182
-	 * @return IJob|null
183
-	 * @suppress SqlInjectionChecker
184
-	 */
185
-	public function getNext() {
186
-		$query = $this->connection->getQueryBuilder();
187
-		$query->select('*')
188
-			->from('jobs')
189
-			->where($query->expr()->lte('reserved_at', $query->createNamedParameter($this->timeFactory->getTime() - $this->jobTimeOut, IQueryBuilder::PARAM_INT)))
190
-			->andWhere($query->expr()->lte('last_checked', $query->createNamedParameter($this->timeFactory->getTime(), IQueryBuilder::PARAM_INT)))
191
-			->orderBy('last_checked', 'ASC')
192
-			->setMaxResults(1);
193
-
194
-		$update = $this->connection->getQueryBuilder();
195
-		$update->update('jobs')
196
-			->set('reserved_at', $update->createNamedParameter($this->timeFactory->getTime()))
197
-			->set('last_checked', $update->createNamedParameter($this->timeFactory->getTime()))
198
-			->where($update->expr()->eq('id', $update->createParameter('jobid')))
199
-			->andWhere($update->expr()->eq('reserved_at', $update->createParameter('reserved_at')))
200
-			->andWhere($update->expr()->eq('last_checked', $update->createParameter('last_checked')));
201
-
202
-		$result = $query->execute();
203
-		$row = $result->fetch();
204
-		$result->closeCursor();
205
-
206
-		if ($row) {
207
-			$update->setParameter('jobid', $row['id']);
208
-			$update->setParameter('reserved_at', $row['reserved_at']);
209
-			$update->setParameter('last_checked', $row['last_checked']);
210
-			$count = $update->execute();
211
-
212
-			if ($count === 0) {
213
-				// Background job already executed elsewhere, try again.
214
-				return $this->getNext();
215
-			}
216
-			$job = $this->buildJob($row);
217
-
218
-			if ($job === null) {
219
-				// set the last_checked to 12h in the future to not check failing jobs all over again
220
-				$reset = $this->connection->getQueryBuilder();
221
-				$reset->update('jobs')
222
-					->set('reserved_at', $reset->expr()->literal(0, IQueryBuilder::PARAM_INT))
223
-					->set('last_checked', $reset->createNamedParameter($this->timeFactory->getTime() + 12 * 3600, IQueryBuilder::PARAM_INT))
224
-					->where($reset->expr()->eq('id', $reset->createNamedParameter($row['id'], IQueryBuilder::PARAM_INT)));
225
-				$reset->execute();
226
-
227
-				// Background job from disabled app, try again.
228
-				return $this->getNext();
229
-			}
230
-
231
-			return $job;
232
-		} else {
233
-			return null;
234
-		}
235
-	}
236
-
237
-	/**
238
-	 * @param int $id
239
-	 * @return IJob|null
240
-	 */
241
-	public function getById($id) {
242
-		$query = $this->connection->getQueryBuilder();
243
-		$query->select('*')
244
-			->from('jobs')
245
-			->where($query->expr()->eq('id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
246
-		$result = $query->execute();
247
-		$row = $result->fetch();
248
-		$result->closeCursor();
249
-
250
-		if ($row) {
251
-			return $this->buildJob($row);
252
-		} else {
253
-			return null;
254
-		}
255
-	}
256
-
257
-	/**
258
-	 * get the job object from a row in the db
259
-	 *
260
-	 * @param array $row
261
-	 * @return IJob|null
262
-	 */
263
-	private function buildJob($row) {
264
-		try {
265
-			try {
266
-				// Try to load the job as a service
267
-				/** @var IJob $job */
268
-				$job = \OC::$server->query($row['class']);
269
-			} catch (QueryException $e) {
270
-				if (class_exists($row['class'])) {
271
-					$class = $row['class'];
272
-					$job = new $class();
273
-				} else {
274
-					// job from disabled app or old version of an app, no need to do anything
275
-					return null;
276
-				}
277
-			}
278
-
279
-			$job->setId($row['id']);
280
-			$job->setLastRun($row['last_run']);
281
-			$job->setArgument(json_decode($row['argument'], true));
282
-			return $job;
283
-		} catch (AutoloadNotAllowedException $e) {
284
-			// job is from a disabled app, ignore
285
-			return null;
286
-		}
287
-	}
288
-
289
-	/**
290
-	 * set the job that was last ran
291
-	 *
292
-	 * @param IJob $job
293
-	 */
294
-	public function setLastJob(IJob $job) {
295
-		$this->unlockJob($job);
296
-		$this->config->setAppValue('backgroundjob', 'lastjob', $job->getId());
297
-	}
298
-
299
-	/**
300
-	 * Remove the reservation for a job
301
-	 *
302
-	 * @param IJob $job
303
-	 * @suppress SqlInjectionChecker
304
-	 */
305
-	public function unlockJob(IJob $job) {
306
-		$query = $this->connection->getQueryBuilder();
307
-		$query->update('jobs')
308
-			->set('reserved_at', $query->expr()->literal(0, IQueryBuilder::PARAM_INT))
309
-			->where($query->expr()->eq('id', $query->createNamedParameter($job->getId(), IQueryBuilder::PARAM_INT)));
310
-		$query->execute();
311
-	}
312
-
313
-	/**
314
-	 * get the id of the last ran job
315
-	 *
316
-	 * @return int
317
-	 * @deprecated 9.1.0 - The functionality behind the value is deprecated, it
318
-	 *    only tells you which job finished last, but since we now allow multiple
319
-	 *    executors to run in parallel, it's not used to calculate the next job.
320
-	 */
321
-	public function getLastJob() {
322
-		return (int) $this->config->getAppValue('backgroundjob', 'lastjob', 0);
323
-	}
324
-
325
-	/**
326
-	 * set the lastRun of $job to now
327
-	 *
328
-	 * @param IJob $job
329
-	 */
330
-	public function setLastRun(IJob $job) {
331
-		$query = $this->connection->getQueryBuilder();
332
-		$query->update('jobs')
333
-			->set('last_run', $query->createNamedParameter(time(), IQueryBuilder::PARAM_INT))
334
-			->where($query->expr()->eq('id', $query->createNamedParameter($job->getId(), IQueryBuilder::PARAM_INT)));
335
-		$query->execute();
336
-	}
337
-
338
-	/**
339
-	 * @param IJob $job
340
-	 * @param $timeTaken
341
-	 */
342
-	public function setExecutionTime(IJob $job, $timeTaken) {
343
-		$query = $this->connection->getQueryBuilder();
344
-		$query->update('jobs')
345
-			->set('execution_duration', $query->createNamedParameter($timeTaken, IQueryBuilder::PARAM_INT))
346
-			->where($query->expr()->eq('id', $query->createNamedParameter($job->getId(), IQueryBuilder::PARAM_INT)));
347
-		$query->execute();
348
-	}
349
-
350
-	/**
351
-	 * checks if a job is still running (reserved_at time is smaller than 12 hours ago)
352
-	 *
353
-	 * Background information:
354
-	 *
355
-	 * The 12 hours is the same timeout that is also used to re-schedule an non-terminated
356
-	 * job (see getNext()). The idea here is to give a job enough time to run very
357
-	 * long but still be able to recognize that it maybe crashed and re-schedule it
358
-	 * after the timeout. It's more likely to be crashed at that time than it ran
359
-	 * that long.
360
-	 *
361
-	 * In theory it could lead to an nearly endless loop (as in - at most 12 hours).
362
-	 * The cron command will not start new jobs when maintenance mode is active and
363
-	 * this method is only executed in maintenance mode (see where it is called in
364
-	 * the upgrader class. So this means in the worst case we wait 12 hours when a
365
-	 * job has crashed. On the other hand: then the instance should be fixed anyways.
366
-	 *
367
-	 * @return bool
368
-	 */
369
-	public function isAnyJobRunning(): bool {
370
-		$query = $this->connection->getQueryBuilder();
371
-		$query->select('*')
372
-			->from('jobs')
373
-			->where($query->expr()->gt('reserved_at', $query->createNamedParameter($this->timeFactory->getTime() - $this->jobTimeOut, IQueryBuilder::PARAM_INT)))
374
-			->setMaxResults(1);
375
-		$result = $query->execute();
376
-		$row = $result->fetch();
377
-		$result->closeCursor();
378
-
379
-		if ($row) {
380
-			return true;
381
-		}
382
-		return false;
383
-	}
42
+    /** @var IDBConnection */
43
+    protected $connection;
44
+
45
+    /**@var IConfig */
46
+    protected $config;
47
+
48
+    /**@var ITimeFactory */
49
+    protected $timeFactory;
50
+
51
+    /** @var int - 12 hours * 3600 seconds*/
52
+    private $jobTimeOut = 43200;
53
+
54
+    /**
55
+     * @param IDBConnection $connection
56
+     * @param IConfig $config
57
+     * @param ITimeFactory $timeFactory
58
+     */
59
+    public function __construct(IDBConnection $connection, IConfig $config, ITimeFactory $timeFactory) {
60
+        $this->connection = $connection;
61
+        $this->config = $config;
62
+        $this->timeFactory = $timeFactory;
63
+    }
64
+
65
+    /**
66
+     * @param IJob|string $job
67
+     * @param mixed $argument
68
+     */
69
+    public function add($job, $argument = null) {
70
+        if (!$this->has($job, $argument)) {
71
+            if ($job instanceof IJob) {
72
+                $class = get_class($job);
73
+            } else {
74
+                $class = $job;
75
+            }
76
+
77
+            $argument = json_encode($argument);
78
+            if (strlen($argument) > 4000) {
79
+                throw new \InvalidArgumentException('Background job arguments can\'t exceed 4000 characters (json encoded)');
80
+            }
81
+
82
+            $query = $this->connection->getQueryBuilder();
83
+            $query->insert('jobs')
84
+                ->values([
85
+                    'class' => $query->createNamedParameter($class),
86
+                    'argument' => $query->createNamedParameter($argument),
87
+                    'last_run' => $query->createNamedParameter(0, IQueryBuilder::PARAM_INT),
88
+                    'last_checked' => $query->createNamedParameter($this->timeFactory->getTime(), IQueryBuilder::PARAM_INT),
89
+                ]);
90
+            $query->execute();
91
+        }
92
+    }
93
+
94
+    /**
95
+     * @param IJob|string $job
96
+     * @param mixed $argument
97
+     */
98
+    public function remove($job, $argument = null) {
99
+        if ($job instanceof IJob) {
100
+            $class = get_class($job);
101
+        } else {
102
+            $class = $job;
103
+        }
104
+
105
+        $query = $this->connection->getQueryBuilder();
106
+        $query->delete('jobs')
107
+            ->where($query->expr()->eq('class', $query->createNamedParameter($class)));
108
+        if (!is_null($argument)) {
109
+            $argument = json_encode($argument);
110
+            $query->andWhere($query->expr()->eq('argument', $query->createNamedParameter($argument)));
111
+        }
112
+        $query->execute();
113
+    }
114
+
115
+    /**
116
+     * @param int $id
117
+     */
118
+    protected function removeById($id) {
119
+        $query = $this->connection->getQueryBuilder();
120
+        $query->delete('jobs')
121
+            ->where($query->expr()->eq('id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
122
+        $query->execute();
123
+    }
124
+
125
+    /**
126
+     * check if a job is in the list
127
+     *
128
+     * @param IJob|string $job
129
+     * @param mixed $argument
130
+     * @return bool
131
+     */
132
+    public function has($job, $argument) {
133
+        if ($job instanceof IJob) {
134
+            $class = get_class($job);
135
+        } else {
136
+            $class = $job;
137
+        }
138
+        $argument = json_encode($argument);
139
+
140
+        $query = $this->connection->getQueryBuilder();
141
+        $query->select('id')
142
+            ->from('jobs')
143
+            ->where($query->expr()->eq('class', $query->createNamedParameter($class)))
144
+            ->andWhere($query->expr()->eq('argument', $query->createNamedParameter($argument)))
145
+            ->setMaxResults(1);
146
+
147
+        $result = $query->execute();
148
+        $row = $result->fetch();
149
+        $result->closeCursor();
150
+
151
+        return (bool) $row;
152
+    }
153
+
154
+    /**
155
+     * get all jobs in the list
156
+     *
157
+     * @return IJob[]
158
+     * @deprecated 9.0.0 - This method is dangerous since it can cause load and
159
+     * memory problems when creating too many instances.
160
+     */
161
+    public function getAll() {
162
+        $query = $this->connection->getQueryBuilder();
163
+        $query->select('*')
164
+            ->from('jobs');
165
+        $result = $query->execute();
166
+
167
+        $jobs = [];
168
+        while ($row = $result->fetch()) {
169
+            $job = $this->buildJob($row);
170
+            if ($job) {
171
+                $jobs[] = $job;
172
+            }
173
+        }
174
+        $result->closeCursor();
175
+
176
+        return $jobs;
177
+    }
178
+
179
+    /**
180
+     * get the next job in the list
181
+     *
182
+     * @return IJob|null
183
+     * @suppress SqlInjectionChecker
184
+     */
185
+    public function getNext() {
186
+        $query = $this->connection->getQueryBuilder();
187
+        $query->select('*')
188
+            ->from('jobs')
189
+            ->where($query->expr()->lte('reserved_at', $query->createNamedParameter($this->timeFactory->getTime() - $this->jobTimeOut, IQueryBuilder::PARAM_INT)))
190
+            ->andWhere($query->expr()->lte('last_checked', $query->createNamedParameter($this->timeFactory->getTime(), IQueryBuilder::PARAM_INT)))
191
+            ->orderBy('last_checked', 'ASC')
192
+            ->setMaxResults(1);
193
+
194
+        $update = $this->connection->getQueryBuilder();
195
+        $update->update('jobs')
196
+            ->set('reserved_at', $update->createNamedParameter($this->timeFactory->getTime()))
197
+            ->set('last_checked', $update->createNamedParameter($this->timeFactory->getTime()))
198
+            ->where($update->expr()->eq('id', $update->createParameter('jobid')))
199
+            ->andWhere($update->expr()->eq('reserved_at', $update->createParameter('reserved_at')))
200
+            ->andWhere($update->expr()->eq('last_checked', $update->createParameter('last_checked')));
201
+
202
+        $result = $query->execute();
203
+        $row = $result->fetch();
204
+        $result->closeCursor();
205
+
206
+        if ($row) {
207
+            $update->setParameter('jobid', $row['id']);
208
+            $update->setParameter('reserved_at', $row['reserved_at']);
209
+            $update->setParameter('last_checked', $row['last_checked']);
210
+            $count = $update->execute();
211
+
212
+            if ($count === 0) {
213
+                // Background job already executed elsewhere, try again.
214
+                return $this->getNext();
215
+            }
216
+            $job = $this->buildJob($row);
217
+
218
+            if ($job === null) {
219
+                // set the last_checked to 12h in the future to not check failing jobs all over again
220
+                $reset = $this->connection->getQueryBuilder();
221
+                $reset->update('jobs')
222
+                    ->set('reserved_at', $reset->expr()->literal(0, IQueryBuilder::PARAM_INT))
223
+                    ->set('last_checked', $reset->createNamedParameter($this->timeFactory->getTime() + 12 * 3600, IQueryBuilder::PARAM_INT))
224
+                    ->where($reset->expr()->eq('id', $reset->createNamedParameter($row['id'], IQueryBuilder::PARAM_INT)));
225
+                $reset->execute();
226
+
227
+                // Background job from disabled app, try again.
228
+                return $this->getNext();
229
+            }
230
+
231
+            return $job;
232
+        } else {
233
+            return null;
234
+        }
235
+    }
236
+
237
+    /**
238
+     * @param int $id
239
+     * @return IJob|null
240
+     */
241
+    public function getById($id) {
242
+        $query = $this->connection->getQueryBuilder();
243
+        $query->select('*')
244
+            ->from('jobs')
245
+            ->where($query->expr()->eq('id', $query->createNamedParameter($id, IQueryBuilder::PARAM_INT)));
246
+        $result = $query->execute();
247
+        $row = $result->fetch();
248
+        $result->closeCursor();
249
+
250
+        if ($row) {
251
+            return $this->buildJob($row);
252
+        } else {
253
+            return null;
254
+        }
255
+    }
256
+
257
+    /**
258
+     * get the job object from a row in the db
259
+     *
260
+     * @param array $row
261
+     * @return IJob|null
262
+     */
263
+    private function buildJob($row) {
264
+        try {
265
+            try {
266
+                // Try to load the job as a service
267
+                /** @var IJob $job */
268
+                $job = \OC::$server->query($row['class']);
269
+            } catch (QueryException $e) {
270
+                if (class_exists($row['class'])) {
271
+                    $class = $row['class'];
272
+                    $job = new $class();
273
+                } else {
274
+                    // job from disabled app or old version of an app, no need to do anything
275
+                    return null;
276
+                }
277
+            }
278
+
279
+            $job->setId($row['id']);
280
+            $job->setLastRun($row['last_run']);
281
+            $job->setArgument(json_decode($row['argument'], true));
282
+            return $job;
283
+        } catch (AutoloadNotAllowedException $e) {
284
+            // job is from a disabled app, ignore
285
+            return null;
286
+        }
287
+    }
288
+
289
+    /**
290
+     * set the job that was last ran
291
+     *
292
+     * @param IJob $job
293
+     */
294
+    public function setLastJob(IJob $job) {
295
+        $this->unlockJob($job);
296
+        $this->config->setAppValue('backgroundjob', 'lastjob', $job->getId());
297
+    }
298
+
299
+    /**
300
+     * Remove the reservation for a job
301
+     *
302
+     * @param IJob $job
303
+     * @suppress SqlInjectionChecker
304
+     */
305
+    public function unlockJob(IJob $job) {
306
+        $query = $this->connection->getQueryBuilder();
307
+        $query->update('jobs')
308
+            ->set('reserved_at', $query->expr()->literal(0, IQueryBuilder::PARAM_INT))
309
+            ->where($query->expr()->eq('id', $query->createNamedParameter($job->getId(), IQueryBuilder::PARAM_INT)));
310
+        $query->execute();
311
+    }
312
+
313
+    /**
314
+     * get the id of the last ran job
315
+     *
316
+     * @return int
317
+     * @deprecated 9.1.0 - The functionality behind the value is deprecated, it
318
+     *    only tells you which job finished last, but since we now allow multiple
319
+     *    executors to run in parallel, it's not used to calculate the next job.
320
+     */
321
+    public function getLastJob() {
322
+        return (int) $this->config->getAppValue('backgroundjob', 'lastjob', 0);
323
+    }
324
+
325
+    /**
326
+     * set the lastRun of $job to now
327
+     *
328
+     * @param IJob $job
329
+     */
330
+    public function setLastRun(IJob $job) {
331
+        $query = $this->connection->getQueryBuilder();
332
+        $query->update('jobs')
333
+            ->set('last_run', $query->createNamedParameter(time(), IQueryBuilder::PARAM_INT))
334
+            ->where($query->expr()->eq('id', $query->createNamedParameter($job->getId(), IQueryBuilder::PARAM_INT)));
335
+        $query->execute();
336
+    }
337
+
338
+    /**
339
+     * @param IJob $job
340
+     * @param $timeTaken
341
+     */
342
+    public function setExecutionTime(IJob $job, $timeTaken) {
343
+        $query = $this->connection->getQueryBuilder();
344
+        $query->update('jobs')
345
+            ->set('execution_duration', $query->createNamedParameter($timeTaken, IQueryBuilder::PARAM_INT))
346
+            ->where($query->expr()->eq('id', $query->createNamedParameter($job->getId(), IQueryBuilder::PARAM_INT)));
347
+        $query->execute();
348
+    }
349
+
350
+    /**
351
+     * checks if a job is still running (reserved_at time is smaller than 12 hours ago)
352
+     *
353
+     * Background information:
354
+     *
355
+     * The 12 hours is the same timeout that is also used to re-schedule an non-terminated
356
+     * job (see getNext()). The idea here is to give a job enough time to run very
357
+     * long but still be able to recognize that it maybe crashed and re-schedule it
358
+     * after the timeout. It's more likely to be crashed at that time than it ran
359
+     * that long.
360
+     *
361
+     * In theory it could lead to an nearly endless loop (as in - at most 12 hours).
362
+     * The cron command will not start new jobs when maintenance mode is active and
363
+     * this method is only executed in maintenance mode (see where it is called in
364
+     * the upgrader class. So this means in the worst case we wait 12 hours when a
365
+     * job has crashed. On the other hand: then the instance should be fixed anyways.
366
+     *
367
+     * @return bool
368
+     */
369
+    public function isAnyJobRunning(): bool {
370
+        $query = $this->connection->getQueryBuilder();
371
+        $query->select('*')
372
+            ->from('jobs')
373
+            ->where($query->expr()->gt('reserved_at', $query->createNamedParameter($this->timeFactory->getTime() - $this->jobTimeOut, IQueryBuilder::PARAM_INT)))
374
+            ->setMaxResults(1);
375
+        $result = $query->execute();
376
+        $row = $result->fetch();
377
+        $result->closeCursor();
378
+
379
+        if ($row) {
380
+            return true;
381
+        }
382
+        return false;
383
+    }
384 384
 }
Please login to merge, or discard this patch.
lib/private/BackgroundJob/Job.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -55,17 +55,17 @@
 block discarded – undo
55 55
 
56 56
 		try {
57 57
 			$jobStartTime = time();
58
-			$logger->debug('Run ' . get_class($this) . ' job with ID ' . $this->getId(), ['app' => 'cron']);
58
+			$logger->debug('Run '.get_class($this).' job with ID '.$this->getId(), ['app' => 'cron']);
59 59
 			$this->run($this->argument);
60 60
 			$timeTaken = time() - $jobStartTime;
61 61
 
62
-			$logger->debug('Finished ' . get_class($this) . ' job with ID ' . $this->getId() . ' in ' . $timeTaken . ' seconds', ['app' => 'cron']);
62
+			$logger->debug('Finished '.get_class($this).' job with ID '.$this->getId().' in '.$timeTaken.' seconds', ['app' => 'cron']);
63 63
 			$jobList->setExecutionTime($this, $timeTaken);
64 64
 		} catch (\Exception $e) {
65 65
 			if ($logger) {
66 66
 				$logger->logException($e, [
67 67
 					'app' => 'core',
68
-					'message' => 'Error while running background job (class: ' . get_class($this) . ', arguments: ' . print_r($this->argument, true) . ')'
68
+					'message' => 'Error while running background job (class: '.get_class($this).', arguments: '.print_r($this->argument, true).')'
69 69
 				]);
70 70
 			}
71 71
 		}
Please login to merge, or discard this patch.
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -28,72 +28,72 @@
 block discarded – undo
28 28
 use OCP\ILogger;
29 29
 
30 30
 abstract class Job implements IJob {
31
-	/**
32
-	 * @var int $id
33
-	 */
34
-	protected $id;
31
+    /**
32
+     * @var int $id
33
+     */
34
+    protected $id;
35 35
 
36
-	/**
37
-	 * @var int $lastRun
38
-	 */
39
-	protected $lastRun;
36
+    /**
37
+     * @var int $lastRun
38
+     */
39
+    protected $lastRun;
40 40
 
41
-	/**
42
-	 * @var mixed $argument
43
-	 */
44
-	protected $argument;
41
+    /**
42
+     * @var mixed $argument
43
+     */
44
+    protected $argument;
45 45
 
46
-	/**
47
-	 * @param JobList $jobList
48
-	 * @param ILogger|null $logger
49
-	 */
50
-	public function execute($jobList, ILogger $logger = null) {
51
-		$jobList->setLastRun($this);
52
-		if ($logger === null) {
53
-			$logger = \OC::$server->getLogger();
54
-		}
46
+    /**
47
+     * @param JobList $jobList
48
+     * @param ILogger|null $logger
49
+     */
50
+    public function execute($jobList, ILogger $logger = null) {
51
+        $jobList->setLastRun($this);
52
+        if ($logger === null) {
53
+            $logger = \OC::$server->getLogger();
54
+        }
55 55
 
56
-		try {
57
-			$jobStartTime = time();
58
-			$logger->debug('Run ' . get_class($this) . ' job with ID ' . $this->getId(), ['app' => 'cron']);
59
-			$this->run($this->argument);
60
-			$timeTaken = time() - $jobStartTime;
56
+        try {
57
+            $jobStartTime = time();
58
+            $logger->debug('Run ' . get_class($this) . ' job with ID ' . $this->getId(), ['app' => 'cron']);
59
+            $this->run($this->argument);
60
+            $timeTaken = time() - $jobStartTime;
61 61
 
62
-			$logger->debug('Finished ' . get_class($this) . ' job with ID ' . $this->getId() . ' in ' . $timeTaken . ' seconds', ['app' => 'cron']);
63
-			$jobList->setExecutionTime($this, $timeTaken);
64
-		} catch (\Exception $e) {
65
-			if ($logger) {
66
-				$logger->logException($e, [
67
-					'app' => 'core',
68
-					'message' => 'Error while running background job (class: ' . get_class($this) . ', arguments: ' . print_r($this->argument, true) . ')'
69
-				]);
70
-			}
71
-		}
72
-	}
62
+            $logger->debug('Finished ' . get_class($this) . ' job with ID ' . $this->getId() . ' in ' . $timeTaken . ' seconds', ['app' => 'cron']);
63
+            $jobList->setExecutionTime($this, $timeTaken);
64
+        } catch (\Exception $e) {
65
+            if ($logger) {
66
+                $logger->logException($e, [
67
+                    'app' => 'core',
68
+                    'message' => 'Error while running background job (class: ' . get_class($this) . ', arguments: ' . print_r($this->argument, true) . ')'
69
+                ]);
70
+            }
71
+        }
72
+    }
73 73
 
74
-	abstract protected function run($argument);
74
+    abstract protected function run($argument);
75 75
 
76
-	public function setId($id) {
77
-		$this->id = $id;
78
-	}
76
+    public function setId($id) {
77
+        $this->id = $id;
78
+    }
79 79
 
80
-	public function setLastRun($lastRun) {
81
-		$this->lastRun = $lastRun;
82
-	}
80
+    public function setLastRun($lastRun) {
81
+        $this->lastRun = $lastRun;
82
+    }
83 83
 
84
-	public function setArgument($argument) {
85
-		$this->argument = $argument;
86
-	}
84
+    public function setArgument($argument) {
85
+        $this->argument = $argument;
86
+    }
87 87
 
88
-	public function getId() {
89
-		return $this->id;
90
-	}
88
+    public function getId() {
89
+        return $this->id;
90
+    }
91 91
 
92
-	public function getLastRun() {
93
-		return $this->lastRun;
94
-	}
92
+    public function getLastRun() {
93
+        return $this->lastRun;
94
+    }
95 95
 
96
-	public function getArgument() {
97
-		return $this->argument;
98
-	}
96
+    public function getArgument() {
97
+        return $this->argument;
98
+    }
99 99
 }
Please login to merge, or discard this patch.
lib/public/BackgroundJob/IJobList.php 1 patch
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -32,100 +32,100 @@
 block discarded – undo
32 32
  * @since 7.0.0
33 33
  */
34 34
 interface IJobList {
35
-	/**
36
-	 * Add a job to the list
37
-	 *
38
-	 * @param \OCP\BackgroundJob\IJob|string $job
39
-	 * @param mixed $argument The argument to be passed to $job->run() when the job is exectured
40
-	 * @since 7.0.0
41
-	 */
42
-	public function add($job, $argument = null);
35
+    /**
36
+     * Add a job to the list
37
+     *
38
+     * @param \OCP\BackgroundJob\IJob|string $job
39
+     * @param mixed $argument The argument to be passed to $job->run() when the job is exectured
40
+     * @since 7.0.0
41
+     */
42
+    public function add($job, $argument = null);
43 43
 
44
-	/**
45
-	 * Remove a job from the list
46
-	 *
47
-	 * @param \OCP\BackgroundJob\IJob|string $job
48
-	 * @param mixed $argument
49
-	 * @since 7.0.0
50
-	 */
51
-	public function remove($job, $argument = null);
44
+    /**
45
+     * Remove a job from the list
46
+     *
47
+     * @param \OCP\BackgroundJob\IJob|string $job
48
+     * @param mixed $argument
49
+     * @since 7.0.0
50
+     */
51
+    public function remove($job, $argument = null);
52 52
 
53
-	/**
54
-	 * check if a job is in the list
55
-	 *
56
-	 * @param \OCP\BackgroundJob\IJob|string $job
57
-	 * @param mixed $argument
58
-	 * @return bool
59
-	 * @since 7.0.0
60
-	 */
61
-	public function has($job, $argument);
53
+    /**
54
+     * check if a job is in the list
55
+     *
56
+     * @param \OCP\BackgroundJob\IJob|string $job
57
+     * @param mixed $argument
58
+     * @return bool
59
+     * @since 7.0.0
60
+     */
61
+    public function has($job, $argument);
62 62
 
63
-	/**
64
-	 * get all jobs in the list
65
-	 *
66
-	 * @return \OCP\BackgroundJob\IJob[]
67
-	 * @since 7.0.0
68
-	 * @deprecated 9.0.0 - This method is dangerous since it can cause load and
69
-	 * memory problems when creating too many instances.
70
-	 */
71
-	public function getAll();
63
+    /**
64
+     * get all jobs in the list
65
+     *
66
+     * @return \OCP\BackgroundJob\IJob[]
67
+     * @since 7.0.0
68
+     * @deprecated 9.0.0 - This method is dangerous since it can cause load and
69
+     * memory problems when creating too many instances.
70
+     */
71
+    public function getAll();
72 72
 
73
-	/**
74
-	 * get the next job in the list
75
-	 *
76
-	 * @return \OCP\BackgroundJob\IJob|null
77
-	 * @since 7.0.0
78
-	 */
79
-	public function getNext();
73
+    /**
74
+     * get the next job in the list
75
+     *
76
+     * @return \OCP\BackgroundJob\IJob|null
77
+     * @since 7.0.0
78
+     */
79
+    public function getNext();
80 80
 
81
-	/**
82
-	 * @param int $id
83
-	 * @return \OCP\BackgroundJob\IJob|null
84
-	 * @since 7.0.0
85
-	 */
86
-	public function getById($id);
81
+    /**
82
+     * @param int $id
83
+     * @return \OCP\BackgroundJob\IJob|null
84
+     * @since 7.0.0
85
+     */
86
+    public function getById($id);
87 87
 
88
-	/**
89
-	 * set the job that was last ran to the current time
90
-	 *
91
-	 * @param \OCP\BackgroundJob\IJob $job
92
-	 * @since 7.0.0
93
-	 */
94
-	public function setLastJob(IJob $job);
88
+    /**
89
+     * set the job that was last ran to the current time
90
+     *
91
+     * @param \OCP\BackgroundJob\IJob $job
92
+     * @since 7.0.0
93
+     */
94
+    public function setLastJob(IJob $job);
95 95
 
96
-	/**
97
-	 * Remove the reservation for a job
98
-	 *
99
-	 * @param IJob $job
100
-	 * @since 9.1.0
101
-	 */
102
-	public function unlockJob(IJob $job);
96
+    /**
97
+     * Remove the reservation for a job
98
+     *
99
+     * @param IJob $job
100
+     * @since 9.1.0
101
+     */
102
+    public function unlockJob(IJob $job);
103 103
 
104
-	/**
105
-	 * get the id of the last ran job
106
-	 *
107
-	 * @return int
108
-	 * @since 7.0.0
109
-	 * @deprecated 9.1.0 - The functionality behind the value is deprecated, it
110
-	 *    only tells you which job finished last, but since we now allow multiple
111
-	 *    executors to run in parallel, it's not used to calculate the next job.
112
-	 */
113
-	public function getLastJob();
104
+    /**
105
+     * get the id of the last ran job
106
+     *
107
+     * @return int
108
+     * @since 7.0.0
109
+     * @deprecated 9.1.0 - The functionality behind the value is deprecated, it
110
+     *    only tells you which job finished last, but since we now allow multiple
111
+     *    executors to run in parallel, it's not used to calculate the next job.
112
+     */
113
+    public function getLastJob();
114 114
 
115
-	/**
116
-	 * set the lastRun of $job to now
117
-	 *
118
-	 * @param IJob $job
119
-	 * @since 7.0.0
120
-	 */
121
-	public function setLastRun(IJob $job);
115
+    /**
116
+     * set the lastRun of $job to now
117
+     *
118
+     * @param IJob $job
119
+     * @since 7.0.0
120
+     */
121
+    public function setLastRun(IJob $job);
122 122
 
123
-	/**
124
-	 * set the run duration of $job
125
-	 *
126
-	 * @param IJob $job
127
-	 * @param $timeTaken
128
-	 * @since 12.0.0
129
-	 */
130
-	public function setExecutionTime(IJob $job, $timeTaken);
123
+    /**
124
+     * set the run duration of $job
125
+     *
126
+     * @param IJob $job
127
+     * @param $timeTaken
128
+     * @since 12.0.0
129
+     */
130
+    public function setExecutionTime(IJob $job, $timeTaken);
131 131
 }
Please login to merge, or discard this patch.