SilverStripe 3 to 4 Upgrade - NameSpace imports (use) Wrong

Silverstripe Version 3 and 4.x (latest):

Question:

Can I automatically add the use statements of namespaces in my existing code?

I ran

# upgrade-code -vSilverStripe Upgrader 1.4.3
upgrade-code add-namespace -r "\mwlr" vendor/mwlr/portals2-common/code
modified:       pagetypes/BasePage.php
@@ -1,5 +1,37 @@
 <?php
+
+namespace mwlr;
+
 use Ramsey\Uuid\Uuid;
+use SiteTree;
+use Director;
+use Member;
+use SiteConfig;
+use DB;
+use CheckboxField;
+use HTMLEditorField;
+use UploadField;
+use CSPRequirements_Backend;
+use BaseAppPage;
+use ContentController;
+use PermissionProvider;
+use Page;
+use Permission;
+use Security;
+use Requirements;
+use DataObject;
+use SecurityToken;
+use SSViewer;
+use ArrayList;
+use MemberProfilePage;
+use MemberConfirmationEmail;
+use Email;
+use ArrayData;
+use FieldList;
+use TextField;
+use FormAction;
+use Form;
+
 
 /**
  * Class BasePage

However, the page crashes when I try to load it with these changes.

Also, if I use VSCode to ‘Import All Classes’, the result is:

use Ramsey\Uuid\Uuid;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\CMS\Controllers\ContentController;

I also tried running the ‘all’ command to no end.

Am I missing something?

What error message are you getting? Anything on-screen or in the server logs?

Thanks for getting back to me.

I already found the problem with the upgrader that I was experiencing. The upgrader seems to not be perfect, which is fair enough as it is a hard problem.

What I did was to move the module files to

app/src/mymodulenamespace

and then delete some of my custom class files.

Then the upgrader could actually work on the remaining class files. However, it didn’t separate out the controllers, so I wrote a script for that. If I have time to make it more generic, I’ll share it. It’s written in JS though because that was the quickest for me.