joomlatools / joomlatools-composer

Composer extension installer for Joomla.
https://www.joomlatools.com/developer/tools/composer/
GNU General Public License v3.0
52 stars 13 forks source link

Undefined constant JPATH_COMPONENT_ADMINISTRATOR #16

Closed GlassGruber closed 9 years ago

GlassGruber commented 9 years ago

Hello there, thanks a lot for this, I'm a rookie with composer and command line but actually already love this incredible plugin!

I've tried installing JCE, this is my code for it

{
    "type": "package",
    "package": {
        "name": "vendor/jce",
        "type": "joomla-installer",
        "version": "1.0.0",
        "dist": {
            "url": "https://www.joomlacontenteditor.net/downloads/editor/joomla-3?task=callelement&format=raw&item_id=1133&element=f85c494b-2b32-4109-b8c1-083cca2b7db6&method=download&args[0]=a51aaa52300b0ccdf84d03ca4c75f67c",
            "type": "zip"
        },
        "require": {
            "joomlatools/installer": "*"
        }
    }
}

Unfortunately after downloading correctly I have this error

[ErrorException]
Use of undefined constant JPATH_COMPONENT_ADMINISTRATOR - assumed 'JPATH_COMPONENT_ADMINISTRATOR'

I guess its something to do with their code maybe, but was wondering if maybe I did something wrong on my side too.

Side question: what is the purpose of the version number? (in both "package" declaration and "require"). How can I tell to grab the last available? I saw that even specifing the ver number it will anyway get the last version, so another question could be how can I tell him to get a specific version?

Thanks a lot for sharing this!

stevenrombauts commented 9 years ago

Hi @UberGruber, glad to hear you are having fun with our little plugin too!

The JPATH_COMPONENT_ADMINISTRATOR constant does not exist in the command line context. The issue here is that we can't really set it ourselves because it would not make any sense: Joomla sets its value to whatever component it is rendering in the current page (see JComponentHelper::renderComponent()). How it gets invoked in the JCE installer is unclear to me but if you look at its value when you install the package via the Installation Manager, it is set to /path/to/your/site/administrator/components/com_installer (and not to com_jce for example) on install time.

It would be best if you ask the JCE team for help on this one. There is a lot happening in their installation scripts and they will know best what's going on at every step. I would suggest you open up an issue on their widgetfactory/jce repository and reference this one. I'd be happy to follow-up and answer any questions that might come up.

About the version numbers: if we define a package manually as you did in your example, we also need to give it a version. Composer has no idea where to look up the exact version otherwise. When you set a version in the require block, it will look up that specific version in all available packages (= those you defined manually and those published on packagist).

To have Composer always install the latest version of a package, you'll need to keep on defining the new versions as a package block manually. This is of course not ideal. This approach is available so you can create composer-installable packages for extension that you do not maintain yourself.

Ideally, you add a composer.json manifest to your own code and publish that on GitHub, for example. Composer can then automatically find the latest version by looking at the available tags. (in the case of JCE, it would automatically recognise these tags) We've described this process briefly on our developer documentation.

I hope that answers your questions. If there's anything else you'd like to know, give us a shout.

GlassGruber commented 9 years ago

Hey there thanks for your thorough answer! I've placed as suggested a mention on their issue tracker. Hope there is a quick easy fix without refactoring a lot!

For the version number question, that's how I thought it worked, my confusion was due to the fact that no matter what ver is specified in the require and package declaration, I get the last available version, but I think I found the quibble: is this because I give a direct download url to the specified package? Symply put I go to the extension website, copy the available "download" url and use it in my composer.json file.

How can I hadle to install an extension that has no github\packagist repository?

Thanks a lot for your time (even on sunday!)

stevenrombauts commented 9 years ago

Yes, you get the version that the zip file contains. Composer has no idea about the version of the software that sits inside your zip file.

To handle extensions without github/packagist repo's, you keep on doing as you are doing now; by manually writing the package definitions yourself, and pointing to the correct download file. To further automate this you could write some scripts that check the extensions you want for new versions, and automatically generates a new package description when there is a new one available.

To improve this even further, you could setup your own repository using Satis. All you need to do then is add the repository to your composer.json files in your Joomla installations and install from there. Then you just need to update your central Satis package list to include the latest versions when they come out. You then run composer update on your Joomla installations afterwards.

GlassGruber commented 9 years ago

Satis looks very interesting! Let's see now what is going to happen with JCE (if you wish we can close this issue). Thank you for your time!

GlassGruber commented 9 years ago

As suggested the issue was with that constant defined https://github.com/widgetfactory/jce/commit/284699b984eec7eda077306cc7a89c26230b68c4. Now everything is working, thank you for your help!

stevenrombauts commented 9 years ago

Great to hear you got it sorted @UberGruber!

Happy coding :)