Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Admin app - Use the autoloader #10881

Merged
merged 6 commits into from
Jul 18, 2016
Merged

Admin app - Use the autoloader #10881

merged 6 commits into from
Jul 18, 2016

Conversation

mbabker
Copy link
Contributor

@mbabker mbabker commented Jun 20, 2016

Summary of Changes

Load files in the admin app by including the required classes to the autoloader.

Testing Instructions

The admin app should still function correctly.

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<form>
<fields name="filter">
<fields name="filter" addfieldpath="/administrator/components/com_banners/models/fields">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you only use these forms going through JModelForm objects then sure. If
they load any other way the dependency wouldn't be loaded. I equate it to
relying on something else to load jQuery when you depend on it.

On Monday, June 20, 2016, Dimitri Grammatikogianni notifications@github.com
wrote:

In administrator/components/com_banners/models/forms/filter_banners.xml
#10881 (comment):

@@ -1,6 +1,6 @@

- -

@mbabker https://github.com/mbabker isn't this supposed to autoload by
https://github.com/joomla/joomla-cms/blob/staging/libraries/legacy/model/form.php#L203-L206
?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/joomla/joomla-cms/pull/10881/files/5f19de3d1f3851054f65ed03611262be65340315#r67783423,
or mute the thread
https://github.com/notifications/unsubscribe/AAWfoeL9oXQo7eQDLYLivxj4CStNBLhUks5qNx3ngaJpZM4I6I8J
.

@pritalpatel
Copy link

I have tested this item ✅ successfully on b7afe6c

I have tested it using automatic test suits which I have created to test content and user feature. All were successful after applying this patch. Created video for this tests here https://youtu.be/D4TKK4VUIHg

(Regarding testing instructions first I was confused by word "admin app" in testing info. But later I understand that it's mean to Joomla! Administrator tests)

Thanks.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/10881.

@@ -66,8 +66,6 @@ public function display($tpl = null)

$this->addToolbar();

require_once JPATH_COMPONENT . '/models/fields/bannerclient.php';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mbabker
Why JLoader::register() is not used after removing this code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could not find a direct use of the class that this was loading in the code. Meaning either it's being loaded as part of a form (where the lookup path should be included in the XML or added with a JFormHelper::addFieldPath() call) or it was being loaded needlessly.

@alikon
Copy link
Contributor

alikon commented Jul 3, 2016

I have tested this item ✅ successfully on b7afe6c

with this patch applyed for a couple of days the admin side still works as expected


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/10881.

@brianteeman
Copy link
Contributor

rtc


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/10881.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Jul 3, 2016
@@ -12,7 +12,7 @@
use Joomla\Registry\Registry;

jimport('joomla.filesystem.path');
require_once JPATH_COMPONENT . '/helpers/menus.php';
JLoader::register('MenusHelper', JPATH_COMPONENT . '/helpers/menus.php');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mbabker please see #11164

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general that's why the JPATH_COMPONENT path constants should only serve one purpose in Joomla until 4.0 is released; raise deprecation notices. Those are in part why it is so freakin' difficult to work between different components, because that path is not constant by any means.

@joomla-cms-bot
Copy link

This PR has received new commits.

CC: @alikon, @pritalpatel

@infograf768
Copy link
Member

@mbabker
looks like a typo for com_menus
com_media instead of com_menus for the loader

@mbabker
Copy link
Contributor Author

mbabker commented Jul 17, 2016

Fixed. Copy/Paste errors suck.

@@ -57,7 +57,7 @@ public function display($cachable = false, $urlparams = false)
return $view->display();
}

JLoader::register('ModulesHelper', JPATH_COMPONENT . '/helpers/modules.php');
JLoader::register('ModulesHelper', JPATH_ADMINISTRATOR . '/components/com_messages/helpers/modules.php');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

com_modules, not com_messages

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FML

@@ -11,7 +11,7 @@

JFormHelper::loadFieldClass('list');

require_once __DIR__ . '/../../helpers/installer.php';
JLoader::register('InstallerHelper', JPATH_ADMINISTRATOR . '/components/com_installer/helpers/installer.php');
Copy link
Contributor

@ggppdk ggppdk Jul 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is right, but it is now using JPATH_ADMINISTRATOR+component_folder, it could have kept the usage of __ DIR __

JLoader::register('InstallerHelper', dirname(__DIR__, 2)  .  '/helpers/installer.php');

I say this because in other cases you keep the usage of __ DIR __, but in some you do not

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. I personally prefer absolute paths over relative when practical. I
    dislike trying to read paths in include statements with directory traversal
    like that because I think it makes it harder to follow.

  2. The second param on dirname() is only present as of PHP 7.0.

On Monday, July 18, 2016, Georgios Papadakis notifications@github.com
wrote:

In
administrator/components/com_installer/models/fields/extensionstatus.php
#10881 (comment):

