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

Appearance settings

Major Craft 3 API Updates#4

Merged
michaelrog merged 5 commits into
3.x.devTopShelfCraft/Walk:3.x.devfrom
feature/api-changesTopShelfCraft/Walk:feature/api-changesCopy head branch name to clipboard
Oct 22, 2018
Merged

Major Craft 3 API Updates#4
michaelrog merged 5 commits into
3.x.devTopShelfCraft/Walk:3.x.devfrom
feature/api-changesTopShelfCraft/Walk:feature/api-changesCopy head branch name to clipboard

Conversation

@jalendport

Copy link
Copy Markdown
  • Updated the maxPowerCaptain() method call to the latest Craft 3 API.
  • We should only be passing $userdata to the $callable if it exists, otherwise we can end up with errors.
  • Rewrote the task infrastructure to use the new Craft 3 queue and jobs:
    • Moved the tasks/* to the new Craft 3 queue/jobs/* directory and updated the job methods to the new API.
    • Updated the method we use to push new jobs to the queue to the new Craft 3 API.
    • Changed any use of the word task\tasks in the repo to job\jobs to stay consistent.

Fixes #2

Jalen Davenport added 3 commits October 20, 2018 09:49
Moved the `tasks/*` to the new Craft 3 `queue/jobs/*` directory and updated the job methods to the new API.
Updated the method we use to push new jobs to the queue to the new Craft 3 API.
Changed any use of the word `task\tasks` in the repo to `job\jobs` to stay consistent.
Comment thread src/helpers/WalkHelper.php

@michaelrog michaelrog left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(Duplicate comment.)


if (is_callable($callable))
{
return array_walk($array, $callable, $userdata);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Did an error come up in your testing? The $userdata param should be null (default value from the method signature) if no argument is provided, which should be fine to pass into the array_walk...?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I did yes; check out the latter half of #2. It's complaining that the parameter passed to the $callable needs to be a boolean but we're passing null. Based on the array_walk docs, the $userdata parameter is optional hence the solution I used here. If there is a better way to solve I'd love to know because it doesn't seem like the cleanest method 🤔

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A ha! So, you're right — we need to only pass that parameter downstream if the argument is actually provided — but it has nothing to do with array_walk.

Specifically, array_walk doesn't care what kind of argument is passed there. It's the downstream method that cares. (In this case, saveElement is looking for a boolean param, probably to toggle some validation logic. The fact that we were passing a default null was fine with array_walk, but saveElement complained.)

We can't predict whether a target method will ever expect a second param, so we shouldn't presume to put a default value there. We should let our user do that, in cases where they know it's relevant to the target method.

However, a simple truthiness check isn't a good idea here. (What if the $userdata is false, or null, or [], or 0, or anything else that casts to a false boolean? That argument will never be passed through.) The correct check to use here is isset().

Comment thread src/queue/jobs/CallOnElementJob.php Outdated
Comment thread src/queue/jobs/CallOnValueJob.php Outdated
@michaelrog
michaelrog merged commit 8b8b7af into 3.x.dev Oct 22, 2018
@michaelrog
michaelrog deleted the feature/api-changes branch October 22, 2018 13:48
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.