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

exec command #12528

Merged
merged 2 commits into from
Jan 11, 2023
Merged

exec command #12528

merged 2 commits into from
Jan 11, 2023

Conversation

brandonkelly
Copy link
Member

Adds a new exec command, which executes a single PHP statement and outputs the result.

Examples:

> php craft exec "'hello world'"
= "hello world"
> php craft exec "echo 'hello world'"
Output:
hello world
> php craft exec "Craft::\$app->version"
= "4.3.6.1"
> php craft exec "craft\elements\Entry::find()->asArray()->one()"
= array:38 [
    "id" => 24
    "canonicalId" => null
    "fieldLayoutId" => 197
    "uid" => "09fec6f1-89bf-425e-9fe6-a2d632bb6cf3"
    "enabled" => 1
    "archived" => 0
    "dateLastMerged" => null
    "dateCreated" => "2014-07-31 22:04:17"
    "dateUpdated" => "2016-06-03 17:43:36"
    "siteSettingsId" => 24
    "slug" => "the-future-of-augmented-reality"
    "siteId" => 1
    "uri" => "news/the-future-of-augmented-reality"
    "enabledForSite" => 1
    "sectionId" => 2
    "typeId" => 2
    "authorId" => 1
    "postDate" => "2016-05-07 00:00:00"
    "expiryDate" => null
    "contentId" => 13
    "title" => "The Future of Augmented Reality"
    "field_address" => null
    "field_backgroundColor" => null
    "field_body" => null
    "field_contactUsLabel" => null
    "field_copyrightNotice" => null
    "field_email" => null
    "field_featuredEntry" => 0
    "field_heading" => "Your iPhone Is No Longer a Way To Hide"
    "field_indexHeading" => null
    "field_linkUrl" => null
    "field_shortDescription" => """
      <p>\r\n
      \tNam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis.\r\n
      </p>
      """
    "field_subheading" => "But is now a way to connect with the world"
    "root" => null
    "lft" => null
    "rgt" => null
    "level" => null
    "structureId" => null
  ]

@brandonkelly brandonkelly requested a review from a team as a code owner January 11, 2023 22:33
@linear
Copy link

linear bot commented Jan 11, 2023

DEV-1070 `exec` command

[ci skip]
@brandonkelly brandonkelly merged commit 8245621 into 4.4 Jan 11, 2023
@brandonkelly brandonkelly deleted the feature/dev-1070-exec-command branch January 11, 2023 22:34
@michaelrog
Copy link

michaelrog commented Jan 12, 2023

From @brandonkelly in Discord...

shell is wonderful, but there are times when I'm testing some new element query param or something, and it's nice to be able to test it with exec, each time re-bootstrapping Craft with the latest code changes
Whereas shell will stick with the same initialized Craft application that was there when you first started the command

@brandonkelly
Copy link
Member Author

What he said!

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