Skip to content

[12.x] Fix model pruning when non model files are in the same directory #56071

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

Open
wants to merge 6 commits into
base: 12.x
Choose a base branch
from

Conversation

rojtjo
Copy link
Contributor

@rojtjo rojtjo commented Jun 17, 2025

The changes introduced in #56060 broke the model:prune command since it doesn't check if the given class is actually an Eloquent model before calling one of it's methods. This PR fixes that by adding a simple type check while still using the newly introduced isPrunable method to perform the check.

Please note that for the most part this PR is setup code to allow testing for the error.

Related: #56068

Copy link

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@rojtjo rojtjo marked this pull request as ready for review June 17, 2025 22:17
@rojtjo
Copy link
Contributor Author

rojtjo commented Jun 17, 2025

We might also want this check in this section

/**
* Prune the given model.
*
* @param string $model
* @return void
*/
protected function pruneModel(string $model)
{
$instance = new $model;
$chunkSize = property_exists($instance, 'prunableChunkSize')
? $instance->prunableChunkSize
: $this->option('chunk');
$total = $model::isPrunable()
? $instance->pruneAll($chunkSize)
: 0;
if ($total == 0) {
$this->components->info("No prunable [$model] records found.");
}
}
, but that seems to mess up the error messages defined in the other tests. Thoughts?

@crynobone crynobone linked an issue Jun 18, 2025 that may be closed by this pull request
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.

model:prune vs models in app directory
1 participant