Skip to content
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

Undefined index notice on nested call #97

Closed
ravage84 opened this issue Sep 13, 2016 · 5 comments
Closed

Undefined index notice on nested call #97

ravage84 opened this issue Sep 13, 2016 · 5 comments

Comments

@ravage84
Copy link
Contributor

My situation:

Rack hasMany RackUnit (fully pedendent)
RackUnit belongsTo Reservation (optionally)

Deleting a Rack, deletes all its RackUnit.
If one of those RackUnit belongTo a Reservation, that Reservation will be deleted, too.
If a Reservation gets deleted, another behavior will unset (means updated, not deleted) all reserved RackUnit.

This leads to a nested call stack, which in turn leads to a Undefined index: RackUnit notice.

The simplified call stack is:

  1. beforeDelete() RackUnit 123
    • Sets the original data for RackUnit 123
  2. delete() Reservation ABC
  3. Update RackUnit 123
  4. beforeSave() RackUnit 123
    • Overwrites the original data for RackUnit 123 (still same content)
  5. afterSave() RackUnit 123
    • Unsets the original data for RackUnit 123
  6. afterDelete() RackUnit 123
    • Original data for RackUnit 123 is missing!

I see two workarounds an one solution.

  1. Workaround 1: Do not unset the original data, which means the original data stacks up. Is this a problem?
  2. Workaround 2: Return empty arrray, if key is not set, which is a silent error
  3. Solution: Implement a pushable/popable stack of original data.
@ravage84
Copy link
Contributor Author

Both workarounds seem to work and pass the (updated) tests.

ravage84 added a commit to ravage84/CakePHP-Audit-Log-Plugin that referenced this issue Sep 13, 2016
@ravage84
Copy link
Contributor Author

Not unsetting the original data could be a problem on this line:
https://github.com/robwilkerson/CakePHP-Audit-Log-Plugin/blob/2.0.1/Model/Behavior/AuditableBehavior.php#L210

@xhs345 do you know why there is no afterAuditDelete callback hook?

ravage84 added a commit to ravage84/CakePHP-Audit-Log-Plugin that referenced this issue Sep 13, 2016
Also refactores all original data related actions into reusable methods.
@xhs345
Copy link
Collaborator

xhs345 commented Sep 13, 2016

@ravage84 Nope, don't know why

@ravage84
Copy link
Contributor Author

Easy, already documented as #82

xhs345 pushed a commit that referenced this issue Jan 22, 2017
@xhs345
Copy link
Collaborator

xhs345 commented Jan 22, 2017

Closing this since your fix has been merged

@xhs345 xhs345 closed this as completed Jan 22, 2017
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

No branches or pull requests

2 participants