-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[LDAP] Add "applyOperations" method to EntryManager #27069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
fc42f19
to
7395dfd
Compare
|
||
/** | ||
* @param string $dn | ||
* @param iterable|array|ModificationInterface[] $modifications |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think iterable|ModificationInterface[]
is sufficient here. the indent is a bit off though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here are some minor comments
ping @csarrazi since you're our LDAP referent :)
@@ -62,4 +63,12 @@ public function rename(Entry $entry, $newRdn, $removeOldRdn = true); | |||
* @throws LdapException | |||
*/ | |||
public function remove(Entry $entry); | |||
|
|||
/** | |||
* @param string $dn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be removed (duplicates the signature
|
||
/** | ||
* @param string $dn | ||
* @param iterable|array|ModificationInterface[] $modifications |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need for "array"
* @param string $dn | ||
* @param iterable|array|ModificationInterface[] $modifications | ||
* | ||
* @return bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
conflicts with :void
* | ||
* @return bool | ||
* | ||
* @throws LdapException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hinting when would be great
* @param string $dn | ||
* @param iterable|array|ModificationInterface[] $modifications | ||
* | ||
* @return bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(see previous comments that apply to this docblock also)
} | ||
|
||
if (!@ldap_modify_batch($this->getConnectionResource(), $dn, $modificationsMapped)) { | ||
throw new LdapException( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be on one line
|
||
if (!@ldap_modify_batch($this->getConnectionResource(), $dn, $modificationsMapped)) { | ||
throw new LdapException( | ||
sprintf('Could execute batch modification on "%s": %s', $dn, ldap_error($this->getConnectionResource())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could not?
& missing dot at end of message
private function assertValidModificationType(int $type): void | ||
{ | ||
if (!in_array($type, $this->validModificationTypes, true)) { | ||
throw new LdapException(sprintf('%s is not a valid modification type.', $type)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing double quotes around %s
LDAP_MODIFY_BATCH_REPLACE, | ||
); | ||
|
||
public function __construct($modificationType, string $attribute, array $values = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing type hint on $modificationType?
interface ModificationInterface | ||
{ | ||
/** | ||
* @return array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean the whole Interface or only the docblock?
@nicolas-grekas Thanks for your feedback. I will correct these spots. Sorry for steeling your time with inconsistent Docblocks. I was not sure about introducing the ModificationInterface at all. Maybe that's over engineered? |
I'm really not fond of adding new methods to I'm absolutely not against adding new methods directly to the Also, I would also remove the I feel that in the long term, would should use the That was actually the design that I wished for at first, but this was never done due to time constraints. |
Ok.
Is
I also thought about this direction but it will be much more work, like UnitOfWork state management, correct? What to do? Simplify the current approach like you suggested or close the PR for the moment? Thanks for your review! |
Keep the current approach for now, just remove the method from the interface. Regarding UpdateOperation, the remove is only applied to a single attribute value, or all values for a single attribute, but this is in reality a form of update. In LDAP, entries are the first class objects. Attributes are directly embedded within an entry, which means that all these operations (add, remove, remove_all, update) are actually all part of the same update. |
Okay, thanks! I will update the PR tonight. |
@csarrazi I updated the code as you have suggested. Test Results because LDAP is not covered by Travis: I have used an openldap docker image for testing and pointed the bootstrap directory to the fixtures. @csarrazi How do you run the tests? Maybe including this docker stuff in |
@mablae You can use the csarrazi/symfony-ldap Docker container, if you want to test easily :) This is what I actually run for testing on my end: docker run -d --name ldap -p 3389:389 \
-v "/Users/csarrazi/Projects/csarrazi/symfony/src/Symfony/Component/Ldap/Tests/Fixtures/data:/init-ldap.d" \
-e "LDAP_SUFFIX=dc=symfony,dc=com" \
-e "LDAP_ROOTDN=cn=admin,dc=symfony,dc=com" \
-e "LDAP_ROOTPW=symfony" \
csarrazi/symfony-ldap |
fcfc95e
to
ed180f4
Compare
* | ||
* @throws UpdateOperationException in case of an error | ||
*/ | ||
public function applyOperations(string $dn, iterable $modifications): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$operations
*/ | ||
public function applyOperations(string $dn, iterable $modifications): void | ||
{ | ||
$modificationsMapped = array(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$mappedOperations
public function applyOperations(string $dn, iterable $modifications): void | ||
{ | ||
$modificationsMapped = array(); | ||
foreach ($modifications as $modification) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$operations as $operation
Docs PR added, too |
From my side it's ready, what do you think, @csarrazi ? |
LGTM. Sorry for the late answer, the week has been pretty busy, as always :) |
Someone please remove "Need work" in that case. 😄 If anything is missing or can made better just let me know. We even have still some time until |
Ping @nicolas-grekas |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with some minor comments (mainly CS)
/** | ||
* @param int $operationType An LDAP_MODIFY_BATCH_* constant | ||
* @param string $attribute The attribute to batch modify on | ||
* @param array|null $values |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This @param
can be removed (as it does not add anything that is not already in the signature)
|
||
/** | ||
* @param string $dn Distinguished name to apply operations on | ||
* @param iterable|UpdateOperation[] $operations An array or iterable of Modification instances |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose that Modification
should be UpdateOperation
here.
@@ -121,4 +122,22 @@ private function getConnectionResource() | |||
|
|||
return $this->connection->getResource(); | |||
} | |||
|
|||
/** | |||
* @param string $dn Distinguished name to apply operations on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this one can be removed. $dn
in this context is pretty clear.
Also introduce new UpdateOperation class.
40b19f6
to
8fc09c7
Compare
Thanks @fabpot ! I have updated the code according to your suggestions and rebased/squashed it against current master. |
Thank you @mablae. |
…ablae) This PR was merged into the 4.2-dev branch. Discussion ---------- [LDAP] Add "applyOperations" method to EntryManager | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #27039 | License | MIT | Doc PR | symfony/symfony-docs#9715 This PR adds a new method called `applyOperations` to the LDAP `EntryManager` class. Internally it is mapping the new `UpdateOperation` object to the `ldap_modify_batch` method. Tests green against openldap. Thanks for any feedback. Todo: * [x] Add Docs PR Commits ------- 8fc09c7 Add applyOperations batch method to EntryManager
This PR was merged into the master branch. Discussion ---------- [LDAP] Add docs for applyOperations method See PR symfony/symfony#27069 Commits ------- 74fed75 [LDAP] Add docs for applyOperations method
This PR adds a new method called
applyOperations
to the LDAPEntryManager
class.Internally it is mapping the new
UpdateOperation
object to theldap_modify_batch
method.Tests green against openldap.
Thanks for any feedback.
Todo: