0

I am currenty working on a custom installation profile that enables modules, performs some db queries and so forth.

It also sets my default theme and admin_theme...

Nothing too special ;-)

I have 2 db_update queries as well, located in my .install file.

The first one works perfectly

// Enable the admin theme.
db_update('system')
->fields(array('status' => 1))
->condition('type', 'theme')
->condition('name', 'rubik')
->execute();

The second one gets 'ignored'

// Locate menus is right regions
db_update('block')
->fields(array('status' => 1, 'region' => 'sidebar_first'))
->condition('delta','menu-left-menu')
->condition('theme', 'mytheme')
->execute();

I have tried the last query with devel/php and then everything works perfectly.

What am i missing?

When i put the query in a .module file it works as well...

Thanks for any advice!

2
  • Have you checked the db to make sure the record you're updating actually exists at that point? It might not yet depending on what hook in your install profile the code is in
    – Clive
    Commented Aug 29, 2014 at 20:04
  • Dear Clive, That seems the only logical explanation. i was performing it in a hook_install() of my install profile.
    – Guardian
    Commented Aug 30, 2014 at 15:10

2 Answers 2

0

db_update it is a selectable object. It builds SQL queries. https://api.drupal.org/api/drupal/includes!database!database.inc/function/db_update/7

Yes. Everything is in database. You can changes by queries. You should use api functions or common approaches.

Theme data is stored as variables, for Drupal it is enough.

variable_set('theme', 'my_theme');
variable_set('admin_theme', 'theme_name');

https://api.drupal.org/api/drupal/includes!bootstrap.inc/function/variable_set/7 It says that if you want change it by queries you need update the variable table.

Also when you manipulate with cache-able objects(blocks here) you need clean cache.

cache_clear_all();
4
  • Dear viktor, thanks for your reply. I am aware of the variable get and set functions. But, if im not wrong, i cannot use this to set a menu in a certain region in code? It also keeps me wondering why the first db_update query works and the second does not...thanks again!
    – Guardian
    Commented Aug 29, 2014 at 19:31
  • Run the second query look how many rows are affected. I guess that conditions are wrong. Commented Aug 29, 2014 at 19:34
  • Dear viktor, the query works fine when i run itin devel/php or in a another module. Just not in the install profile. Thanks again!
    – Guardian
    Commented Aug 29, 2014 at 19:40
  • It seems you need to set right dependencies. You need to look an order of your hook that is invoked. Commented Aug 30, 2014 at 8:01
0

I fixed this issue by:

Changing my db_update() query to a db_insert query and move it in an install task in the .profile file.

This way i am sure that the query is ran at the latest possible moment.

Thanks all for your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.