|
I had Gallery2 installed on my website. I don't remember what was the original version I installed, but after an upgrade to 2.2.1 version of Gallery2 I got an error saying that the default theme, matrix, was inactive or not installed. My Gallery2 instance at that point was unusable, because any page I attempted to go to was throwing this error. This article describes how I fixed it.
When I originally posted this article, I said my fix was partial: Gallery2 still didn't work correctly. When I tried to add new images to it, I got a database error. But I figured out what I did wrong, and restored Gallery2 to its full functionality. I am now able to add images and perform all the other actions one might want to do with Gallery2. Here is just the updated part that describes the solution to that last problem.
Here is the full text of the error I got after the upgrade:
Configuration Error: Missing Theme
This album is configured to use the matrix theme, but it is either inactive or not installed. To fix this problem you can install or activate this theme or select another default theme.
Except in reality I could neither "install or activate this theme" nor "select another default theme". Those links don't take you anywhere useful. One of them, in fact, takes you back to the Gallery2 upgrader, where you can engage in the useless exercise of redoing the upgrade, only to end up in the same place, with a missing theme. I couldn't do anything else with my Gallery2 instance after this. It was useless. I could not revert to the old version either, even though I had saved it. The old version was throwing different kinds of errors.
Needless to say, I felt bad about it, given that I had literally thousands of pictures in my Gallery2 instance, along with elaborate captions. Recreating my album hierarchy by hand, re-uploading pictures and copy-pasting their captions would have taken many days.
My rant against both Gallery2 maintainers and my web hosting company (which played a part in this misfortune) could be found here.
So I tried to find ways to fix this error:
1. I sought Google's advice (unsuccessfully);
2. I found my own way to fix it.
The reader should feel free to skip directly to (2), since (1) is just my tale of woe. :-) To cut to the chase, my fix consisted of just 3 actions:
- Finding out the problem was in the old database;
- Installing a fresh Gallery2 in a new subdomain;
- Importing some tables from the old database to the new.
One of the first results that comes up when you search for the missing theme error message, or various permutations of its terms, is this: http://gallery.menalto.com/node/44309. This page directs me to another page:
I get a warning for missing themes / modules in the upgrader, what should I do?
It says:
Probably you chose the wrong package for your upgrade. Only the full package has all official themes and modules. Another reason could be that you were using non-official / 3rd party modules / themes and you forgot to keep them in your modules/ or themes/ folder.
* If the themes / modules that are missing are official ones, you can download them from the Download Page.
* For 3rd party / non-official themes, please check the User Contributions page for the latest version of your modules / themes
If you can't get the latest version of a specific module / theme and nothing helps, the following SQL query can help you to get at least through the upgrade wizard:
delete from g2_PluginMap WHERE g_pluginId = 'PGtheme';
However, I don't have a row with g_pluginId = 'PGtheme' unless PGtheme was supposed to be the name of the missing theme.
It further says:
If a theme that is now unavailable was used as default theme or for one of your albums specifically, you will also have to update the g2_PluginParameterMap database table to change the default theme, e.g.
UPDATE g2_PluginParameterMap SET g_parameterValue = 'matrix' where g_pluginId = 'core' and g_parameterName = 'default.theme';
But in my database this row in the g2_PluginParameterMap was already set to matrix:
module core 0 default.theme matrix
The text further says:
If after removing incompatible modules you see errors when editing items in your Gallery like this:
in modules/core/classes/helpers/GalleryFactoryHelper_simple.class at line 208 (gallerycoreapi::error)
in modules/core/classes/helpers/GalleryFactoryHelper_medium.class at line 59 (galleryfactoryhelper_simple::newinstance)
in modules/core/classes/GalleryCoreApi.class at line 124 (galleryfactoryhelper_medium::newinstancebyid)
, check the g2_FactoryMap table in the database for references to the removed modules.
I don't have incompatible modules, this does not apply to me.
Reading on:
If this still don't solve your problem, a last resort would be to delete the cache directory located inside your g2data directory (this is where all the photos are stored so don't go and delete the folder album!!! Just the one named cache)!
Removing the cache directory did not solve the problem. So, this and other advice I saw on the net regarding this problem (and there wasn't much good advice) turned out to be useless.
For the time being, until I figured out what to do about this problem, I wanted to at least put Gallery2 into maintenance mode. This is presumably done by adding this line to config.php
$gallery->setConfig('mode.maintenance', true);
Well, I'm not sure how Gallery2 should behave in the maintenance mode, but at least you would think it would print out some simple message informing the user that it's shut down for maintenance, and stop spewing the missing theme error? Not so. Putting Gallery2 into maintenance mode didn't make any difference. I was still getting that message.
Then I made an attempt to debug the code and find out why it thought the matrix theme was missing. I wasn't making much progress. To delve into an unfamiliar source code, to try to understand their creators' thinking, didn't seem like a quick and easy task. So I decided to try something else.
Leaving alone the corrupted instance of Gallery2 for a while, I did a fresh install of Gallery2 into a different subdomain on my web site. Let's call it new.mydomain.com, as opposed to old.mydomain.com, where the corrupted Gallery2 instance lived.
During the installation into new.mydomain.com, at the database setup step I decided to point the installer to the old database, underlying the corrupted Gallery2 instance. The installer gave me this warning:
Gallery tables already exist in this database! But there is no 'versions.dat' file in your G2 storage directory which we interpret as a broken state of G2. Either create a versions.dat file with the correct format if you think your G2 should still work or select a clean install, which will erase all data in the database and in the storage directory.
I copied the versions.dat file from the old g2data directory (the one in old.mydomain.com). I told Gallery2 installer I wanted to use the existing database tables for the new install. However, after I completed the setup process, I got the missing theme error again.
It was time to try something else. I deleted the install at new.mydomain.com and reinstalled Gallery2 from scratch in the same subdomain, using a new, empty database. This time I didn't get the missing theme message. This made me think that the problem was that the old database did not get properly updated during the upgrade.
My suspicions point to the table g2_PluginParameterMap. Several entries in it list the API versions for the matrix theme:
g_pluginType g_pluginId g_itemId g_parameterName g_parameterValue
theme matrix 0 _version 1.0.0
theme matrix 0 _requiredCoreApi 6,5
theme matrix 0 _requiredThemeApi 2,1
Is it possible that during the upgrade a newer version of matrix was installed, but the database still listed the old version, so the code can no longer find the version listed in the database? Or something like that?
I don't know. And I don't know which API versions of which modules are dependent on which API versions of other modules, so I did not attempt to manually change those version numbers in the database to see if this will fix the problem. Instead, here is what I did.
Since I had a working, fresh installation of Gallery2, I decided to
-- copy the g2data/albums directory from the old installation to the new,
-- import some of the tables from the old Gallery2 database into the new one. I mean, of course, I imported only the tables that contain information about the items in my gallery (e.g. image names, summaries, descriptions, sizes), not the information about the Gallery2 itself! The latter kind of tables were precisely what I wanted to keep, as they contained the correct info about API versions, etc. After examining Gallery2 tables it seemed to me that the tables with user-generated data were nicely decoupled from the "system" tables (tables that contain info about Gallery2). So this seemed not an impossible task.
The tables with user-generated data are these:
g2_AccessMap
g2_AccessSubscriberMap
g2_AlbumItem
g2_ChildEntity
g2_DataItem
g2_Derivative
g2_DerivativeImage
g2_DerivativePrefsMap
g2_DescendentCountsMap
g2_Entity
g2_FileSystemEntity
g2_Item
g2_ItemAttributesMap
g2_PhotoItem
Or rather, I should say that those were the tables that were relevant to me. There are a few more tables in Gallery2 that can possibly have user-generated data: g2_AnimationItem, g2_Comment, g2_CustomFieldMap, g2_MovieItem. Probably g2_ExternalIdMap, g2_FailedLoginsMap, g2_Group, g2_PendingUser, g2_RatingMap, g2_RatingCacheMap, g2_UnknownItem, g2_User, g2_UserGroupMap as well? But my Gallery2 instance did not have any users other than admin, no non-default groups, no comments, no ratings, no movie items or animation items, so all these tables were empty. Thus, the tables I wanted to import into the new database were limited to the list above.
Then there is the table g2_SequenceId. This is the table I overlooked at first. Neglecting to import it caused Gallery2 to throw errors when trying to add new images. Those errors said that Gallery2 attempted to create items with duplicate ids. (Each Gallery2 item -- an image or an album -- has a unique id.) I had to find out where item ids were generated, and it turned out to be g2_SequenceId table. This table has only one column, named, appropriately, id. I'm guessing it is an auto-incremented field, whose value is increased by 1 every time a user tries to insert an item into Gallery2. So all I had to do was to look up the value of this field in the old Gallery2 database: it contained the id of the last inserted item. I set the id field to this value in the new database's g2_SequenceId table, and everything worked from then on.
Here is a list of tables I definitely did NOT want to import. I'm not very sure about the role of some of these tables, but I'm pretty sure that most of them either contain information about the Gallery2 itself, or have not changed when I populated my Gallery2 instance with images and data.
g2_CacheMap
g2_ExifPropertiesMap
g2_FactoryMap
g2_Lock
g2_MaintenanceMap
g2_MimeTypeMap
g2_PermissionSetMap
g2_PluginMap
g2_PluginPackageMap
g2_PluginPackageMap
g2_PluginParameterMap
g2_Schema
g2_SessionMap
g2_TkOperatnMap
g2_TkOperatnMimeTypeMap
g2_TkOperatnParameterMap
g2_TkPropertyMap
g2_TkPropertyMimeTypeMap
After importing the tables, the new Gallery2 instance worked, and displayed all of my images! But it was still in the new.mydomain.com subdomain, so all the links out there on the web that pointed to old.mydomain.com would not work. So all I had to do is login into my account at my web hosting provider, and make it so that new.mydomain.com would mirror old.mydomain.com. After that, the URLs starting with old.mydomain.com continue to work, only they (unbeknownst to the user) point to new.mydomain.com. |