silverstripe / silverstripe-upgrader

A tool to help upgrade your code to handle API changes in packages you used.
BSD 3-Clause "New" or "Revised" License
39 stars 20 forks source link

Incorect use statements written #50

Open worikgh opened 6 years ago

worikgh commented 6 years ago

upgrade-code add-namespace adds use statements to code files, E.g., "use SiteTree" when it should be use SilverStripe\CMS\Model\SiteTree;

When run over a Page.php file from a SS 3 project

tractorcow commented 6 years ago

@worikgh you need to run upgrade-code upgrade before adding namespace to a project; If it's kept the use SiteTree it's because the code being namespaced was still pointing to the un-upgraded class name.

I should probably point out, you can't namespace Page since it's the one un-namespaceable class :)

tractorcow commented 6 years ago

Can you show me the command (in full) you ran and I'll test it locally, but this probably just needs to be clarified in the docs.

worikgh commented 6 years ago

~/.config/composer/vendor/bin/upgrade-code add-namespace "OurCo\NAME" NAME/mysite/code/Page.php --write

It would be usual to use the Page.php that composer creates, I guess. But I have a lot of classes I made under SS v3

NightJar commented 6 years ago

I'm lead to believe that this functionality is correct @worikgh - the first step is to add all the namespaces using the tool, the second step is to run upgrade, which will convert all those non-namespaced statements to their fully qualified version.

The importance between these two tasks is that the first simply looks at the current file(set), adding use statements for each class therein, and perhaps more importantly generating the .upgrade.yml file. The second task will read all of your project's .upgrade.yml files (i.e. including modules), and update files where appropriate. This way source files from outside your module/project (such as SilverStripe\CMS\Model\SiteTree) will also be considered in the upgrade.

You'll notice that running upgrade first will give you a "missing .upgrade.yml file" error, this is the importance of running add-namespace first (see #53 and #54).

However; with this said it could both be clearer in the docs, and also work with respect to silverstripe-vendormodule code. Maybe this latter issue is the true root of the issue, I'm unsure. I'm just relaying info delivered to me by folks more experienced in the tools usage than I :)