I would like to know whether anyone has successfully included CCK using an installation profile, and if so, how to set it up so that CCK and its sub-modules can be installed and enabled in the installation process. The installation profile I am testing is set up to download the source code from drupal.org (which works) and then uses the _profile_modules (as prescribed) to enable those modules.

CCK raises problems with the installation. Specifically, the included submods (e.g. optionwidgets, text, etc.) fail if they are included in the array of modules to enable on install. Line 6 in each submod's install file is:

include_once('./'. drupal_get_path('module', 'content') .'/content.module');

In the installation routine, drupal_get_path returns nothing, resulting in the incorrect path of ".//content.module" in each submod's install file. I have tried using '../../content.module', but this didn't work.

While one can set these up after the fact, it would be nice to be able to set them up in the installation itself.

Any ideas?

David

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

Title: CCK 6.x Installation » CCK 6.x Cannot Be Used in Install Profiles
Category: support » bug
Status: Active » Needs review
FileSize
10.19 KB

I ran into this also. When install.inc calls the drupal_check_profile() function, it loads all the needed .install files. Unfortunately the database's system table doesn't exist yet, so any calls to drupal_get_path() throw a PHP error and the installation fails.

It looks like the Date module package is already familiar with this problem, and has solved it by creating a date_load() function to be called from the install profile that loads the necessary includes.

This patch mimics that approach for use in CCK, applies to DRUPAL-6--2 branch.

quicksketch’s picture

FileSize
5.98 KB

Well I was mimicking the Date package, but looks like KarenS is too fast for me :)

This patch mimics the approach used by the latest version of the Date package, where dependent modules are simply manually enabled when they're needed. So now all CCK dependent module simply call module_enable('content') in their install hooks.

sunfish62’s picture

Title: CCK 6.x Cannot Be Used in Install Profiles » CCK 6.x Cannot Be Set Up in Install Profiles

I'll apply this and see whether it works for me. Thanks for the help.

sunfish62’s picture

Um. Nevermind. I'll change this when I can test...

yched’s picture

I'm not sure I understand the patch.
The intent of the incriminated include_once() line is to ensure content.module file is loaded even when updates are being run on diabled cck / field modules.

The patch replaces it with simply enabling content.module when a field module gets enabled, which :
- doesn't cover the case above
- shouldn't be needed according to module dependency ?

quicksketch’s picture

FileSize
4.94 KB

The problem is that in install profiles, the "system" database table isn't available. Calls to "drupal_get_path()" ultimately query the system table, and since it's not around, a mySQL error is thrown and the installation fails.

The original issue this all stems from is #209041: optionwidgets.install calls content_notify, where the include_once was originally added.

To reproduce, add "content" and "text" modules to the default.profile and try to install Drupal. To get extra fun, put them in the wrong order, with "text" before "content".

As for this being the correct solution... I don't think it is either. It's what date.module was doing so I assumed it would work fine. Instead, I'd recommend we use drupal_load() every time we need the module file, as including module files is it's entire purpose (like module_load_include() for include files).

This patch makes it so that CCK can be installed though install profiles, and with the modules in any order. Drupal does not install the modules in dependency order when using an install profile. Alternatively, we can cut out all the includes entirely if we decide that install profiles should just put modules in the right order.

quicksketch’s picture

It looks like in Drupal 6, all enabled modules are always loaded while running update.php (this should address the issue yched raised in #5). To test the content_* functions, I added a pseudo update the text.install just to check function availability. Remove the include_once() at the top of the text.install file, then add this update:

function text_update_6002() {
  $ret = array();
  if (function_exists('content_database_info')) {
    $ret[] = array('success' => TRUE, 'query' => 'content_database_info exists');
  }
  if (function_exists('content_notify')) {
    $ret[] = array('success' => TRUE, 'query' => 'content_notify exists');
  }
  return $ret;
}

Run update 6002, and the functions should exist.

KarenS’s picture

There is another complication -- in D6 all modules that are in the folder get their updates run EVEN IF THEY'RE NOT ENABLED. And for extra fun, they get updated in a random order that ignores weights and dependencies.

Then on top of that if you have a module that is dependent on another module and the other module is not enabled (Like when you change dependencies in the code, which I did in the Date module) you end up with the dependent module disabled even if the module that depends on it is enabled, breaking all kinds of things. There are a couple core issues about these problems, but nothing done with it yet.

I don't know that my solution was the right one, it was basically a desperation move after trying other things that all broke in one setup or another.

yched’s picture

As a re: to quicksketch's #6, I think I'm all for 'install profiles should just put modules in the right order'.

I'm not sure where this puts us wrt the 'ensure content.module is loaded when running updates for text.module even when both are disabled' issue. It looks like this still requires some explicit loading, right ?

KarenS’s picture

The problem with #6 that install profiles should put modules in right order is that the update will *not* put them in the right order, so we still can't make assumptions about that. But profiles are part of install, not update, right? And I think core now *does* put modules in the right order for installs, just not for updates.

I must be missing something, but I don't understand how #7 will do anything :/

I agree we don't need to enable the modules, just include them (enabling was to fix a different problem in the date module). I think we're good if we either explicitly include any necessary files in every function or create a text_load() function that includes everything and invoke it from every function. Either one will get the includes out of the global space, which is the main problem.

sunfish62’s picture

I think my original need is being lost. The point is that I want to install *and enable* CCK sub-modules on an installation profile, but cannot. I am not concerned with updates or disabled features. So the discussion about performance with update.php is unrelated here, as is any discussion about disabled sub-modules.

As I understand from this discussion, the main installation routine installs modules in a random order. However, the base routine is able to determine either that a dependency is not present, or will not be present after the installation is complete, since it can throw an error if a dependency is not being met. This functionality is not carryied through to CCK's sub-modules, however. CCK's sub-modules should be installable under the same circumstances as main modules. This is not the case for some reason.

On a slight tangent, is there something in CCK's content module that optionwidget actually, functionally NEEDS on installation? If there is not, then why can't optionwidget.install check the modules array and, if 'content' is there (that is, scheduled to be installed) install optionwidget knowing that content will be there once the process is complete? I assume that this is how the main installation routine functions.

WRT #6 and #9, the two of you are suggesting that profile builders should be required to put the install modules in a specific order. I am STRONGLY NOT in agreement with that idea. I think putting the onus on profile builders to manage the module dependency tree is pretty shortsighted and not very realistic. The existence of package managers in other environments (like Linux) supports my position.

As a person who's trying to build a simple installation profile for my own edification, I think that the easiest way for me to keep track of the modules that I want to install is to list them in alphabetical order. Even with that, it is confusing, since the profiles I have seen all separate core required modules from core extra modules from additional content modules, resulting in three different lists that you have to keep track of.

From my perspective, it should be possible for non-developers--for example, people who want to offer a Drupal-based CMS solution in a package--to create installation profiles that work without the profile creator knowing or learning about this. To me, the ideal installation process would allow me to list the modules I want, after which the routine would:

a) obtain the latest source code for those modules from a reliable location,
b) obtain the latest source code for any dependencies for those modules,
c) place all the code in the appropriate location based on my selection, and
d) activate those modules appropriately--including deciding the necessary order.

We're a ways from that right now.

David

quicksketch’s picture

sunfish62, you're request is beyond the abilities of the CCK team. It'll require changes to Drupal core to effectively make it so that you can specify modules in any order in install profiles. The solution posted in#6 just makes it so that you can 1) install CCK at all and 2) install the included sub-modules in any order.

KarenS: Core does not put modules in the right order when using an install profile (though it does when you enable several modules at once after installation). In an install profile, core uses the order that the modules are specified by the profile. I'm all for not using my temporary fix that makes it so CCK can be installed in any order, because it doesn't solve the larger problem that core should really handle for us.

sunfish62’s picture

Quicksketch--
I went on a bit of a rant there. Sorry. It just felt like the original problem was getting lost, and I vented some of my frustrations. I will try to take the bigger issues over to Groups (where I know you're involved with installation stuff).

I will try what you offered in #6. My next question is this: if I applied a patch from earlier in the message queue, do I apply the later patch against the original source, or can I apply it on top of the earlier one?

Thanks,
David

dopry’s picture

Status: Needs review » Closed (fixed)

sunfish... just do everthing manually if you gotta... figure out what functions you need to run from the .install files... it will a least get the job done if core isn't prepared to do the job properly yet.

sunfish62’s picture

Dopry--

I appreciate that you're trying to help. My goal with an installation profile is to avoid doing everything manually. I am not much of a programmer, and my hope is that the installation routines can get smooth enough so that the Not Much Of A Programmer types can create a Drupal installation with the features they want, and, um, install it.

Moreover, it seems to me that since the trend in Drupaldom is towards everything going into CCK and Views (which is what I seem to see on many of the different threads in contributed modules I browse), that it would be really essential that CCK be installable via Drupal's own installation routine.

David

sunfish62’s picture

Status: Closed (fixed) » Needs review

Since the patch hasn't been reviewed, setting that back...

quicksketch’s picture

Let's recap on the problem here:

- Drupal core checks the requirements of modules before allowing installation in a profile.
- Because hook_requirements() lives in the .install file, Drupal loads that file.
- Any use of the database (such as using the drupal_get_path() function) immediately when loading the file will cause installation to fail, because the database has no tables in it.

I doubt that we'll be able to correct this in Drupal 6 (anyone looked at the RTBC list recently?) so I think our only option is to do all module includes in every function when needed.

hass’s picture

Subscribe

yched’s picture

Bumping to critical, RC5 blocker.

yched’s picture

quicksketch : thx for the recap, this is welcome.
Couldn''t we simply get away with calling drupal_load('module', 'content'); at the top-level of all our .install files ?

quicksketch’s picture

Unfortunately drupal_load() follows the same path as drupal_get_path().

drupal_load() => drupal_get_filename() => db_query("SELECT filename FROM {system} WHERE name = '%s' AND type = '%s'", $name, $type))

There is a check for db_is_active() before doing the query... but it looks like the db is active, there just aren't any tables in it yet :P Maybe we could correct this in core simply by setting the $active_db to FALSE when doing the check? I'm not sure if that'd be considered a hack.

yched’s picture

Hm, too bad. I just stopped at the db_active() check and thought it would be ok.
OK, so here's the candidate patch. Removes all top-level includes, and calls drupal_load('module', 'content') in any function (including updates) that makes use of content's API.

I tested it to work OK for a D5 -> D6 upgrade with all cck modules disabled.
Can we have a final test that it works OK for an install profile that sets up CCK ?

yched’s picture

sunfish62’s picture

I will try to test the patch on a fresh install tonight or tomorrow and report back.

arhak’s picture

subscribing

arhak’s picture

questions:
1- Isn't the installation profile taking dependencies into account to know which modules to install first? (I thought it did)
2- What would be the consequences of an install profile which remove the line 6 of all sub-modules of CCK?
3- Can't be treated separately the install profile and the update cases?

Aren Cambre’s picture

Priority: Normal » Critical

yched said this is critical in #19.

sunfish62’s picture

Sorry to be dim. I was having trouble because I wasn't patching the dev copy. I will try to test this out now.

David

yched’s picture

sunfish62: Patches always apply to the latest -dev code.

brmassa’s picture

Status: Needs review » Reviewed & tested by the community

Guys,

patch is working. (against CVS).

However, the CVS version still complain about " Fatal error: Class 'views_handler_filter_float' not found in ...cck/includes/content.views.inc on line 187". Since its not related to this bug, marking it as tested.

regards,

massa

yched’s picture

brmassa : 'Patch is working' is not very explicit.
Can you confirm that you could install CCK as part of an install profile ?

+ The error you see is because you need Views 6.x-2.x-dev, not RC1

brmassa’s picture

Yves,

sorry. i meant it installed correctly using a profile.

i got the error, but all tables from all cck modules were created as expected (i saw them on phpmyadmin). The error means that the install phase was complete, coz was called by normal Views operation.

regards,

massa

brmassa’s picture

Yves,

i did again the install (with views), successfully.

regards,

massa

sunfish62’s picture

@yched #31: You mention needing views 6.x-2.x-dev, but looking at drupal.org/project/views I don't see such an animal. I am getting the same error as seen in #30. It's hard for me to tell that the CCK problem is fixed, since I still can't complete an installation. brmassa has had success, but I'd still like to, as well...

yched’s picture

sunfish62 : You need to follow 'view all releases' on views project page. Then, it's at the bottom of the page. Not the most obvious place, I agree.
Direct link is http://drupal.org/node/95897

I'll commit this ASAP, thx brmassa, and thx quicksketch for insisting.

john.karahalis’s picture

I am working on an Installation Profile and have been having the same problem. After applying the patch, I am able to enable and use CCK with the installation profile.

Will these modifications make it into the final release of CCK 2, or will people using installation profiles need to apply this patch manually?

sunfish62’s picture

With an updated Views, it goes through fine. Thanks for getting this to work! I think this will be important for the future.

David

yched’s picture

Committed. Thks all !

yched’s picture

Status: Reviewed & tested by the community » Fixed
yched’s picture

Feedback welcome from 'install profile'-savvy people in #295914: CCK in install profile - undefined function content_instance_tablename()

quicksketch’s picture

Thanks yched! You're everyone's hero!

Anonymous’s picture

Status: Fixed » Closed (fixed)

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