Yes, I did it. I imported new images with every product import so now I have 15000+ images in my media library.
for id in $(wp db query "SELECT id FROM wp_posts WHERE post_date <= '2023-03-20' AND post_date >= '2023-03-15' AND post_type='attachment' AND post_parent=0 AND post_author NOT IN(1,4)" --skip-column-names); do wp post delete --force $id; done
This is the wp cli command that does the job. I found it here.
Just to see how many images will be deleted you can use following query:
wp db query "SELECT COUNT(id) FROM wp_posts WHERE post_date <= '2023-03-20' AND post_date >= '2023-03-01' AND post_type='attachment' AND post_parent = 0 AND post_author NOT IN (1,4)"
You can modify post_author IDs and date ranges as you like. For testing you can as LIMIT parameter to the query.
laravel-app.mydomain.com – this uses php 8.0
wordpress.mydomain.com – this uses php 7.4
If I need to use command line interface (cli) then php version is always the same that I have set for my main domain settings. If I need to use specific PHP version in cli then I need PHPRC prefix before command of export PHPRC in the beginning of the bash script.
At some point var_dump in Postman started printing HTML instead of json and made debugging experience worse. I used php artisan serve and suspected that my CLI php is using xdebug. This advice I found helpful.
sudo phpdismod -s cli xdebug – to disable xdebug
sudo phpenmod -s cli xdebug – to enable xdebug
This is how you can disable and enable xdebug from command line. After this that <pre> thing should go away from Postman responses.
I need to test helper method that accepts Illuminate\Database\Eloquent\Collection as a parameter. But I can not figure out how to prepare it inside a unit test. My logic says it should be simple to create Collection from assoc array. But I just can’t get it to work.
At the moment, not to get stuck, I will probably use feature testing (because if feature (API endpoint) works then probably my helper method also works). Though, it feels stupid workaround.
Created new Laravel project by composer create-project laravel/laravel example-app. Trying to run tests/Feature/ExampleTest.php in PhpStorm and I get an error Class 'phpunit' could not be found in '/home/robert/phpunit-test-app/vendor/phpunit/phpunit/phpunit'. What does it even mean?! 😀 There are no answers on Google at the moment and this post will probably rank well.
For some reason my CLI interpreter did not make any sense. It took me quite a few hours to figure it out.