@@ -11,7 +11,7 @@

JFormHelper::loadFieldClass('list');

-require_once DIR . '/../../helpers/installer.php';
+JLoader::register('InstallerHelper', JPATH_ADMINISTRATOR . '/components/com_installer/helpers/installer.php');

This is right, but it is now absolute path, it could have remain a
"relative" using the DIR:

JLoader::register('InstallerHelper', dirname(DIR, 2) . '/helpers/installer.php');

I say this because in other cases you keep the usage of DIR, but in
some you do not


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/joomla/joomla-cms/pull/10881/files/ec8218c23101f868671104e3c8505f357337677d#r71102143,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAWfoRDLWy8U5Vzyv4f6C78Q2lDDpyBoks5qWxSvgaJpZM4I6I8J
.

@infograf768
Copy link
Member

@mbabker
I am also curious: why use DIR in some cases and full path in others?
Shall we not use all over the fullpath?

@mbabker
Copy link
Contributor Author

mbabker commented Jul 18, 2016

The DIR constant is an absolute path, specifically to the directory the
file is located in. IMO it's more readable to use it as able (mostly when
the path being loaded is the same level or under the file referencing it).

On Monday, July 18, 2016, infograf768 notifications@github.com wrote:

@mbabker https://github.com/mbabker
I am also curious: why use DIR in some cases and full path in others?
Shall we not use all over the fullpath?


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#10881 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAWfobpl7lMnlKTAhJnWvAnw8eU3lqbCks5qWzuFgaJpZM4I6I8J
.

@ggppdk
Copy link
Contributor

ggppdk commented Jul 18, 2016

@mbabker

The DIR constant is an absolute path, specifically to the directory the file is located in.

yes about "absolute path" , it is

but the benefit of it is that you don't need to care much about what is exactly this absolute path is,
it helps avoiding the hardcoding of component name
e.g.
/components/com_installer/

  • effectively behaving as relative paths are used

the argument , if same folder or parent folder, then we use it __ DIR __, but if parent - parent folder we don't use , sounds strange to me

@mbabker
Copy link
Contributor Author

mbabker commented Jul 18, 2016

It's a personal preference and AFAIK there is no style rule regarding how paths should be referenced. I'd suggest either absolute paths using __DIR__ or one of the JPATH_ constants referencing an application root, but I personally dislike require __DIR__ . '/../../folder/file.php' structures and avoid using them. As for when I use JPATH_ or __DIR__ it really boils down to where the file in question lies in the filesystem more than anything; I don't see the need to write out the full path if I'm including a file in either the same directory or a subdirectory from the file I'm in.

If we're going to nitpick over this stuff, I'll just close my autoloader PRs. I'm also not a fan of PRs getting held up because people want to try and apply arbitrary standards to them.

@infograf768
Copy link
Member

I have tested this item ✅ successfully on ec8218c


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/10881.

@mbabker
Copy link
Contributor Author

mbabker commented Jul 18, 2016

Also, before I end ranting, a benefit to using absolute paths versus relative is you don't have to change the include reference if you move the file. If I move the file calling require __DIR__ . '/../../folder/file.php' to another directory, I have to update the reference (OK, same goes for anything using __DIR__ honestly; using JPATH_ avoids that completely but IMO it's unnecessary overkill sometimes).

@infograf768
Copy link
Member

anyhow, this works fine here and solves the issue we had with the gsoc project.
@andrepereiradasilva can you test again so that we get this in staging?

@andrepereiradasilva
Copy link
Contributor

I have tested this item ✅ successfully on ec8218c

on code review


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/10881.

@ggppdk
Copy link
Contributor

ggppdk commented Jul 18, 2016

Also, before I end ranting, a benefit to using absolute paths versus relative is you don't have to change the include reference if you move the file. If I move the file calling require DIR . '/../../folder/file.php' to another directory, I have to update the reference (OK, same goes for anything using DIR honestly; using JPATH_ avoids that completely but IMO it's unnecessary overkill sometimes).

@mbabker
Agreed that is why i prefer to use JPATH too

  • easier to copy or move the code
  • easier to read (for me)

I'm also not a fan of PRs getting held up because people want to try and apply arbitrary standards to them.

and i hope that you don't imply that i am preventing a good PR, i was just asking, i had said the paths are good.

@mbabker
Copy link
Contributor Author

mbabker commented Jul 18, 2016

Not trying to imply anything at all, sorry if it comes across that way. Just seen a lot more than I'd like lately folks requesting changes to PRs simply because they're already editing the lines they'd like to see changed.

@wilsonge wilsonge merged commit a0f1f5a into joomla:staging Jul 18, 2016
@wilsonge wilsonge added this to the Joomla 3.6.1 milestone Jul 18, 2016
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Jul 18, 2016
@mbabker mbabker deleted the Use-The-Autoloader branch July 18, 2016 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.