Add API function to get module/theme info without rebuilding it.

pwolanin - August 27, 2009 - 19:29
Project:Drupal
Version:7.x-dev
Component:system.module
Category:task
Priority:critical
Assigned:Unassigned
Status:closed
Issue tags:API addition, API change, API clean-up, D7 API clean-up
Description

In D6/D7 it's impossible to ask system module to just give you a nice copy of the data from the {system} table - for example for building a form with a list of module names or descriptions.

This function http://api.drupal.org/api/function/system_get_module_data/7 always rebuilds evertyhing from scratch - which is appropriate for the system_modules page, but not everywhere.

#1

pwolanin - August 27, 2009 - 19:43
Status:active» needs review
AttachmentSizeStatusTest resultOperations
get_info-561452-1.patch1017 bytesIdleFailed: Failed to install HEAD.View details | Re-test

#2

ksenzee - August 27, 2009 - 19:54

I wonder if it makes sense to add a $rebuild parameter, which if it were TRUE would call system_get_[module|theme]_data for you. That would make this a nice clean entry point for either cached or rebuilt data. Either way, it's a bit of a WTF to have no API for running the db query, so this seems like a good addition.

#3

David_Rothstein - August 27, 2009 - 21:24

Yes, this looks like it would be useful - although it's interesting that nowhere in core would actually use it right now :) Although I can immediately think of one followup patch that would make use of it.

I think maybe the PHP docblock could use a little work - it's a little unclear from reading it what "get the .info data" and "module or theme information" actually mean. I kind of want to see a bit more explanation of what it is this function actually returns. But otherwise this seems like it should go in.

A further useful followup, besides what Katherine mentioned, might be to rename the existing system_get_module_data() function to something like system_rebuild_module_data() - and similar for themes...

#4

pwolanin - August 27, 2009 - 22:30

We probably could use it in core - for example on the by-module page. There's no reason we have to build fresh there.

#5

pwolanin - August 28, 2009 - 20:31

updated patch per suggestions above with conversion of the by-modules page to use the new API function.

AttachmentSizeStatusTest resultOperations
get_info-561452-5.patch11.88 KBIdleFailed: Failed to apply patch.View details | Re-test

#6

pwolanin - August 28, 2009 - 20:33

minor whitespace fix.

AttachmentSizeStatusTest resultOperations
get_info-561452-6.patch11.88 KBIdleFailed: Failed to apply patch.View details | Re-test

#7

ksenzee - August 28, 2009 - 21:08

