Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
fabpot merged 1 commit intosymfony:masterfrommablae:feature-ldap-batch
May 18, 2018

Conversation

@mablae
Copy link
Contributor

@mablaemablae commentedApr 26, 2018
edited
Loading

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets#27039
LicenseMIT
Doc PRsymfony/symfony-docs#9715

This PR adds a new method calledapplyOperations to the LDAPEntryManager class.
Internally it is mapping the newUpdateOperation object to theldap_modify_batch method.

Tests green against openldap.

Thanks for any feedback.

Todo:

  • Add Docs PR

csarrazi reacted with thumbs up emoji
@mablaemablae changed the titleAdd modifyBatch method to LDAP EntryManager[LDAP] Add modifyBatch method to EntryManagerApr 26, 2018

/**
* @param string $dn
* @param iterable|array|ModificationInterface[] $modifications
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I thinkiterable|ModificationInterface[] is sufficient here. the indent is a bit off though

@nicolas-grekasnicolas-grekas added this to thenext milestoneApr 29, 2018
Copy link
Member

@nicolas-grekasnicolas-grekas left a 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 :)

publicfunctionremove(Entry$entry);

/**
* @param string $dn

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

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

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

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

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)) {
thrownewLdapException(

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)) {
thrownewLdapException(
sprintf('Could execute batch modification on "%s": %s',$dn,ldap_error($this->getConnectionResource()))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Couldnot?
& missing dot at end of message

privatefunctionassertValidModificationType(int$type):void
{
if (!in_array($type,$this->validModificationTypes,true)) {
thrownewLdapException(sprintf('%s is not a valid modification type.',$type));

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,
);

publicfunction__construct($modificationType,string$attribute,array$values =null)

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

should be removed

Copy link
ContributorAuthor

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?

@mablae
Copy link
ContributorAuthor

@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?

@csarrazi
Copy link
Contributor

I'm really not fond of adding new methods toEntryManagerInterface, especially since this method is a direct 1:1 conversion of the PHP extension'sldap_modify_batch function.

I'm absolutely not against adding new methods directly to theExtLdap'sEntryManager, but that method should not be in the globalEntryManager interface (especially since this is also a breaking change), as this leaks PHP's poorly designed LDAP extension. The whole point of the component is to hide that logic.

Also, I would also remove theModificationInterface, as it is only used by the extension.
We will design something better, and more flexible in later versions of the component. I would also change the name of theModification class to something more specific, likeUpdateOperation as, the batch operations actually only update a single entry's attribute, in an atomic way, and renamemodifyBatch() toapplyOperations().

I feel that in the long term, would should use theupdate(Entry $entry) to apply a change set for a given entry. TheEntry class should actually calculate and hold the change set, until changes are be applied with the EM'supdate(Entry $entry) method. The actual logic behind the update would then be completely hidden from the implementation details.

That was actually the design that I wished for at first, but this was never done due to time constraints.

@mablae
Copy link
ContributorAuthor

mablae commentedApr 30, 2018
edited
Loading

I'm really not fond of adding new methods to EntryManagerInterface, especially since this method is a direct 1:1 conversion of the PHP extension's ldap_modify_batch function.

Ok.

I'm absolutely not against adding new methods directly to the ExtLdap's EntryManager, but that method should not be in the global EntryManager interface (especially since this is also a breaking change), as this leaks PHP's poorly designed LDAP extension. The whole point of the component is to hide that logic.

Also, I would also remove the ModificationInterface, as it is only used by the extension.
We will design something better, and more flexible in later versions of the component. I would also change the name of the Modification class to something more specific, like UpdateOperation as, the batch operations actually only update a single entry's attribute, in an atomic way, and rename modifyBatch() to applyOperations().

IsUpdateOperation really a good fit for removal?

I feel that in the long term, would should use theupdate(Entry $entry) to apply a change set for a given entry. The Entry class should actually calculate and hold the change set, until changes are be applied with the EM's update(Entry $entry) method. The actual logic behind the update would then be completely hidden from the implementation details.

That was actually the design that I wished for at first, but this was never done due to time constraints.

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!

@csarrazi
Copy link
Contributor

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.

@mablae
Copy link
ContributorAuthor

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.

@mablaemablae changed the title[LDAP] Add modifyBatch method to EntryManager[LDAP] Add "applyOperations" method to EntryManagerApr 30, 2018
@mablae
Copy link
ContributorAuthor

mablae commentedApr 30, 2018
edited
Loading

@csarrazi I updated the code as you have suggested.

Test Results because LDAP is not covered by Travis:

image

I have used an openldap docker image for testing and pointed the bootstrap directory to the fixtures.
Worked like a charm after removing the root org from base.ldif which was already created by the docker image:https://gist.github.com/mablae/f23cc8d715c8b2a1de23a656b1fe8499

@csarrazi How do you run the tests? Maybe including this docker stuff inTests makes sense?

@csarrazi
Copy link
Contributor

@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
mablae reacted with thumbs up emoji

*
* @throws UpdateOperationException in case of an error
*/
publicfunctionapplyOperations(string$dn,iterable$modifications):void
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

$operations

*/
publicfunctionapplyOperations(string$dn,iterable$modifications):void
{
$modificationsMapped =array();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

$mappedOperations

publicfunctionapplyOperations(string$dn,iterable$modifications):void
{
$modificationsMapped =array();
foreach ($modificationsas$modification) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

$operations as $operation

@mablae
Copy link
ContributorAuthor

Docs PR added, too

@mablae
Copy link
ContributorAuthor

From my side it's ready, what do you think,@csarrazi ?

@csarrazi
Copy link
Contributor

LGTM. Sorry for the late answer, the week has been pretty busy, as always :)

mablae reacted with thumbs up emoji

@mablae
Copy link
ContributorAuthor

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 until4.2 to make better.

@csarrazi
Copy link
Contributor

Ping@nicolas-grekas

Copy link
Member

@fabpotfabpot left a 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
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I suppose thatModification should beUpdateOperation here.

}

/**
* @param string $dn Distinguished name to apply operations on
Copy link
Member

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.
@mablae
Copy link
ContributorAuthor

Thanks@fabpot !

I have updated the code according to your suggestions and rebased/squashed it against current master.

@fabpot
Copy link
Member

Thank you@mablae.

@fabpotfabpot merged commit8fc09c7 intosymfony:masterMay 18, 2018
fabpot added a commit that referenced this pull requestMay 18, 2018
…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#9715This 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 PRCommits-------8fc09c7 Add applyOperations batch method to EntryManager
mablae added a commit to mablae/symfony-docs that referenced this pull requestMay 19, 2018
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull requestMay 22, 2018
This PR was merged into the master branch.Discussion----------[LDAP] Add docs for applyOperations methodSee PRsymfony/symfony#27069Commits-------74fed75 [LDAP] Add docs for applyOperations method
@nicolas-grekasnicolas-grekas modified the milestones:next,4.1Nov 1, 2018
This was referencedNov 3, 2018
@mablaemablae deleted the feature-ldap-batch branchDecember 13, 2018 03:25
Guikingone pushed a commit to Guikingone/symfony-docs that referenced this pull requestFeb 12, 2019
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@fabpotfabpotfabpot approved these changes

+2 more reviewers

@linaorilinaorilinaori left review comments

@csarrazicsarrazicsarrazi requested changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

4.1

Development

Successfully merging this pull request may close these issues.

6 participants

@mablae@csarrazi@fabpot@nicolas-grekas@linaori@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp