XF 2.2 Anything to clean up old files?

digitalpoint

Well-known member
I started running some code compatibility checks for PHP 8.1 and most everything that came up were old PHP files that weren't even part of XenForo any longer (but still existed on the server).

So then I started down the road of making a XenForo Cli command that reads the hashes.json files, looks at all the files that don't have an entry there, but exist on the server. Low and behold, the first site I tried it on, there were over 1,500 files that are "leftover" from previous versions of XenForo.

Once I realized how many there actually were, I figured I would check if I'm just building something that already exists (bigger issue than I realized). Is there something I'm missing in XF that cleans up old/unused files before I keep working on this?

Code:
...[clipped a ton]...

src/vendor/stripe/stripe-php/tests/Stripe/CouponTest.php
src/vendor/stripe/stripe-php/tests/Stripe/ProductTest.php
src/vendor/stripe/stripe-php/tests/Stripe/HttpClient/CurlClientTest.php
src/vendor/stripe/stripe-php/tests/Stripe/ApiRequestorTest.php
src/vendor/stripe/stripe-php/tests/Stripe/ExchangeRateTest.php
src/vendor/stripe/stripe-php/tests/Stripe/TransferReversalTest.php
src/vendor/stripe/stripe-php/tests/Stripe/PlanTest.php
src/vendor/stripe/stripe-php/tests/Stripe/PersonTest.php
src/vendor/stripe/stripe-php/tests/Stripe/SubscriptionTest.php
src/vendor/stripe/stripe-php/tests/Stripe/PriceTest.php
src/vendor/stripe/stripe-php/tests/Stripe/PaymentIntentTest.php
src/vendor/stripe/stripe-php/tests/Stripe/WebhookTest.php
src/vendor/stripe/stripe-php/tests/Stripe/StripeTelemetryTest.php
src/vendor/stripe/stripe-php/tests/bootstrap.php
src/vendor/stripe/stripe-php/tests/TestHelper.php
src/vendor/stripe/stripe-php/phpunit.no_autoload.xml
src/vendor/swiftmailer/swiftmailer/phpunit.xml.dist
src/vendor/swiftmailer/swiftmailer/.php_cs.dist
src/vendor/swiftmailer/swiftmailer/.gitignore
src/vendor/swiftmailer/swiftmailer/lib/swift_required_pear.php
src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Encoding.php
src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/MailTransport.php
src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/MailTransport.php
src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/MailInvoker.php
src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/SimpleMailInvoker.php
src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/SignedMessage.php
src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Grammar.php
src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/HeaderFactory.php
src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/HeaderSet.php
src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/ParameterizedHeader.php
src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/Message.php
src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mime/MimeEntity.php
src/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Validate.php
src/vendor/swiftmailer/swiftmailer/lib/swift_init.php
src/vendor/swiftmailer/swiftmailer/.travis.yml
src/vendor/swiftmailer/swiftmailer/README
src/vendor/swiftmailer/swiftmailer/.gitattributes
src/vendor/swiftmailer/swiftmailer/VERSION
src/vendor/swiftmailer/swiftmailer/.github/ISSUE_TEMPLATE.md
src/vendor/swiftmailer/swiftmailer/.github/PULL_REQUEST_TEMPLATE.md
src/vendor/composer/platform_check.php
src/vendor/pelago/emogrifier/phpcs.xml.dist
src/vendor/pelago/emogrifier/config/phpmd.xml
src/vendor/pelago/emogrifier/config/php-cs-fixer.php
src/vendor/pelago/emogrifier/src/Emogrifier/CssConcatenator.php
src/vendor/pelago/emogrifier/Classes/Emogrifier.php
src/vendor/pelago/emogrifier/.gitignore
src/vendor/pelago/emogrifier/.travis.yml
src/vendor/pelago/emogrifier/CODE_OF_CONDUCT.md
src/vendor/pelago/emogrifier/CONTRIBUTING.md
src/vendor/spomky-labs/base64url/infection.json.dist
src/vendor/oyejorge/less.php/bin/lessc
src/vendor/oyejorge/less.php/.gitignore
src/vendor/oyejorge/less.php/.gitattributes
src/vendor/psr/log/.gitignore
src/vendor/laminas/laminas-mail/src/Header/HeaderLocatorInterface.php
src/vendor/laminas/laminas-mail/src/Header/HeaderLocator.php
src/vendor/laminas/laminas-validator/src/UndisclosedPassword.php
src/index.html
src/vendor-patch/League/Flysystem/CorruptedPathDetected.php
src/vendor-patch/League/Flysystem/Util.php
src/vendor-patch/Laminas/Mail/Address.php
src/vendor-patch/Laminas/Mail/Headers.php
src/vendor-patch/Zend/Mail/Address.php
src/vendor-patch/Zend/Mail/Headers.php
src/XF/Job/LikeCount.php
src/XF/Job/UserRemoveLikes.php
src/XF/AddOn/CheckRequirementsInterface.php
src/XF/Permission/AbstractFlatPermissions.php
src/XF/Template/Compiler/Fn/PreEscaped.php
src/XF/Template/Compiler/Fn/Vars.php
src/XF/Template/Compiler/Fn/IncludeFn.php
src/XF/Template/Compiler/Fn/AbstractFn.php
src/XF/Template/Compiler/Fn/EmptyFn.php
src/XF/Template/Compiler/Fn/Phrase.php
src/XF/Install/Upgrade/2001170-2011.php
src/XF/Like/ProfilePostComment.php
src/XF/Like/ConversationMessage.php
src/XF/Like/ProfilePost.php
src/XF/Like/Post.php
src/XF/Option/EnableTrophies.php
src/XF/Mvc/Entity/RapidEntity.php
src/XF/Import/Importer/vBulletinBlogTrait.php
src/XF/Import/Importer/vBulletin36.php
src/XF/Import/Importer/XenForo2.php
src/XF/Import/Importer/vBulletin4WithBlog.php
src/XF/Import/Importer/vBulletin.php
src/XF/Import/Importer/vBulletin4.php
src/XF/Import/Importer/vBulletin5.php
src/XF/Import/Importer/vBulletin4BlogTrait.php
src/XF/Import/Importer/vBulletinWithBlog.php
src/XF/Import/Data/vBulletinBlogUser.php
src/XF/Import/Data/vBulletinBlogEntry.php
src/XF/Import/Data/vBulletinBlogText.php
src/XF/Import/Data/vBulletinBlogAttachmentVB4.php
src/XF/Import/Data/vBulletinBlogAttachment.php
src/XF/Admin/Controller/RapidController.php
src/XF/Authentication/IPBoard.php
src/XF/Authentication/IPBoard40x.php