Line 202 of the patch is a docblock line in hook_system_info_alter() that goes past 80 characters (to be fair, it went past 80 chars before, but now it's really sticking its neck out there). Otherwise RTBC.

#8

pwolanin - August 29, 2009 - 01:20
Status:needs review» reviewed & tested by the community

ok, wrapped doxygen

AttachmentSizeStatusTest resultOperations
get_info-561452-8.patch33.7 KBIdleFailed: Failed to apply patch.View details | Re-test

#9

pwolanin - August 29, 2009 - 01:22

oops - ignore that patch - diffed w/out a recent core commit merged in

AttachmentSizeStatusTest resultOperations
get_info-561452-9.patch12.13 KBIdleFailed: Failed to apply patch.View details | Re-test

#10

ksenzee - August 29, 2009 - 06:32

Looks good.

#11

David_Rothstein - August 29, 2009 - 20:04
Status:reviewed & tested by the community» needs review

The latest patch used a static variable, but the API does not automatically reset it - for example, if system_rebuild_module_data() is called, that should reset the static variable in system_get_info().

I actually prefer the original version (without the static). It doesn't seem like this is a function that will get called that often, and even then, usually on pages where micro-optimization is not that important. It's also only one database query, so not that big of a deal.

The attached patch removes the static, and also replaces call_user_func() with $function() syntax, which is usually cleaner. I also added to the code comments for system_get_info() a bit.

Everything else looks fine to me... ready to go in now?

AttachmentSizeStatusTest resultOperations
get_info-561452-11.patch14.4 KBIdleFailed: Failed to apply patch.View details | Re-test

#12

pwolanin - August 29, 2009 - 20:20

Ah, I see what you mean about the static not being reset that way. Without it is fine too.

#13

pwolanin - August 29, 2009 - 20:25
Status:needs review» reviewed & tested by the community

I used call_user_func() since there were no parameters and it made the code more compact. Either that or the variable function name are the same to me.

#14

pwolanin - August 30, 2009 - 13:21

tagging

#15

Dries - August 31, 2009 - 06:08
Status:reviewed & tested by the community» needs work

I think system_get_info() would be cleaner if we dropped the $rebuild parameter. We don't really need it because there is a separate API for it.

#16

David_Rothstein - September 1, 2009 - 04:13
Status:needs work» needs review

Here's a version that is updated to chase HEAD and also remove the $rebuild parameter.

Should be RTBC if the tests pass.

AttachmentSizeStatusTest resultOperations
get_info-561452-16.patch13.66 KBIdleFailed: Failed to apply patch.View details | Re-test

#17

ksenzee - September 1, 2009 - 05:10
Status:needs review» reviewed & tested by the community

Well, the point of the $rebuild parameter was to remove the API inconsistency between system_get_info('module') and system_rebuild_module_data(). Ideally they would both take a parameter, or neither one would. But that is a minor nitpicky detail, and this is RTBC anyway.

#18

System Message - September 29, 2009 - 19:10
Status:reviewed & tested by the community» needs work

The last submitted patch failed testing.

#19

ksenzee - October 1, 2009 - 00:35
Issue tags:+API clean-up

No time for a reroll atm, but tagging.

#20

sun - October 1, 2009 - 18:40

Very nice patch! This might kill some performance issues in the queue.

+++ modules/system/system.module 1 Sep 2009 04:10:26 -0000
@@ -1852,12 +1852,35 @@ function system_update_files_database(&$
+ * @see system_rebuild_module_data()
+ * @see system_rebuild_theme_data()
+ */
+function system_get_info($type) {

Why not

system_get_info($type)
and
system_rebuild_info($type)

?

This review is powered by Dreditor.

#21

catch - October 2, 2009 - 02:13

Sun just pointed me here from #591734: Reduce system table queries in the critical path. Due to the lack of an API function, we currently query the system table 3-4 times per request to get very similar information. I'm not sure this patch would do what that one needs in terms of the array structure (see comments over there), since it's trying to solve a different problem, but subscribing here anyway.

#22

sun - October 9, 2009 - 13:02
Category:feature request» task
Priority:normal» critical
Issue tags:+D7 API clean-up

Tagging absolutely critical clean-ups for D7. Do not touch this tag. Please either help with this or one of the other patches having this tag.

#23

sun - October 13, 2009 - 04:32
Status:needs work» reviewed & tested by the community

I now understand why the proposal I gave doesn't make sense - because those two rebuilding functions are totally different.

So back to RTBC.

AttachmentSizeStatusTest resultOperations
drupal.module-theme-rebuild.patch14.8 KBIdleFailed: Failed to apply patch.View details | Re-test

#24

webchick - October 13, 2009 - 05:26
Status:reviewed & tested by the community» needs work
Issue tags:+Needs Documentation

Seems sensible. Committed to HEAD.

Needs documenting in the upgrade guide.

#25

sun - October 13, 2009 - 05:32
Issue tags:-D7 API clean-up

.

#26

alexanderpas - October 18, 2009 - 00:55
Issue tags:+D7 API clean-up

Seems like i'm unable to get information about the dependencies trough this new function.

#27

andypost - October 20, 2009 - 04:57

@alexanderpas try my.php

<?php

define
('DRUPAL_ROOT', getcwd());

require_once
DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

$info = system_get_info('module');
var_export($info['dashboard']);
?>

array ( 'name' => 'Dashboard', 'description' => 'A module that provides a dashboard interface for organizing and tracking various information within your site.', 'core' => '7.x', 'package' => 'Core', 'version' => '7.0-dev', 'files' => array ( 0 => 'dashboard.module', ), 'dependencies' => array ( 0 => 'block', ), 'dependents' => array ( ), 'php' => '5.2.0', 'bootstrap' => 0, )

#28

alexanderpas - October 20, 2009 - 15:09

yes, that way it worked, however, the other way, it didn't work.

<?php
define
('DRUPAL_ROOT', getcwd());

require_once
DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

$info = system_get_info('module');
var_export($info['dashboard']);
var_export($info['block']);
?>

array ( 'name' => 'Dashboard', 'description' => 'A module that provides a dashboard interface for organizing and tracking various information within your site.', 'core' => '7.x', 'package' => 'Core', 'version' => '7.0-dev', 'files' => array ( 0 => 'dashboard.module', ), 'dependencies' => array ( 0 => 'block', ), 'dependents' => array ( ), 'php' => '5.2.0', 'bootstrap' => 0, )

array ( 'name' => 'Block', 'description' => 'Controls the visual building blocks a page is constructed with. Blocks are boxes of content rendered into an area, or region, of a web page.', 'package' => 'Core', 'version' => '7.0-dev', 'core' => '7.x', 'files' => array ( 0 => 'block.module', 1 => 'block.admin.inc', 2 => 'block.install', 3 => 'block.test', ), 'dependencies' => array ( ), 'dependents' => array ( ), 'php' => '5.2.0', 'bootstrap' => 0, )

block doesn't show dashboard depends on it.

#29

andypost - October 20, 2009 - 16:35

Hm, I found no info in DB, suppose this information is not stored in DB but could be a nice feature.

This needs one _for loop_ before saving or after reading DB because stored info possibly could be different from real state

#30

David_Rothstein - October 26, 2009 - 04:34
Status:needs work» needs review
Issue tags:-Needs Documentation

Following up on this, I've updated the existing documentation at http://drupal.org/update/modules/6/7#system_rebuild_module_data (since these functions were already renamed once before during the D7 cycle).

Also, here's a followup patch that gets one stray reference to _system_get_theme_data() that I found in the codebase, and also converts another case (on the permission page) where we were previously scanning the filesystem unnecessarily but now can use the new API function instead -- that one had been annoying me for a while :)

Regarding #26-#29, that sounds like a separate issue -- the function introduced here just takes whatever it finds in the database, so if the dependency information isn't correctly making it into the database, sounds like you should file that as a separate bug report?

AttachmentSizeStatusTest resultOperations
system-get-info-followup-561452-30.patch1.66 KBIdlePassed: 14482 passes, 0 fails, 0 exceptionsView details | Re-test

#31

andypost - October 26, 2009 - 23:38
Status:needs review» reviewed & tested by the community

Tested, suppose it brings a little performance to permissions page

#32

webchick - October 27, 2009 - 04:08
Status:reviewed & tested by the community» fixed

Committed to HEAD! Thanks!

#33

sun - October 27, 2009 - 16:57

+++ modules/system/system.module 13 Oct 2009 04:26:37 -0000
@@ -1847,12 +1847,35 @@ function system_update_files_database(&$
+function system_get_info($type) {
+  $info = array();
+  $result = db_query('SELECT name, info FROM {system} WHERE type = :type AND status = 1', array(':type' => $type));

What bugs me a bit is that I still need to invoke the rebuilding functions in case I want to do something with all available modules/themes (not only enabled). I have several use-cases for that and at least two contrib modules (of mine) that would highly appreciate a way (perhaps via an optional second argument $include_disabled = FALSE?) to retrieve that info without rebuilding it from scratch.

I'm on crack. Are you, too?

#34

System Message - November 10, 2009 - 17:00
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.