Skip to content

Plugin, Tests, Overhaul, Many more features#7

Open
zeroasterisk wants to merge 9 commits intojamienay:masterfrom
AudiologyHoldings:dev
Open

Plugin, Tests, Overhaul, Many more features#7
zeroasterisk wants to merge 9 commits intojamienay:masterfrom
AudiologyHoldings:dev

Conversation

@zeroasterisk
Copy link

I merged your project with my own implementation of something similar...

I decided that this was worthwhile, benefiting from the "best of both" implementations.

  • Now a Plugin (easier install, better isolation)
  • Now you can pass in more settings, including your own custom contain and saveAllOptions
  • Now more effectively recursive (resilient even if the behavior isn't setup on recursed models)
  • Now you can inject (via Hash::merge & Hash::insert) before save - useful for data ceanup
  • Now you can use your own custom copyPrepareDataCustom() method to custom-clean data if needed
  • Now a few more methods are public, for possible direct usefulness and for easier testing (see README)
  • Now tested...
$ ./cake test Copyable Model/Behavior/CopyableBehavior
---------------------------------------------------------------
CakePHP Test Shell
---------------------------------------------------------------
PHPUnit 3.7.38 by Sebastian Bergmann.

............

Time: 1.62 seconds, Memory: 22.25Mb

OK (12 tests, 98 assertions)

Details

  • added unit testing for CopyableBehavior
  • switched to passing through the $record/$data vs keeping on Behavior
  • switched to passing through the $contain vs keeping on Behavior
  • switched to more dynamic settings - allows more recursion
    onto Models which don't have this Behavior setup/configured
  • switched to "sticky" settings - when used via copy()
    this takes priority over defaults, but not over per-Model settings
  • added support for custom settings for $contain (if set, does not generate)
  • added support for custom settings for $saveAllOptions
  • replaced old public generateContain() with copyGenerateContain()
    renamed to match public method "psuedo-namespacing" - prefixed w/ "copy"
    old alias retained for backwards compatibilty
  • exposed new public copyFindData() which does our lookup
  • exposed new public copyPrepareData() which does our conversion
  • exposed new public copySaveAll() which does our save
  • exposed new $Model->copyData array, for inspection of data before and after conversion
  • now we support data injection via merge or insert
  • put in default, empty settings for ^
  • replaced $data with $record for consistency

rchavik and others added 7 commits May 9, 2014 17:22
- [x] added unit testing for CopyableBehavior
- [x] switched to passing through the $record/$data vs keeping on Behavior
- [x] switched to passing through the $contain vs keeping on Behavior
- [x] switched to more dynamic settings - allows more recursion
      onto Models which don't have this Behavior setup/configured
- [x] switched to "sticky" settings - when used via copy()
      this takes priority over defaults, but not over per-Model settings
- [x] added support for custom settings for $contain (if set, does not generate)
- [x] added support for custom settings for $saveAllOptions
- [x] replaced old public generateContain() with copyGenerateContain()
      renamed to match public method "psuedo-namespacing" - prefixed w/ "copy"
      old alias retained for backwards compatibilty
- [x] exposed new public copyFindData() which does our lookup
- [x] exposed new public copyPrepareData() which does our convertion
- [x] exposed new public copySaveAll() which does our save
- [x] exposed new $Model->copyData array, for inspection of data before and after convertion
you can optionally inject data after prepare/convertion before save.
- [x] now we support data injection via merge or insert
- [x] put in default, empty settings for ^
- [x] replaced `$data` with `$record` for consistancy
@zeroasterisk
Copy link
Author

@rchavik @jamienay I'd appreciate a review if you wanna take a look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants