Magento2: Added theme is not registered during production mode

Created on 23 Dec 2015  路  38Comments  路  Source: magento/magento2

It seems that added / installed themes are not registered if they are added to a site which is already installed and is set to production mode. By registered I mean that they are not added to the theme table.

After looking at the code it seems that themes are registered differently depending on mode.

In developer mode:

In production mode:

This means that if you have a running site in production mode and you decide to install a new theme it will not be registered in the theme table which means that it will not be selectable in the admin.

Steps to reproduce:

  1. Install Magento2, run the installation wizard
  2. Set deploy mode to production, php bin/magento deploy:mode:set production
  3. Add a theme with: composer require
  4. Run php bin/magento setup:upgrade

    Expected result:

The installed theme should be registered in the theme table.

Actual result:

The installed theme is not registered in the theme table.

Ready for Work

Most helpful comment

Not fixed in 2.0.5 either.

THE PROBLEM

=== frontend -> Magento/luma -> nb_NO ===
.................................................................................................................................................................................................................
Successful: 2038 files; errors: 0
---

=== frontend -> MyVendor/Base -> nb_NO ===
Unable to load theme by specified key: 'MyVendor/Base'>

NOW LETS SEE:

mysql> select * from theme;
+----------+-----------+-----------------+-------------------+----------------------------------+-------------+-----------+------+-----------------+
| theme_id | parent_id | theme_path      | theme_title       | preview_image                    | is_featured | area      | type | code            |
+----------+-----------+-----------------+-------------------+----------------------------------+-------------+-----------+------+-----------------+
|        1 |      NULL | Magento/blank   | Magento Blank     | preview_image_5710e776daadc.jpeg |           0 | frontend  |    0 | Magento/blank   |
|        2 |         1 | Magento/luma    | Magento Luma      | preview_image_5710e776ee428.jpeg |           0 | frontend  |    0 | Magento/luma    |
|        3 |      NULL | Magento/backend | Magento 2 backend | NULL                             |           0 | adminhtml |    0 | Magento/backend |
+----------+-----------+-----------------+-------------------+----------------------------------+-------------+-----------+------+-----------------+

3 rows in set (0,06 sec)

TEMPORARY SOLUTION:

mysql> insert into theme (parent_id,theme_path,theme_title,preview_image,is_featured,area,type,code) \
       VALUES ('1','MyVendor/Base','MyVendor Base', NULL, 0, 'frontend', 0, 'MyVendor/Base');

All 38 comments

Hi @moleman. Thank you for your inquiry but it is not a bug. Such actions like updating code, adding themes etc aren't supposed to be performed on production since they may lead to unpredictable and unstable site work. Usually such changes should be done not in production mode on some staging server and lately published on production.

@slavvka Yes, and that is what we do. We have a build server that builds the sites cleanly with Composer and this is where the new code is introduced. These build artifacts are then deployed to staging and production servers and we then run setup:upgrade to upgrade the database in production after the deployment of the code is done.

So, whats the correct workflow then when you want to add a new theme to a production site so that the theme gets registered in the theme database table? Because currently if we add a new theme it never gets registered because of the issue above.

@slavvka This may not sound like a bug at first read, but the OP isn't talking about developing on a production site, but rather a deployment procedure. There are CLI commands to enable/disable modules, and to "uninstall" a theme, but none to install/activate/register a theme. Builds must be pushed to production in some fashion, and then setup:upgrade run to execute install scripts, and new components moving to production as part of a build need to be registered somehow, whether that is automatic when setup:upgrade is done (as would be expected) or at minimum via a CLI command to register them with the system so it knows about them.

If there is an existing mechanism in the system to roll non-module components out to production and register them without re-installing the software from scratch, it would be great if you could make note of what that is. If there isn't a way to do this, then it is a bug and needs to be solved.

I have the same experience. Similarly we are not attempting to install a theme directly to production, rather we are installing/creating a theme in dev. then much like @moleman, we use composer to generate a fresh code instance on a clean server before deploying the updated code to the production environment. The successful deployment then triggers 'setup:upgrade' to be run on the production servers in order to run the module updates and schema upgrades. _(I see no other sensible way of performing data-install and updates on the production DB...)_

None of this process adds a new theme record to the 'theme' table so not sure how this is supposed to be achieved.... set the site to developer mode to allow the theme to register... surely not!

I too am interested in what approach is therefore recommended be to update the theme records (and other schema / record changes) in a production environment if this is by "design".

Surely this is a bug that needs fixing.....

Thank you all for your input, we have created MAGETWO-47999 to fix it.

@moleman thank you for reporting. We have merged a fix in the develop branch, hence closing this ticket. Please create a new ticket if issues still arise.

@mazhalai Could you comment on what the ultimate fix was/is? I'm not seeing commits tagged with this GH issue id, and it's unclear from the thread if this was being fixed by having setup:upgrade add the theme or via some other means.

Based on commit 0132caf431 it looks like they should now be auto-registered when setup:upgrade is run. Thanks @mazhalai!

@mazhalai

How do I know that the patch will be available for production if I install magento2 by below command:
composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition magento2

thank you.

@mazhalai @slavvka @davidalger @alankent
Could you provide some "estimated release version" info marking issue as resolved by your internal ticket ID, to let us know when it should be released?

I spend a lot of time trying to figure out if that fix was released or not and still have no idea...
Official release notes also don't contains any info about resolved github/internal issues, so how we can know what was fixed?

@Igloczek the fix is in the develop branch, but it hasn't been added to a release yet.

The way to tell if a fix is in a release version:

Don't you think this is a ridiculous "solution" for tracking issues status?

@Igloczek sorry we cannot share access to our internal tracking.

How about Github milestones and referencing Github issues in commit messages?

@mazhalai can you at least shed some light on when the patch might make it into an official release? according to this ticket this bug was fixed mid january - since then 4 release versions happened...

@Igloczek yes I apologize for the Github issue in the commit message, but we do not track Github milestones in tickets.

@heldchen It was fixed in mid Feb and contributed in Mar, not Jan. @elenleonova any comment on next patch release date?

Finally found this issue! So basically right now custom themes does not register. I did not understand why my theme did not appear, but this explains everything.

hi, @mazhalai
Is the bug fixed in 2.0.4 version?
I had upgrade my magent2 to 2.0.4 but I still can't register my customized theme.
Any suggestion to verify step by step?
thank you.

@woei66 No this is not added in 2.0.X yet ( It's just in develop branch ) and not 2.0:

2.X branch: https://github.com/magento/magento2/blame/2.0/app/code/Magento/Theme/Model/Theme/Registration.php

vs

Develop: https://github.com/magento/magento2/blame/develop/app/code/Magento/Theme/Model/Theme/Registration.php

Search for MAGETWO-47999

on both of those links, you see that the fix is only in develop branch!

This fix is urgent. Please add to 2.0.5!

@benmarks @maksek
That's what I'm talking about on Developers Paradise - we have closed issue, resolved by some of your internal ticket (without referencing github issue in commit msg) and merged into develop - AFAIK it should be available in next release.
But... two months and two releases later - still not available, no one knows when it should be added to stable version 馃槬

What's the proper/recommended fix until this goes into a prod. release? Switch production to developer mode, run upgrade, and switch back?

EDIT: my dev env is in "developer" mode and the theme files are all present. Running upgrade doesn't register the theme either.

I fix it on production using SQL query to manually add record to theme table.

Thanks @Igloczek - the direct SQL insert seems like the quick option.

Not fixed in 2.0.5 either.

THE PROBLEM

=== frontend -> Magento/luma -> nb_NO ===
.................................................................................................................................................................................................................
Successful: 2038 files; errors: 0
---

=== frontend -> MyVendor/Base -> nb_NO ===
Unable to load theme by specified key: 'MyVendor/Base'>

NOW LETS SEE:

mysql> select * from theme;
+----------+-----------+-----------------+-------------------+----------------------------------+-------------+-----------+------+-----------------+
| theme_id | parent_id | theme_path      | theme_title       | preview_image                    | is_featured | area      | type | code            |
+----------+-----------+-----------------+-------------------+----------------------------------+-------------+-----------+------+-----------------+
|        1 |      NULL | Magento/blank   | Magento Blank     | preview_image_5710e776daadc.jpeg |           0 | frontend  |    0 | Magento/blank   |
|        2 |         1 | Magento/luma    | Magento Luma      | preview_image_5710e776ee428.jpeg |           0 | frontend  |    0 | Magento/luma    |
|        3 |      NULL | Magento/backend | Magento 2 backend | NULL                             |           0 | adminhtml |    0 | Magento/backend |
+----------+-----------+-----------------+-------------------+----------------------------------+-------------+-----------+------+-----------------+

3 rows in set (0,06 sec)

TEMPORARY SOLUTION:

mysql> insert into theme (parent_id,theme_path,theme_title,preview_image,is_featured,area,type,code) \
       VALUES ('1','MyVendor/Base','MyVendor Base', NULL, 0, 'frontend', 0, 'MyVendor/Base');

@peec all fixes from github are targeting 2.1 release, you won't see them in patch releases yet. For this particular i got confirmation - will be targeting 2.0.7

I'm using Magento 2.0.7 at this moment, and seem it still not be patched yet.

Can someone update the documentation and explain what are virtual and staging theme types and when to use them? Can't find anything about it. Thanks!

@maksek @mazhalai this fix was reverted in https://github.com/magento/magento2/commit/c4e5f323a8a7c6d0060b5603f4e571fe3a3eb76e and this issue still exists.

Could you re-open it and fix?

@maksek @mazhalai I'm still seeing this issue on 2.1.2 as well. Is there a new ticket open that covers this issue?

@erikhansen agreed. Just ran into this and followed @peec mysql code to resolve it.

Anyway around this in production mode, using 2.1.0? I tried adding it directly in the theme table and appears to be successful, however then get an error saving products 'Required Parameter theme_dir was not passed'. If I remove the theme I entered manually in the table the error goes away when saving products. @gil-- have you tested saving products after adding the row manually?

@jpratt are you 100% sure that theme_dir was correct?
Solution with manual adding them via SQL query is 100% correct and works well for us and as you can see by votes, many other ppl.

@Igloczek running setup:upgrade doesn't detect and add the new design into the theme table as well?

When I tried it, I only notices is adding 1 instead of 0 in TYPE column.

I'm having this problem in v2.2.3 as well. This is causes problems when testing new themes in integration/staging websites, which are usually set to production mode to mimic the live site as closely as possible.

My workaround for that is to switch to developer mode, load the admin (so the row in the theme table gets created), and then switch back to production mode. This is in case someone would like to avoid manual updates to the DB.

The fix should really be formally included in releases before closing the Github issue. No integrator would use the develop branch when working with actual websites.

This bug is still present in 2.2.5.
@magento-engcom-team maybe this issue should be reopened

This bug is still present, I add a custom adminhtml theme,but not working in developer mode

@penglongyun admin themes work differently, your problem it's probably not related to this issue.
Check the docs for details:

Was this page helpful?
0 / 5 - 0 ratings