Total: 1567
 
There is this resource which cleans up XF1 files, but I'm not aware of anything for XF2 files.

 
Ya I saw that when looking to see if something existed... in my case, it's a site that was never on XF1, so these 1,500+ legacy files are all from XF2 at some point.

I guess that answers my question though about if I should keep working on this or if something I can't find exists already. :)
 
Once I realized how many there actually were, I figured I would check if I'm just building something that already exists (bigger issue than I realized). Is there something I'm missing in XF that cleans up old/unused files before I keep working on this?
Latest XenForo knows how to inspect hashes.json for uninstalled add-ons and generate file lists which aren't referenced by any other hashes.json file.

It isn't quite what you are doing but would be a starting point
 
Ended up getting it sorted out already. Ended up with files I added (things like robots.txt), some random empty files that XF ships with that aren't in hashes.json, and the contents of src/vendor-patch (for some reason they don't have hashes generated... not sure why they wouldn't, but they don't). Looks better now.

Code:
twin1:web # php cmd.php dp:legacy-files
library/.htaccess
library/index.html
robots.txt
src/.htaccess
src/config.php.default
src/index.html
src/vendor-patch/League/Flysystem/CorruptedPathDetected.php
src/vendor-patch/League/Flysystem/Util.php
src/config.php
styles/index.html
styles/default/index.html
favicon.ico
htaccess.txt
missing_ipn.php
js/swfupload/Flash/swfupload.swf
js/swfupload/swfupload.min.js
js/swfupload/index.html
js/index.html
js/devjs.php
js/videojs/video-js.swf
.well-known/apple-developer-merchantid-domain-association

Total: 21

That site went from 5,357 to 4,198 PHP files (and far better compatibility with PHP 8.1). :)
 
I didn't really do anything terribly fancy with it. Like it doesn't automatically delete files (I figured that might be too risky to lose files that might not be listed in hashes.json for whatever reason). If I had done that, those 21 files I didn't want to delete would have been deleted. So really just used it as an tool to get a list of files for review (and manual deletion).

You can do something similar (and in some ways better) with vimdiff like so (the two paths given are the one for your live site and one that contains a fresh set from xenforo zip file):

Bash:
vimdiff <(cd /home/sites/example.com/web/src/; find . | sort) <(cd /home/sites/example.com/xf-2.2.8p1/upload/src; find . | sort)
 
It would be nice for Xenforo to integrate this type of simple file cleanup prior to every update. That way if a needed file accidentally gets deleted during the cleanup the update that runs immediately after would reinstall the needed file.

When you click to update:
1. Cleanup existing files comparing them to last version update
2. Run new update

Seems like a simple solution to me to always keep obsolete files cleaned up.
 
Top Bottom